@openagents-org/agent-launcher 0.2.201 → 0.2.202
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 +9 -0
- package/src/adapters/codex.js +27 -7
- package/src/cli.js +7 -1
- package/src/daemon.js +82 -14
- package/src/probe.js +14 -9
package/package.json
CHANGED
package/registry.json
CHANGED
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
|
|
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/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;
|