@openagents-org/agent-launcher 0.2.213 → 0.2.215

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openagents-org/agent-launcher",
3
- "version": "0.2.213",
3
+ "version": "0.2.215",
4
4
  "description": "OpenAgents Launcher — install, configure, and run AI coding agents from your terminal",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/registry.json CHANGED
@@ -616,8 +616,7 @@
616
616
  {
617
617
  "name": "LLM_BASE_URL",
618
618
  "description": "Custom OpenAI-compatible base URL (leave empty to use Hermes's own provider login)",
619
- "required": false,
620
- "placeholder": "https://api.openai.com/v1"
619
+ "required": false
621
620
  },
622
621
  {
623
622
  "name": "LLM_MODEL",
@@ -1844,8 +1843,7 @@
1844
1843
  {
1845
1844
  "name": "DEEPSEEK_BASE_URL",
1846
1845
  "description": "Optional gateway/proxy base URL. Leave blank for the public DeepSeek API. A URL ending in a version segment (e.g. https://relay.example.com/v1, or OpenAgents credits) is used as an OpenAI-compatible chat-completions endpoint; any other URL must speak the Anthropic Messages API (e.g. https://api.deepseek.com/anthropic).",
1847
- "required": false,
1848
- "placeholder": "https://api.deepseek.com/anthropic"
1846
+ "required": false
1849
1847
  },
1850
1848
  {
1851
1849
  "name": "DEEPSEEK_MODEL",
@@ -2254,8 +2252,7 @@
2254
2252
  {
2255
2253
  "name": "CODEBUDDY_BASE_URL",
2256
2254
  "description": "Advanced. Endpoint override, for an enterprise or self-hosted deployment. Blank means the endpoint the region above selects.",
2257
- "required": false,
2258
- "placeholder": "https://www.codebuddy.cn"
2255
+ "required": false
2259
2256
  }
2260
2257
  ],
2261
2258
  "check_ready": {
@@ -198,6 +198,9 @@ class BaseAdapter {
198
198
  this._cursorFile = this._cursorFilePath();
199
199
  this._lastPersistedCursor = null;
200
200
  this._resumedFromCursor = false;
201
+ // No cursor and no head: polls read from the start of history until they
202
+ // come back empty (see _skipExistingEvents).
203
+ this._unanchored = false;
201
204
  this._running = false;
202
205
  this._sessionId = null; // issued by server on /v1/join; used to prove liveness
203
206
  this._processedIds = new Set();
@@ -550,7 +553,15 @@ class BaseAdapter {
550
553
  this._lastEventId = head;
551
554
  this._persistCursor(head);
552
555
  this._log(`Skipped existing events, cursor at ${head}`);
556
+ return;
553
557
  }
558
+ // The head lookup failed (network not up yet, a 5xx) or the workspace is
559
+ // empty. Polling with no cursor reads from the start of history, and a
560
+ // fresh start is not a replay, so every old message that named this agent
561
+ // was run again, one after another — a Codex hitting 429 posted an error
562
+ // every ~20s for an hour. Age-filter until the backlog is drained.
563
+ this._unanchored = true;
564
+ this._log('Could not find the head of the event stream — skipping stale messages until caught up', 'warn');
554
565
  }
555
566
 
556
567
  // ------------------------------------------------------------------
@@ -1286,6 +1297,10 @@ class BaseAdapter {
1286
1297
  continue;
1287
1298
  }
1288
1299
 
1300
+ // The cursor stops moving (or none comes back) only once the poll has
1301
+ // reached the end of the stream. An empty `messages` alone does not say
1302
+ // that: it is the page after events for other agents were dropped.
1303
+ const caughtUp = !rawCursor || rawCursor === this._lastEventId;
1289
1304
  if (rawCursor) {
1290
1305
  this._lastEventId = rawCursor;
1291
1306
  this._persistCursor(rawCursor);
@@ -1293,8 +1308,9 @@ class BaseAdapter {
1293
1308
  // Only the first poll after resuming from a persisted cursor is a
1294
1309
  // replay; later polls carry live traffic and are never age-filtered
1295
1310
  // (a skewed local clock must not make a live agent go deaf).
1296
- const isReplay = this._resumedFromCursor;
1311
+ const isReplay = this._resumedFromCursor || this._unanchored;
1297
1312
  this._resumedFromCursor = false;
1313
+ if (caughtUp) this._unanchored = false;
1298
1314
  const staleByChannel = {};
1299
1315
 
1300
1316
  // Deduplicate
@@ -465,7 +465,7 @@ class CodexAdapter extends BaseAdapter {
465
465
  await this._sendRunFailure(msgChannel, result, { partial: true });
466
466
  }
467
467
  return;
468
- } else if (result.exitCode !== 0 && threadId && attempt === 0) {
468
+ } else if (result.exitCode !== 0 && threadId && attempt === 0 && !CodexAdapter._serviceRefused(result)) {
469
469
  // Stale thread — clear and retry fresh
470
470
  this._log(`Stale thread detected for ${msgChannel}, clearing and retrying`);
471
471
  delete this._channelThreads[msgChannel];
@@ -604,7 +604,7 @@ class CodexAdapter extends BaseAdapter {
604
604
  }
605
605
  });
606
606
 
607
- proc.on('exit', async (code) => {
607
+ proc.on('exit', async (code, signal) => {
608
608
  // Wait for all in-flight processLine calls
609
609
  try { await _pendingLines; } catch {}
610
610
 
@@ -617,7 +617,7 @@ class CodexAdapter extends BaseAdapter {
617
617
 
618
618
  const stderrBuf = CodexAdapter._decodeOutput(Buffer.concat(stderrChunks));
619
619
  if (code !== 0) {
620
- this._log(`Codex CLI exited with code ${code}`);
620
+ this._log(`Codex CLI exited with code ${code}${signal ? ` (${signal})` : ''}`);
621
621
  if (stderrBuf.trim()) {
622
622
  this._log(`stderr: ${stderrBuf.trim().slice(0, 500)}`);
623
623
  }
@@ -626,6 +626,7 @@ class CodexAdapter extends BaseAdapter {
626
626
  resolve({
627
627
  responseText: responseTexts.join('\n').trim(),
628
628
  exitCode: code,
629
+ signal,
629
630
  stderr: stderrBuf,
630
631
  errorMessage: lastErrorMessage,
631
632
  turnFailed,
@@ -742,13 +743,31 @@ class CodexAdapter extends BaseAdapter {
742
743
  return Boolean(turnFailed) || (exitCode !== 0 && exitCode !== undefined);
743
744
  }
744
745
 
746
+ /**
747
+ * True when the model service turned the run away (rate limit, quota,
748
+ * credentials, network) — nothing to do with the thread being resumed. Such
749
+ * a run was read as a stale thread: the thread was dropped, losing the
750
+ * conversation, and the same refused request was sent a second time.
751
+ */
752
+ static _serviceRefused({ errorMessage, stderr } = {}) {
753
+ const refused = /\b(401|402|403|429)\b|too many requests|rate.?limit|usage limit|quota|credits|unauthorized|forbidden|error sending request/i;
754
+ if (refused.test(String(errorMessage || ''))) return true;
755
+ // Only the end of stderr, where the reason the run died is: a stale
756
+ // thread whose earlier log mentioned a quota was kept, and every later
757
+ // message in that channel failed until restart.
758
+ const lastLines = String(stderr || '').split(/\r?\n/).filter((l) => l.trim()).slice(-5).join('\n');
759
+ return refused.test(lastLines);
760
+ }
761
+
745
762
  /**
746
763
  * Pick the most informative failure detail from a run result:
747
- * turn.failed / error event message → stderr tail → exit code. Redacted.
764
+ * turn.failed / error event message → stderr tail → signal → exit code.
765
+ * Redacted.
748
766
  */
749
- static _failureDetail({ errorMessage, stderr, exitCode } = {}) {
767
+ static _failureDetail({ errorMessage, stderr, exitCode, signal } = {}) {
750
768
  const raw = String(errorMessage || '').trim()
751
769
  || CodexAdapter._stderrReason(stderr)
770
+ || (signal ? `codex was terminated by ${signal}` : '')
752
771
  || (exitCode ? `codex exited with code ${exitCode}` : '');
753
772
  const detail = CodexAdapter._explain(CodexAdapter._unwrap(raw));
754
773
  return CodexAdapter._redact(detail).slice(0, 500).trim();
@@ -767,7 +786,10 @@ class CodexAdapter extends BaseAdapter {
767
786
  * when neither exists does the raw tail stand.
768
787
  */
769
788
  static _stderrReason(stderr) {
770
- const lines = String(stderr || '').split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
789
+ // The stdin banner is never a reason: a run whose stderr holds nothing
790
+ // else falls through to the exit code instead of quoting the banner.
791
+ const lines = String(stderr || '').split(/\r?\n/).map((l) => l.trim())
792
+ .filter((l) => l && !/^Reading (prompt|additional input) from stdin/i.test(l));
771
793
  if (!lines.length) return '';
772
794
  const TRACE = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN|ERROR)\s+(?:[\w:]+:\s+)?(.*)$/;
773
795
  const plain = [];
@@ -775,7 +797,7 @@ class CodexAdapter extends BaseAdapter {
775
797
  for (const line of lines) {
776
798
  const m = line.match(TRACE);
777
799
  if (!m) {
778
- if (!/^Reading (prompt|additional input) from stdin/i.test(line)) plain.push(line);
800
+ plain.push(line);
779
801
  } else if (m[1] === 'ERROR' && m[2] && !errors.includes(m[2])) {
780
802
  errors.push(m[2]);
781
803
  }
@@ -100,6 +100,9 @@ function needsDoctorMigration(message) {
100
100
  return /requires[^\n]*\bmigration\b/i.test(text) && /openclaw doctor --fix/i.test(text);
101
101
  }
102
102
 
103
+ /** OpenClaw's refusal to run embedded while a Gateway owns the state. */
104
+ const GATEWAY_RUNNING = /A Gateway is running for this state directory/i;
105
+
103
106
  /** Budget for one `openclaw doctor --fix` run. */
104
107
  const DOCTOR_REPAIR_TIMEOUT_MS = 120000;
105
108
 
@@ -383,7 +386,7 @@ class OpenClawAdapter extends BaseAdapter {
383
386
  */
384
387
  async _runCliAgentWithMigration(userMessage, channel) {
385
388
  try {
386
- return await this._runCliAgent(userMessage, channel);
389
+ return await this._runCliTurn(userMessage, channel);
387
390
  } catch (e) {
388
391
  // At most one repair per turn; a repair that failed is not retried on
389
392
  // every later message.
@@ -396,7 +399,23 @@ class OpenClawAdapter extends BaseAdapter {
396
399
  this._doctorRepairFailed = true;
397
400
  throw e;
398
401
  }
399
- return this._runCliAgent(userMessage, channel);
402
+ return this._runCliTurn(userMessage, channel);
403
+ }
404
+ }
405
+
406
+ /**
407
+ * One turn, embedded (`--local`) by default. OpenClaw refuses an embedded
408
+ * run while the user's own Gateway serves the same state directory — "A
409
+ * Gateway is running for this state directory … Run without --local to use
410
+ * it" — and every message failed that way. Hand the turn to that Gateway.
411
+ */
412
+ async _runCliTurn(userMessage, channel) {
413
+ try {
414
+ return await this._runCliAgent(userMessage, channel);
415
+ } catch (e) {
416
+ if (!GATEWAY_RUNNING.test((e && e.message) || '')) throw e;
417
+ this._log('A Gateway is running for this OpenClaw state — retrying the turn through it');
418
+ return this._runCliAgent(userMessage, channel, { local: false });
400
419
  }
401
420
  }
402
421
 
@@ -471,7 +490,7 @@ class OpenClawAdapter extends BaseAdapter {
471
490
  return { spawnBin: binary, spawnArgs: args };
472
491
  }
473
492
 
474
- _runCliAgent(userMessage, channel) {
493
+ _runCliAgent(userMessage, channel, { local = true } = {}) {
475
494
  return new Promise((resolve, reject) => {
476
495
  // Stopped while this turn was being prepared: start nothing (no tokens).
477
496
  if (this._stoppedBeforeStart(channel)) {
@@ -496,7 +515,7 @@ class OpenClawAdapter extends BaseAdapter {
496
515
 
497
516
  const args = [
498
517
  '--log-level', 'trace',
499
- 'agent', '--local',
518
+ 'agent', ...(local ? ['--local'] : []),
500
519
  '--agent', this.openclawAgentId,
501
520
  '--session-id', sessionKey,
502
521
  '--message', userMessage,
package/src/cli.js CHANGED
@@ -1059,6 +1059,11 @@ async function cmdProbe(connector, flags, positional) {
1059
1059
  } catch {}
1060
1060
 
1061
1061
  const result = await connector.probeAgentType(type, { agentEnv });
1062
+ // The daemon probes by agent name: a name that is neither an agent here nor
1063
+ // a type is an agent that is gone, not a type the catalog lacks.
1064
+ if (!agentEnv && result.code === 'unknown_type') {
1065
+ result.message = `No agent named '${target}' on this device`;
1066
+ }
1062
1067
 
1063
1068
  if (flags && flags.json) {
1064
1069
  // Machine consumers (the daemon's probe_agent node command) read ONLY
package/src/config.js CHANGED
@@ -45,9 +45,32 @@ class Config {
45
45
 
46
46
  // -- Write --
47
47
 
48
+ /**
49
+ * Replace the file in one step. A plain writeFileSync truncates first, and
50
+ * the daemon and its `agn` children read this file all the time: a probe
51
+ * started right after a create read it empty and reported the new agent as
52
+ * "Unknown agent type '<name>'", and a read-modify-write in that window
53
+ * saves the empty list back. Windows can refuse the rename while a reader
54
+ * holds the file open, so that case retries and then writes in place.
55
+ */
48
56
  save(config) {
49
57
  fs.mkdirSync(this.configDir, { recursive: true });
50
- fs.writeFileSync(this.configFile, serializeYaml(config), 'utf-8');
58
+ const text = serializeYaml(config);
59
+ const tmp = `${this.configFile}.${process.pid}.tmp`;
60
+ fs.writeFileSync(tmp, text, 'utf-8');
61
+ for (let attempt = 0; attempt < 3; attempt++) {
62
+ try {
63
+ fs.renameSync(tmp, this.configFile);
64
+ return;
65
+ } catch (err) {
66
+ if (!['EPERM', 'EACCES', 'EBUSY'].includes(err.code)) {
67
+ try { fs.unlinkSync(tmp); } catch {}
68
+ throw err;
69
+ }
70
+ }
71
+ }
72
+ try { fs.unlinkSync(tmp); } catch {}
73
+ fs.writeFileSync(this.configFile, text, 'utf-8');
51
74
  }
52
75
 
53
76
  addAgent({ name, type, role, path: agentPath, env }) {
package/src/daemon.js CHANGED
@@ -39,6 +39,12 @@ const CLI_MODELS_RETRY_MS = 9 * 60 * 1000;
39
39
  // stopped. A few rather than one per type: each child loads the whole core.
40
40
  const RUNTIME_DETECT_GROUPS = 4;
41
41
  const RUNTIME_DETECT_TIMEOUT_MS = 90 * 1000;
42
+ // Probe results that mean the setup was never finished (no key, no sign-in,
43
+ // not installed). Time alone does not change them, and re-running them every
44
+ // hour re-reported the same failure all day; they are swept daily, and again
45
+ // as soon as detection sees the type installed or signed in.
46
+ const SETUP_INCOMPLETE = new Set(['not_ready', 'not_logged_in', 'missing_api_key', 'not_installed', 'install_failed']);
47
+ const SETUP_INCOMPLETE_MAX_AGE_MS = 24 * 3600 * 1000;
42
48
 
43
49
  /**
44
50
  * Mask an API key for display (same shape the workspace backend uses for
@@ -247,6 +253,29 @@ class Daemon {
247
253
  }
248
254
  }
249
255
 
256
+ /**
257
+ * A sign-in done in a terminal, or an install, changes no agent config, so
258
+ * nothing re-probes on its own and the daily sweep is far off. Re-probe the
259
+ * unfinished agents of a type as soon as detection sees it become installed
260
+ * or signed in.
261
+ */
262
+ _probeNewlyReady(previous) {
263
+ const became = new Set((this._runtimes || []).filter((rt) => {
264
+ const before = previous.get(rt.type);
265
+ return before && ((rt.installed && !before.installed) || (rt.ready && !before.ready));
266
+ }).map((rt) => rt.type));
267
+ if (!became.size) return;
268
+ const due = this.config.getAgents().filter((a) => became.has(a.type)
269
+ && this._probes[a.name] && SETUP_INCOMPLETE.has(this._probes[a.name].code));
270
+ if (!due.length) return;
271
+ (async () => {
272
+ for (const a of due) {
273
+ try { await this._probeAgent(a.name); } catch {}
274
+ }
275
+ this._nodeHeartbeat();
276
+ })();
277
+ }
278
+
250
279
  /** Report a runtime install that failed while creating `name`, as its probe result. */
251
280
  _recordInstallFailure(name, type, error) {
252
281
  let install = null;
@@ -275,7 +304,8 @@ class Daemon {
275
304
  for (const a of this.config.getAgents()) {
276
305
  const last = this._probes[a.name];
277
306
  const age = last && last.at ? Date.now() - Date.parse(last.at) : Infinity;
278
- if (age < maxAgeMs) continue;
307
+ const limit = last && SETUP_INCOMPLETE.has(last.code) ? Math.max(maxAgeMs, SETUP_INCOMPLETE_MAX_AGE_MS) : maxAgeMs;
308
+ if (age < limit) continue;
279
309
  try { await this._probeAgent(a.name); } catch {}
280
310
  }
281
311
  this._nodeHeartbeat();
@@ -994,6 +1024,7 @@ class Daemon {
994
1024
  const order = types.length ? types : [...found.keys()];
995
1025
  this._runtimes = order.map((type) => found.get(type) || previous.get(type)).filter(Boolean);
996
1026
  this._cliModelsAfterDetection(previous);
1027
+ this._probeNewlyReady(previous);
997
1028
  }
998
1029
 
999
1030
  /**
package/src/probe.js CHANGED
@@ -34,7 +34,7 @@ const os = require('os');
34
34
  const { spawn } = require('./wsl');
35
35
  const { getEnhancedEnv } = require('./paths');
36
36
  const { shouldUseShellForBinary, REASON } = require('./adapters/health-status');
37
- const { decodeConsoleOutput, BENIGN_CLI_OUTPUT, stripCliNoise } = require('./adapters/utils');
37
+ const { decodeConsoleOutput, BENIGN_CLI_OUTPUT, stripCliNoise, redactSecrets } = require('./adapters/utils');
38
38
  const { formatAuthGuidance } = require('./auth-guidance');
39
39
  const { isCliLogin, stripForCliLogin, typeEnvFor } = require('./env');
40
40
  const { configuredModel } = require('./agent-model');
@@ -90,10 +90,15 @@ function installCommandFor(entry) {
90
90
  /** Redact anything that looks like a secret before output leaves the device. */
91
91
  function scrub(text) {
92
92
  if (!text) return '';
93
- return String(text)
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 ****');
98
+ // Then everything the adapters strip from quoted CLI text: a Codex probe
99
+ // that failed after printing a token-shaped blob showed that blob as its
100
+ // reason, on the device card in the workspace.
101
+ return redactSecrets(masked);
97
102
  }
98
103
 
99
104
  function tail(text, cap) {
@@ -133,7 +138,11 @@ function classifyOutputText(text) {
133
138
  // — the one misreading that sends a user to re-authenticate a working key.
134
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;
135
140
  if (/rate[- ]?limit|too many requests|\b429\b|overloaded|\b529\b/.test(text)) return CODE.RATE_LIMITED;
136
- 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;
137
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;
138
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;
139
148
  // A sign-in that exists but has run out — Claude Code: "Failed to
@@ -346,6 +355,25 @@ function shellQuoted(binary, shell) {
346
355
  return shell && !/^".*"$/.test(binary) ? `"${binary}"` : binary;
347
356
  }
348
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
+
349
377
  /**
350
378
  * The one line worth reporting from a failed run.
351
379
  *
@@ -355,8 +383,15 @@ function shellQuoted(binary, shell) {
355
383
  * with the timeout named first.
356
384
  */
357
385
  function failureMessage(res, code, timeoutMs) {
358
- const lines = (s) => String(s || '').split(/\r?\n/).map((l) => l.trim())
359
- .filter((l) => l && !BENIGN_OUTPUT.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));
360
395
  const all = [...lines(res.stderr), ...lines(res.stdout)];
361
396
  const telling = all.find((l) => classifyOutputText(l.toLowerCase()) === code);
362
397
  const detail = tail(telling || lines(res.stderr).join('\n') || lines(res.stdout).join('\n'), OUTPUT_CAP);
@@ -660,4 +695,4 @@ async function probeAgentType(connector, type, opts = {}) {
660
695
  });
661
696
  }
662
697
 
663
- module.exports = { probeAgentType, classifyFailure, buildGuidance, authFlavor, installCommandFor, scrub, CODE, DEFAULT_TIMEOUT_MS };
698
+ module.exports = { probeAgentType, classifyFailure, buildGuidance, authFlavor, installCommandFor, scrub, failureMessage, CODE, DEFAULT_TIMEOUT_MS };
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 —
@@ -154,7 +170,7 @@ async function testLLMConnection(env, opts = {}) {
154
170
  max_tokens: 32,
155
171
  messages: [{ role: 'user', content: 'Say hi in 5 words.' }],
156
172
  });
157
- const res = await request(url, { headers, body });
173
+ const res = await requestCompletion(url, { headers, body });
158
174
  return completionResult(res, { isAnthropic: true, model });
159
175
  }
160
176
 
@@ -183,7 +199,7 @@ async function testLLMConnection(env, opts = {}) {
183
199
  };
184
200
  if (hasKimiConfig) requestBody.max_tokens = 32;
185
201
  else requestBody.max_completion_tokens = 32;
186
- const res = await request(`${baseUrl}/chat/completions`, { headers, body: JSON.stringify(requestBody) });
202
+ const res = await requestCompletion(`${baseUrl}/chat/completions`, { headers, body: JSON.stringify(requestBody) });
187
203
  last = completionResult(res, { isAnthropic: false, model: candidate });
188
204
  if (last.success) return last;
189
205
  // Only a model WE picked moves on to the next one. A configured model is