@openagents-org/agent-launcher 0.2.214 → 0.2.216

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.
@@ -1339,6 +1339,13 @@ class OpenCodeAdapter extends BaseAdapter {
1339
1339
  let category;
1340
1340
  if (isPostinstallStubOutput(hay)) {
1341
1341
  category = 'install_incomplete';
1342
+ } else if (has(/(?:unrecognized|unknown) (?:flag|option|argument)s?:?\s*['"`]?--?[a-z]/)) {
1343
+ // The CLI refused a flag this adapter always passes, so it is not a
1344
+ // build we support (one whose version string we could not read gets
1345
+ // through the preflight). It printed its usage too, and that came out
1346
+ // as "produced output this version could not parse", which said nothing
1347
+ // about reinstalling.
1348
+ category = 'unsupported_version';
1342
1349
  } else if (has(/\b(401|403)\b/) || has(/unauthor|invalid api key|invalid_api_key|authentication|auth(entication)? failed|forbidden|invalid token|no api key|missing api key|permission denied/)) {
1343
1350
  category = 'auth_failed';
1344
1351
  } else if (has(/\b429\b/) || has(/rate.?limit|too many requests|quota|overloaded/)) {
package/src/daemon.js CHANGED
@@ -22,9 +22,10 @@ const { LogWriter } = require('./log-writer');
22
22
  const { redactDiagnostic } = require('./adapters/health-status');
23
23
  const { installCommandFor } = require('./probe');
24
24
 
25
- /** Types whose endpoint is one device-wide config file of their own. OpenClaw
26
- * left it: each keyed agent gets a private store (adapters/openclaw.js). */
27
- const SHARED_NATIVE_CONFIG = new Set(['hermes']);
25
+ /** Types whose endpoint is one device-wide config file of their own. None
26
+ * left: OpenClaw gives each keyed agent a private store (adapters/openclaw.js)
27
+ * and Hermes a provider of its own in its config.yaml (adapters/hermes.js). */
28
+ const SHARED_NATIVE_CONFIG = new Set();
28
29
 
29
30
  // A signed-in agent's model list is asked for again after this long. What a
30
31
  // CLI is offered changes when the CLI is upgraded (a vendor holds new models
@@ -39,6 +40,12 @@ const CLI_MODELS_RETRY_MS = 9 * 60 * 1000;
39
40
  // stopped. A few rather than one per type: each child loads the whole core.
40
41
  const RUNTIME_DETECT_GROUPS = 4;
41
42
  const RUNTIME_DETECT_TIMEOUT_MS = 90 * 1000;
43
+ // Probe results that mean the setup was never finished (no key, no sign-in,
44
+ // not installed). Time alone does not change them, and re-running them every
45
+ // hour re-reported the same failure all day; they are swept daily, and again
46
+ // as soon as detection sees the type installed or signed in.
47
+ const SETUP_INCOMPLETE = new Set(['not_ready', 'not_logged_in', 'missing_api_key', 'not_installed', 'install_failed']);
48
+ const SETUP_INCOMPLETE_MAX_AGE_MS = 24 * 3600 * 1000;
42
49
 
43
50
  /**
44
51
  * Mask an API key for display (same shape the workspace backend uses for
@@ -247,6 +254,29 @@ class Daemon {
247
254
  }
248
255
  }
249
256
 
257
+ /**
258
+ * A sign-in done in a terminal, or an install, changes no agent config, so
259
+ * nothing re-probes on its own and the daily sweep is far off. Re-probe the
260
+ * unfinished agents of a type as soon as detection sees it become installed
261
+ * or signed in.
262
+ */
263
+ _probeNewlyReady(previous) {
264
+ const became = new Set((this._runtimes || []).filter((rt) => {
265
+ const before = previous.get(rt.type);
266
+ return before && ((rt.installed && !before.installed) || (rt.ready && !before.ready));
267
+ }).map((rt) => rt.type));
268
+ if (!became.size) return;
269
+ const due = this.config.getAgents().filter((a) => became.has(a.type)
270
+ && this._probes[a.name] && SETUP_INCOMPLETE.has(this._probes[a.name].code));
271
+ if (!due.length) return;
272
+ (async () => {
273
+ for (const a of due) {
274
+ try { await this._probeAgent(a.name); } catch {}
275
+ }
276
+ this._nodeHeartbeat();
277
+ })();
278
+ }
279
+
250
280
  /** Report a runtime install that failed while creating `name`, as its probe result. */
251
281
  _recordInstallFailure(name, type, error) {
252
282
  let install = null;
@@ -275,7 +305,8 @@ class Daemon {
275
305
  for (const a of this.config.getAgents()) {
276
306
  const last = this._probes[a.name];
277
307
  const age = last && last.at ? Date.now() - Date.parse(last.at) : Infinity;
278
- if (age < maxAgeMs) continue;
308
+ const limit = last && SETUP_INCOMPLETE.has(last.code) ? Math.max(maxAgeMs, SETUP_INCOMPLETE_MAX_AGE_MS) : maxAgeMs;
309
+ if (age < limit) continue;
279
310
  try { await this._probeAgent(a.name); } catch {}
280
311
  }
281
312
  this._nodeHeartbeat();
@@ -721,11 +752,9 @@ class Daemon {
721
752
  * set up in the launcher onto another one's key, endpoint and model: add a
722
753
  * second DeepSeek or CodeArts agent from the workspace, and the first one
723
754
  * ran on the new one's settings from its next restart.
724
- * Hermes keeps sharing: its endpoint lives in one config file of its own
725
- * for the whole device, which only a save to <type>.env updates (index.js
726
- * _configureNativeAuth), so a key kept on the agent would never reach it.
727
- * OpenClaw writes each keyed agent's private openclaw.json from the agent's
728
- * own env when it starts, so it keeps its key on the agent like the rest.
755
+ * OpenClaw writes each keyed agent's private openclaw.json, and Hermes each
756
+ * keyed agent's own provider, from the agent's own env when it runs, so
757
+ * both keep their keys on the agent like the rest.
729
758
  */
730
759
  _keepsKeysPerAgent(type) {
731
760
  return !SHARED_NATIVE_CONFIG.has(type);
@@ -994,6 +1023,7 @@ class Daemon {
994
1023
  const order = types.length ? types : [...found.keys()];
995
1024
  this._runtimes = order.map((type) => found.get(type) || previous.get(type)).filter(Boolean);
996
1025
  this._cliModelsAfterDetection(previous);
1026
+ this._probeNewlyReady(previous);
997
1027
  }
998
1028
 
999
1029
  /**
package/src/index.js CHANGED
@@ -115,10 +115,9 @@ class AgentConnector {
115
115
  const agentType = type || 'openclaw';
116
116
  this.config.addAgent({ name, type: agentType, role: role || 'worker', path, env });
117
117
  // A key entered while ADDING the agent needs the same native side effects
118
- // as one saved later: OpenClaw and Hermes read a custom endpoint only from
119
- // their own config. Without this a new agent's test passed on the form's
120
- // key while the run used a stale one ("401 Invalid token") or none at all
121
- // (Hermes falling back to OpenRouter: "401 Missing Authentication header").
118
+ // as one saved later: OpenClaw reads a custom endpoint only from its own
119
+ // config. Without this a new agent's test passed on the form's key while
120
+ // the run used a stale one ("401 Invalid token").
122
121
  if (env && Object.keys(env).length) {
123
122
  this._configureAgentNativeAuth(agentType, env, name);
124
123
  }
@@ -129,14 +128,15 @@ class AgentConnector {
129
128
  * _configureNativeAuth for one agent, on the env it actually runs with: the
130
129
  * type's keys and endpoint only when it has none of its own and does not
131
130
  * sign in through its CLI (typeEnvFor). Merging all of <type>.env pushed a
132
- * key saved there earlier into Hermes's config.yaml for an agent created on
133
- * the sign-in tab, which then ran on that key (401).
131
+ * key saved there earlier into the CLI's config for an agent created on the
132
+ * sign-in tab, which then ran on that key (401).
134
133
  */
135
134
  _configureAgentNativeAuth(agentType, agentEnv, agentName) {
136
135
  const typeEnv = typeEnvFor(agentType, this.env.load(agentType), this.registry, agentEnv);
137
136
  this._configureNativeAuth(agentType, { ...typeEnv, ...agentEnv }, agentName);
138
137
  // A Hermes agent moved to the `hermes setup` sign-in gets back the
139
- // provider the custom endpoint replaced.
138
+ // provider an earlier version's custom endpoint replaced. (A keyed Hermes
139
+ // agent writes its own provider when it runs: HermesAdapter._endpoint.)
140
140
  if (agentType === 'hermes' && isCliLogin(agentEnv)) {
141
141
  try { require('./adapters/hermes').restoreNativeAuth(); } catch {}
142
142
  }
@@ -151,12 +151,6 @@ class AgentConnector {
151
151
  ? OpenClawAdapter.instanceEnv(agentName, env, this._configDir)
152
152
  : env);
153
153
  }
154
- // Hermes reads a custom endpoint only from its own config.yaml, so the
155
- // saved LLM_* values must be pushed through `hermes config set` — the
156
- // env file alone leaves it "No inference provider configured".
157
- if (agentType === 'hermes') {
158
- require('./adapters/hermes').configureNativeAuth(env);
159
- }
160
154
  } catch {}
161
155
  }
162
156
 
@@ -255,16 +255,35 @@ const PROBES = {
255
255
  uv: { probe: probeUv, remedy: uvRemedy },
256
256
  };
257
257
 
258
+ /** Registry platform names, as the `install` commands are keyed. */
259
+ const REGISTRY_PLATFORM = { darwin: 'macos', linux: 'linux', win32: 'windows' };
260
+
261
+ /**
262
+ * Whether `install.requires_on` limits a dependency to other platforms.
263
+ * Claude Code needs git only on Windows (it runs its shell through Git Bash);
264
+ * the npm install on macOS and Linux never touches git, yet a mac without the
265
+ * Command Line Tools was told to install them before it could get Claude.
266
+ * A separate field rather than a suffix inside `requires`, so an older core
267
+ * reading the same catalog keeps checking git everywhere instead of nowhere.
268
+ */
269
+ function requiredHere(entry, name, platform) {
270
+ const only = entry.install.requires_on && entry.install.requires_on[name];
271
+ if (!Array.isArray(only)) return true;
272
+ return only.includes(REGISTRY_PLATFORM[platform] || platform);
273
+ }
274
+
258
275
  /**
259
276
  * Check a registry entry's `install.requires` against the machine.
277
+ * @param {string} [platform] - seam for tests; production passes nothing.
260
278
  * @returns {{ ok: boolean, missing: Array<{name: string, action: string|null, summary: string, command: string, alternative: string|null}> }}
261
279
  */
262
- function checkInstallPrereqs(entry) {
280
+ function checkInstallPrereqs(entry, platform = process.platform) {
263
281
  const requires = entry && entry.install ? entry.install.requires : null;
264
282
  if (!Array.isArray(requires) || requires.length === 0) return { ok: true, missing: [] };
265
283
 
266
284
  const missing = [];
267
285
  for (const name of requires) {
286
+ if (!requiredHere(entry, name, platform)) continue;
268
287
  const spec = PROBES[String(name || '').toLowerCase()];
269
288
  if (!spec) continue; // no probe → the installer's problem, not ours
270
289
  let result;
package/src/paths.js CHANGED
@@ -869,6 +869,12 @@ function _addWindowsPaths(dirs) {
869
869
  // Node.js install
870
870
  _push(dirs, path.join(programFiles, 'nodejs'));
871
871
 
872
+ // Kiro CLI — install.ps1 runs an MSI that installs kiro-cli.exe into
873
+ // %ProgramFiles%\Kiro-Cli and edits the machine PATH, which an
874
+ // already-running daemon never sees. (install.sh uses ~/.local/bin, or
875
+ // /usr/local/bin for a system-wide install — both searched already.)
876
+ _push(dirs, path.join(programFiles, 'Kiro-Cli'));
877
+
872
878
  // nvm for Windows
873
879
  const nvmHome = process.env.NVM_HOME;
874
880
  if (nvmHome) {
package/src/probe.js CHANGED
@@ -92,7 +92,8 @@ function scrub(text) {
92
92
  if (!text) return '';
93
93
  const masked = String(text)
94
94
  .replace(/sk-[A-Za-z0-9_-]{8,}/g, 'sk-****')
95
- .replace(/(api[-_ ]?key["':\s=]+)[A-Za-z0-9_-]{8,}/gi, '$1****')
95
+ // Not a plain word: "Incorrect API key provided: sk-…" lost "provided".
96
+ .replace(/(api[-_ ]?key["':\s=]+)([A-Za-z0-9_-]{8,})/gi, (m, p, v) => (/^[a-z]+$/.test(v) ? m : `${p}****`))
96
97
  .replace(/Bearer\s+[A-Za-z0-9._-]{8,}/gi, 'Bearer ****');
97
98
  // Then everything the adapters strip from quoted CLI text: a Codex probe
98
99
  // that failed after printing a token-shaped blob showed that blob as its
@@ -137,7 +138,11 @@ function classifyOutputText(text) {
137
138
  // — the one misreading that sends a user to re-authenticate a working key.
138
139
  if (/credit balance|insufficient[_ ]?(quota|credits|funds)|payment required|\b402\b|billing|quota[_ ]?exceeded|exceeded your current quota|额度|余额|欠费|余额不足/.test(text)) return CODE.OUT_OF_CREDIT;
139
140
  if (/rate[- ]?limit|too many requests|\b429\b|overloaded|\b529\b/.test(text)) return CODE.RATE_LIMITED;
140
- if (/enotfound|econnrefused|econnreset|etimedout|eai_again|fetch failed|socket hang up|network error|self[- ]signed certificate|unable to get local issuer/.test(text)) return CODE.NETWORK;
141
+ // "error sending request for url (…)" is how Codex (Rust) says the host
142
+ // was unreachable; a Codex that could not reach chatgpt.com ran out the
143
+ // probe clock and was reported as waiting for interactive input. "Request
144
+ // to <host> timed out" is the direct API test's own deadline (utils.js).
145
+ if (/enotfound|econnrefused|econnreset|etimedout|eai_again|fetch failed|socket hang up|network error|error sending request|request to \S+ timed out|self[- ]signed certificate|unable to get local issuer/.test(text)) return CODE.NETWORK;
141
146
  if (/api key.{0,24}(not set|not found|missing)|no api key|missing api key|environment variable.{0,40}(is )?(not set|required)/.test(text)) return CODE.MISSING_API_KEY;
142
147
  if (/invalid.{0,12}(api.?key|x-api-key|token)|incorrect api key|authentication[_ ]?error|invalid credentials|\b401\b|unauthorized|forbidden|\b403\b/.test(text)) return CODE.INVALID_API_KEY;
143
148
  // A sign-in that exists but has run out — Claude Code: "Failed to
@@ -350,6 +355,25 @@ function shellQuoted(binary, shell) {
350
355
  return shell && !/^".*"$/.test(binary) ? `"${binary}"` : binary;
351
356
  }
352
357
 
358
+ /**
359
+ * Whether a line is an encoded blob rather than words. A whole-line run of
360
+ * base64/base64url characters is one; so is a line where mixed-case
361
+ * alphanumeric runs (and already-redacted spans) make up half of it — a
362
+ * Codex timeout reported a fragment of a dumped object, `…849-1.0.1.
363
+ * [REDACTED]\",md: '3P2K.…`, as its reason. Hex ids, paths and URL paths
364
+ * have no mixed-case runs and are not counted.
365
+ */
366
+ function mostlyEncoded(line) {
367
+ if (/^[A-Za-z0-9+/=._-]{24,}$/.test(line)) return true;
368
+ const body = line.replace(/\s+/g, '');
369
+ const unredacted = line.replace(/\[REDACTED\]/g, '');
370
+ let encoded = line.length - unredacted.length;
371
+ for (const run of unredacted.match(/[A-Za-z0-9+/=_.-]{16,}/g) || []) {
372
+ if (/\d/.test(run) && /[a-z]/.test(run) && /[A-Z]/.test(run)) encoded += run.length;
373
+ }
374
+ return encoded * 2 >= body.length;
375
+ }
376
+
353
377
  /**
354
378
  * The one line worth reporting from a failed run.
355
379
  *
@@ -359,11 +383,15 @@ function shellQuoted(binary, shell) {
359
383
  * with the timeout named first.
360
384
  */
361
385
  function failureMessage(res, code, timeoutMs) {
362
- // A line that is one long run of base64/base64url characters is an encoded
363
- // blob (a token, encrypted reasoning), never a sentence that says why the
364
- // CLI failed. JSON and URLs have characters outside that set and stay.
365
- const lines = (s) => String(s || '').split(/\r?\n/).map((l) => l.trim())
366
- .filter((l) => l && !BENIGN_OUTPUT.test(l) && !/^[A-Za-z0-9+/=._-]{24,}$/.test(l));
386
+ // A line that is mostly encoded blob (a token, encrypted reasoning) never
387
+ // says why the CLI failed, and neither does a stack frame: a crashed Node
388
+ // shim showed only its last frames, `…(file:///C:/…/codex.js:108:9) at
389
+ // file:///…`, with the `Error:` line above them cut off. JSON and URLs stay.
390
+ // Each line is scrubbed before that test: a provider that echoes the whole
391
+ // key (`401 Incorrect API key provided: sk-proj-…`) had the one line that
392
+ // explains the failure dropped as encoded.
393
+ const lines = (s) => String(s || '').split(/\r?\n/).map((l) => scrub(l.trim()))
394
+ .filter((l) => l && !BENIGN_OUTPUT.test(l) && !mostlyEncoded(l) && !/^at\s+\S/.test(l));
367
395
  const all = [...lines(res.stderr), ...lines(res.stdout)];
368
396
  const telling = all.find((l) => classifyOutputText(l.toLowerCase()) === code);
369
397
  const detail = tail(telling || lines(res.stderr).join('\n') || lines(res.stdout).join('\n'), OUTPUT_CAP);
package/src/utils.js CHANGED
@@ -37,12 +37,28 @@ function request(url, { method = 'POST', headers = {}, body = null, timeout = 15
37
37
  res.on('end', () => resolve({ status: res.statusCode, data }));
38
38
  });
39
39
  req.on('error', (e) => resolve({ error: e.message }));
40
- req.on('timeout', () => { req.destroy(); resolve({ error: 'Request timed out' }); });
40
+ // Name the host and the deadline: a bare "Request timed out" on the
41
+ // device card did not say whether the provider or the network was slow.
42
+ req.on('timeout', () => { req.destroy(); resolve({ error: `Request to ${parsedUrl.host} timed out after ${Math.round(timeout / 1000)}s` }); });
41
43
  if (body) req.write(body);
42
44
  req.end();
43
45
  });
44
46
  }
45
47
 
48
+ /**
49
+ * The test completion. 15s read as broken a slow relay that answers in 20, and
50
+ * a dropped connection failed the whole test: give it 30s and one more try on
51
+ * a timeout or reset. A host that does not resolve is not retried.
52
+ */
53
+ const COMPLETION_TIMEOUT_MS = 30000;
54
+ const RETRYABLE = /timed out|econnreset|socket hang up|eai_again/i;
55
+
56
+ async function requestCompletion(url, opts) {
57
+ const res = await request(url, { ...opts, timeout: COMPLETION_TIMEOUT_MS });
58
+ if (!res.error || !RETRYABLE.test(res.error)) return res;
59
+ return request(url, { ...opts, timeout: COMPLETION_TIMEOUT_MS });
60
+ }
61
+
46
62
  /**
47
63
  * The chat models an OpenAI-compatible endpoint says it serves, or [] when it
48
64
  * publishes no readable list. A list we cannot read is not a test failure —
@@ -66,10 +82,22 @@ async function servedModels(apiBase, headers) {
66
82
  }
67
83
  }
68
84
 
85
+ /**
86
+ * The test asks for a few tokens to stay cheap. A reasoning model can spend
87
+ * them all thinking, and OpenAI then refuses with "Could not finish the message
88
+ * because max_tokens or model output limit was reached". The key and the model
89
+ * were both accepted, which is everything this test checks, and reporting it as
90
+ * a failure marked an agent that works as broken.
91
+ */
92
+ const OUTPUT_LIMIT_REACHED = /max_tokens or model output limit was reached/i;
93
+
69
94
  /** Read one completion response into the result shape. */
70
95
  function completionResult(res, { isAnthropic, model }) {
71
96
  if (res.error) return { success: false, error: res.error };
72
97
  const { status, data } = res;
98
+ if (status >= 400 && OUTPUT_LIMIT_REACHED.test(data || '')) {
99
+ return { success: true, model: model || '?', response: '' };
100
+ }
73
101
  try {
74
102
  const parsed = JSON.parse(data);
75
103
  let text, usedModel;
@@ -154,7 +182,7 @@ async function testLLMConnection(env, opts = {}) {
154
182
  max_tokens: 32,
155
183
  messages: [{ role: 'user', content: 'Say hi in 5 words.' }],
156
184
  });
157
- const res = await request(url, { headers, body });
185
+ const res = await requestCompletion(url, { headers, body });
158
186
  return completionResult(res, { isAnthropic: true, model });
159
187
  }
160
188
 
@@ -183,7 +211,7 @@ async function testLLMConnection(env, opts = {}) {
183
211
  };
184
212
  if (hasKimiConfig) requestBody.max_tokens = 32;
185
213
  else requestBody.max_completion_tokens = 32;
186
- const res = await request(`${baseUrl}/chat/completions`, { headers, body: JSON.stringify(requestBody) });
214
+ const res = await requestCompletion(`${baseUrl}/chat/completions`, { headers, body: JSON.stringify(requestBody) });
187
215
  last = completionResult(res, { isAnthropic: false, model: candidate });
188
216
  if (last.success) return last;
189
217
  // Only a model WE picked moves on to the next one. A configured model is