@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.
- package/icons/kiro.svg +11 -0
- package/package.json +1 -1
- package/registry.json +103 -3
- package/src/adapters/acp-client.js +217 -0
- package/src/adapters/base.js +17 -1
- package/src/adapters/claude.js +64 -8
- package/src/adapters/codex.js +142 -33
- package/src/adapters/hermes.js +164 -87
- package/src/adapters/index.js +4 -1
- package/src/adapters/kiro-runtime.js +318 -0
- package/src/adapters/kiro.js +813 -0
- package/src/adapters/opencode.js +7 -0
- package/src/daemon.js +39 -9
- package/src/index.js +7 -13
- package/src/install-preflight.js +20 -1
- package/src/paths.js +6 -0
- package/src/probe.js +35 -7
- package/src/utils.js +31 -3
package/src/adapters/codex.js
CHANGED
|
@@ -25,7 +25,7 @@ const https = require('https');
|
|
|
25
25
|
|
|
26
26
|
const { whereBinary } = require('../paths');
|
|
27
27
|
const BaseAdapter = require('./base');
|
|
28
|
-
const { redactSecrets, formatAttachmentsForPrompt, decodeConsoleOutput } = require('./utils');
|
|
28
|
+
const { redactSecrets, formatAttachmentsForPrompt, decodeConsoleOutput, BENIGN_CLI_OUTPUT } = require('./utils');
|
|
29
29
|
const { buildOpenclawSystemPrompt } = require('./workspace-prompt');
|
|
30
30
|
|
|
31
31
|
const IS_WINDOWS = process.platform === 'win32';
|
|
@@ -42,6 +42,38 @@ const DIRECT_IDLE_TIMEOUT_MS = 120000;
|
|
|
42
42
|
const DIRECT_TOTAL_TIMEOUT_MS = 300000;
|
|
43
43
|
const TEXT_FILE_RE = /\.(md|markdown|txt|text|csv|tsv|json|jsonl|ya?ml|toml|ini|xml|html?|log|sql|sh|py|js|mjs|cjs|ts|tsx|jsx|java|go|rs|rb|php|c|h|cc|cpp|hpp|cs|swift|kt)$/i;
|
|
44
44
|
|
|
45
|
+
// How much of a failure's own words reach the channel.
|
|
46
|
+
const FAILURE_DETAIL_CAP = 500;
|
|
47
|
+
// `codex exec -` prints this first on every run, failed or not. It led every
|
|
48
|
+
// failure message, and when it was all stderr held the user read
|
|
49
|
+
// "Codex failed to complete this run. > Reading prompt from stdin..." and
|
|
50
|
+
// nothing else.
|
|
51
|
+
const CODEX_STDIN_BANNER = /^Reading (?:prompt|additional input) from stdin\.\.\.$/i;
|
|
52
|
+
// codex's own log records: timestamp, level, module, message. The timestamp
|
|
53
|
+
// and module took half the quote.
|
|
54
|
+
const CODEX_LOG_RECORD = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN|ERROR)\s+(?:[\w:]+:\s+)?(.*)$/;
|
|
55
|
+
// Things codex says beside a run rather than about it, such as a config key
|
|
56
|
+
// it skipped. Quoted only when nothing else was said.
|
|
57
|
+
const CODEX_SIDE_NOTE = /^warning:/i;
|
|
58
|
+
// Codex's wording when the model service could not be reached or the stream
|
|
59
|
+
// dropped. Seen in the field from devices that cannot reach OpenAI, and
|
|
60
|
+
// reproduced against codex-cli 0.160 behind a dead proxy: the run then fails
|
|
61
|
+
// with only "workspace routing discovery failed" (or "timed out"), and the
|
|
62
|
+
// connection errors are in stderr.
|
|
63
|
+
const CODEX_CONNECTION_FAILURE = /error sending request|Connection failed|failed to connect to websocket: IO error|tls handshake|dns error|failed to lookup address|stream disconnected before completion|workspace routing discovery (?:failed|timed out)|request timed out/i;
|
|
64
|
+
// codex retrying a failed connection by itself: "Reconnecting... 2/5 (why)".
|
|
65
|
+
const CODEX_RECONNECTING = /^Reconnecting\.\.\.\s*\d+\/\d+\s*(?:\((.*)\))?\s*$/i;
|
|
66
|
+
// The service answered and said no: a key, a plan, a quota, or a model it
|
|
67
|
+
// will not serve. Network advice would send the user the wrong way. The
|
|
68
|
+
// terms of _serviceRefused, less "error sending request" (that one is a
|
|
69
|
+
// connection failure), plus a 400 and a rejected model.
|
|
70
|
+
const SERVICE_REFUSAL = /\b(400|401|402|403|429)\b|too many requests|rate.?limit|usage limit|quota|credits|unauthori[sz]ed|forbidden|model_not_found|model\b[^\n]{0,80}?\b(?:not supported|does not exist|not available)/i;
|
|
71
|
+
// How many of stderr's last lines count as evidence of a lost connection.
|
|
72
|
+
// codex logs `WARN … failed to refresh available models: request timed out`
|
|
73
|
+
// on runs that then fail for another reason (a quota, a model), and the
|
|
74
|
+
// whole of stderr read as a network failure.
|
|
75
|
+
const CONNECTION_EVIDENCE_LINES = 5;
|
|
76
|
+
|
|
45
77
|
class CodexAdapter extends BaseAdapter {
|
|
46
78
|
/**
|
|
47
79
|
* @param {object} opts - BaseAdapter opts plus:
|
|
@@ -465,8 +497,13 @@ class CodexAdapter extends BaseAdapter {
|
|
|
465
497
|
await this._sendRunFailure(msgChannel, result, { partial: true });
|
|
466
498
|
}
|
|
467
499
|
return;
|
|
468
|
-
} else if (result.exitCode !== 0 && threadId && attempt === 0) {
|
|
469
|
-
// Stale thread — clear and retry fresh
|
|
500
|
+
} else if (result.exitCode !== 0 && threadId && attempt === 0 && !result.turnStarted && !CodexAdapter._serviceRefused(result)) {
|
|
501
|
+
// Stale thread — clear and retry fresh. Only when the turn never
|
|
502
|
+
// started: a thread codex cannot resume fails at once with nothing
|
|
503
|
+
// on stdout ("no rollout found for thread id"). A resumed turn
|
|
504
|
+
// that then failed (no network, a quota) was taken for a stale
|
|
505
|
+
// thread too, so the channel's thread was thrown away and the
|
|
506
|
+
// whole failing run waited out a second time.
|
|
470
507
|
this._log(`Stale thread detected for ${msgChannel}, clearing and retrying`);
|
|
471
508
|
delete this._channelThreads[msgChannel];
|
|
472
509
|
this._saveSessions();
|
|
@@ -525,6 +562,8 @@ class CodexAdapter extends BaseAdapter {
|
|
|
525
562
|
const stderrChunks = [];
|
|
526
563
|
let lastErrorMessage = '';
|
|
527
564
|
let turnFailed = false;
|
|
565
|
+
let turnStarted = false;
|
|
566
|
+
let reconnectNoted = false;
|
|
528
567
|
let _pendingLines = Promise.resolve();
|
|
529
568
|
|
|
530
569
|
if (proc.stderr) {
|
|
@@ -551,6 +590,8 @@ class CodexAdapter extends BaseAdapter {
|
|
|
551
590
|
this._saveSessions();
|
|
552
591
|
this._log(`Thread started: ${event.thread_id}`);
|
|
553
592
|
}
|
|
593
|
+
} else if (eventType === 'turn.started') {
|
|
594
|
+
turnStarted = true;
|
|
554
595
|
} else if (eventType === 'item.completed') {
|
|
555
596
|
const item = event.item || {};
|
|
556
597
|
if (item.type === 'agent_message' && item.text) {
|
|
@@ -592,6 +633,14 @@ class CodexAdapter extends BaseAdapter {
|
|
|
592
633
|
const errMsg = event.message || JSON.stringify(event);
|
|
593
634
|
lastErrorMessage = errMsg;
|
|
594
635
|
this._log(`Error event: ${errMsg}`);
|
|
636
|
+
// codex retries a failing connection by itself and says nothing
|
|
637
|
+
// else while it does, so the channel just showed "thinking". Say
|
|
638
|
+
// so once per run; the retries come in bursts of five.
|
|
639
|
+
const status = reconnectNoted ? '' : CodexAdapter._reconnectStatus(errMsg);
|
|
640
|
+
if (status) {
|
|
641
|
+
reconnectNoted = true;
|
|
642
|
+
try { await this.sendStatus(msgChannel, status); } catch {}
|
|
643
|
+
}
|
|
595
644
|
}
|
|
596
645
|
};
|
|
597
646
|
|
|
@@ -630,6 +679,7 @@ class CodexAdapter extends BaseAdapter {
|
|
|
630
679
|
stderr: stderrBuf,
|
|
631
680
|
errorMessage: lastErrorMessage,
|
|
632
681
|
turnFailed,
|
|
682
|
+
turnStarted,
|
|
633
683
|
});
|
|
634
684
|
});
|
|
635
685
|
|
|
@@ -743,51 +793,85 @@ class CodexAdapter extends BaseAdapter {
|
|
|
743
793
|
return Boolean(turnFailed) || (exitCode !== 0 && exitCode !== undefined);
|
|
744
794
|
}
|
|
745
795
|
|
|
796
|
+
/**
|
|
797
|
+
* True when the model service turned the run away (rate limit, quota,
|
|
798
|
+
* credentials, network) — nothing to do with the thread being resumed. Such
|
|
799
|
+
* a run was read as a stale thread: the thread was dropped, losing the
|
|
800
|
+
* conversation, and the same refused request was sent a second time.
|
|
801
|
+
*/
|
|
802
|
+
static _serviceRefused({ errorMessage, stderr } = {}) {
|
|
803
|
+
const refused = /\b(401|402|403|429)\b|too many requests|rate.?limit|usage limit|quota|credits|unauthorized|forbidden|error sending request/i;
|
|
804
|
+
if (refused.test(String(errorMessage || ''))) return true;
|
|
805
|
+
// Only the end of stderr, where the reason the run died is: a stale
|
|
806
|
+
// thread whose earlier log mentioned a quota was kept, and every later
|
|
807
|
+
// message in that channel failed until restart.
|
|
808
|
+
const lastLines = String(stderr || '').split(/\r?\n/).filter((l) => l.trim()).slice(-5).join('\n');
|
|
809
|
+
return refused.test(lastLines);
|
|
810
|
+
}
|
|
811
|
+
|
|
746
812
|
/**
|
|
747
813
|
* Pick the most informative failure detail from a run result:
|
|
748
814
|
* turn.failed / error event message → stderr tail → signal → exit code.
|
|
749
815
|
* Redacted.
|
|
816
|
+
*
|
|
817
|
+
* The cap applies to the quoted reason, before the advice is added, so a
|
|
818
|
+
* long stderr cannot push the advice out of the message.
|
|
750
819
|
*/
|
|
751
820
|
static _failureDetail({ errorMessage, stderr, exitCode, signal } = {}) {
|
|
752
821
|
const raw = String(errorMessage || '').trim()
|
|
753
822
|
|| CodexAdapter._stderrReason(stderr)
|
|
754
823
|
|| (signal ? `codex was terminated by ${signal}` : '')
|
|
755
824
|
|| (exitCode ? `codex exited with code ${exitCode}` : '');
|
|
756
|
-
const
|
|
757
|
-
return CodexAdapter.
|
|
825
|
+
const reason = CodexAdapter._redact(CodexAdapter._unwrap(raw)).slice(0, FAILURE_DETAIL_CAP).trim();
|
|
826
|
+
return reason ? CodexAdapter._explain(reason, stderr) : '';
|
|
758
827
|
}
|
|
759
828
|
|
|
760
829
|
/**
|
|
761
|
-
*
|
|
830
|
+
* One status line for codex retrying a connection, or '' for any other
|
|
831
|
+
* error event. A retry it recovers from is not a failure, so this says it
|
|
832
|
+
* is retrying, not that it failed.
|
|
833
|
+
*/
|
|
834
|
+
static _reconnectStatus(message) {
|
|
835
|
+
const m = CODEX_RECONNECTING.exec(String(message || '').trim());
|
|
836
|
+
if (!m) return '';
|
|
837
|
+
const why = CodexAdapter._redact(m[1] || '').slice(0, 120).trim();
|
|
838
|
+
return `Codex is having trouble reaching the model service and is retrying${why ? ` (${why})` : ''}…`;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* The part of codex's stderr that says why the run failed.
|
|
762
843
|
*
|
|
763
844
|
* codex logs through `tracing` on stderr — `2026-10-27T04:08:56.500Z WARN
|
|
764
845
|
* codex_skills::interface: …` — and echoes "Reading prompt from stdin..."
|
|
765
|
-
* (or "Reading additional input from stdin...").
|
|
766
|
-
*
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
846
|
+
* (or "Reading additional input from stdin...") on every run. A plain tail
|
|
847
|
+
* of the last lines was mostly that noise. So, in order: lines the CLI
|
|
848
|
+
* printed for a person; failing those, its ERROR records with timestamp and
|
|
849
|
+
* module stripped; failing those, its warnings. The banner and known-harmless
|
|
850
|
+
* lines are never a reason: a clean exit with only the banner reads as "no
|
|
851
|
+
* reply", not as "> Reading prompt from stdin...".
|
|
852
|
+
*
|
|
853
|
+
* The cut is taken from the END: codex's own "Error: …" line comes last, and
|
|
854
|
+
* keeping the first 500 characters cut it in half behind long log lines.
|
|
771
855
|
*/
|
|
772
856
|
static _stderrReason(stderr) {
|
|
773
|
-
|
|
774
|
-
// else falls through to the exit code instead of quoting the banner.
|
|
775
|
-
const lines = String(stderr || '').split(/\r?\n/).map((l) => l.trim())
|
|
776
|
-
.filter((l) => l && !/^Reading (prompt|additional input) from stdin/i.test(l));
|
|
777
|
-
if (!lines.length) return '';
|
|
778
|
-
const TRACE = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN|ERROR)\s+(?:[\w:]+:\s+)?(.*)$/;
|
|
779
|
-
const plain = [];
|
|
857
|
+
const said = [];
|
|
780
858
|
const errors = [];
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
859
|
+
const notes = [];
|
|
860
|
+
for (const raw of String(stderr || '').split(/\r?\n/)) {
|
|
861
|
+
const line = raw.trim();
|
|
862
|
+
if (!line || CODEX_STDIN_BANNER.test(line)) continue;
|
|
863
|
+
const record = CODEX_LOG_RECORD.exec(line);
|
|
864
|
+
if (record) {
|
|
865
|
+
const [, level, message] = record;
|
|
866
|
+
const bucket = level === 'ERROR' ? errors : level === 'WARN' ? notes : null;
|
|
867
|
+
if (bucket && message && !bucket.includes(message)) bucket.push(message);
|
|
868
|
+
} else if (!BENIGN_CLI_OUTPUT.test(line)) {
|
|
869
|
+
(CODEX_SIDE_NOTE.test(line) ? notes : said).push(line);
|
|
787
870
|
}
|
|
788
871
|
}
|
|
789
|
-
const picked =
|
|
790
|
-
|
|
872
|
+
const picked = said.length ? said : errors.length ? errors : notes;
|
|
873
|
+
const text = picked.slice(-5).join('\n');
|
|
874
|
+
return text.length > FAILURE_DETAIL_CAP ? `…${text.slice(-(FAILURE_DETAIL_CAP - 1))}` : text;
|
|
791
875
|
}
|
|
792
876
|
|
|
793
877
|
/**
|
|
@@ -820,13 +904,38 @@ class CodexAdapter extends BaseAdapter {
|
|
|
820
904
|
* match is on the backend's own wording, so an unrelated failure is passed
|
|
821
905
|
* through untouched.
|
|
822
906
|
*/
|
|
823
|
-
static _explain(detail) {
|
|
824
|
-
|
|
825
|
-
|
|
907
|
+
static _explain(detail, stderr = '') {
|
|
908
|
+
// Ahead of the network check: a model that needs a newer Codex can
|
|
909
|
+
// arrive with connection warnings in stderr, and the upgrade is the fix.
|
|
910
|
+
if (/requires a newer version|upgrade to the latest (app|version)/i.test(detail)) {
|
|
911
|
+
return `${detail}\n\nUpdate the Codex CLI from OpenAgents Launcher ` +
|
|
912
|
+
'(Agents → Codex → Update), or run `npm install -g @openai/codex@latest`, ' +
|
|
913
|
+
'then try again. Picking an older model also works around it for now.';
|
|
914
|
+
}
|
|
915
|
+
// The other half of a connection failure: it is this device's network,
|
|
916
|
+
// not Codex and not the agent's settings. Without it the user saw log
|
|
917
|
+
// lines about websockets and a model list. The reason quoted can be as
|
|
918
|
+
// bare as "workspace routing discovery failed", so the end of stderr
|
|
919
|
+
// counts as evidence too, and a refusal in either rules it out.
|
|
920
|
+
// Only the last few lines, and not codex's warnings: it warns of a timed
|
|
921
|
+
// out model refresh on runs that then fail for a quota or a model.
|
|
922
|
+
// Not the lines of codex's own ChatGPT MCP connector: they report its
|
|
923
|
+
// sign-in to a side service, and an "AuthRequired" there says nothing
|
|
924
|
+
// about why the run failed.
|
|
925
|
+
const logged = String(stderr || '').split(/\r?\n/)
|
|
926
|
+
.filter((l) => {
|
|
927
|
+
if (!l.trim() || /rmcp::/.test(l)) return false;
|
|
928
|
+
const record = CODEX_LOG_RECORD.exec(l.trim());
|
|
929
|
+
return !record || record[1] === 'ERROR';
|
|
930
|
+
})
|
|
931
|
+
.slice(-CONNECTION_EVIDENCE_LINES)
|
|
932
|
+
.join('\n');
|
|
933
|
+
const evidence = `${detail}\n${logged}`;
|
|
934
|
+
if (CODEX_CONNECTION_FAILURE.test(evidence) && !SERVICE_REFUSAL.test(evidence)) {
|
|
935
|
+
return `${detail}\n\nCodex lost its connection to the model service (OpenAI, or the base URL ` +
|
|
936
|
+
"this agent is set to). Check this device's network, proxy or firewall, then try again.";
|
|
826
937
|
}
|
|
827
|
-
return
|
|
828
|
-
'(Agents → Codex → Update), or run `npm install -g @openai/codex@latest`, ' +
|
|
829
|
-
'then try again. Picking an older model also works around it for now.';
|
|
938
|
+
return detail;
|
|
830
939
|
}
|
|
831
940
|
|
|
832
941
|
/** Redact secrets (keys, tokens, bearer/authorization, query secrets) from diagnostics. */
|
package/src/adapters/hermes.js
CHANGED
|
@@ -41,6 +41,13 @@ const { classifyRunFailure, classifiedError, isClassifiedError } = require('./ru
|
|
|
41
41
|
const { maskSecretValues } = require('./utils');
|
|
42
42
|
|
|
43
43
|
const IS_WINDOWS = process.platform === 'win32';
|
|
44
|
+
/** The variable each run hands its key in; every agent's provider names it as key_env. */
|
|
45
|
+
const PROVIDER_KEY_ENV = 'OPENAGENTS_HERMES_API_KEY';
|
|
46
|
+
// `hermes config set` calls from all Hermes agents in this process, one at a time.
|
|
47
|
+
let configWrites = Promise.resolve();
|
|
48
|
+
let legacyEndpointReleased = false;
|
|
49
|
+
/** A Windows launcher script, which Node runs only through cmd.exe. */
|
|
50
|
+
const isWindowsShim = (file) => /\.(cmd|bat)$/i.test(String(file || ''));
|
|
44
51
|
const HERMES_INSTALL_HINT = IS_WINDOWS
|
|
45
52
|
? 'powershell -NoProfile -ExecutionPolicy Bypass -Command "irm https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.ps1 | iex"'
|
|
46
53
|
: 'curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash';
|
|
@@ -155,6 +162,41 @@ class HermesAdapter extends BaseAdapter {
|
|
|
155
162
|
// ------------------------------------------------------------------
|
|
156
163
|
|
|
157
164
|
_findHermesBinary() {
|
|
165
|
+
const found = this._locateHermesBinary();
|
|
166
|
+
return IS_WINDOWS ? HermesAdapter.nativeExeFor(found) : found;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The hermes.exe a Windows `.cmd`/`.bat` launcher stands for, else `file`.
|
|
171
|
+
*
|
|
172
|
+
* Every turn runs `hermes chat -q <prompt>` with the prompt as an argument.
|
|
173
|
+
* Node will not start a `.cmd` without a shell (EINVAL since the
|
|
174
|
+
* CVE-2024-27980 fix), and a shell is no answer: cmd.exe re-reads the prompt
|
|
175
|
+
* text, so `&`, `|` or `%` in a message would run as commands. A launcher
|
|
176
|
+
* found first on PATH therefore failed every message with "spawn EINVAL".
|
|
177
|
+
* Looked for, in order: a hermes.exe beside it, an .exe the launcher names
|
|
178
|
+
* (absolute, or relative to its own folder as `%~dp0`), and the native
|
|
179
|
+
* installer's venv.
|
|
180
|
+
*/
|
|
181
|
+
static nativeExeFor(file, { exists = fs.existsSync, read = fs.readFileSync, localAppData } = {}) {
|
|
182
|
+
if (!file || !isWindowsShim(file)) return file;
|
|
183
|
+
const dir = path.win32.dirname(file);
|
|
184
|
+
const candidates = [path.win32.join(dir, 'hermes.exe')];
|
|
185
|
+
let text = '';
|
|
186
|
+
try { text = String(read(file, 'utf8')).slice(0, 64 * 1024); } catch {}
|
|
187
|
+
for (const m of text.matchAll(/"?((?:%~?dp0%?\\?|[A-Za-z]:\\)[^"\r\n]*?\.exe)"?/gi)) {
|
|
188
|
+
const named = m[1].replace(/^%~?dp0%?\\?/i, `${dir}\\`);
|
|
189
|
+
candidates.push(path.win32.normalize(named));
|
|
190
|
+
}
|
|
191
|
+
const appData = localAppData || process.env.LOCALAPPDATA || path.win32.join(os.homedir(), 'AppData', 'Local');
|
|
192
|
+
candidates.push(path.win32.join(appData, 'hermes', 'hermes-agent', 'venv', 'Scripts', 'hermes.exe'));
|
|
193
|
+
for (const c of candidates) {
|
|
194
|
+
try { if (exists(c)) return c; } catch {}
|
|
195
|
+
}
|
|
196
|
+
return file;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
_locateHermesBinary() {
|
|
158
200
|
const home = os.homedir();
|
|
159
201
|
|
|
160
202
|
// Tier 1: PATH (enriched env so we see the dirs the launcher adds; a fresh
|
|
@@ -556,9 +598,105 @@ class HermesAdapter extends BaseAdapter {
|
|
|
556
598
|
);
|
|
557
599
|
if (resumeSessionId) args.push('--resume', resumeSessionId);
|
|
558
600
|
if (this.yolo) args.push('--yolo');
|
|
601
|
+
const endpoint = this._endpoint();
|
|
602
|
+
if (endpoint) {
|
|
603
|
+
args.push('--provider', endpoint.provider);
|
|
604
|
+
if (endpoint.model) args.push('-m', endpoint.model);
|
|
605
|
+
}
|
|
559
606
|
return args;
|
|
560
607
|
}
|
|
561
608
|
|
|
609
|
+
/**
|
|
610
|
+
* This agent's own endpoint, or null for one on Hermes's own sign-in.
|
|
611
|
+
*
|
|
612
|
+
* Hermes reads a custom endpoint only from its config.yaml, and once kept a
|
|
613
|
+
* single one for the whole device under `model:`. Every keyed Hermes agent
|
|
614
|
+
* wrote its URL and key there, so the last one saved ran all of them: a
|
|
615
|
+
* second agent on another relay took over the first one's endpoint, and a
|
|
616
|
+
* key rewritten under a running session ended it with
|
|
617
|
+
* "launch_credentials_unavailable". Each agent now has a provider of its
|
|
618
|
+
* own under `providers:`, named for the agent and picked per run with
|
|
619
|
+
* `--provider`; its key is never written to the file but read from this
|
|
620
|
+
* run's environment through the provider's `key_env`.
|
|
621
|
+
*/
|
|
622
|
+
_endpoint() {
|
|
623
|
+
const env = this.agentEnv || {};
|
|
624
|
+
const baseUrl = String(env.LLM_BASE_URL || '').trim().replace(/\/+$/, '');
|
|
625
|
+
if (!baseUrl) return null;
|
|
626
|
+
return {
|
|
627
|
+
provider: HermesAdapter.providerName(this.agentName),
|
|
628
|
+
baseUrl,
|
|
629
|
+
apiKey: String(env.LLM_API_KEY || env.OPENAI_API_KEY || '').trim(),
|
|
630
|
+
model: String(env.LLM_MODEL || '').trim(),
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* The `providers:` key for an agent. Hermes takes lower-case letters,
|
|
636
|
+
* digits, `-` and `_`; a name that had to be changed to fit gets a short
|
|
637
|
+
* hash of the original, so `Hermes 1` and `hermes-1` stay two providers.
|
|
638
|
+
*/
|
|
639
|
+
static providerName(agentName) {
|
|
640
|
+
const raw = String(agentName || '');
|
|
641
|
+
const slug = raw.toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^[-_]+|[-_]+$/g, '').slice(0, 40) || 'agent';
|
|
642
|
+
if (slug === raw) return `openagents-${slug}`;
|
|
643
|
+
const hash = crypto.createHash('sha1').update(raw).digest('hex').slice(0, 6);
|
|
644
|
+
return `openagents-${slug}-${hash}`;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Write this agent's provider into the config.yaml its runs read (its
|
|
649
|
+
* profile's), once per endpoint. `hermes config set` owns the schema and
|
|
650
|
+
* the file's location; writes from every Hermes agent in this daemon are
|
|
651
|
+
* queued, because each is a read-modify-write of the same file and two at
|
|
652
|
+
* once could drop one agent's entry.
|
|
653
|
+
*/
|
|
654
|
+
async _ensureProvider(endpoint) {
|
|
655
|
+
const stamp = [this._hermesBin, this.hermesProfile, endpoint.provider, endpoint.baseUrl].join('\n');
|
|
656
|
+
if (this._providerStamp === stamp) return;
|
|
657
|
+
const profile = this.hermesProfile && this.hermesProfile !== 'default' ? ['-p', this.hermesProfile] : [];
|
|
658
|
+
const key = `providers.${endpoint.provider}`;
|
|
659
|
+
const write = async () => {
|
|
660
|
+
HermesAdapter.releaseLegacyEndpoint();
|
|
661
|
+
await this._hermesConfigSet([...profile, 'config', 'set', `${key}.api`, endpoint.baseUrl]);
|
|
662
|
+
await this._hermesConfigSet([...profile, 'config', 'set', `${key}.key_env`, PROVIDER_KEY_ENV]);
|
|
663
|
+
};
|
|
664
|
+
const queued = configWrites.then(write, write);
|
|
665
|
+
configWrites = queued.catch(() => {});
|
|
666
|
+
try {
|
|
667
|
+
await queued;
|
|
668
|
+
} catch (e) {
|
|
669
|
+
throw classifiedError(
|
|
670
|
+
`Hermes could not save this agent's endpoint to its config.yaml: ${this._redact(e && e.message)}`,
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
this._providerStamp = stamp;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/** One `hermes config set …`, in the environment this agent's runs get. */
|
|
677
|
+
_hermesConfigSet(args) {
|
|
678
|
+
const bridged = bridgeSpawn(this._hermesBin, args, { env: { ...(this.agentEnv || process.env) }, windowsHide: true });
|
|
679
|
+
return new Promise((resolve, reject) => {
|
|
680
|
+
execFile(bridged.file, bridged.args, { ...bridged.opts, timeout: 30000 }, (err, _stdout, stderr) => {
|
|
681
|
+
if (err) reject(new Error(String(stderr || '').trim() || err.message));
|
|
682
|
+
else resolve();
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Hand back the device-wide `model:` lines an earlier version wrote for a
|
|
689
|
+
* keyed agent (restoreNativeAuth: only while they are still exactly what it
|
|
690
|
+
* wrote). No agent needs them now, and left in place they kept a relay and
|
|
691
|
+
* its key under the user's own `hermes` and every signed-in agent. Once per
|
|
692
|
+
* process.
|
|
693
|
+
*/
|
|
694
|
+
static releaseLegacyEndpoint() {
|
|
695
|
+
if (legacyEndpointReleased) return;
|
|
696
|
+
legacyEndpointReleased = true;
|
|
697
|
+
try { HermesAdapter.restoreNativeAuth(); } catch {}
|
|
698
|
+
}
|
|
699
|
+
|
|
562
700
|
/**
|
|
563
701
|
* Run one Hermes turn and report what became of it.
|
|
564
702
|
*
|
|
@@ -575,11 +713,24 @@ class HermesAdapter extends BaseAdapter {
|
|
|
575
713
|
if (this._stoppedBeforeStart(channelName)) {
|
|
576
714
|
return { stopped: true, exitCode: null, text: '', sessionId: null, detail: '' };
|
|
577
715
|
}
|
|
716
|
+
// Only a launcher script was found (nativeExeFor had no hermes.exe to
|
|
717
|
+
// swap in): say so instead of Node's bare "spawn EINVAL".
|
|
718
|
+
if (IS_WINDOWS && isWindowsShim(this._hermesBin) && !isWslBinary(this._hermesBin)) {
|
|
719
|
+
throw classifiedError(
|
|
720
|
+
`Hermes was found only as the launcher script ${this._hermesBin}, which cannot be run ` +
|
|
721
|
+
'with the message as an argument. Reinstall Hermes so that hermes.exe is present, ' +
|
|
722
|
+
`then restart the agent: ${HERMES_INSTALL_HINT}`,
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const endpoint = this._endpoint();
|
|
727
|
+
if (endpoint) await this._ensureProvider(endpoint);
|
|
578
728
|
const args = this._buildHermesCmd(prompt, resumeId);
|
|
579
|
-
this._log(`Running hermes (profile=${this.hermesProfile}, channel=${channelName}, resume=${!!resumeId})`);
|
|
729
|
+
this._log(`Running hermes (profile=${this.hermesProfile}, channel=${channelName}, resume=${!!resumeId}${endpoint ? `, provider=${endpoint.provider}` : ''})`);
|
|
580
730
|
|
|
581
731
|
const env = { ...(this.agentEnv || process.env) };
|
|
582
732
|
if (prefillFile) env[PREFILL_ENV] = prefillFile;
|
|
733
|
+
if (endpoint) env[PROVIDER_KEY_ENV] = endpoint.apiKey;
|
|
583
734
|
|
|
584
735
|
// A hermes that lives inside WSL is rewritten to `wsl.exe -e <path> …` by
|
|
585
736
|
// the bridge in ../wsl (which also forces detached off, there being no
|
|
@@ -803,87 +954,17 @@ class HermesAdapter extends BaseAdapter {
|
|
|
803
954
|
return removed;
|
|
804
955
|
}
|
|
805
956
|
|
|
806
|
-
/**
|
|
807
|
-
* Point Hermes at a custom OpenAI-compatible endpoint from user-provided
|
|
808
|
-
* LLM_API_KEY / LLM_BASE_URL / LLM_MODEL values. Called by saveAgentEnv when
|
|
809
|
-
* type === 'hermes', same pattern as OpenClaw's configureNativeAuth.
|
|
810
|
-
*
|
|
811
|
-
* Hermes has no env-var path for a custom endpoint (OPENAI_BASE_URL is
|
|
812
|
-
* honored only for its built-in openai provider) — the supported form is the
|
|
813
|
-
* `model:` section of its config.yaml:
|
|
814
|
-
* model: { default: <id>, provider: custom, base_url: <url>, api_key: <key> }
|
|
815
|
-
* Rather than hand-writing that YAML (and clobbering user config), drive
|
|
816
|
-
* Hermes's own `hermes config set` CLI: it owns the schema, merges into the
|
|
817
|
-
* existing file, and resolves its platform config path itself (~/.hermes on
|
|
818
|
-
* Unix, %LOCALAPPDATA%\hermes on native Windows, in-distro under WSL).
|
|
819
|
-
*
|
|
820
|
-
* Without this, a remotely-created hermes agent died on every message with
|
|
821
|
-
* "No inference provider configured" — the workspace's API-key field was a
|
|
822
|
-
* silent no-op for this type.
|
|
823
|
-
*
|
|
824
|
-
* Only acts when LLM_BASE_URL is set: a user signed in via `hermes setup`
|
|
825
|
-
* (the Nous login) must keep their own provider selection untouched.
|
|
826
|
-
*
|
|
827
|
-
* The `model:` lines this replaces are recorded (recordNativeAuth), so
|
|
828
|
-
* restoreNativeAuth can hand them back when an agent moves to the sign-in.
|
|
829
|
-
*/
|
|
830
|
-
static configureNativeAuth(env) {
|
|
831
|
-
const vals = env || {};
|
|
832
|
-
const baseUrl = String(vals.LLM_BASE_URL || '').trim().replace(/\/+$/, '');
|
|
833
|
-
if (!baseUrl) return { skipped: true, reason: 'no LLM_BASE_URL' };
|
|
834
|
-
const model = String(vals.LLM_MODEL || '').trim();
|
|
835
|
-
const apiKey = String(vals.LLM_API_KEY || '').trim();
|
|
836
|
-
|
|
837
|
-
// Borrow the adapter's binary resolution without running the constructor.
|
|
838
|
-
const probe = Object.create(HermesAdapter.prototype);
|
|
839
|
-
probe._log = () => {};
|
|
840
|
-
const bin = probe._findHermesBinary();
|
|
841
|
-
if (!bin) return { skipped: true, reason: 'hermes binary not found' };
|
|
842
|
-
// An in-distro hermes keeps its config inside WSL, out of reach of a file read.
|
|
843
|
-
const configFile = isWslBinary(bin) ? null : HermesAdapter.configFile();
|
|
844
|
-
const before = configFile ? readTextOrEmpty(configFile) : null;
|
|
845
|
-
|
|
846
|
-
const { execFileSync } = require('child_process');
|
|
847
|
-
const run = (args) => {
|
|
848
|
-
// Same rewrite the spawn bridge does, for the one call here that needs to
|
|
849
|
-
// be synchronous: an in-distro hermes is only reachable through wsl.exe.
|
|
850
|
-
const { file, args: argv } = bridgeSpawn(bin, args);
|
|
851
|
-
execFileSync(file, argv, {
|
|
852
|
-
stdio: 'ignore',
|
|
853
|
-
timeout: 20000,
|
|
854
|
-
windowsHide: true,
|
|
855
|
-
});
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
run(['config', 'set', 'model.provider', 'custom']);
|
|
859
|
-
run(['config', 'set', 'model.base_url', baseUrl]);
|
|
860
|
-
if (model) run(['config', 'set', 'model.default', model]);
|
|
861
|
-
if (apiKey) run(['config', 'set', 'model.api_key', apiKey]);
|
|
862
|
-
if (configFile) {
|
|
863
|
-
try { HermesAdapter.recordNativeAuth(configFile, before, readTextOrEmpty(configFile)); } catch {}
|
|
864
|
-
}
|
|
865
|
-
return { configured: true };
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
/** The default profile's config.yaml, the one `hermes config set` writes. */
|
|
869
|
-
static configFile(env = process.env) {
|
|
870
|
-
const homeEnv = String(env.HERMES_HOME || '').trim();
|
|
871
|
-
const home = homeEnv || (IS_WINDOWS
|
|
872
|
-
? path.join(env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local'), 'hermes')
|
|
873
|
-
: path.join(os.homedir(), '.hermes'));
|
|
874
|
-
return path.join(home, 'config.yaml');
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
/** Where the `model:` lines from before configureNativeAuth are kept. */
|
|
957
|
+
/** Where the `model:` lines replaced by an earlier version's custom endpoint are kept. */
|
|
878
958
|
static nativeAuthRecordFile() {
|
|
879
959
|
return path.join(os.homedir(), '.openagents', 'native-auth', 'hermes.json');
|
|
880
960
|
}
|
|
881
961
|
|
|
882
962
|
/**
|
|
883
|
-
* Remember what
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
963
|
+
* Remember what writing a custom endpoint into `model:` replaced (earlier
|
|
964
|
+
* versions did; each agent now has a provider of its own, see _endpoint).
|
|
965
|
+
* `original` is each managed `model:` line from before the FIRST custom
|
|
966
|
+
* endpoint, kept across later ones; `written` identifies each as that write
|
|
967
|
+
* left it, by hash only, so the key it wrote is not copied here.
|
|
887
968
|
*/
|
|
888
969
|
static recordNativeAuth(configFile, beforeText, afterText) {
|
|
889
970
|
const recordFile = HermesAdapter.nativeAuthRecordFile();
|
|
@@ -899,13 +980,13 @@ class HermesAdapter extends BaseAdapter {
|
|
|
899
980
|
}
|
|
900
981
|
|
|
901
982
|
/**
|
|
902
|
-
* Hand Hermes back the `model:` lines
|
|
903
|
-
* agent that now runs on the `hermes setup` sign-in
|
|
983
|
+
* Hand Hermes back the `model:` lines an earlier version replaced with a
|
|
984
|
+
* custom endpoint, for an agent that now runs on the `hermes setup` sign-in
|
|
985
|
+
* (and, through releaseLegacyEndpoint, once for every device). Without this the custom
|
|
904
986
|
* endpoint and key stayed in config.yaml, and the signed-in agent kept
|
|
905
987
|
* calling them (401 once the key was gone or wrong).
|
|
906
988
|
*
|
|
907
|
-
* Only while every one of them is still exactly what
|
|
908
|
-
* wrote: lines the user has changed since (`hermes setup`, `hermes model`)
|
|
989
|
+
* Only while every one of them is still exactly what that write left: lines the user has changed since (`hermes setup`, `hermes model`)
|
|
909
990
|
* are theirs and stay. Either way the record is dropped.
|
|
910
991
|
*/
|
|
911
992
|
static restoreNativeAuth() {
|
|
@@ -929,7 +1010,7 @@ class HermesAdapter extends BaseAdapter {
|
|
|
929
1010
|
}
|
|
930
1011
|
|
|
931
1012
|
/**
|
|
932
|
-
* The lines of a config.yaml text that
|
|
1013
|
+
* The lines of a config.yaml text that a custom endpoint used to be written to, verbatim
|
|
933
1014
|
* or null where absent: the top-level `model:` line itself (`hermes config
|
|
934
1015
|
* set` turns a plain `model: <id>` into a mapping) and its `default`,
|
|
935
1016
|
* `provider`, `base_url` and `api_key` keys.
|
|
@@ -970,7 +1051,7 @@ class HermesAdapter extends BaseAdapter {
|
|
|
970
1051
|
}
|
|
971
1052
|
}
|
|
972
1053
|
|
|
973
|
-
// What
|
|
1054
|
+
// What a custom endpoint used to be written to in config.yaml: the `model:` line and these keys under it.
|
|
974
1055
|
const MODEL_KEYS = ['default', 'provider', 'base_url', 'api_key'];
|
|
975
1056
|
const MODEL_LINE_NAMES = ['header', ...MODEL_KEYS];
|
|
976
1057
|
|
|
@@ -1002,10 +1083,6 @@ function hashLine(line) {
|
|
|
1002
1083
|
return line == null ? null : crypto.createHash('sha256').update(line).digest('hex');
|
|
1003
1084
|
}
|
|
1004
1085
|
|
|
1005
|
-
function readTextOrEmpty(file) {
|
|
1006
|
-
try { return fs.readFileSync(file, 'utf8'); } catch { return ''; }
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
1086
|
function readRecord(file) {
|
|
1010
1087
|
try {
|
|
1011
1088
|
const record = JSON.parse(fs.readFileSync(file, 'utf8'));
|
package/src/adapters/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const MiMoCodeAdapter = require('./mimo-code');
|
|
|
31
31
|
const QoderAdapter = require('./qoder');
|
|
32
32
|
const QoderCnAdapter = require('./qoder-cn');
|
|
33
33
|
const QwenCodeAdapter = require('./qwen-code');
|
|
34
|
+
const KiroAdapter = require('./kiro');
|
|
34
35
|
|
|
35
36
|
const ADAPTER_MAP = {
|
|
36
37
|
openclaw: OpenClawAdapter,
|
|
@@ -59,11 +60,12 @@ const ADAPTER_MAP = {
|
|
|
59
60
|
qoder: QoderAdapter,
|
|
60
61
|
'qoder-cn': QoderCnAdapter,
|
|
61
62
|
'qwen-code': QwenCodeAdapter,
|
|
63
|
+
kiro: KiroAdapter,
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
/**
|
|
65
67
|
* Create an adapter instance for the given agent type.
|
|
66
|
-
* @param {string} type - Agent type (openclaw, claude, codex, opencode, nanoclaw, cursor, hermes, gemini, kimi, aider, goose, copilot, cline, amp, mini-swe-agent, pi, deepseek, antigravity, commandcode, openworker, codebuddy, codearts, mimo-code, qoder, qoder-cn, qwen-code)
|
|
68
|
+
* @param {string} type - Agent type (openclaw, claude, codex, opencode, nanoclaw, cursor, hermes, gemini, kimi, aider, goose, copilot, cline, amp, mini-swe-agent, pi, deepseek, antigravity, commandcode, openworker, codebuddy, codearts, mimo-code, qoder, qoder-cn, qwen-code, kiro)
|
|
67
69
|
* @param {object} opts - Adapter constructor options
|
|
68
70
|
* @returns {BaseAdapter}
|
|
69
71
|
*/
|
|
@@ -102,6 +104,7 @@ module.exports = {
|
|
|
102
104
|
QoderAdapter,
|
|
103
105
|
QoderCnAdapter,
|
|
104
106
|
QwenCodeAdapter,
|
|
107
|
+
KiroAdapter,
|
|
105
108
|
createAdapter,
|
|
106
109
|
ADAPTER_MAP,
|
|
107
110
|
};
|