@openagents-org/agent-launcher 0.2.201 → 0.2.203
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/registry.json +15 -6
- package/src/adapters/codex.js +27 -7
- package/src/adapters/deepseek-runtime.js +26 -3
- package/src/adapters/deepseek.js +6 -1
- package/src/adapters/openclaw.js +116 -41
- package/src/cli.js +7 -1
- package/src/daemon.js +82 -14
- package/src/env.js +28 -7
- package/src/probe.js +14 -9
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -246,6 +246,15 @@
|
|
|
246
246
|
null
|
|
247
247
|
]
|
|
248
248
|
},
|
|
249
|
+
"probe": {
|
|
250
|
+
"args": [
|
|
251
|
+
"exec",
|
|
252
|
+
"--skip-git-repo-check",
|
|
253
|
+
"hi"
|
|
254
|
+
],
|
|
255
|
+
"timeout_s": 120,
|
|
256
|
+
"skip_cli_with_key": true
|
|
257
|
+
},
|
|
249
258
|
"check_ready": {
|
|
250
259
|
"env_all": [
|
|
251
260
|
"OPENAI_API_KEY",
|
|
@@ -1784,12 +1793,12 @@
|
|
|
1784
1793
|
"requires": [
|
|
1785
1794
|
"nodejs"
|
|
1786
1795
|
],
|
|
1787
|
-
"supported_version": "0.1
|
|
1796
|
+
"supported_version": "0.2.1-rc.2",
|
|
1788
1797
|
"verify": "dsh -V >/dev/null 2>&1",
|
|
1789
1798
|
"verify_win": "dsh -V >nul 2>nul",
|
|
1790
|
-
"macos": "npm install -g @deepseek-ai/dsh@0.1
|
|
1791
|
-
"linux": "npm install -g @deepseek-ai/dsh@0.1
|
|
1792
|
-
"windows": "npm install -g @deepseek-ai/dsh@0.1
|
|
1799
|
+
"macos": "npm install -g @deepseek-ai/dsh@0.2.1-rc.2",
|
|
1800
|
+
"linux": "npm install -g @deepseek-ai/dsh@0.2.1-rc.2",
|
|
1801
|
+
"windows": "npm install -g @deepseek-ai/dsh@0.2.1-rc.2"
|
|
1793
1802
|
},
|
|
1794
1803
|
"uninstall": {
|
|
1795
1804
|
"macos": "npm uninstall -g @deepseek-ai/dsh",
|
|
@@ -1820,9 +1829,9 @@
|
|
|
1820
1829
|
},
|
|
1821
1830
|
{
|
|
1822
1831
|
"name": "DEEPSEEK_BASE_URL",
|
|
1823
|
-
"description": "Optional gateway/proxy base URL. Leave blank for the public DeepSeek API.",
|
|
1832
|
+
"description": "Optional gateway/proxy base URL speaking the Anthropic Messages API. Leave blank for the public DeepSeek API (https://api.deepseek.com/anthropic).",
|
|
1824
1833
|
"required": false,
|
|
1825
|
-
"placeholder": "https://api.deepseek.com"
|
|
1834
|
+
"placeholder": "https://api.deepseek.com/anthropic"
|
|
1826
1835
|
},
|
|
1827
1836
|
{
|
|
1828
1837
|
"name": "DEEPSEEK_MODEL",
|
package/src/adapters/codex.js
CHANGED
|
@@ -218,16 +218,30 @@ class CodexAdapter extends BaseAdapter {
|
|
|
218
218
|
if (!isWindows || !/\.(cmd|bat)$/.test(lower)) return { file: bin, args: [], shell: false };
|
|
219
219
|
try {
|
|
220
220
|
const content = fs.readFileSync(bin, 'utf-8');
|
|
221
|
-
|
|
221
|
+
// Both npm shim styles: `"%dp0%\x.js"` and the older `"%~dp0\x.js"`.
|
|
222
|
+
const js = content.match(/%~?dp0%?\\([^\s"*?]+\.[cm]?js)/i);
|
|
222
223
|
if (js) {
|
|
223
224
|
return { file: this._findNodeBin(), args: [path.resolve(path.dirname(bin), js[1])], shell: false };
|
|
224
225
|
}
|
|
225
|
-
const exe = content.match(
|
|
226
|
+
const exe = content.match(/%~?dp0%?\\([^\s"*?]+\.exe)/i);
|
|
226
227
|
if (exe) return { file: path.resolve(path.dirname(bin), exe[1]), args: [], shell: false };
|
|
227
228
|
} catch {}
|
|
228
|
-
// A shim we can't read through still has to run under cmd.exe.
|
|
229
|
-
//
|
|
230
|
-
|
|
229
|
+
// A shim we can't read through still has to run under cmd.exe. Build that
|
|
230
|
+
// command line here (see _spawnArgv): `shell: true` would join the
|
|
231
|
+
// arguments unquoted, cutting a working dir or relay flag at a space.
|
|
232
|
+
return { file: process.env.ComSpec || 'cmd.exe', args: [], shell: false, cmdShim: bin };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* argv + spawn options for `exec` running `rest`. A `cmdShim` goes through
|
|
237
|
+
* `cmd /d /s /c "<line>"` with every part quoted (`/s` strips only the
|
|
238
|
+
* outer pair), passed verbatim so Node adds no quoting of its own.
|
|
239
|
+
*/
|
|
240
|
+
_spawnArgv(exec, rest) {
|
|
241
|
+
if (!exec.cmdShim) return { argv: [...exec.args, ...rest], windowsVerbatimArguments: false };
|
|
242
|
+
const quote = (a) => `"${String(a).replace(/"/g, '""')}"`;
|
|
243
|
+
const line = [exec.cmdShim, ...rest].map(quote).join(' ');
|
|
244
|
+
return { argv: ['/d', '/s', '/c', `"${line}"`], windowsVerbatimArguments: true };
|
|
231
245
|
}
|
|
232
246
|
|
|
233
247
|
_findNodeBin() {
|
|
@@ -367,7 +381,11 @@ class CodexAdapter extends BaseAdapter {
|
|
|
367
381
|
async _handleViaSubprocess(content, msgChannel, attachments = []) {
|
|
368
382
|
// A missing cwd fails the spawn itself, and Node blames the shell for it
|
|
369
383
|
// ("spawn C:\Windows\system32\cmd.exe ENOENT"), which names nothing the
|
|
370
|
-
// user can fix.
|
|
384
|
+
// user can fix. A configured folder that was never made (or was cleaned
|
|
385
|
+
// up) is simply created; only one that cannot be is named instead.
|
|
386
|
+
if (this.workingDir && !CodexAdapter._dirExists(this.workingDir)) {
|
|
387
|
+
try { fs.mkdirSync(this.workingDir, { recursive: true }); } catch {}
|
|
388
|
+
}
|
|
371
389
|
if (this.workingDir && !CodexAdapter._dirExists(this.workingDir)) {
|
|
372
390
|
await this.sendError(msgChannel, `Working directory does not exist: ${this.workingDir}`);
|
|
373
391
|
return;
|
|
@@ -472,13 +490,15 @@ class CodexAdapter extends BaseAdapter {
|
|
|
472
490
|
if (this._stoppedBeforeStart(msgChannel)) return { stopped: true, responseText: '', exitCode: null };
|
|
473
491
|
return new Promise((resolve, reject) => {
|
|
474
492
|
const exec = this._resolveExec(cmd[0]);
|
|
475
|
-
const
|
|
493
|
+
const { argv, windowsVerbatimArguments } = this._spawnArgv(exec, cmd.slice(1));
|
|
494
|
+
const proc = spawn(exec.file, argv, {
|
|
476
495
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
477
496
|
env,
|
|
478
497
|
cwd: this.workingDir,
|
|
479
498
|
detached: !IS_WINDOWS,
|
|
480
499
|
windowsHide: true,
|
|
481
500
|
shell: exec.shell,
|
|
501
|
+
windowsVerbatimArguments,
|
|
482
502
|
});
|
|
483
503
|
this._channelProcesses[msgChannel] = proc;
|
|
484
504
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* so the adapter itself stays a thin subprocess driver. The split mirrors
|
|
6
6
|
* cline-stream.js / pi-stream.js.
|
|
7
7
|
*
|
|
8
|
-
* Verified against @deepseek-ai/dsh 0.1
|
|
8
|
+
* Verified against @deepseek-ai/dsh 0.2.1-rc.2 (bin `dsh` -> lib/bin.js, ESM).
|
|
9
9
|
*
|
|
10
10
|
* Three things here exist because dsh is unlike every other CLI in this repo:
|
|
11
11
|
*
|
|
12
|
-
* 1. It is a PREVIEW release (`0.1
|
|
12
|
+
* 1. It is a PREVIEW release (`0.2.1-rc.2`) and upstream says compatibility may
|
|
13
13
|
* break between previews, so the gate is exact equality — not a floor. The
|
|
14
14
|
* two version comparators already in this repo (installer.js's
|
|
15
15
|
* `compareVersions`, pi-stream.js's `parseVersion`) both DROP the `-rc.N`
|
|
@@ -45,7 +45,7 @@ const path = require('path');
|
|
|
45
45
|
* from there and only falls back here when the registry entry cannot be read at
|
|
46
46
|
* all. Mirrors pi-stream.js's MIN_PI_VERSION rationale.
|
|
47
47
|
*/
|
|
48
|
-
const SUPPORTED_DSH_VERSION = '0.1
|
|
48
|
+
const SUPPORTED_DSH_VERSION = '0.2.1-rc.2';
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* dsh's Node requirement, from the upstream repository's root package.json:
|
|
@@ -424,6 +424,27 @@ function buildPrivatePatch({ model, provider, permissionMode } = {}) {
|
|
|
424
424
|
return { text: lines.join('\n'), mode };
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
// ---------------------------------------------------------------------------
|
|
428
|
+
// Base URL
|
|
429
|
+
// ---------------------------------------------------------------------------
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Whether `url` is DeepSeek's own API root rather than a gateway.
|
|
433
|
+
*
|
|
434
|
+
* dsh talks to DeepSeek over the Anthropic Messages API and defaults to
|
|
435
|
+
* `https://api.deepseek.com/anthropic`. The OpenAI-style roots people copy
|
|
436
|
+
* from DeepSeek's docs (and that other agents' setup forms prefill) —
|
|
437
|
+
* `https://api.deepseek.com` and `…/v1` — answer that API with a 404, so the
|
|
438
|
+
* adapter drops them and lets dsh use its default.
|
|
439
|
+
*/
|
|
440
|
+
function isOfficialDeepseekRoot(url) {
|
|
441
|
+
let parsed;
|
|
442
|
+
try { parsed = new URL(String(url || '').trim()); } catch { return false; }
|
|
443
|
+
if (parsed.hostname.toLowerCase() !== 'api.deepseek.com') return false;
|
|
444
|
+
const p = parsed.pathname.replace(/\/+$/, '').toLowerCase();
|
|
445
|
+
return p === '' || p === '/v1';
|
|
446
|
+
}
|
|
447
|
+
|
|
427
448
|
// ---------------------------------------------------------------------------
|
|
428
449
|
// Permission mode
|
|
429
450
|
// ---------------------------------------------------------------------------
|
|
@@ -616,6 +637,8 @@ module.exports = {
|
|
|
616
637
|
yamlScalar,
|
|
617
638
|
buildPrivatePatch,
|
|
618
639
|
|
|
640
|
+
isOfficialDeepseekRoot,
|
|
641
|
+
|
|
619
642
|
normalizePermissionMode,
|
|
620
643
|
resolvePermissionMode,
|
|
621
644
|
|
package/src/adapters/deepseek.js
CHANGED
|
@@ -74,6 +74,7 @@ const {
|
|
|
74
74
|
classifyNodeVersion,
|
|
75
75
|
cleanStdout,
|
|
76
76
|
defaultInstallCommand,
|
|
77
|
+
isOfficialDeepseekRoot,
|
|
77
78
|
nodeRequirementText,
|
|
78
79
|
resolvePermissionMode,
|
|
79
80
|
safeDshHomeName,
|
|
@@ -400,7 +401,8 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
400
401
|
}
|
|
401
402
|
|
|
402
403
|
_baseUrl() {
|
|
403
|
-
|
|
404
|
+
const base = String(this.agentEnv.DEEPSEEK_BASE_URL || this.agentEnv.LLM_BASE_URL || '').trim();
|
|
405
|
+
return isOfficialDeepseekRoot(base) ? '' : base;
|
|
404
406
|
}
|
|
405
407
|
|
|
406
408
|
_model() {
|
|
@@ -567,8 +569,11 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
567
569
|
|
|
568
570
|
const key = this._apiKey();
|
|
569
571
|
if (key) env.DEEPSEEK_API_KEY = key;
|
|
572
|
+
// Set or cleared, never inherited: env already carries the raw agent value,
|
|
573
|
+
// and _baseUrl() drops DeepSeek's own OpenAI-style roots.
|
|
570
574
|
const base = this._baseUrl();
|
|
571
575
|
if (base) env.DEEPSEEK_BASE_URL = base;
|
|
576
|
+
else delete env.DEEPSEEK_BASE_URL;
|
|
572
577
|
|
|
573
578
|
// The task file references this by NAME; the value never appears in it.
|
|
574
579
|
env[TOKEN_ENV] = this.token;
|
package/src/adapters/openclaw.js
CHANGED
|
@@ -66,6 +66,23 @@ function retireOwnLegacyAuthProfiles(knownKeys) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Whether OpenClaw refused to start because local state from an older release
|
|
71
|
+
* still needs its own migration ("Legacy workspace setup state requires
|
|
72
|
+
* migration …; run openclaw doctor --fix", "requires legacy credential
|
|
73
|
+
* migration; run openclaw doctor --fix").
|
|
74
|
+
*
|
|
75
|
+
* Every upgrade across a storage change hits this, and the user's only way out
|
|
76
|
+
* was a terminal. The adapter runs that same Doctor repair itself and retries.
|
|
77
|
+
*/
|
|
78
|
+
function needsDoctorMigration(message) {
|
|
79
|
+
const text = String(message || '');
|
|
80
|
+
return /requires[^\n]*\bmigration\b/i.test(text) && /openclaw doctor --fix/i.test(text);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Budget for one `openclaw doctor --fix` run. */
|
|
84
|
+
const DOCTOR_REPAIR_TIMEOUT_MS = 120000;
|
|
85
|
+
|
|
69
86
|
class OpenClawAdapter extends BaseAdapter {
|
|
70
87
|
/**
|
|
71
88
|
* @param {object} opts - BaseAdapter opts plus:
|
|
@@ -281,7 +298,7 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
281
298
|
await this.sendStatus(msgChannel, 'thinking...');
|
|
282
299
|
|
|
283
300
|
try {
|
|
284
|
-
const responseText = await this.
|
|
301
|
+
const responseText = await this._runCliAgentWithMigration(content, msgChannel);
|
|
285
302
|
if (this._stoppingChannels.has(msgChannel)) return;
|
|
286
303
|
|
|
287
304
|
if (responseText) {
|
|
@@ -299,6 +316,101 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
299
316
|
// CLI mode (openclaw agent --local)
|
|
300
317
|
// ------------------------------------------------------------------
|
|
301
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Run the turn; when OpenClaw refuses to start over an unmigrated state
|
|
321
|
+
* store, run its Doctor repair once and retry. Doctor archives what it
|
|
322
|
+
* migrates rather than deleting it.
|
|
323
|
+
*/
|
|
324
|
+
async _runCliAgentWithMigration(userMessage, channel) {
|
|
325
|
+
try {
|
|
326
|
+
return await this._runCliAgent(userMessage, channel);
|
|
327
|
+
} catch (e) {
|
|
328
|
+
// At most one repair per turn; a repair that failed is not retried on
|
|
329
|
+
// every later message.
|
|
330
|
+
if (!needsDoctorMigration(e && e.message) || this._doctorRepairFailed) throw e;
|
|
331
|
+
this._log('OpenClaw needs a state migration — running openclaw doctor --fix --non-interactive');
|
|
332
|
+
await this.sendStatus(channel, 'Migrating OpenClaw local data...').catch(() => {});
|
|
333
|
+
const repair = await this._runDoctorRepair();
|
|
334
|
+
this._log(`Doctor repair ${repair.ok ? 'finished' : `failed: ${repair.detail}`}`);
|
|
335
|
+
if (!repair.ok) {
|
|
336
|
+
this._doctorRepairFailed = true;
|
|
337
|
+
throw e;
|
|
338
|
+
}
|
|
339
|
+
return this._runCliAgent(userMessage, channel);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** `openclaw doctor --fix --non-interactive`, resolved to {ok, detail}. */
|
|
344
|
+
_runDoctorRepair() {
|
|
345
|
+
return new Promise((resolve) => {
|
|
346
|
+
const binary = this._openclawBinary || this._findOpenclawBinary();
|
|
347
|
+
if (!binary) { resolve({ ok: false, detail: 'OpenClaw binary not found' }); return; }
|
|
348
|
+
const { spawnBin, spawnArgs } = this._spawnTarget(binary, ['doctor', '--fix', '--non-interactive']);
|
|
349
|
+
let tail = '';
|
|
350
|
+
const keepTail = (d) => { tail = (tail + d).slice(-300); };
|
|
351
|
+
let proc;
|
|
352
|
+
try {
|
|
353
|
+
proc = spawn(spawnBin, spawnArgs, {
|
|
354
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
355
|
+
env: this._spawnEnv(),
|
|
356
|
+
cwd: this.workingDir || process.env.HOME || '/',
|
|
357
|
+
timeout: DOCTOR_REPAIR_TIMEOUT_MS,
|
|
358
|
+
windowsHide: true,
|
|
359
|
+
});
|
|
360
|
+
} catch (err) {
|
|
361
|
+
resolve({ ok: false, detail: err.message });
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
proc.stdout.on('data', keepTail);
|
|
365
|
+
proc.stderr.on('data', keepTail);
|
|
366
|
+
proc.on('error', (err) => resolve({ ok: false, detail: err.message }));
|
|
367
|
+
proc.on('exit', (code) => resolve({ ok: code === 0, detail: `exit ${code}: ${tail.trim()}` }));
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** The child environment for an `openclaw` run. */
|
|
372
|
+
_spawnEnv() {
|
|
373
|
+
const spawnEnv = { ...(this.agentEnv || process.env) };
|
|
374
|
+
if (IS_WINDOWS) {
|
|
375
|
+
const nodeBinDir = path.dirname(process.execPath);
|
|
376
|
+
const npmBin = path.join(process.env.APPDATA || '', 'npm');
|
|
377
|
+
const portableDir = path.join(os.homedir(), '.openagents', 'nodejs');
|
|
378
|
+
const runtimeBin = path.join(getRuntimePrefix('openclaw'), 'node_modules', '.bin');
|
|
379
|
+
for (const p of [runtimeBin, nodeBinDir, npmBin, portableDir]) {
|
|
380
|
+
if (p && !(spawnEnv.PATH || '').includes(p)) {
|
|
381
|
+
spawnEnv.PATH = p + path.delimiter + (spawnEnv.PATH || '');
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return spawnEnv;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* How to start `openclaw <args>`: always node + openclaw.mjs directly (no
|
|
390
|
+
* shims, no cmd.exe, cross-platform). This avoids Windows .cmd shim issues
|
|
391
|
+
* and Unicode path encoding problems.
|
|
392
|
+
*/
|
|
393
|
+
_spawnTarget(binary, args) {
|
|
394
|
+
const portableDir = path.join(os.homedir(), '.openagents', 'nodejs');
|
|
395
|
+
// Unified path first (symlink on Unix), then legacy bin/ fallback, then system node
|
|
396
|
+
const nodeUnified = path.join(portableDir, IS_WINDOWS ? 'node.exe' : 'node');
|
|
397
|
+
let nodeBin = fs.existsSync(nodeUnified) ? nodeUnified : path.join(portableDir, 'bin', 'node');
|
|
398
|
+
if (!fs.existsSync(nodeBin)) nodeBin = whereBinary('node') || 'node';
|
|
399
|
+
|
|
400
|
+
// binary from _findOpenclawBinary() is already resolved to .mjs when possible
|
|
401
|
+
if (binary && binary.endsWith('.mjs')) {
|
|
402
|
+
// Direct node + .mjs invocation (works for managed, legacy, AND global installs)
|
|
403
|
+
return { spawnBin: nodeBin, spawnArgs: [binary, ...args] };
|
|
404
|
+
}
|
|
405
|
+
// Check managed locations explicitly
|
|
406
|
+
const runtimeMjs = path.join(getRuntimePrefix('openclaw'), 'node_modules', 'openclaw', 'openclaw.mjs');
|
|
407
|
+
const legacyMjs = path.join(portableDir, 'node_modules', 'openclaw', 'openclaw.mjs');
|
|
408
|
+
const openclawMjs = fs.existsSync(runtimeMjs) ? runtimeMjs : (fs.existsSync(legacyMjs) ? legacyMjs : null);
|
|
409
|
+
if (openclawMjs) return { spawnBin: nodeBin, spawnArgs: [openclawMjs, ...args] };
|
|
410
|
+
// Last resort: spawn binary directly with shell (handles .cmd on Windows)
|
|
411
|
+
return { spawnBin: binary, spawnArgs: args };
|
|
412
|
+
}
|
|
413
|
+
|
|
302
414
|
_runCliAgent(userMessage, channel) {
|
|
303
415
|
return new Promise((resolve, reject) => {
|
|
304
416
|
// Stopped while this turn was being prepared: start nothing (no tokens).
|
|
@@ -333,18 +445,7 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
333
445
|
|
|
334
446
|
this._log(`CLI: ${binary} ${args.slice(0, 5).join(' ')} ...`);
|
|
335
447
|
|
|
336
|
-
const spawnEnv =
|
|
337
|
-
if (IS_WINDOWS) {
|
|
338
|
-
const nodeBinDir = path.dirname(process.execPath);
|
|
339
|
-
const npmBin = path.join(process.env.APPDATA || '', 'npm');
|
|
340
|
-
const portableDir2 = path.join(os.homedir(), '.openagents', 'nodejs');
|
|
341
|
-
const runtimeBin = path.join(getRuntimePrefix('openclaw'), 'node_modules', '.bin');
|
|
342
|
-
for (const p of [runtimeBin, nodeBinDir, npmBin, portableDir2]) {
|
|
343
|
-
if (p && !(spawnEnv.PATH || '').includes(p)) {
|
|
344
|
-
spawnEnv.PATH = p + path.delimiter + (spawnEnv.PATH || '');
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
448
|
+
const spawnEnv = this._spawnEnv();
|
|
348
449
|
|
|
349
450
|
// Tool name → human-readable status
|
|
350
451
|
const toolLabels = {
|
|
@@ -382,34 +483,7 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
382
483
|
const stderrFd = fs.openSync(stderrFile, 'w');
|
|
383
484
|
this._log('Spawn: stderr → ' + stderrFile);
|
|
384
485
|
|
|
385
|
-
|
|
386
|
-
// This avoids Windows .cmd shim issues and Unicode path encoding problems.
|
|
387
|
-
const portableDir = path.join(os.homedir(), '.openagents', 'nodejs');
|
|
388
|
-
// Unified path first (symlink on Unix), then legacy bin/ fallback, then system node
|
|
389
|
-
const nodeUnified = path.join(portableDir, IS_WINDOWS ? 'node.exe' : 'node');
|
|
390
|
-
let nodeBin = fs.existsSync(nodeUnified) ? nodeUnified : path.join(portableDir, 'bin', 'node');
|
|
391
|
-
if (!fs.existsSync(nodeBin)) nodeBin = whereBinary('node') || 'node';
|
|
392
|
-
|
|
393
|
-
// binary from _findOpenclawBinary() is already resolved to .mjs when possible
|
|
394
|
-
let spawnBin, spawnArgs;
|
|
395
|
-
if (binary && binary.endsWith('.mjs')) {
|
|
396
|
-
// Direct node + .mjs invocation (works for managed, legacy, AND global installs)
|
|
397
|
-
spawnBin = nodeBin;
|
|
398
|
-
spawnArgs = [binary, ...args];
|
|
399
|
-
} else {
|
|
400
|
-
// Check managed locations explicitly
|
|
401
|
-
const runtimeMjs = path.join(getRuntimePrefix('openclaw'), 'node_modules', 'openclaw', 'openclaw.mjs');
|
|
402
|
-
const legacyMjs = path.join(portableDir, 'node_modules', 'openclaw', 'openclaw.mjs');
|
|
403
|
-
const openclawMjs = fs.existsSync(runtimeMjs) ? runtimeMjs : (fs.existsSync(legacyMjs) ? legacyMjs : null);
|
|
404
|
-
if (openclawMjs) {
|
|
405
|
-
spawnBin = nodeBin;
|
|
406
|
-
spawnArgs = [openclawMjs, ...args];
|
|
407
|
-
} else {
|
|
408
|
-
// Last resort: spawn binary directly with shell (handles .cmd on Windows)
|
|
409
|
-
spawnBin = binary;
|
|
410
|
-
spawnArgs = args;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
486
|
+
const { spawnBin, spawnArgs } = this._spawnTarget(binary, args);
|
|
413
487
|
const proc = spawn(spawnBin, spawnArgs, {
|
|
414
488
|
stdio: ['ignore', 'pipe', stderrFd],
|
|
415
489
|
env: spawnEnv,
|
|
@@ -703,3 +777,4 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
703
777
|
|
|
704
778
|
module.exports = OpenClawAdapter;
|
|
705
779
|
module.exports.retireOwnLegacyAuthProfiles = retireOwnLegacyAuthProfiles;
|
|
780
|
+
module.exports.needsDoctorMigration = needsDoctorMigration;
|
package/src/cli.js
CHANGED
|
@@ -360,7 +360,13 @@ async function cmdRuntimes(connector, flags) {
|
|
|
360
360
|
// Used by the daemon to report node runtimes to the workspace (Add-agent
|
|
361
361
|
// gallery). Emits ONLY JSON on stdout.
|
|
362
362
|
if (flags && flags.json) {
|
|
363
|
-
|
|
363
|
+
// --types a,b,c limits the run to those entries: the daemon splits
|
|
364
|
+
// detection over several of these so one slow CLI cannot hold up the rest.
|
|
365
|
+
const only = typeof flags.types === 'string'
|
|
366
|
+
? new Set(flags.types.split(',').map((s) => s.trim()).filter(Boolean))
|
|
367
|
+
: null;
|
|
368
|
+
const catalog = connector.registry.getCatalogSync().filter((e) => !only || only.has(e.name));
|
|
369
|
+
const runtimes = catalog.map((e) => {
|
|
364
370
|
let h;
|
|
365
371
|
try { h = connector.healthCheck(e.name); } catch { h = {}; }
|
|
366
372
|
// Credential contract, upward half: STATUS goes up, the secret stays on
|
package/src/daemon.js
CHANGED
|
@@ -26,6 +26,11 @@ const CLI_MODELS_MAX_AGE_MS = 3600 * 1000;
|
|
|
26
26
|
// may have failed for a passing reason (a slow start, an update mid-way). A
|
|
27
27
|
// little under the 10-minute sweep, so the next pass retries it.
|
|
28
28
|
const CLI_MODELS_RETRY_MS = 9 * 60 * 1000;
|
|
29
|
+
// Runtime detection runs as this many CLI children side by side, each checking
|
|
30
|
+
// its share of the catalog, and a child still running after the limit is
|
|
31
|
+
// stopped. A few rather than one per type: each child loads the whole core.
|
|
32
|
+
const RUNTIME_DETECT_GROUPS = 4;
|
|
33
|
+
const RUNTIME_DETECT_TIMEOUT_MS = 90 * 1000;
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Mask an API key for display (same shape the workspace backend uses for
|
|
@@ -724,16 +729,50 @@ class Daemon {
|
|
|
724
729
|
}
|
|
725
730
|
}
|
|
726
731
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Re-detect the installed/logged-in runtimes. A call made while one is
|
|
734
|
+
* already running joins it, so start-up, the periodic refresh and a
|
|
735
|
+
* workspace's Re-detect never run side by side.
|
|
736
|
+
*/
|
|
737
|
+
_refreshRuntimes() {
|
|
738
|
+
if (!this._runtimesInFlight) {
|
|
739
|
+
this._runtimesInFlight = this._detectRuntimes()
|
|
740
|
+
.catch(() => {})
|
|
741
|
+
.finally(() => { this._runtimesInFlight = null; });
|
|
742
|
+
}
|
|
743
|
+
return this._runtimesInFlight;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Detection checks each type with blocking CLI calls (--version, a login
|
|
748
|
+
* check), one after another. Run over the whole catalog in one child, a
|
|
749
|
+
* single CLI that hung held every result back, and the workspace sat on
|
|
750
|
+
* "Detecting…". The catalog is split over a few children run side by side,
|
|
751
|
+
* each with a time limit; a group that runs out keeps its last results.
|
|
752
|
+
*/
|
|
753
|
+
async _detectRuntimes() {
|
|
754
|
+
let types = [];
|
|
755
|
+
try { types = this.registry.getCatalogSync().map((e) => e.name); } catch {}
|
|
756
|
+
const groups = types.length
|
|
757
|
+
? Array.from({ length: Math.min(RUNTIME_DETECT_GROUPS, types.length) }, (_, i) =>
|
|
758
|
+
types.filter((_, j) => j % RUNTIME_DETECT_GROUPS === i))
|
|
759
|
+
: [null];
|
|
760
|
+
const found = new Map();
|
|
761
|
+
await Promise.all(groups.map(async (group) => {
|
|
762
|
+
const args = group ? ['runtimes', '--json', '--types', group.join(',')] : ['runtimes', '--json'];
|
|
763
|
+
try {
|
|
764
|
+
const r = await this._runAgn(args, { timeoutMs: RUNTIME_DETECT_TIMEOUT_MS });
|
|
765
|
+
if (r.code !== 0 || !r.stdout) return;
|
|
731
766
|
const parsed = JSON.parse(r.stdout.trim());
|
|
732
|
-
if (Array.isArray(parsed))
|
|
767
|
+
if (Array.isArray(parsed)) for (const rt of parsed) if (rt && rt.type) found.set(rt.type, rt);
|
|
768
|
+
} catch {
|
|
769
|
+
// this group keeps its previous snapshot
|
|
733
770
|
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
|
|
771
|
+
}));
|
|
772
|
+
if (!found.size) return;
|
|
773
|
+
const previous = new Map((this._runtimes || []).map((rt) => [rt.type, rt]));
|
|
774
|
+
const order = types.length ? types : [...found.keys()];
|
|
775
|
+
this._runtimes = order.map((type) => found.get(type) || previous.get(type)).filter(Boolean);
|
|
737
776
|
}
|
|
738
777
|
|
|
739
778
|
/**
|
|
@@ -938,8 +977,11 @@ async _runNodeCommand(n, cmd) {
|
|
|
938
977
|
}
|
|
939
978
|
}
|
|
940
979
|
|
|
941
|
-
/**
|
|
942
|
-
|
|
980
|
+
/**
|
|
981
|
+
* Run this launcher's own CLI as a child process, capturing output. With
|
|
982
|
+
* `timeoutMs`, a child still running then is killed and reported as failed.
|
|
983
|
+
*/
|
|
984
|
+
_runAgn(cliArgs, { timeoutMs } = {}) {
|
|
943
985
|
return new Promise((resolve) => {
|
|
944
986
|
let bin;
|
|
945
987
|
try {
|
|
@@ -952,6 +994,9 @@ async _runNodeCommand(n, cmd) {
|
|
|
952
994
|
// Run from home so a created agent's default working dir is sensible
|
|
953
995
|
// (not the ~/.openagents config dir).
|
|
954
996
|
cwd: os.homedir(),
|
|
997
|
+
// A timed detection owns its process group, so its CLI descendants
|
|
998
|
+
// can be stopped too without signalling the daemon itself.
|
|
999
|
+
detached: !!timeoutMs && !IS_WINDOWS,
|
|
955
1000
|
// The daemon has no console of its own (it is spawned DETACHED), so a
|
|
956
1001
|
// child without this gets a fresh console window — the blank black box
|
|
957
1002
|
// that used to appear every time _refreshRuntimes() ran.
|
|
@@ -959,10 +1004,32 @@ async _runNodeCommand(n, cmd) {
|
|
|
959
1004
|
});
|
|
960
1005
|
let stdout = '';
|
|
961
1006
|
let stderr = '';
|
|
1007
|
+
let settled = false;
|
|
1008
|
+
const finish = (result) => {
|
|
1009
|
+
if (settled) return;
|
|
1010
|
+
settled = true;
|
|
1011
|
+
clearTimeout(timer);
|
|
1012
|
+
resolve(result);
|
|
1013
|
+
};
|
|
1014
|
+
const timer = timeoutMs ? setTimeout(() => {
|
|
1015
|
+
if (IS_WINDOWS && child.pid) {
|
|
1016
|
+
// Killing only node.exe leaves the CLI (and its shell) running.
|
|
1017
|
+
const killer = spawn('taskkill', ['/T', '/F', '/PID', String(child.pid)], {
|
|
1018
|
+
windowsHide: true, stdio: 'ignore', timeout: 5000,
|
|
1019
|
+
});
|
|
1020
|
+
const fallback = () => { try { child.kill('SIGKILL'); } catch {} };
|
|
1021
|
+
killer.on('error', fallback);
|
|
1022
|
+
killer.on('close', (code) => { if (code !== 0) fallback(); });
|
|
1023
|
+
} else {
|
|
1024
|
+
try { process.kill(-child.pid, 'SIGKILL'); }
|
|
1025
|
+
catch { try { child.kill('SIGKILL'); } catch {} }
|
|
1026
|
+
}
|
|
1027
|
+
finish({ code: 1, stdout, stderr: `${stderr}timed out after ${timeoutMs}ms`, timedOut: true });
|
|
1028
|
+
}, timeoutMs) : null;
|
|
962
1029
|
child.stdout.on('data', (d) => { stdout += d.toString(); });
|
|
963
1030
|
child.stderr.on('data', (d) => { stderr += d.toString(); });
|
|
964
|
-
child.on('error', (e) =>
|
|
965
|
-
child.on('close', (code) =>
|
|
1031
|
+
child.on('error', (e) => finish({ code: 1, stdout, stderr: stderr || e.message }));
|
|
1032
|
+
child.on('close', (code) => finish({ code, stdout, stderr }));
|
|
966
1033
|
});
|
|
967
1034
|
}
|
|
968
1035
|
|
|
@@ -1050,8 +1117,9 @@ async _runNodeCommand(n, cmd) {
|
|
|
1050
1117
|
);
|
|
1051
1118
|
|
|
1052
1119
|
// Detect installed/logged-in agent runtimes for the Add-agent gallery. Runs
|
|
1053
|
-
// in a child process (off the event loop), refreshed periodically.
|
|
1054
|
-
|
|
1120
|
+
// in a child process (off the event loop), refreshed periodically. The
|
|
1121
|
+
// first result goes up at once rather than on the next 10s heartbeat.
|
|
1122
|
+
this._refreshRuntimes().then(() => this._nodeHeartbeat()).catch(() => {});
|
|
1055
1123
|
this._runtimesInterval = setInterval(() => this._refreshRuntimes(), 120000);
|
|
1056
1124
|
|
|
1057
1125
|
// Smoke-test configured agent types periodically (each probe spends one
|
package/src/env.js
CHANGED
|
@@ -203,15 +203,36 @@ function modelKeys(agentType, registry) {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
*
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
* Whether the agent's own env carries a key (not just an endpoint).
|
|
207
|
+
*/
|
|
208
|
+
function hasOwnKey(agentType, registry, agentEnv) {
|
|
209
|
+
if (!agentEnv) return false;
|
|
210
|
+
for (const key of credentialKeys(agentType, registry)) {
|
|
211
|
+
if (/BASE_URL$/.test(key)) continue;
|
|
212
|
+
if (String(agentEnv[key] == null ? '' : agentEnv[key]).trim()) return true;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The part of <type>.env an agent runs on. All of it for an agent that brings
|
|
219
|
+
* no credentials of its own.
|
|
220
|
+
*
|
|
221
|
+
* A signed-in agent, or one with a key of its own, takes none of the type's
|
|
222
|
+
* keys or endpoints, and none of its model either: that model was picked for
|
|
223
|
+
* the type key's endpoint (a relay's openai-gpt-oss-20b), which neither the
|
|
224
|
+
* account behind a sign-in nor the agent's own provider serves. Resolution
|
|
225
|
+
* maps the generic LLM_* names over the provider ones, so a relay left in
|
|
226
|
+
* <type>.env used to override an agent configured for DeepSeek: its
|
|
227
|
+
* LLM_BASE_URL and LLM_MODEL became PI_BASE_URL and PI_MODEL, and the agent's
|
|
228
|
+
* key went to the relay. Its model is the one in its own env, else the CLI's
|
|
229
|
+
* default.
|
|
211
230
|
*/
|
|
212
231
|
function typeEnvFor(agentType, typeEnv, registry, agentEnv) {
|
|
213
|
-
|
|
214
|
-
|
|
232
|
+
const signedIn = isCliLogin(agentEnv);
|
|
233
|
+
if (!signedIn && !hasOwnKey(agentType, registry, agentEnv)) return typeEnv;
|
|
234
|
+
const out = { ...typeEnv };
|
|
235
|
+
for (const key of credentialKeys(agentType, registry)) delete out[key];
|
|
215
236
|
for (const key of modelKeys(agentType, registry)) delete out[key];
|
|
216
237
|
return out;
|
|
217
238
|
}
|
package/src/probe.js
CHANGED
|
@@ -415,7 +415,20 @@ async function probeAgentType(connector, type, opts = {}) {
|
|
|
415
415
|
});
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
-
|
|
418
|
+
// Hoisted above the CLI tier: a failing CLI probe consults it too (below),
|
|
419
|
+
// and `skip_cli_with_key` hands keyed agents straight to it.
|
|
420
|
+
// `probe.api_test: false` opts out for an agent whose key is not a model
|
|
421
|
+
// API key (Cursor's is for Cursor's own service): an OpenAI-style call with
|
|
422
|
+
// it proves nothing either way.
|
|
423
|
+
const apiTestable = !(entry.probe && entry.probe.api_test === false);
|
|
424
|
+
const hasApiKey = apiTestable && !!(agentEnv.LLM_API_KEY || agentEnv.OPENAI_API_KEY || agentEnv.ANTHROPIC_API_KEY
|
|
425
|
+
|| agentEnv.ANTHROPIC_AUTH_TOKEN || agentEnv.KIMI_API_KEY || agentEnv.MOONSHOT_API_KEY);
|
|
426
|
+
|
|
427
|
+
// `probe.skip_cli_with_key`: the adapter points the CLI at a key's endpoint
|
|
428
|
+
// with launch flags (Codex's `-c model_providers…`) that a bare probe run
|
|
429
|
+
// does not carry, so with a key the CLI would test the wrong endpoint.
|
|
430
|
+
const cliProbeApplies = !(entry.probe && entry.probe.skip_cli_with_key && hasApiKey);
|
|
431
|
+
const probeArgs = cliProbeApplies && entry.probe && Array.isArray(entry.probe.args) ? entry.probe.args : null;
|
|
419
432
|
const altCheck = entry.check_ready && entry.check_ready.alt_check;
|
|
420
433
|
const hasLiveCli = !!((probeArgs && health.binary) || altCheck);
|
|
421
434
|
|
|
@@ -442,14 +455,6 @@ async function probeAgentType(connector, type, opts = {}) {
|
|
|
442
455
|
|| (entry.probe && entry.probe.timeout_s ? entry.probe.timeout_s * 1000 : DEFAULT_TIMEOUT_MS);
|
|
443
456
|
const env = stripForCliLogin(type, { ...getEnhancedEnv(), ...agentEnv }, connector.registry, opts.agentEnv);
|
|
444
457
|
|
|
445
|
-
// Hoisted above the CLI tier: a failing CLI probe consults it too (below).
|
|
446
|
-
// `probe.api_test: false` opts out for an agent whose key is not a model
|
|
447
|
-
// API key (Cursor's is for Cursor's own service): an OpenAI-style call with
|
|
448
|
-
// it proves nothing either way.
|
|
449
|
-
const apiTestable = !(entry.probe && entry.probe.api_test === false);
|
|
450
|
-
const hasApiKey = apiTestable && !!(agentEnv.LLM_API_KEY || agentEnv.OPENAI_API_KEY || agentEnv.ANTHROPIC_API_KEY
|
|
451
|
-
|| agentEnv.ANTHROPIC_AUTH_TOKEN || agentEnv.KIMI_API_KEY || agentEnv.MOONSHOT_API_KEY);
|
|
452
|
-
|
|
453
458
|
// ── Live tier 1: the agent's own CLI, when the registry declares how ──
|
|
454
459
|
if (hasLiveCli) {
|
|
455
460
|
const shell = probeArgs && health.binary ? shouldUseShellForBinary(health.binary) : true;
|