@openagents-org/agent-launcher 0.2.208 → 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.
@@ -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
 
@@ -101,7 +111,7 @@ class ClaudeAdapter extends BaseAdapter {
101
111
  this._channelProcesses = {}; // channel → child process
102
112
  this._stoppingChannels = new Set();
103
113
  this._persistentProcs = {}; // channel → { proc, lineBuffer, pendingLines, idleTimer, messageResolve }
104
- // Knowledge pinning (decision log + glossary) lives in BaseAdapter; this
114
+ // Knowledge pinning (glossary) lives in BaseAdapter; this
105
115
  // adapter fetches directly in _handleMessage because the result also
106
116
  // drives the persistent-process staleness check.
107
117
  this._IDLE_TIMEOUT_MS = 60 * 60 * 1000; // 1 hour
@@ -458,11 +468,12 @@ class ClaudeAdapter extends BaseAdapter {
458
468
  return null;
459
469
  }
460
470
 
461
- _buildClaudeCmd(prompt, channelName, { skipResume = false, browserEnabled = false, decisionLog = null, glossary = null } = {}) {
471
+ _buildClaudeCmd(prompt, channelName, { skipResume = false, browserEnabled = false, glossary = null } = {}) {
462
472
  const claudeBin = this._findClaudeBinary();
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
@@ -475,7 +486,6 @@ class ClaudeAdapter extends BaseAdapter {
475
486
  model: this.modelLabel(),
476
487
  browserEnabled,
477
488
  toolMode: this.toolMode,
478
- decisionLog,
479
489
  glossary,
480
490
  });
481
491
 
@@ -576,7 +586,7 @@ class ClaudeAdapter extends BaseAdapter {
576
586
  mcpWriteTools.push(`${pfx}workspace_image_save`);
577
587
  }
578
588
  if (!this.disabledModules.has('knowledge')) {
579
- // The decision-log/glossary protocol instructs these by name — they
589
+ // The glossary protocol instructs these by name — they
580
590
  // must be callable or the pinned knowledge silently stops updating.
581
591
  mcpTools.push(`${pfx}workspace_list_knowledge`, `${pfx}workspace_read_knowledge`);
582
592
  mcpWriteTools.push(`${pfx}workspace_write_knowledge`);
@@ -1138,7 +1148,7 @@ class ClaudeAdapter extends BaseAdapter {
1138
1148
  try {
1139
1149
  await this.sendStatus(
1140
1150
  msgChannel,
1141
- 'Claude context reached its limit. Starting a fresh session from the channel recap and pinned decisions.'
1151
+ 'Claude context reached its limit. Starting a fresh session from the channel recap.'
1142
1152
  );
1143
1153
  } catch {}
1144
1154
  }
@@ -1192,7 +1202,10 @@ class ClaudeAdapter extends BaseAdapter {
1192
1202
  return null;
1193
1203
  }
1194
1204
  try {
1195
- 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');
1196
1209
  if (remaining.length === 0) return null;
1197
1210
  const items = remaining.map((t) => `- ${t.content}`).join('\n');
1198
1211
  return {
@@ -1222,16 +1235,15 @@ class ClaudeAdapter extends BaseAdapter {
1222
1235
  }
1223
1236
 
1224
1237
  /**
1225
- * The pinned decision log / glossary, rendered exactly as in the system
1238
+ * The pinned glossary, rendered exactly as in the system
1226
1239
  * prompt, framed as replacing the copy the running session started with.
1227
1240
  * Returns '' when nothing is pinned.
1228
1241
  */
1229
- _pinnedUpdatePreamble(msgChannel, decisionLog, glossary) {
1242
+ _pinnedUpdatePreamble(msgChannel, glossary) {
1230
1243
  const sections = buildPinnedSections({
1231
1244
  toolMode: this.toolMode,
1232
1245
  channelName: msgChannel,
1233
1246
  mode: this._mode,
1234
- decisionLog,
1235
1247
  glossary,
1236
1248
  }).join('').trim();
1237
1249
  if (!sections) return '';
@@ -1313,23 +1325,18 @@ class ClaudeAdapter extends BaseAdapter {
1313
1325
 
1314
1326
  await this.sendStatus(msgChannel, 'thinking...');
1315
1327
 
1316
- // Read the channel's pinned knowledge (decision log + glossary) up front
1317
- // — the fast-path staleness check and any (re)spawn below both need it.
1318
- const decisions = await this._fetchDecisionLog(msgChannel);
1328
+ // Read the channel's pinned knowledge (glossary) up front — the
1329
+ // fast-path staleness check and any (re)spawn below both need it.
1319
1330
  const glossary = await this._fetchGlossary(msgChannel);
1320
1331
  // null fingerprint = a fetch failed, current state unknown; never treat
1321
1332
  // that as a change (it would churn respawns on every workspace hiccup).
1322
1333
  // The fingerprint covers entry ids AND content — both are pinned into
1323
1334
  // the prompt, and a recreated entry can change id without changing content.
1324
- const pinnedHash = (decisions.error || glossary.error)
1335
+ const pinnedHash = glossary.error
1325
1336
  ? null
1326
1337
  : pinnedFingerprint([
1327
- { entryId: decisions.entryId, content: decisions.content },
1328
1338
  { entryId: glossary.entryId, content: glossary.content },
1329
1339
  ]);
1330
- const decisionLogOpt = decisions.available
1331
- ? { enabled: true, state: decisions.state, entryId: decisions.entryId, content: decisions.error ? '' : (decisions.content || '') }
1332
- : null;
1333
1340
  const glossaryOpt = (glossary.available && glossary.state === 'found' && glossary.content)
1334
1341
  ? { enabled: true, entryId: glossary.entryId, content: glossary.content, scope: glossary.scope || 'channel' }
1335
1342
  : null;
@@ -1357,15 +1364,14 @@ class ClaudeAdapter extends BaseAdapter {
1357
1364
  : `Model changed to ${this.workspaceModel || '(default)'} for ${msgChannel} — respawning with resume`);
1358
1365
  await this._killPersistentProc(msgChannel);
1359
1366
  } else {
1360
- // A pinned-knowledge change no longer restarts the process. Agents
1361
- // edit the decision log themselves on nearly every decision, and the
1367
+ // A pinned-knowledge change no longer restarts the process. The
1362
1368
  // restart killed whatever they had running in the background (a
1363
1369
  // sub-agent mid-build) and replayed into a false "agent hit an error".
1364
1370
  // The new version rides in with this message instead and supersedes
1365
1371
  // the copy baked into the system prompt.
1366
1372
  let turnContent = content;
1367
1373
  if (pinnedStale) {
1368
- const update = this._pinnedUpdatePreamble(msgChannel, decisionLogOpt, glossaryOpt);
1374
+ const update = this._pinnedUpdatePreamble(msgChannel, glossaryOpt);
1369
1375
  if (update) turnContent = `${update}\n\n---\n\n${content}`;
1370
1376
  existingPP.pinnedHash = pinnedHash;
1371
1377
  this._log(`Pinned knowledge changed for ${msgChannel} — passing the update to the running session`);
@@ -1435,7 +1441,6 @@ class ClaudeAdapter extends BaseAdapter {
1435
1441
  const built = this._buildClaudeCmd(effectiveContent, msgChannel, {
1436
1442
  skipResume: attempt > 0,
1437
1443
  browserEnabled,
1438
- decisionLog: decisionLogOpt,
1439
1444
  glossary: glossaryOpt,
1440
1445
  });
1441
1446
  cmd = built.cmd;
@@ -1454,7 +1459,6 @@ class ClaudeAdapter extends BaseAdapter {
1454
1459
  // When the fetch errored (pinnedHash null) hash what was actually
1455
1460
  // pinned, so the next successful fetch triggers a re-pin.
1456
1461
  pp.pinnedHash = pinnedHash !== null ? pinnedHash : pinnedFingerprint([
1457
- { entryId: decisionLogOpt && decisionLogOpt.entryId, content: decisionLogOpt && decisionLogOpt.content },
1458
1462
  { entryId: glossaryOpt && glossaryOpt.entryId, content: glossaryOpt && glossaryOpt.content },
1459
1463
  ]);
1460
1464
  pp.spawnMode = this._mode;
@@ -1490,7 +1494,7 @@ class ClaudeAdapter extends BaseAdapter {
1490
1494
  try {
1491
1495
  await this.sendStatus(
1492
1496
  msgChannel,
1493
- 'Claude session could not be resumed. Rebuilding context from the channel recap and pinned decisions.'
1497
+ 'Claude session could not be resumed. Rebuilding context from the channel recap.'
1494
1498
  );
1495
1499
  } catch {}
1496
1500
  continue;
@@ -1523,7 +1527,14 @@ class ClaudeAdapter extends BaseAdapter {
1523
1527
  break;
1524
1528
  } catch (e) {
1525
1529
  this._log(`Error handling message: ${e.message}`);
1526
- 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);
1527
1538
  break;
1528
1539
  }
1529
1540
  }
@@ -1534,4 +1545,17 @@ class ClaudeAdapter extends BaseAdapter {
1534
1545
  }
1535
1546
  }
1536
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
+
1537
1561
  module.exports = ClaudeAdapter;
@@ -50,7 +50,7 @@ class CodexAdapter extends BaseAdapter {
50
50
  constructor(opts) {
51
51
  super(opts);
52
52
  this.disabledModules = opts.disabledModules || new Set();
53
- // Pin the channel's decision log + glossary into the system prompt.
53
+ // Pin the channel's glossary into the system prompt.
54
54
  this._usesPinnedContext = true;
55
55
 
56
56
  const env = this.agentEnv || process.env;
@@ -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
@@ -87,7 +87,7 @@ class CopilotAdapter extends BaseAdapter {
87
87
  constructor(opts) {
88
88
  super(opts);
89
89
  this.disabledModules = opts.disabledModules || new Set();
90
- // Pin the channel's decision log + glossary into the system prompt.
90
+ // Pin the channel's glossary into the system prompt.
91
91
  this._usesPinnedContext = true;
92
92
 
93
93
  const env = this.agentEnv || process.env;
@@ -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);
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * Pure helpers for knowledge pinning ("constraint pinning").
3
3
  *
4
- * Two kinds of knowledge entries get pinned into agent prompts:
5
- * - The decision log: a per-channel entry recording every decision the user
6
- * has confirmed.
7
- * - The glossary: a per-channel (or workspace-wide) entry defining shared
8
- * terms and fields, so agents collaborating on the same spec cannot drift
9
- * into different readings of the same name.
4
+ * The glossary — a per-channel (or workspace-wide) entry defining shared
5
+ * terms and fields — is pinned into agent prompts, so agents collaborating
6
+ * on the same spec cannot drift into different readings of the same name.
7
+ * (Agents used to keep a per-channel "Decisions for channel …" log too; that
8
+ * was removed because it created a knowledge page for nearly every thread.)
10
9
  *
11
10
  * Adapters re-read the pinned entries on every message and inject them into
12
11
  * the prompt — the only position that survives both auto-compaction and a
@@ -25,18 +24,10 @@ const RECAP_LINE_MAX_CHARS = 2000;
25
24
  const PINNED_DECISIONS_MAX_CHARS = 4000;
26
25
 
27
26
  /**
28
- * Canonical knowledge-entry title for a channel's decision log. The slug the
27
+ * Canonical knowledge-entry title for a channel's glossary. The slug the
29
28
  * backend derives from it is NOT stable (collisions get a numeric suffix), so
30
29
  * lookups must match on this exact title, never on the slug.
31
30
  */
32
- function decisionLogTitle(channelName) {
33
- return `Decisions for channel ${channelName}`;
34
- }
35
-
36
- /**
37
- * Canonical knowledge-entry title for a channel's glossary. Same exact-title
38
- * matching rules as the decision log.
39
- */
40
31
  function glossaryTitle(channelName) {
41
32
  return `Glossary for channel ${channelName}`;
42
33
  }
@@ -101,11 +92,6 @@ function pickEntryByTitle(entries, title) {
101
92
  return { entry: sorted[0], duplicates: matches.length - 1 };
102
93
  }
103
94
 
104
- /** Back-compat wrapper: pick a channel's decision-log entry by its title. */
105
- function pickDecisionEntry(entries, channelName) {
106
- return pickEntryByTitle(entries, decisionLogTitle(channelName));
107
- }
108
-
109
95
  /**
110
96
  * Fit the decision log into a character budget without ever cutting a line
111
97
  * in half. Over budget, whole lines are kept from the head (earliest
@@ -209,12 +195,10 @@ module.exports = {
209
195
  PINNED_DECISIONS_MAX_CHARS,
210
196
  RECAP_LINE_MAX_CHARS,
211
197
  WORKSPACE_GLOSSARY_TITLE,
212
- decisionLogTitle,
213
198
  glossaryTitle,
214
199
  hashDecisions,
215
200
  decisionFingerprint,
216
201
  pinnedFingerprint,
217
- pickDecisionEntry,
218
202
  pickEntryByTitle,
219
203
  renderPinnedDecisions,
220
204
  isRecapEligible,
@@ -66,10 +66,20 @@ const NODE_MIN_22 = [22, 19, 0];
66
66
  const ROW = {
67
67
  AGENT_DEFAULT_MODEL: 'agent-default-model',
68
68
  APPROVAL: 'approval',
69
+ LLM_PI_AI: 'llm-pi-ai',
69
70
  PERMISSION: 'permission',
70
71
  USER_QUESTIONS: 'user-questions',
71
72
  };
72
73
 
74
+ /** The pi-ai route an OpenAI-compatible gateway is served through. */
75
+ const GATEWAY_PROVIDER = 'openai-gateway';
76
+
77
+ /** The model a gateway route runs when none is configured. */
78
+ const DEFAULT_GATEWAY_MODEL = 'deepseek-v4-flash';
79
+
80
+ /** Where DeepSeek's own model list is read (its OpenAI-style root). */
81
+ const DEEPSEEK_MODELS_BASE = 'https://api.deepseek.com/v1';
82
+
73
83
  /** Permission modes dsh's `permission-presets` row declares. */
74
84
  const PERMISSION_MODES = ['read-only', 'workspace-write', 'danger-full-access'];
75
85
 
@@ -380,12 +390,14 @@ function yamlScalar(value) {
380
390
  * `never` is what gives non-interactive execution that is still confined to
381
391
  * the workspace for writes. (Reads are not confined in any mode.)
382
392
  * 3. The model/provider override, since `agent-default-model` is a composition
383
- * row rather than an environment variable.
393
+ * row rather than an environment variable. For an OpenAI-compatible
394
+ * gateway (`gatewayBaseUrl`) that is a pi-ai chat-completions route plus
395
+ * the default model pointing at it — see classifyDshEndpoint.
384
396
  *
385
397
  * A patch REPLACES the targeted row's whole `config`, so each row below is
386
398
  * written out complete rather than as a partial merge.
387
399
  */
388
- function buildPrivatePatch({ model, provider, permissionMode } = {}) {
400
+ function buildPrivatePatch({ model, provider, permissionMode, gatewayBaseUrl } = {}) {
389
401
  const mode = normalizePermissionMode(permissionMode) || 'workspace-write';
390
402
  const sandboxFor = (m) => (m === 'read-only' ? 'read-only' : m === 'danger-full-access' ? 'danger-full-access' : 'workspace-write');
391
403
 
@@ -412,7 +424,28 @@ function buildPrivatePatch({ model, provider, permissionMode } = {}) {
412
424
  lines.push(' approval: never');
413
425
  }
414
426
 
415
- if (model || provider) {
427
+ if (gatewayBaseUrl) {
428
+ // An OpenAI-compatible gateway has no Messages API for dsh's DeepSeek
429
+ // provider to call, so the run goes through dsh's pi-ai provider instead,
430
+ // as a chat-completions route of its own. pi-ai needs the model listed
431
+ // on the route, so the model is never left to the harness default here.
432
+ const gatewayModel = model || DEFAULT_GATEWAY_MODEL;
433
+ lines.push('');
434
+ lines.push(`- id: ${ROW.LLM_PI_AI}`);
435
+ lines.push(' config:');
436
+ lines.push(' providers:');
437
+ lines.push(` ${GATEWAY_PROVIDER}:`);
438
+ lines.push(' api: openai-completions');
439
+ lines.push(` baseURL: ${yamlScalar(gatewayBaseUrl)}`);
440
+ lines.push(' apiKeyEnv: DEEPSEEK_API_KEY');
441
+ lines.push(' models:');
442
+ lines.push(` - id: ${yamlScalar(gatewayModel)}`);
443
+ lines.push('');
444
+ lines.push(`- id: ${ROW.AGENT_DEFAULT_MODEL}`);
445
+ lines.push(' config:');
446
+ lines.push(` provider: ${GATEWAY_PROVIDER}`);
447
+ lines.push(` model: ${yamlScalar(gatewayModel)}`);
448
+ } else if (model || provider) {
416
449
  lines.push('');
417
450
  lines.push(`- id: ${ROW.AGENT_DEFAULT_MODEL}`);
418
451
  lines.push(' config:');
@@ -445,6 +478,40 @@ function isOfficialDeepseekRoot(url) {
445
478
  return p === '' || p === '/v1';
446
479
  }
447
480
 
481
+ /**
482
+ * Which API dsh should use for a configured base URL.
483
+ *
484
+ * - `native`: blank, or one of DeepSeek's own OpenAI-style roots. dsh uses
485
+ * its default, `https://api.deepseek.com/anthropic`.
486
+ * - `openai`: an OpenAI-compatible gateway — a base ending in a version
487
+ * segment (`…/v1`), which is how OpenAI-style relays (OpenAgents credits
488
+ * included) are written. These serve chat completions and no Messages
489
+ * API, so dsh's DeepSeek provider got a 404 from every one of them.
490
+ * - `anthropic`: anything else, used as given for the Messages API.
491
+ */
492
+ function classifyDshEndpoint(url) {
493
+ const raw = String(url || '').trim();
494
+ if (!raw || isOfficialDeepseekRoot(raw)) return 'native';
495
+ let parsed;
496
+ try { parsed = new URL(raw); } catch { return 'anthropic'; }
497
+ const p = parsed.pathname.replace(/\/+$/, '').toLowerCase();
498
+ return /\/v\d+$/.test(p) ? 'openai' : 'anthropic';
499
+ }
500
+
501
+ /**
502
+ * Where to list the models a DeepSeek Harness agent can run, and over which
503
+ * protocol. DeepSeek's own host serves its list on the OpenAI-style root
504
+ * whichever form of its URL was configured, a blank base included (the
505
+ * agent always holds a DeepSeek key).
506
+ */
507
+ function dshModelsEndpoint(url) {
508
+ const raw = String(url || '').trim();
509
+ let host = '';
510
+ try { host = new URL(raw).hostname.toLowerCase(); } catch {}
511
+ if (!raw || host === 'api.deepseek.com') return { baseUrl: DEEPSEEK_MODELS_BASE, protocol: 'openai' };
512
+ return { baseUrl: raw, protocol: classifyDshEndpoint(raw) === 'openai' ? 'openai' : 'anthropic' };
513
+ }
514
+
448
515
  // ---------------------------------------------------------------------------
449
516
  // Permission mode
450
517
  // ---------------------------------------------------------------------------
@@ -638,6 +705,9 @@ module.exports = {
638
705
  buildPrivatePatch,
639
706
 
640
707
  isOfficialDeepseekRoot,
708
+ classifyDshEndpoint,
709
+ dshModelsEndpoint,
710
+ GATEWAY_PROVIDER,
641
711
 
642
712
  normalizePermissionMode,
643
713
  resolvePermissionMode,
@@ -75,6 +75,7 @@ const {
75
75
  cleanStdout,
76
76
  defaultInstallCommand,
77
77
  isOfficialDeepseekRoot,
78
+ classifyDshEndpoint,
78
79
  nodeRequirementText,
79
80
  resolvePermissionMode,
80
81
  safeDshHomeName,
@@ -405,6 +406,12 @@ class DeepSeekAdapter extends BaseAdapter {
405
406
  return isOfficialDeepseekRoot(base) ? '' : base;
406
407
  }
407
408
 
409
+ /** The configured base when it is an OpenAI-compatible gateway, else ''. */
410
+ _gatewayBaseUrl() {
411
+ const base = this._baseUrl();
412
+ return classifyDshEndpoint(base) === 'openai' ? base : '';
413
+ }
414
+
408
415
  _model() {
409
416
  return String(this.agentEnv.DEEPSEEK_MODEL || this.agentEnv.LLM_MODEL || '').trim();
410
417
  }
@@ -538,7 +545,7 @@ class DeepSeekAdapter extends BaseAdapter {
538
545
  * starts mid-write can never read a half-file.
539
546
  */
540
547
  _writePrivatePatch() {
541
- const { text } = buildPrivatePatch({ model: this._model() });
548
+ const { text } = buildPrivatePatch({ model: this._model(), gatewayBaseUrl: this._gatewayBaseUrl() });
542
549
  const tmp = `${this._patchFile}.${process.pid}.tmp`;
543
550
  fs.writeFileSync(tmp, text, { encoding: 'utf-8', mode: 0o600 });
544
551
  fs.renameSync(tmp, this._patchFile);
@@ -570,8 +577,9 @@ class DeepSeekAdapter extends BaseAdapter {
570
577
  const key = this._apiKey();
571
578
  if (key) env.DEEPSEEK_API_KEY = key;
572
579
  // Set or cleared, never inherited: env already carries the raw agent value,
573
- // and _baseUrl() drops DeepSeek's own OpenAI-style roots.
574
- const base = this._baseUrl();
580
+ // and _baseUrl() drops DeepSeek's own OpenAI-style roots. A gateway is
581
+ // reached through the patch's pi-ai route, not dsh's DeepSeek provider.
582
+ const base = this._gatewayBaseUrl() ? '' : this._baseUrl();
575
583
  if (base) env.DEEPSEEK_BASE_URL = base;
576
584
  else delete env.DEEPSEEK_BASE_URL;
577
585
 
@@ -39,7 +39,7 @@ class GeminiAdapter extends BaseAdapter {
39
39
  constructor(opts) {
40
40
  super(opts);
41
41
  this.disabledModules = opts.disabledModules || new Set();
42
- // Pin the channel's decision log + glossary into the prompt (read-only:
42
+ // Pin the channel's glossary into the prompt (read-only:
43
43
  // Gemini has no MCP server and no workspace skill, so it cannot write
44
44
  // the knowledge entries — it only needs to SEE them).
45
45
  this._usesPinnedContext = true;
@@ -226,7 +226,6 @@ class GeminiAdapter extends BaseAdapter {
226
226
  channelName,
227
227
  mode: this._mode,
228
228
  model: this.modelLabel(),
229
- decisionLog: pinned.decisionLog ? { ...pinned.decisionLog, writeAccess: false } : null,
230
229
  glossary: pinned.glossary ? { ...pinned.glossary, writeAccess: false } : null,
231
230
  });
232
231
 
@@ -143,7 +143,7 @@ class GooseAdapter extends BaseAdapter {
143
143
  constructor(opts) {
144
144
  super(opts);
145
145
  this.disabledModules = opts.disabledModules || new Set();
146
- // Pin the channel's decision log + glossary into the per-turn --system
146
+ // Pin the channel's glossary into the per-turn --system
147
147
  // prompt (read-only: Goose gets no workspace API commands, so it can
148
148
  // only SEE the pinned knowledge, not update it).
149
149
  this._usesPinnedContext = true;
@@ -258,7 +258,6 @@ class GooseAdapter extends BaseAdapter {
258
258
  + buildPinnedSections({
259
259
  channelName,
260
260
  mode: this._mode,
261
- decisionLog: pinned.decisionLog ? { ...pinned.decisionLog, writeAccess: false } : null,
262
261
  glossary: pinned.glossary ? { ...pinned.glossary, writeAccess: false } : null,
263
262
  }).join('\n');
264
263
  if (this.workingDir) {
@@ -46,6 +46,10 @@ const HERMES_INSTALL_HINT = IS_WINDOWS
46
46
  : 'curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash';
47
47
  const SESSION_ID_RE = /session_id:\s*(\S+)/;
48
48
  const SESSION_LINE_RE = /^session_id:\s*\S+$/;
49
+ // Hermes validates the toolsets in its own config.yaml before the turn starts
50
+ // and prints this to stdout, ahead of the reply, when one is unknown to the
51
+ // installed version (e.g. `messaging` left over in `platform_toolsets.cli`).
52
+ const TOOLSET_WARNING_RE = /^Warning: Unknown toolsets:/;
49
53
  // What Hermes prints, in place of a session_id, when `--resume` names a
50
54
  // session it no longer has. Upstream localises that line
51
55
  // (t("cli.resume.session_not_found")), so this only matches the English text;
@@ -120,7 +124,7 @@ class HermesAdapter extends BaseAdapter {
120
124
  constructor(opts) {
121
125
  super(opts);
122
126
  this.disabledModules = opts.disabledModules || new Set();
123
- // Pin the channel's decision log + glossary into the context prefix.
127
+ // Pin the channel's glossary into the context prefix.
124
128
  this._usesPinnedContext = true;
125
129
  this.hermesProfile = this._resolveProfile(opts.hermesProfile, this.agentName);
126
130
  this.hermesSource = opts.hermesSource || 'tool';
@@ -509,6 +513,11 @@ class HermesAdapter extends BaseAdapter {
509
513
  const stripped = line.trim();
510
514
  if (!stripped) continue;
511
515
  if (stripped.startsWith('↻ Resumed session ')) continue;
516
+ // Only before the reply begins: the reply itself may quote the line.
517
+ if (!lines.length && TOOLSET_WARNING_RE.test(stripped)) {
518
+ this._log?.(`Hermes config: ${stripped} (check toolsets in ~/.hermes/config.yaml)`, 'warn');
519
+ continue;
520
+ }
512
521
  lines.push(line);
513
522
  }
514
523
  return { text: lines.join('\n').trim(), sessionId };
@@ -58,7 +58,7 @@ class LlmDirectAdapter extends BaseAdapter {
58
58
  constructor(opts) {
59
59
  super(opts);
60
60
  this.disabledModules = opts.disabledModules || new Set();
61
- // Pin the channel's decision log + glossary into the system prompt.
61
+ // Pin the channel's glossary into the system prompt.
62
62
  this._usesPinnedContext = true;
63
63
  this._adapterLabel = opts.adapterLabel || 'LLM';
64
64
  this._modelEnvVar = opts.modelEnvVar || '';
@@ -98,7 +98,7 @@ class OpenCodeAdapter extends BaseAdapter {
98
98
  constructor(opts) {
99
99
  super(opts);
100
100
  this.disabledModules = opts.disabledModules || new Set();
101
- // Pin the channel's decision log + glossary into the system prompt.
101
+ // Pin the channel's glossary into the system prompt.
102
102
  this._usesPinnedContext = true;
103
103
 
104
104
  // Agent home directory: ~/.openagents/agents/{agentName}/ — scratch storage