@openagents-org/agent-launcher 0.2.209 → 0.2.210

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.209",
3
+ "version": "0.2.210",
4
4
  "description": "OpenAgents Launcher — install, configure, and run AI coding agents from your terminal",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1868,7 +1868,7 @@ class BaseAdapter {
1868
1868
  async cleanupTodos(channel) {
1869
1869
  try {
1870
1870
  const result = await this.client.getTodos(this.workspaceId, channel, this.token, {
1871
- all: false,
1871
+ all: false, source: `openagents:${this.agentName}`,
1872
1872
  });
1873
1873
  const todos = (result && result.todos) || [];
1874
1874
  const hasActive = todos.some((t) => t.status === 'pending' || t.status === 'in_progress');
@@ -1889,10 +1889,13 @@ class BaseAdapter {
1889
1889
  async getRemainingTodos(channel) {
1890
1890
  try {
1891
1891
  const result = await this.client.getTodos(this.workspaceId, channel, this.token, {
1892
- all: false,
1892
+ all: false, source: `openagents:${this.agentName}`,
1893
1893
  });
1894
1894
  const todos = (result && result.todos) || [];
1895
- return todos.filter((t) => t.status === 'pending' || t.status === 'in_progress');
1895
+ // Defend against older endpoints returning the entire channel's list.
1896
+ return todos.filter((t) => (!t.created_by || t.created_by === `openagents:${this.agentName}`)
1897
+ && (!t.assignee || t.assignee === this.agentName || t.assignee === `openagents:${this.agentName}`)
1898
+ && (t.status === 'pending' || t.status === 'in_progress'));
1896
1899
  } catch {
1897
1900
  return [];
1898
1901
  }
@@ -25,6 +25,7 @@ const { formatAttachmentsForPrompt, SESSION_DEFAULT_RE, generateSessionTitle, st
25
25
  const { buildClaudeSystemPrompt, buildClaudeSkillMd, buildPinnedSections, workspaceSkillName } = require('./workspace-prompt');
26
26
  const { pinnedFingerprint, sampleRecap } = require('./decision-log');
27
27
  const { defaultAgentWorkdir, whichBinary, whereBinary } = require('../paths');
28
+ const { isPostinstallStub } = require('../postinstall-stub');
28
29
 
29
30
  const IS_WINDOWS = process.platform === 'win32';
30
31
 
@@ -54,6 +55,13 @@ class ClaudeAdapter extends BaseAdapter {
54
55
  * for envs saved by an older launcher or coming from anywhere else. Only
55
56
  * for a NON-official base — api.anthropic.com wants x-api-key.
56
57
  *
58
+ * 3. Turn MCP tool search off behind a relay (ENABLE_TOOL_SEARCH=false).
59
+ * Claude Code 2.1.304 made it the default behind a custom base URL, and
60
+ * the deferred-tool content blocks it sends are rejected by relays whose
61
+ * schema predates them (422 "unknown variant `tool_definition`, expected
62
+ * `tool_reference`"). Newer CLIs retry without it, but only after the
63
+ * rejected request, on every turn. A value the user set is left alone.
64
+ *
57
65
  * @param {Record<string, string>} baseEnv
58
66
  * @returns {Record<string, string>}
59
67
  */
@@ -75,15 +83,17 @@ class ClaudeAdapter extends BaseAdapter {
75
83
  }
76
84
 
77
85
  const base = (env.ANTHROPIC_BASE_URL || '').trim();
86
+ if (!base) return env;
87
+ let official = false;
88
+ try {
89
+ const host = new URL(base).hostname.toLowerCase();
90
+ official = host === 'anthropic.com' || host.endsWith('.anthropic.com');
91
+ } catch { official = false; }
92
+ if (official) return env;
93
+
78
94
  const key = (env.ANTHROPIC_API_KEY || '').trim();
79
- if (key && base && !(env.ANTHROPIC_AUTH_TOKEN || '').trim()) {
80
- let official = false;
81
- try {
82
- const host = new URL(base).hostname.toLowerCase();
83
- official = host === 'anthropic.com' || host.endsWith('.anthropic.com');
84
- } catch { official = false; }
85
- if (!official) env.ANTHROPIC_AUTH_TOKEN = key;
86
- }
95
+ if (key && !(env.ANTHROPIC_AUTH_TOKEN || '').trim()) env.ANTHROPIC_AUTH_TOKEN = key;
96
+ if (!(env.ENABLE_TOOL_SEARCH || '').trim()) env.ENABLE_TOOL_SEARCH = 'false';
87
97
  return env;
88
98
  }
89
99
 
@@ -463,6 +473,7 @@ class ClaudeAdapter extends BaseAdapter {
463
473
  if (!claudeBin) {
464
474
  throw new Error('claude CLI not found. Install with: curl -fsSL https://claude.ai/install.sh | bash');
465
475
  }
476
+ if (isPostinstallStub(claudeBin)) throw new Error(ClaudeAdapter.INSTALL_INCOMPLETE);
466
477
 
467
478
  // The builder emits the correct tool-reference block for toolMode directly
468
479
  // (mcp → workspace_* tools, skills → openagents-workspace skill), so there
@@ -1191,7 +1202,10 @@ class ClaudeAdapter extends BaseAdapter {
1191
1202
  return null;
1192
1203
  }
1193
1204
  try {
1194
- const remaining = await this.getRemainingTodos(msgChannel);
1205
+ // Pending includes work waiting for a human or an earlier step.
1206
+ // Only explicitly active work is eligible for automatic continuation.
1207
+ const remaining = (await this.getRemainingTodos(msgChannel))
1208
+ .filter((todo) => todo.status === 'in_progress');
1195
1209
  if (remaining.length === 0) return null;
1196
1210
  const items = remaining.map((t) => `- ${t.content}`).join('\n');
1197
1211
  return {
@@ -1513,7 +1527,14 @@ class ClaudeAdapter extends BaseAdapter {
1513
1527
  break;
1514
1528
  } catch (e) {
1515
1529
  this._log(`Error handling message: ${e.message}`);
1516
- await this.sendError(msgChannel, `Error processing message: ${this._redact(e.message)}`);
1530
+ // EFTYPE: Windows refused to start the file as a program — in practice
1531
+ // the claude-code package's placeholder claude.exe, left behind when
1532
+ // its install script was skipped. The bare errno named nothing a user
1533
+ // could act on.
1534
+ const reason = (e && e.code === 'EFTYPE') || /\bEFTYPE\b/.test(String(e && e.message))
1535
+ ? ClaudeAdapter.INSTALL_INCOMPLETE
1536
+ : `Error processing message: ${this._redact(e.message)}`;
1537
+ await this.sendError(msgChannel, reason);
1517
1538
  break;
1518
1539
  }
1519
1540
  }
@@ -1524,4 +1545,17 @@ class ClaudeAdapter extends BaseAdapter {
1524
1545
  }
1525
1546
  }
1526
1547
 
1548
+ /**
1549
+ * @anthropic-ai/claude-code ships a placeholder where its native binary goes
1550
+ * and swaps the real one in from a postinstall script. With that script
1551
+ * skipped (`ignore-scripts=true` in an npmrc, pnpm, bun) the placeholder is
1552
+ * what runs: shell text on macOS/Linux, and on Windows a `claude.exe` the OS
1553
+ * will not start (spawn EFTYPE).
1554
+ */
1555
+ ClaudeAdapter.INSTALL_INCOMPLETE = 'Claude Code is installed, but its setup never finished: the '
1556
+ + '@anthropic-ai/claude-code package\'s postinstall script did not run (npm `ignore-scripts`, or a '
1557
+ + 'pnpm/bun install), so the `claude` command is only a placeholder. Reinstall Claude Code from the '
1558
+ + 'launcher — or, for a copy you installed yourself, run '
1559
+ + '`npm install -g @anthropic-ai/claude-code --ignore-scripts=false` — then retry.';
1560
+
1527
1561
  module.exports = ClaudeAdapter;
@@ -403,6 +403,7 @@ class CodexAdapter extends BaseAdapter {
403
403
  const fullPrompt = `${context}\n\n---\n\nUser message:\n${content}${this._attachmentInstructions(attachments)}`;
404
404
 
405
405
  // Run up to 2 attempts: first with resume, then fresh if stale
406
+ let relocated = false;
406
407
  for (let attempt = 0; attempt < 2; attempt++) {
407
408
  const cmd = [this._codexBin, 'exec'];
408
409
 
@@ -478,6 +479,22 @@ class CodexAdapter extends BaseAdapter {
478
479
  return;
479
480
  }
480
481
  } catch (e) {
482
+ // The binary was looked up once, when the adapter started. A reinstall
483
+ // or update since then can move or remove it, and every turn failed
484
+ // with "spawn …/.bin/codex ENOENT" until the agent was restarted.
485
+ // Look again and rerun this attempt once.
486
+ if (e && e.code === 'ENOENT' && !relocated) {
487
+ relocated = true;
488
+ const found = this._findCodexBinary();
489
+ if (found) {
490
+ this._log(`Codex binary moved: ${this._codexBin} → ${found}`);
491
+ this._codexBin = found;
492
+ attempt--;
493
+ continue;
494
+ }
495
+ await this.sendError(msgChannel, "⚠️ **Codex couldn't run** — the Codex CLI is no longer installed on this device. Reinstall it from OpenAgents Launcher (Agents → Codex), then try again.");
496
+ return;
497
+ }
481
498
  this._log(`Error in subprocess: ${e.message}`);
482
499
  await this.sendError(msgChannel, `⚠️ **Codex couldn't run** — ${CodexAdapter._redact(e.message)}`);
483
500
  return;
@@ -730,14 +747,43 @@ class CodexAdapter extends BaseAdapter {
730
747
  * turn.failed / error event message → stderr tail → exit code. Redacted.
731
748
  */
732
749
  static _failureDetail({ errorMessage, stderr, exitCode } = {}) {
733
- const stderrTail = String(stderr || '').trim().split('\n').slice(-5).join('\n').trim();
734
750
  const raw = String(errorMessage || '').trim()
735
- || stderrTail
751
+ || CodexAdapter._stderrReason(stderr)
736
752
  || (exitCode ? `codex exited with code ${exitCode}` : '');
737
753
  const detail = CodexAdapter._explain(CodexAdapter._unwrap(raw));
738
754
  return CodexAdapter._redact(detail).slice(0, 500).trim();
739
755
  }
740
756
 
757
+ /**
758
+ * The part of codex's stderr that says why the run died.
759
+ *
760
+ * codex logs through `tracing` on stderr — `2026-10-27T04:08:56.500Z WARN
761
+ * codex_skills::interface: …` — and echoes "Reading prompt from stdin..."
762
+ * (or "Reading additional input from stdin...").
763
+ * A plain tail of the last lines was mostly that noise, so a usage limit or
764
+ * a model the account cannot use reached the chat buried under plugin-cache
765
+ * and skill-icon warnings. Lines the CLI printed for a person win; failing
766
+ * those, the ERROR records with their timestamp and module stripped; only
767
+ * when neither exists does the raw tail stand.
768
+ */
769
+ static _stderrReason(stderr) {
770
+ const lines = String(stderr || '').split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
771
+ if (!lines.length) return '';
772
+ const TRACE = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN|ERROR)\s+(?:[\w:]+:\s+)?(.*)$/;
773
+ const plain = [];
774
+ const errors = [];
775
+ for (const line of lines) {
776
+ const m = line.match(TRACE);
777
+ if (!m) {
778
+ if (!/^Reading (prompt|additional input) from stdin/i.test(line)) plain.push(line);
779
+ } else if (m[1] === 'ERROR' && m[2] && !errors.includes(m[2])) {
780
+ errors.push(m[2]);
781
+ }
782
+ }
783
+ const picked = plain.length ? plain : errors;
784
+ return (picked.length ? picked : lines).slice(-5).join('\n').trim();
785
+ }
786
+
741
787
  /**
742
788
  * Unwrap the API's JSON error envelope so the user reads the sentence, not
743
789
  * the transport. The backend rejects a run with a body like
@@ -638,7 +638,10 @@ class CursorAdapter extends BaseAdapter {
638
638
  // BaseAdapter._handleUserStop cancels the plan before announcing.
639
639
  } else if (!msg._todoNudge) {
640
640
  try {
641
- const remaining = await this.getRemainingTodos(msgChannel);
641
+ // Pending includes work waiting for a human or an earlier step.
642
+ // Only explicitly active work is eligible for automatic continuation.
643
+ const remaining = (await this.getRemainingTodos(msgChannel))
644
+ .filter((todo) => todo.status === 'in_progress');
642
645
  if (remaining.length > 0) {
643
646
  const items = remaining.map((t) => `- ${t.content}`).join('\n');
644
647
  const nudge = `You have ${remaining.length} remaining task(s) from your plan:\n${items}\n\nPlease continue working on them.`;
@@ -653,9 +656,8 @@ class CursorAdapter extends BaseAdapter {
653
656
  });
654
657
  }
655
658
  } catch {}
656
- } else {
657
- try { await this.cleanupTodos(msgChannel); } catch {}
658
659
  }
660
+ // Finishing a reminder does not cancel tasks waiting for user input.
659
661
 
660
662
  if (stoppedByUser) {
661
663
  this._stoppingChannels.delete(msgChannel);
@@ -240,9 +240,15 @@ function decodeConsoleOutput(buf, isWindows = process.platform === 'win32') {
240
240
  * they hid the real one. Claude Code warns about its claude.ai connectors
241
241
  * whenever a key is set, and about a model it does not know (any relay model:
242
242
  * glm, kimi, …) — "…so it assumes a context window of 200000 tokens … Until
243
- * then auto-compact keeps this session within 200k tokens".
243
+ * then auto-compact keeps this session within 200k tokens". Codex does the
244
+ * same for a model missing from its catalog: "warning: Model metadata for
245
+ * `gpt-5.5` not found. Defaulting to fallback metadata…", and logs every
246
+ * run's housekeeping as timestamped WARN/INFO records plus "Reading prompt
247
+ * from stdin...", which filled the smoke test's timeout message. Node's own
248
+ * process warnings ("(node:1234) Warning: …", "(Use `node --trace-warnings
249
+ * ...`") come ahead of the real error from npm-shipped CLIs like CodeBuddy.
244
250
  */
245
- const BENIGN_CLI_OUTPUT = /claude\.ai connectors are disabled|doesn't recognize the model|assumes a context window|auto-compact keeps this session|CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT/i;
251
+ const BENIGN_CLI_OUTPUT = /claude\.ai connectors are disabled|doesn't recognize the model|assumes a context window|auto-compact keeps this session|CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT|Model metadata for .* not found|Defaulting to fallback metadata|^\s*Reading (prompt|additional input) from stdin|^\s*\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN)\s|^\s*\(node:\d+\) (\[\w+\] )?\w*Warning:|^\s*\(Use `node --trace-(warnings|deprecation) \.\.\.`/i;
246
252
 
247
253
  /** CLI output with the known-harmless lines taken out. */
248
254
  function stripCliNoise(text) {
@@ -524,6 +524,12 @@ function buildApiSkillsPrompt({ endpoint, workspaceId, token, agentName, channel
524
524
  'Create or update your to-do list to track progress. The entire list ' +
525
525
  'is replaced each time (send the full list with current statuses).\n\n' +
526
526
  '**Status values:** `pending`, `in_progress`, `completed`\n\n' +
527
+ 'Use `in_progress` only for work you can actively execute now. Before ending a turn, ' +
528
+ 'move tasks waiting for human input, approval, login, or dependencies back to `pending`. ' +
529
+ 'Set the actual assignee when another person or agent owns the next action. ' +
530
+ 'Only your own `in_progress` tasks may automatically continue after a reply; ' +
531
+ 'pending tasks stay visible but do not wake you. When the required input arrives, ' +
532
+ 'mark the relevant task `in_progress` and resume it.\n\n' +
527
533
  '**Update your to-do list:**\n' +
528
534
  `\`${curl} -s -X PUT -H "${h}" -H "Content-Type: application/json" ` +
529
535
  `${baseUrl}/v1/todos -d '{"todos":[` +
@@ -532,7 +538,7 @@ function buildApiSkillsPrompt({ endpoint, workspaceId, token, agentName, channel
532
538
  `],"network":"${workspaceId}","channel":"${channelName}",` +
533
539
  `"source":"openagents:${agentName}"}'\`\n\n` +
534
540
  '**Get your to-do list:**\n' +
535
- `\`${curl} -s -H "${h}" "${baseUrl}/v1/todos?network=${workspaceId}&channel=${channelName}"\`\n\n` +
541
+ `\`${curl} -s -H "${h}" "${baseUrl}/v1/todos?network=${workspaceId}&channel=${channelName}&source=openagents%3A${encodeURIComponent(agentName)}"\`\n\n` +
536
542
  '**IMPORTANT:** When you receive a task with multiple steps or a list of things to do, ' +
537
543
  'ALWAYS create a to-do list first before starting work. This lets the user see your ' +
538
544
  'progress in real time. Update statuses as you work through each item.\n' +
package/src/installer.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
- const { execSync, exec, execFile, spawnSync } = require('child_process');
6
+ const { execSync, execFileSync, exec, execFile, spawnSync } = require('child_process');
7
7
  const {
8
8
  whichBinary,
9
9
  getEnhancedEnv,
@@ -19,7 +19,8 @@ const {
19
19
  const { isWslBinary, bridgedCommandString, wslHomeUnc } = require('./wsl');
20
20
  const { canBlock } = require('./probe-mode');
21
21
  const { EnvManager } = require('./env');
22
- const { nodeDistUrls, installRegistry } = require('./mirrors');
22
+ const { nodeDistUrls, installRegistry, userConfiguredRegistry } = require('./mirrors');
23
+ const { resolveInstallableVersion, fetchPackument, unpinnedPackage } = require('./node-engines');
23
24
  const { readinessReason, REASON } = require('./adapters/health-status');
24
25
  const { resolveCursorNodeEntry } = require('./adapters/cursor-node-entry');
25
26
  const { checkInstallPrereqs, missingPrereqError } = require('./install-preflight');
@@ -1589,6 +1590,12 @@ class Installer {
1589
1590
  // on next install). --registry is added only when we'd be helping — see
1590
1591
  // installRegistry(); a user's own registry choice is never overridden.
1591
1592
  const registry = installRegistry();
1593
+ const direct = this._resolveNodeNpmCli();
1594
+ // `latest` may need a Node newer than the one that will run it.
1595
+ if (direct) {
1596
+ const held = await this._holdBackForNode(pkgArgs, direct.node, registry, onData);
1597
+ pkgArgs.splice(0, pkgArgs.length, ...held);
1598
+ }
1592
1599
  // The verbose log stays: it is the install's progress, and the output the
1593
1600
  // stall watchdog below waits on.
1594
1601
  const npmArgs = [
@@ -1598,7 +1605,6 @@ class Installer {
1598
1605
  ];
1599
1606
  displayCmd = `npm ${npmArgs.join(' ')}`;
1600
1607
 
1601
- const direct = this._resolveNodeNpmCli();
1602
1608
  if (direct) {
1603
1609
  spawnFile = direct.node;
1604
1610
  spawnArgs = [direct.npmCli, ...npmArgs];
@@ -2671,6 +2677,46 @@ class Installer {
2671
2677
  return false;
2672
2678
  }
2673
2679
 
2680
+ /**
2681
+ * Swap an unpinned package (`pkg`, `pkg@latest`) for the newest release
2682
+ * whose `engines.node` accepts the Node that will run it. openclaw raises
2683
+ * its floor without notice (2026.10.6 wanted Node 24.22.1 while the runtime
2684
+ * was 24.21.0) and its preinstall exits 1 below it, so a workspace's remote
2685
+ * "create agent" — which installs here, not through the launcher's own
2686
+ * holdback — failed on every such machine. Anything uncertain (no Node
2687
+ * version, registry unreachable, unreadable range) leaves the args alone.
2688
+ *
2689
+ * @param {string[]} pkgArgs
2690
+ * @param {string} nodeBin the node npm runs under
2691
+ * @param {string|null} registry the `--registry` this install will use
2692
+ * @param {function(string)} [onData]
2693
+ * @returns {Promise<string[]>}
2694
+ */
2695
+ async _holdBackForNode(pkgArgs, nodeBin, registry, onData) {
2696
+ const pkgs = pkgArgs.filter((a) => !a.startsWith('-'));
2697
+ if (pkgs.length !== 1) return pkgArgs;
2698
+ const pkg = unpinnedPackage(pkgs[0]);
2699
+ if (!pkg) return pkgArgs;
2700
+ let nodeVersion;
2701
+ try {
2702
+ nodeVersion = execFileSync(nodeBin, ['-v'], { encoding: 'utf-8', timeout: 5000, windowsHide: true }).trim();
2703
+ } catch { return pkgArgs; }
2704
+ let info;
2705
+ try {
2706
+ info = await fetchPackument(registry || userConfiguredRegistry() || 'https://registry.npmjs.org', pkg);
2707
+ } catch { return pkgArgs; }
2708
+ const latest = info && info['dist-tags'] && info['dist-tags'].latest;
2709
+ const target = resolveInstallableVersion(info, nodeVersion);
2710
+ if (!latest || !target || target === latest) return pkgArgs;
2711
+ const range = info.versions && info.versions[latest] && info.versions[latest].engines
2712
+ && info.versions[latest].engines.node;
2713
+ if (onData) {
2714
+ onData(`${pkg}@${latest} requires Node ${range}, but agents here run on Node ${nodeVersion} — `
2715
+ + `installing ${target}, the newest release that supports it.\n\n`);
2716
+ }
2717
+ return pkgArgs.map((a) => (a === pkgs[0] ? `${pkg}@${target}` : a));
2718
+ }
2719
+
2674
2720
  /**
2675
2721
  * The Node.js the portable runtime gets — the same pin as the launcher's
2676
2722
  * bootstrap/node-version.ts, which owns upgrading an existing runtime; this
@@ -2682,7 +2728,7 @@ class Installer {
2682
2728
  const [major, minor] = String(release).split('.').map(Number);
2683
2729
  if (major < 22 || (major === 22 && minor < 6)) return 'v22.22.3';
2684
2730
  }
2685
- return 'v24.21.0';
2731
+ return 'v24.22.1';
2686
2732
  }
2687
2733
 
2688
2734
  /**
@@ -0,0 +1,173 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Which release of an npm agent can run on the Node that will run it.
5
+ *
6
+ * Every npm agent is installed and run on one Node — the portable runtime in
7
+ * ~/.openagents/nodejs. npm only warns when a package's `engines.node` rules
8
+ * that Node out, so `npm install <pkg>` happily fetches a `latest` the runtime
9
+ * cannot start, and some packages then refuse on their own: openclaw's
10
+ * preinstall exits 1 below its floor (2026.9.3 → Node 24.16, 2026.10.6 →
11
+ * 24.22.1). The launcher's Install button already held such packages back to
12
+ * the newest release that runs; a workspace's remote "create agent" goes
13
+ * through the daemon and this installer instead, and failed outright.
14
+ *
15
+ * Mirrors the launcher's main/agents/node-engines.ts + npm-registry.ts. The
16
+ * grammar read is what packages write in `engines.node`: comparators
17
+ * (>= > <= < =), bare and partial versions (22, 22.1, 22.x, *), caret, tilde,
18
+ * hyphen ranges and `||`. Anything else answers null ("can't tell"), which
19
+ * counts as compatible: a wrong "no" would hold an agent back for nothing.
20
+ */
21
+
22
+ const https = require('https');
23
+ const http = require('http');
24
+
25
+ const PARTIAL = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?$/;
26
+
27
+ function parsePartial(s) {
28
+ const m = PARTIAL.exec(s);
29
+ if (!m) return null;
30
+ const parts = [m[1], m[2], m[3]].map((p) => (p === undefined || /^[xX*]$/.test(p) ? null : Number(p)));
31
+ const wild = parts.indexOf(null);
32
+ return wild === -1 ? parts : parts.map((p, i) => (i < wild ? p : null));
33
+ }
34
+
35
+ function compare(a, b) {
36
+ for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
37
+ return 0;
38
+ }
39
+
40
+ /** One comparator as the [lo, hi) interval it allows, or null when unreadable. */
41
+ function toInterval(comparator) {
42
+ const m = /^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(comparator);
43
+ const parts = m && parsePartial(m[2]);
44
+ if (!m || !parts) return null;
45
+ const op = m[1] || '=';
46
+ const [major, minor, patch] = parts;
47
+ if (major === null) return op === '<' || op === '>' ? null : {};
48
+ const lo = [major, minor ?? 0, patch ?? 0];
49
+ const next = minor === null ? [major + 1, 0, 0]
50
+ : patch === null ? [major, minor + 1, 0]
51
+ : [major, minor, patch + 1];
52
+ switch (op) {
53
+ case '>=': return { lo };
54
+ case '>': return { lo: next };
55
+ case '<': return { hi: lo };
56
+ case '<=': return { hi: next };
57
+ case '~': return { lo, hi: minor === null ? [major + 1, 0, 0] : [major, minor + 1, 0] };
58
+ case '^': return {
59
+ lo,
60
+ hi: major > 0 || minor === null ? [major + 1, 0, 0]
61
+ : minor > 0 || patch === null ? [0, minor + 1, 0]
62
+ : [0, 0, patch + 1],
63
+ };
64
+ default: return { lo, hi: next };
65
+ }
66
+ }
67
+
68
+ function parseSet(set) {
69
+ const s = set.trim();
70
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(s);
71
+ const comparators = hyphen
72
+ ? [`>=${hyphen[1]}`, `<=${hyphen[2]}`]
73
+ : s.replace(/(>=|<=|>|<|=|\^|~)\s+/g, '$1').split(/\s+/).filter(Boolean);
74
+ const out = [];
75
+ for (const c of comparators) {
76
+ const interval = toInterval(c);
77
+ if (!interval) return null;
78
+ out.push(interval);
79
+ }
80
+ return out;
81
+ }
82
+
83
+ /** true / false when the range can be read, null when it can't. */
84
+ function nodeSatisfies(version, range) {
85
+ const v = parsePartial(String(version || '').trim());
86
+ if (!v || v.includes(null)) return null;
87
+ let unreadable = false;
88
+ for (const set of String(range).split('||')) {
89
+ const intervals = parseSet(set);
90
+ if (!intervals) { unreadable = true; continue; }
91
+ if (intervals.every(({ lo, hi }) => (!lo || compare(v, lo) >= 0) && (!hi || compare(v, hi) < 0))) return true;
92
+ }
93
+ return unreadable ? null : false;
94
+ }
95
+
96
+ function compareVersionsDesc(a, b) {
97
+ const pa = a.split('.').map((n) => parseInt(n, 10) || 0);
98
+ const pb = b.split('.').map((n) => parseInt(n, 10) || 0);
99
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
100
+ const x = pa[i] || 0;
101
+ const y = pb[i] || 0;
102
+ if (x !== y) return y - x;
103
+ }
104
+ return 0;
105
+ }
106
+
107
+ function nodeEngineRange(info, version) {
108
+ const range = info && info.versions && info.versions[version] && info.versions[version].engines
109
+ && info.versions[version].engines.node;
110
+ return typeof range === 'string' && range.trim() ? range : null;
111
+ }
112
+
113
+ /**
114
+ * The version to install on `nodeVersion`: `latest` when it accepts that Node,
115
+ * else the newest earlier stable release that does. `latest` comes back
116
+ * unchanged when the Node is unknown or nothing accepts it — npm or the
117
+ * package then says why in its own words.
118
+ */
119
+ function resolveInstallableVersion(info, nodeVersion) {
120
+ const versions = Object.keys((info && info.versions) || {});
121
+ const latest = (info && info['dist-tags'] && info['dist-tags'].latest)
122
+ || versions.filter((v) => /^\d/.test(v) && !v.includes('-')).sort(compareVersionsDesc)[0]
123
+ || null;
124
+ if (!latest || !nodeVersion) return latest;
125
+ const runs = (v) => {
126
+ const range = nodeEngineRange(info, v);
127
+ return !range || nodeSatisfies(nodeVersion, range) !== false;
128
+ };
129
+ if (runs(latest)) return latest;
130
+ const older = versions
131
+ .filter((v) => /^\d/.test(v) && !v.includes('-'))
132
+ .sort(compareVersionsDesc)
133
+ .find((v) => compareVersionsDesc(v, latest) > 0 && runs(v));
134
+ return older || latest;
135
+ }
136
+
137
+ /** npm's abbreviated packument: dist-tags plus each version's engines. */
138
+ function fetchPackument(registry, pkg, { timeoutMs = 10000 } = {}) {
139
+ const url = `${String(registry).replace(/\/+$/, '')}/${encodeURIComponent(pkg).replace('%40', '@')}`;
140
+ const get = (target, hops) => new Promise((resolve, reject) => {
141
+ const mod = target.startsWith('https:') ? https : http;
142
+ const req = mod.get(target, { headers: { Accept: 'application/vnd.npm.install-v1+json' } }, (res) => {
143
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location && hops < 3) {
144
+ res.resume();
145
+ get(new URL(res.headers.location, target).toString(), hops + 1).then(resolve, reject);
146
+ return;
147
+ }
148
+ if (res.statusCode !== 200) { res.resume(); reject(new Error(`HTTP ${res.statusCode}`)); return; }
149
+ let data = '';
150
+ res.setEncoding('utf-8');
151
+ res.on('data', (c) => { data += c; });
152
+ res.on('end', () => { try { resolve(JSON.parse(data)); } catch (e) { reject(e); } });
153
+ });
154
+ req.on('error', reject);
155
+ req.setTimeout(timeoutMs, () => req.destroy(new Error('npm registry timeout')));
156
+ });
157
+ return get(url, 0);
158
+ }
159
+
160
+ /** `openclaw`, `openclaw@latest`, `@scope/pkg@latest` → the package name; null for a pinned spec. */
161
+ function unpinnedPackage(arg) {
162
+ const m = /^(@[^/@\s]+\/[^@\s]+|[^@\s][^@\s]*)(?:@(.*))?$/.exec(String(arg || ''));
163
+ if (!m) return null;
164
+ const spec = m[2];
165
+ return spec === undefined || spec === '' || spec === 'latest' ? m[1] : null;
166
+ }
167
+
168
+ module.exports = {
169
+ nodeSatisfies,
170
+ resolveInstallableVersion,
171
+ fetchPackument,
172
+ unpinnedPackage,
173
+ };
package/src/probe.js CHANGED
@@ -538,6 +538,20 @@ async function probeAgentType(connector, type, opts = {}) {
538
538
  reply: tail(reply, REPLY_CAP),
539
539
  });
540
540
  }
541
+ // The model answered and the CLI then failed to exit — Claude Code held
542
+ // open by a hook or an MCP server reads "Timed out after 120s: Hi! What
543
+ // can I help you with?". Sign-in, endpoint and model all just worked, and
544
+ // chat runs the CLI as a long-lived process where exiting never matters.
545
+ // Only for output that reads as an answer, never as a retry or an error.
546
+ const looksLikeAnswer = reply && !classifyOutputText(output.toLowerCase())
547
+ && !/\b(error|errors|failed|failure|retrying|exception)\b/i.test(reply);
548
+ if (res.timedOut && !res.spawnError && looksLikeAnswer) {
549
+ return done({
550
+ ok: true, method: 'cli', code: CODE.OK,
551
+ message: `Responded (the CLI did not exit within ${Math.round(timeoutMs / 1000)}s)`,
552
+ reply: tail(reply, REPLY_CAP),
553
+ });
554
+ }
541
555
  let code = res.code === 0 && !res.timedOut && !res.spawnError
542
556
  ? CODE.EMPTY_RESPONSE
543
557
  : classifyFailure(output, res);
@@ -934,10 +934,11 @@ class WorkspaceClient {
934
934
  return data.data || data;
935
935
  }
936
936
 
937
- async getTodos(workspaceId, channelName, token, { agent, all } = {}) {
937
+ async getTodos(workspaceId, channelName, token, { agent, all, source } = {}) {
938
938
  const params = new URLSearchParams({ network: workspaceId });
939
939
  if (channelName) params.set('channel', channelName);
940
940
  if (agent) params.set('agent', agent);
941
+ if (source) params.set('source', source);
941
942
  if (all) params.set('all', 'true');
942
943
  const data = await this._get(`/v1/todos?${params}`, this._wsHeaders(token));
943
944
  return data.data || data;