@openagents-org/agent-launcher 0.2.205 → 0.2.206
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 +1 -1
- package/src/adapters/claude.js +6 -1
- package/src/adapters/hermes.js +159 -1
- package/src/index.js +20 -3
package/package.json
CHANGED
package/src/adapters/claude.js
CHANGED
|
@@ -1096,7 +1096,12 @@ class ClaudeAdapter extends BaseAdapter {
|
|
|
1096
1096
|
}
|
|
1097
1097
|
} catch {}
|
|
1098
1098
|
}
|
|
1099
|
-
|
|
1099
|
+
const response = pp.lastResponseText.join('\n').trim();
|
|
1100
|
+
// Consume this turn before posting it. A persistent CLI can emit another
|
|
1101
|
+
// turn when a background task finishes, without a new user message (and
|
|
1102
|
+
// therefore without _sendToPersistentProc resetting the buffer).
|
|
1103
|
+
pp.lastResponseText = [];
|
|
1104
|
+
return response;
|
|
1100
1105
|
}
|
|
1101
1106
|
|
|
1102
1107
|
/** True when the CLI reported the resumed conversation no longer fits. */
|
package/src/adapters/hermes.js
CHANGED
|
@@ -30,7 +30,7 @@ const { execSync, execFile } = require('child_process');
|
|
|
30
30
|
// spawn() here is the WSL bridge from ../wsl: same signature as
|
|
31
31
|
// child_process.spawn, and a straight pass-through unless the resolved CLI
|
|
32
32
|
// lives on the other side of the Windows/WSL boundary.
|
|
33
|
-
const { spawn, bridgeSpawn } = require('../wsl');
|
|
33
|
+
const { spawn, bridgeSpawn, isWslBinary } = require('../wsl');
|
|
34
34
|
|
|
35
35
|
const BaseAdapter = require('./base');
|
|
36
36
|
const { buildOpenclawSystemPrompt } = require('./workspace-prompt');
|
|
@@ -814,6 +814,9 @@ class HermesAdapter extends BaseAdapter {
|
|
|
814
814
|
*
|
|
815
815
|
* Only acts when LLM_BASE_URL is set: a user signed in via `hermes setup`
|
|
816
816
|
* (the Nous login) must keep their own provider selection untouched.
|
|
817
|
+
*
|
|
818
|
+
* The `model:` lines this replaces are recorded (recordNativeAuth), so
|
|
819
|
+
* restoreNativeAuth can hand them back when an agent moves to the sign-in.
|
|
817
820
|
*/
|
|
818
821
|
static configureNativeAuth(env) {
|
|
819
822
|
const vals = env || {};
|
|
@@ -827,6 +830,9 @@ class HermesAdapter extends BaseAdapter {
|
|
|
827
830
|
probe._log = () => {};
|
|
828
831
|
const bin = probe._findHermesBinary();
|
|
829
832
|
if (!bin) return { skipped: true, reason: 'hermes binary not found' };
|
|
833
|
+
// An in-distro hermes keeps its config inside WSL, out of reach of a file read.
|
|
834
|
+
const configFile = isWslBinary(bin) ? null : HermesAdapter.configFile();
|
|
835
|
+
const before = configFile ? readTextOrEmpty(configFile) : null;
|
|
830
836
|
|
|
831
837
|
const { execFileSync } = require('child_process');
|
|
832
838
|
const run = (args) => {
|
|
@@ -844,8 +850,160 @@ class HermesAdapter extends BaseAdapter {
|
|
|
844
850
|
run(['config', 'set', 'model.base_url', baseUrl]);
|
|
845
851
|
if (model) run(['config', 'set', 'model.default', model]);
|
|
846
852
|
if (apiKey) run(['config', 'set', 'model.api_key', apiKey]);
|
|
853
|
+
if (configFile) {
|
|
854
|
+
try { HermesAdapter.recordNativeAuth(configFile, before, readTextOrEmpty(configFile)); } catch {}
|
|
855
|
+
}
|
|
847
856
|
return { configured: true };
|
|
848
857
|
}
|
|
858
|
+
|
|
859
|
+
/** The default profile's config.yaml, the one `hermes config set` writes. */
|
|
860
|
+
static configFile(env = process.env) {
|
|
861
|
+
const homeEnv = String(env.HERMES_HOME || '').trim();
|
|
862
|
+
const home = homeEnv || (IS_WINDOWS
|
|
863
|
+
? path.join(env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local'), 'hermes')
|
|
864
|
+
: path.join(os.homedir(), '.hermes'));
|
|
865
|
+
return path.join(home, 'config.yaml');
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** Where the `model:` lines from before configureNativeAuth are kept. */
|
|
869
|
+
static nativeAuthRecordFile() {
|
|
870
|
+
return path.join(os.homedir(), '.openagents', 'native-auth', 'hermes.json');
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Remember what configureNativeAuth replaced. `original` is each managed
|
|
875
|
+
* `model:` line from before the FIRST custom endpoint, kept across later
|
|
876
|
+
* ones; `written` identifies each as configureNativeAuth left it, by hash
|
|
877
|
+
* only, so the key it wrote is not copied here.
|
|
878
|
+
*/
|
|
879
|
+
static recordNativeAuth(configFile, beforeText, afterText) {
|
|
880
|
+
const recordFile = HermesAdapter.nativeAuthRecordFile();
|
|
881
|
+
const previous = readRecord(recordFile);
|
|
882
|
+
const original = previous && previous.configFile === configFile
|
|
883
|
+
? previous.original
|
|
884
|
+
: HermesAdapter.modelLines(beforeText);
|
|
885
|
+
const written = {};
|
|
886
|
+
for (const [name, line] of Object.entries(HermesAdapter.modelLines(afterText))) written[name] = hashLine(line);
|
|
887
|
+
fs.mkdirSync(path.dirname(recordFile), { recursive: true });
|
|
888
|
+
// `original` may hold a key of the user's own provider.
|
|
889
|
+
fs.writeFileSync(recordFile, JSON.stringify({ configFile, original, written }, null, 2), { mode: 0o600 });
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Hand Hermes back the `model:` lines configureNativeAuth replaced, for an
|
|
894
|
+
* agent that now runs on the `hermes setup` sign-in. Without this the custom
|
|
895
|
+
* endpoint and key stayed in config.yaml, and the signed-in agent kept
|
|
896
|
+
* calling them (401 once the key was gone or wrong).
|
|
897
|
+
*
|
|
898
|
+
* Only while every one of them is still exactly what configureNativeAuth
|
|
899
|
+
* wrote: lines the user has changed since (`hermes setup`, `hermes model`)
|
|
900
|
+
* are theirs and stay. Either way the record is dropped.
|
|
901
|
+
*/
|
|
902
|
+
static restoreNativeAuth() {
|
|
903
|
+
const recordFile = HermesAdapter.nativeAuthRecordFile();
|
|
904
|
+
const record = readRecord(recordFile);
|
|
905
|
+
if (!record) return { skipped: true, reason: 'nothing recorded' };
|
|
906
|
+
const drop = () => { try { fs.unlinkSync(recordFile); } catch {} };
|
|
907
|
+
let text;
|
|
908
|
+
try { text = fs.readFileSync(record.configFile, 'utf8'); } catch {
|
|
909
|
+
drop();
|
|
910
|
+
return { skipped: true, reason: 'config.yaml not found' };
|
|
911
|
+
}
|
|
912
|
+
const current = HermesAdapter.modelLines(text);
|
|
913
|
+
if (Object.keys(current).some((name) => hashLine(current[name]) !== (record.written || {})[name])) {
|
|
914
|
+
drop();
|
|
915
|
+
return { skipped: true, reason: 'model section changed since' };
|
|
916
|
+
}
|
|
917
|
+
fs.writeFileSync(record.configFile, HermesAdapter.restoreModelLines(text, record.original || {}));
|
|
918
|
+
drop();
|
|
919
|
+
return { restored: true };
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* The lines of a config.yaml text that configureNativeAuth writes, verbatim
|
|
924
|
+
* or null where absent: the top-level `model:` line itself (`hermes config
|
|
925
|
+
* set` turns a plain `model: <id>` into a mapping) and its `default`,
|
|
926
|
+
* `provider`, `base_url` and `api_key` keys.
|
|
927
|
+
*/
|
|
928
|
+
static modelLines(text) {
|
|
929
|
+
const { lines, at } = locateModelLines(text);
|
|
930
|
+
const out = {};
|
|
931
|
+
for (const name of MODEL_LINE_NAMES) out[name] = at[name] >= 0 ? lines[at[name]] : null;
|
|
932
|
+
return out;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* `text` with each managed `model:` line put back as `original` has it: a
|
|
937
|
+
* line that was not there before is removed, one that was is restored in
|
|
938
|
+
* place (or under `model:`). Every other line, comments included, is left
|
|
939
|
+
* exactly as it is.
|
|
940
|
+
*/
|
|
941
|
+
static restoreModelLines(text, original) {
|
|
942
|
+
const { lines, at } = locateModelLines(text);
|
|
943
|
+
const eol = /\r\n/.test(String(text || '')) ? '\r\n' : '\n';
|
|
944
|
+
const drop = new Set();
|
|
945
|
+
const insert = [];
|
|
946
|
+
for (const name of MODEL_LINE_NAMES) {
|
|
947
|
+
const was = original[name] == null ? null : String(original[name]);
|
|
948
|
+
if (at[name] >= 0) {
|
|
949
|
+
if (was == null) drop.add(at[name]);
|
|
950
|
+
else lines[at[name]] = was;
|
|
951
|
+
} else if (was != null && name !== 'header') {
|
|
952
|
+
insert.push(was);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
const out = [];
|
|
956
|
+
lines.forEach((line, i) => {
|
|
957
|
+
if (!drop.has(i)) out.push(line);
|
|
958
|
+
if (i === at.header && !drop.has(i)) out.push(...insert);
|
|
959
|
+
});
|
|
960
|
+
return out.join(eol);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// What configureNativeAuth writes into config.yaml: the `model:` line and these keys under it.
|
|
965
|
+
const MODEL_KEYS = ['default', 'provider', 'base_url', 'api_key'];
|
|
966
|
+
const MODEL_LINE_NAMES = ['header', ...MODEL_KEYS];
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Line indexes of the managed `model:` lines (-1 where absent). The section
|
|
970
|
+
* runs to the next top-level key: Hermes's own config.yaml has a long run of
|
|
971
|
+
* column-0 comments inside it, and `hermes config set model.api_key` appends
|
|
972
|
+
* the key after them. Only direct children count, by their indentation.
|
|
973
|
+
*/
|
|
974
|
+
function locateModelLines(text) {
|
|
975
|
+
const lines = String(text || '').split(/\r?\n/);
|
|
976
|
+
const at = Object.fromEntries(MODEL_LINE_NAMES.map((name) => [name, -1]));
|
|
977
|
+
at.header = lines.findIndex((line) => /^model[ \t]*:/.test(line));
|
|
978
|
+
if (at.header < 0) return { lines, at };
|
|
979
|
+
let indent = null;
|
|
980
|
+
for (let i = at.header + 1; i < lines.length; i++) {
|
|
981
|
+
const line = lines[i];
|
|
982
|
+
if (line.trim() === '' || line.startsWith('#')) continue;
|
|
983
|
+
const m = /^([ \t]+)([A-Za-z_]+)[ \t]*:/.exec(line);
|
|
984
|
+
if (!/^[ \t]/.test(line)) break;
|
|
985
|
+
if (/^[ \t]*#/.test(line) || !m) continue;
|
|
986
|
+
if (indent == null) indent = m[1];
|
|
987
|
+
if (m[1] === indent && MODEL_KEYS.includes(m[2]) && at[m[2]] < 0) at[m[2]] = i;
|
|
988
|
+
}
|
|
989
|
+
return { lines, at };
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function hashLine(line) {
|
|
993
|
+
return line == null ? null : crypto.createHash('sha256').update(line).digest('hex');
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function readTextOrEmpty(file) {
|
|
997
|
+
try { return fs.readFileSync(file, 'utf8'); } catch { return ''; }
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function readRecord(file) {
|
|
1001
|
+
try {
|
|
1002
|
+
const record = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
1003
|
+
return record && typeof record.configFile === 'string' ? record : null;
|
|
1004
|
+
} catch {
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
849
1007
|
}
|
|
850
1008
|
|
|
851
1009
|
module.exports = HermesAdapter;
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
require('./win-console').installWindowsHideDefault();
|
|
6
6
|
|
|
7
7
|
const { Config } = require('./config');
|
|
8
|
-
const { EnvManager } = require('./env');
|
|
8
|
+
const { EnvManager, isCliLogin, typeEnvFor } = require('./env');
|
|
9
9
|
const { Registry } = require('./registry');
|
|
10
10
|
const { Installer } = require('./installer');
|
|
11
11
|
const { Daemon } = require('./daemon');
|
|
@@ -119,11 +119,28 @@ class AgentConnector {
|
|
|
119
119
|
// key while the run used a stale one ("401 Invalid token") or none at all
|
|
120
120
|
// (Hermes falling back to OpenRouter: "401 Missing Authentication header").
|
|
121
121
|
if (env && Object.keys(env).length) {
|
|
122
|
-
this.
|
|
122
|
+
this._configureAgentNativeAuth(agentType, env);
|
|
123
123
|
}
|
|
124
124
|
return { success: true };
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* _configureNativeAuth for one agent, on the env it actually runs with: the
|
|
129
|
+
* type's keys and endpoint only when it has none of its own and does not
|
|
130
|
+
* sign in through its CLI (typeEnvFor). Merging all of <type>.env pushed a
|
|
131
|
+
* key saved there earlier into Hermes's config.yaml for an agent created on
|
|
132
|
+
* the sign-in tab, which then ran on that key (401).
|
|
133
|
+
*/
|
|
134
|
+
_configureAgentNativeAuth(agentType, agentEnv) {
|
|
135
|
+
const typeEnv = typeEnvFor(agentType, this.env.load(agentType), this.registry, agentEnv);
|
|
136
|
+
this._configureNativeAuth(agentType, { ...typeEnv, ...agentEnv });
|
|
137
|
+
// A Hermes agent moved to the `hermes setup` sign-in gets back the
|
|
138
|
+
// provider the custom endpoint replaced.
|
|
139
|
+
if (agentType === 'hermes' && isCliLogin(agentEnv)) {
|
|
140
|
+
try { require('./adapters/hermes').restoreNativeAuth(); } catch {}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
127
144
|
/** Push an agent's endpoint and key into the CLI's own config, for the types that need it. */
|
|
128
145
|
_configureNativeAuth(agentType, env) {
|
|
129
146
|
try {
|
|
@@ -270,7 +287,7 @@ class AgentConnector {
|
|
|
270
287
|
// Preserve native auth side effects for agents that need them while
|
|
271
288
|
// keeping the model choice scoped to this individual agent.
|
|
272
289
|
const agentType = agent.type || 'openclaw';
|
|
273
|
-
this.
|
|
290
|
+
this._configureAgentNativeAuth(agentType, saved);
|
|
274
291
|
|
|
275
292
|
return { success: true };
|
|
276
293
|
}
|