@atbash/cli 0.5.15-dev.8 → 0.6.0-dev.1
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/README.md +287 -26
- package/dist/bin/atbash.js +31 -5
- package/dist/bin/atbash.js.map +1 -1
- package/dist/commands/connect.d.ts +40 -50
- package/dist/commands/connect.js +60 -108
- package/dist/commands/connect.js.map +1 -1
- package/dist/commands/github-scan.d.ts +104 -0
- package/dist/commands/github-scan.js +1054 -0
- package/dist/commands/github-scan.js.map +1 -0
- package/dist/commands/held.js +7 -2
- package/dist/commands/held.js.map +1 -1
- package/dist/commands/history.js +4 -1
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/judge-options.d.ts +21 -0
- package/dist/commands/judge-options.js +24 -0
- package/dist/commands/judge-options.js.map +1 -0
- package/dist/commands/judge.js +4 -1
- package/dist/commands/judge.js.map +1 -1
- package/dist/commands/policy.js +4 -1
- package/dist/commands/policy.js.map +1 -1
- package/dist/commands/scan.d.ts +45 -0
- package/dist/commands/scan.js +301 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/setup.d.ts +1 -209
- package/dist/commands/setup.js +128 -947
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/stats.js +3 -1
- package/dist/commands/stats.js.map +1 -1
- package/dist/commands/status.js +4 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/tier.js +4 -1
- package/dist/commands/tier.js.map +1 -1
- package/dist/commands/tools.js +11 -4
- package/dist/commands/tools.js.map +1 -1
- package/dist/commands/whoami.js +4 -1
- package/dist/commands/whoami.js.map +1 -1
- package/dist/lib/grade-llm.d.ts +38 -0
- package/dist/lib/grade-llm.js +64 -0
- package/dist/lib/grade-llm.js.map +1 -0
- package/dist/lib/llm.d.ts +34 -0
- package/dist/lib/llm.js +101 -0
- package/dist/lib/llm.js.map +1 -0
- package/dist/lib/policy.d.ts +40 -0
- package/dist/lib/policy.js +94 -0
- package/dist/lib/policy.js.map +1 -0
- package/dist/lib/risk.d.ts +112 -0
- package/dist/lib/risk.js +288 -0
- package/dist/lib/risk.js.map +1 -0
- package/dist/lib/threats-llm.d.ts +39 -0
- package/dist/lib/threats-llm.js +72 -0
- package/dist/lib/threats-llm.js.map +1 -0
- package/package.json +4 -4
- package/dist/commands/mcp-cmd.d.ts +0 -13
- package/dist/commands/mcp-cmd.js +0 -216
- package/dist/commands/mcp-cmd.js.map +0 -1
- package/dist/shared/atbash-targets.d.ts +0 -49
- package/dist/shared/atbash-targets.js +0 -63
- package/dist/shared/atbash-targets.js.map +0 -1
package/dist/commands/setup.js
CHANGED
|
@@ -43,18 +43,6 @@ exports.resolveKeySource = resolveKeySource;
|
|
|
43
43
|
exports.keyFileContents = keyFileContents;
|
|
44
44
|
exports.isJsonc = isJsonc;
|
|
45
45
|
exports.mergeOpenclawConfig = mergeOpenclawConfig;
|
|
46
|
-
exports.detectIndent = detectIndent;
|
|
47
|
-
exports.serializeLike = serializeLike;
|
|
48
|
-
exports.detectMcpClients = detectMcpClients;
|
|
49
|
-
exports.findHermesPython = findHermesPython;
|
|
50
|
-
exports.wantedRuntime = wantedRuntime;
|
|
51
|
-
exports.mergeHermesEnabledPlugins = mergeHermesEnabledPlugins;
|
|
52
|
-
exports.hermesGatewayRunning = hermesGatewayRunning;
|
|
53
|
-
exports.hermesPluginState = hermesPluginState;
|
|
54
|
-
exports.pythonInstallStrategy = pythonInstallStrategy;
|
|
55
|
-
exports.mergeHermesEnv = mergeHermesEnv;
|
|
56
|
-
exports.hadInlineKey = hadInlineKey;
|
|
57
|
-
exports.mergeMcpServer = mergeMcpServer;
|
|
58
46
|
exports.buildPlan = buildPlan;
|
|
59
47
|
exports.lineDiff = lineDiff;
|
|
60
48
|
exports.renderPlan = renderPlan;
|
|
@@ -67,9 +55,8 @@ const path = __importStar(require("path"));
|
|
|
67
55
|
const child_process_1 = require("child_process");
|
|
68
56
|
const chalk_1 = __importDefault(require("chalk"));
|
|
69
57
|
const jsonc = __importStar(require("jsonc-parser"));
|
|
70
|
-
const yaml_1 = require("yaml");
|
|
71
58
|
const sdk_1 = require("@atbash/sdk");
|
|
72
|
-
const
|
|
59
|
+
const connect_1 = require("./connect");
|
|
73
60
|
/**
|
|
74
61
|
* `atbash setup` — the write half of onboarding.
|
|
75
62
|
*
|
|
@@ -97,11 +84,9 @@ const atbash_targets_1 = require("../shared/atbash-targets");
|
|
|
97
84
|
* 2. It never writes the private key into an MCP client config. The documented
|
|
98
85
|
* `@atbash/mcp` wiring passes the key as an `ATBASH_AGENT_PRIVKEY` env value
|
|
99
86
|
* inside e.g. `claude_desktop_config.json` — a file people screenshot, sync
|
|
100
|
-
* and share
|
|
101
|
-
* published 0.1.3)
|
|
102
|
-
*
|
|
103
|
-
* environment. The config file itself gets NO credential — and an entry that
|
|
104
|
-
* was hand-wired with one has it removed.
|
|
87
|
+
* and share. That package has no key-file fallback today (verified against
|
|
88
|
+
* the published 0.1.3), so MCP clients are REPORTED with the snippet to add
|
|
89
|
+
* by hand rather than silently seeded with a secret.
|
|
105
90
|
* 3. It never edits application source. Code-level integrations (LangChain,
|
|
106
91
|
* LangGraph, AutoGen, Eliza, the SDK boundary) are the owner's to write.
|
|
107
92
|
* 4. It never rewrites a config file that uses comments or trailing commas.
|
|
@@ -223,45 +208,7 @@ function normalizePrivkey(raw) {
|
|
|
223
208
|
const clean = raw.replace(/^0x/i, "").trim().toLowerCase();
|
|
224
209
|
return (0, sdk_1.isValidPrivateKey)(clean) ? clean : "";
|
|
225
210
|
}
|
|
226
|
-
/**
|
|
227
|
-
const MAX_SNIFF_BYTES = 8 * 1024;
|
|
228
|
-
/** Bound the content-sniff so `--keys-dir ~` cannot turn into a directory crawl. */
|
|
229
|
-
const MAX_SNIFF_FILES = 60;
|
|
230
|
-
/** Newest-first, so a freshly downloaded key wins over one from last month. */
|
|
231
|
-
function newestFirst(files) {
|
|
232
|
-
return files
|
|
233
|
-
.map((file) => {
|
|
234
|
-
let mtime = 0;
|
|
235
|
-
try {
|
|
236
|
-
mtime = fs.statSync(file).mtimeMs;
|
|
237
|
-
}
|
|
238
|
-
catch { /* unreadable — sorts last */ }
|
|
239
|
-
return { file, mtime };
|
|
240
|
-
})
|
|
241
|
-
.sort((a, b) => b.mtime - a.mtime)
|
|
242
|
-
.map((e) => e.file);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Files in a directory that plausibly hold an Atbash agent key, newest first.
|
|
246
|
-
*
|
|
247
|
-
* TWO PASSES, and the second one is the point.
|
|
248
|
-
*
|
|
249
|
-
* By name first — `guard-client-key`, `agent-keys-*.txt` and friends — because
|
|
250
|
-
* matching the name is cheap and unambiguous. But a name-only match is a cliff:
|
|
251
|
-
* rename the download, or export from a wallet UI that picks its own filename,
|
|
252
|
-
* and the operator gets "no key file found" while the key sits right there in the
|
|
253
|
-
* directory they explicitly pointed at.
|
|
254
|
-
*
|
|
255
|
-
* So if no name matches, read the small files and keep the ones that actually
|
|
256
|
-
* PARSE as key material. That is a narrow test — `privkey=`, the documented JSON
|
|
257
|
-
* shape, or a file that is nothing but a 64-hex key — not "contains something
|
|
258
|
-
* hex-looking", so an unrelated file does not get mistaken for an identity.
|
|
259
|
-
*
|
|
260
|
-
* Reading files the operator did not name individually is justified by the flag
|
|
261
|
-
* itself: `--keys-dir` is an explicit instruction to look in that directory. It
|
|
262
|
-
* is bounded to small regular files and a file count, nothing is transmitted, and
|
|
263
|
-
* the caller prints WHICH file it used before doing anything with it.
|
|
264
|
-
*/
|
|
211
|
+
/** Files in a directory that plausibly hold an Atbash agent key, newest first. */
|
|
265
212
|
function keyCandidatesInDir(dir) {
|
|
266
213
|
let names;
|
|
267
214
|
try {
|
|
@@ -270,31 +217,21 @@ function keyCandidatesInDir(dir) {
|
|
|
270
217
|
catch {
|
|
271
218
|
return [];
|
|
272
219
|
}
|
|
273
|
-
const
|
|
220
|
+
const matches = names.filter((n) => n === "guard-client-key" ||
|
|
274
221
|
/^agent-keys-.*\.txt$/i.test(n) ||
|
|
275
222
|
/^atbash.*(key|keys).*\.(txt|json)$/i.test(n));
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
for (const name of names) {
|
|
281
|
-
if (examined >= MAX_SNIFF_FILES)
|
|
282
|
-
break;
|
|
283
|
-
const file = path.join(dir, name);
|
|
223
|
+
return matches
|
|
224
|
+
.map((n) => path.join(dir, n))
|
|
225
|
+
.map((file) => {
|
|
226
|
+
let mtime = 0;
|
|
284
227
|
try {
|
|
285
|
-
|
|
286
|
-
if (!stat.isFile() || stat.size === 0 || stat.size > MAX_SNIFF_BYTES)
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
continue;
|
|
228
|
+
mtime = fs.statSync(file).mtimeMs;
|
|
291
229
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return newestFirst(byContent);
|
|
230
|
+
catch { /* unreadable — sorts last */ }
|
|
231
|
+
return { file, mtime };
|
|
232
|
+
})
|
|
233
|
+
.sort((a, b) => b.mtime - a.mtime)
|
|
234
|
+
.map((e) => e.file);
|
|
298
235
|
}
|
|
299
236
|
/**
|
|
300
237
|
* Read a secret from the terminal without echoing it.
|
|
@@ -310,56 +247,23 @@ function keyCandidatesInDir(dir) {
|
|
|
310
247
|
async function promptForKeyOrPath() {
|
|
311
248
|
const { createInterface } = await Promise.resolve().then(() => __importStar(require("node:readline")));
|
|
312
249
|
return new Promise((resolveP) => {
|
|
250
|
+
const input = process.stdin;
|
|
251
|
+
const rl = createInterface({ input, output: process.stdout, terminal: true });
|
|
252
|
+
// Mute the echo so a pasted key does not sit on screen (or in a scrollback
|
|
253
|
+
// buffer that gets screenshotted). A pasted path is muted too; that is a
|
|
254
|
+
// small cost against leaving a private key visible.
|
|
255
|
+
const asMutable = rl;
|
|
313
256
|
const prompt = "Paste the agent's private key, or the path to its key file: ";
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
// suppressor never has to decide what a write IS: after this point, nothing
|
|
321
|
-
// is echoed, unconditionally.
|
|
322
|
-
process.stdout.write(prompt);
|
|
323
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
324
|
-
rl._writeToOutput = () => {
|
|
325
|
-
/* nothing typed after the prompt is ever echoed */
|
|
257
|
+
asMutable._writeToOutput = function (s) {
|
|
258
|
+
if (s.includes(prompt))
|
|
259
|
+
asMutable.output?.write(s);
|
|
260
|
+
else if (s === "\r\n" || s === "\n")
|
|
261
|
+
asMutable.output?.write(s);
|
|
262
|
+
// every other keystroke echo is dropped
|
|
326
263
|
};
|
|
327
|
-
rl.question(
|
|
328
|
-
rl.close();
|
|
329
|
-
// readline's own newline was suppressed along with everything else, so the
|
|
330
|
-
// next line of output would otherwise land on the prompt line.
|
|
331
|
-
process.stdout.write("\n");
|
|
332
|
-
resolveP(answer.trim());
|
|
333
|
-
});
|
|
264
|
+
rl.question(prompt, (answer) => { rl.close(); resolveP(answer.trim()); });
|
|
334
265
|
});
|
|
335
266
|
}
|
|
336
|
-
/**
|
|
337
|
-
* Interpret whatever someone typed at the prompt: a raw key, a file, or a
|
|
338
|
-
* directory to search. Shared by the "no key found" prompt and the "use the
|
|
339
|
-
* existing key?" prompt so both accept the same things — an operator who can
|
|
340
|
-
* paste a path in one place should not find it rejected in the other.
|
|
341
|
-
*/
|
|
342
|
-
async function keyFromAnswer(answer, home) {
|
|
343
|
-
const direct = parseKeyMaterial(answer);
|
|
344
|
-
if (direct)
|
|
345
|
-
return { material: direct, from: "key entered at the prompt" };
|
|
346
|
-
const asPath = expandHome(answer, home);
|
|
347
|
-
if (!exists(asPath))
|
|
348
|
-
return null;
|
|
349
|
-
let isDir = false;
|
|
350
|
-
try {
|
|
351
|
-
isDir = fs.statSync(asPath).isDirectory();
|
|
352
|
-
}
|
|
353
|
-
catch {
|
|
354
|
-
return null;
|
|
355
|
-
}
|
|
356
|
-
const file = isDir ? keyCandidatesInDir(asPath)[0] : asPath;
|
|
357
|
-
if (!file)
|
|
358
|
-
return null;
|
|
359
|
-
const text = readTextFile(file);
|
|
360
|
-
const material = text === null ? null : parseKeyMaterial(text);
|
|
361
|
-
return material ? { material, from: `${file} (given at the prompt)` } : null;
|
|
362
|
-
}
|
|
363
267
|
/**
|
|
364
268
|
* Find the agent key, trying every way an owner could plausibly have it.
|
|
365
269
|
*
|
|
@@ -393,15 +297,7 @@ async function resolveKeySource(opts) {
|
|
|
393
297
|
const dir = expandHome(opts.keysDir, home);
|
|
394
298
|
const candidates = keyCandidatesInDir(dir);
|
|
395
299
|
if (!candidates.length) {
|
|
396
|
-
return {
|
|
397
|
-
error: [
|
|
398
|
-
`No agent key found in ${dir}.`,
|
|
399
|
-
"Looked for guard-client-key / agent-keys-*.txt by name, then read the small",
|
|
400
|
-
"files there to see if any parsed as an agent key. Neither found one.",
|
|
401
|
-
"Point at the file directly with --key-file, or paste the key with no flags",
|
|
402
|
-
"at all and setup will prompt for it.",
|
|
403
|
-
].join("\n"),
|
|
404
|
-
};
|
|
300
|
+
return { error: `No agent key file found in ${dir} (looked for guard-client-key and agent-keys-*.txt).` };
|
|
405
301
|
}
|
|
406
302
|
return fromFile(candidates[0], "--keys-dir");
|
|
407
303
|
}
|
|
@@ -413,39 +309,11 @@ async function resolveKeySource(opts) {
|
|
|
413
309
|
return { material, from: "ATBASH_AGENT_KEY" };
|
|
414
310
|
}
|
|
415
311
|
// 5. Already in the canonical place — a re-run, or a machine set up before.
|
|
416
|
-
//
|
|
417
|
-
// This used to be taken SILENTLY, and that was a trap. A machine that has ever
|
|
418
|
-
// governed one agent already has a key here, so onboarding a SECOND agent
|
|
419
|
-
// picked up the first one's key and then failed registration against a pubkey
|
|
420
|
-
// the operator never chose:
|
|
421
|
-
//
|
|
422
|
-
// Agent key source: existing key file (~/.config/atbash/guard-client-key)
|
|
423
|
-
// That agent is not registered on this deployment.
|
|
424
|
-
//
|
|
425
|
-
// which reads as "onboarding is broken" rather than "I used a different key
|
|
426
|
-
// than you meant". So when there is someone to ask, ask — and make the existing
|
|
427
|
-
// key the easy answer for the common case (a genuine re-run) without making it
|
|
428
|
-
// the only answer.
|
|
429
312
|
const keyFile = path.join(home, ...KEY_FILE_REL);
|
|
430
313
|
if (exists(keyFile)) {
|
|
431
314
|
const found = fromFile(keyFile, "existing key file");
|
|
432
|
-
if (!("error" in found))
|
|
433
|
-
|
|
434
|
-
return found; // non-interactive: same as before
|
|
435
|
-
const existingPub = (0, sdk_1.derivePublicKey)(found.material.privkey);
|
|
436
|
-
process.stdout.write(`\n This machine already has an agent key at ${keyFile}\n` +
|
|
437
|
-
` Public key: ${existingPub}\n`);
|
|
438
|
-
const useExisting = await confirm(" Use that key? [Y/n] ", true);
|
|
439
|
-
if (useExisting)
|
|
440
|
-
return found;
|
|
441
|
-
const answer = await promptForKeyOrPath();
|
|
442
|
-
if (!answer)
|
|
443
|
-
return { error: "No key provided." };
|
|
444
|
-
const supplied = await keyFromAnswer(answer, home);
|
|
445
|
-
if (supplied)
|
|
446
|
-
return supplied;
|
|
447
|
-
return { error: "That is neither a 64-hex private key nor a path that exists." };
|
|
448
|
-
}
|
|
315
|
+
if (!("error" in found))
|
|
316
|
+
return found;
|
|
449
317
|
}
|
|
450
318
|
// 6. The CLI's own config, populated by `atbash set agent-key`.
|
|
451
319
|
const fromConfig = (0, sdk_1.resolve)("agentKey");
|
|
@@ -459,9 +327,20 @@ async function resolveKeySource(opts) {
|
|
|
459
327
|
const answer = await promptForKeyOrPath();
|
|
460
328
|
if (!answer)
|
|
461
329
|
return { error: "No key provided." };
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
464
|
-
return
|
|
330
|
+
const direct = parseKeyMaterial(answer);
|
|
331
|
+
if (direct)
|
|
332
|
+
return { material: direct, from: "interactive prompt" };
|
|
333
|
+
const asPath = expandHome(answer, home);
|
|
334
|
+
if (exists(asPath)) {
|
|
335
|
+
const stat = fs.statSync(asPath);
|
|
336
|
+
if (stat.isDirectory()) {
|
|
337
|
+
const candidates = keyCandidatesInDir(asPath);
|
|
338
|
+
if (candidates.length)
|
|
339
|
+
return fromFile(candidates[0], "directory given at the prompt");
|
|
340
|
+
return { error: `No agent key file found in ${asPath}.` };
|
|
341
|
+
}
|
|
342
|
+
return fromFile(asPath, "file given at the prompt");
|
|
343
|
+
}
|
|
465
344
|
return { error: "That is neither a 64-hex private key nor a path that exists." };
|
|
466
345
|
}
|
|
467
346
|
return {
|
|
@@ -515,504 +394,51 @@ function isJsonc(text) {
|
|
|
515
394
|
function mergeOpenclawConfig(config, home) {
|
|
516
395
|
const out = { ...config };
|
|
517
396
|
const plugins = { ...(isRecord(out.plugins) ? out.plugins : {}) };
|
|
397
|
+
// Which key is this install governed under? Keep an existing legacy entry
|
|
398
|
+
// where it is instead of adding a second one.
|
|
518
399
|
const entries = { ...(isRecord(plugins.entries) ? plugins.entries : {}) };
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const entryKey = legacy && !modern ? OPENCLAW_LEGACY_ENTRY : OPENCLAW_ENTRY;
|
|
523
|
-
const existing = isRecord(entries[entryKey]) ? entries[entryKey] : null;
|
|
524
|
-
// ⚠️ AN EXISTING ENTRY IS TOUCHED AS LITTLE AS POSSIBLE.
|
|
525
|
-
//
|
|
526
|
-
// This function used to assert the full documented shape onto whatever it
|
|
527
|
-
// found, which broke a real machine: a legacy `atbash-plugin` install accepts
|
|
528
|
-
// only `config` and `enabled`, so writing the `hooks` block that the NEW
|
|
529
|
-
// `openclaw` entry documents made the whole file invalid —
|
|
530
|
-
//
|
|
531
|
-
// Invalid config at ~/.openclaw/openclaw.json:
|
|
532
|
-
// - plugins.entries.atbash-plugin: Unrecognized key: "hooks"
|
|
533
|
-
//
|
|
534
|
-
// and OpenClaw then refused to load any config at all. It also added a
|
|
535
|
-
// `load.paths` entry pointing at `extensions/openclaw` on a box whose plugin
|
|
536
|
-
// lives in `extensions/atbash-plugin`, and rewrote an absolute
|
|
537
|
-
// `chromiaSecretPath` to a `~` one for no gain.
|
|
538
|
-
//
|
|
539
|
-
// A plugin that is already installed and registered does not need `allow`,
|
|
540
|
-
// `load` or `hooks` re-declared — it is working. The only thing setup has any
|
|
541
|
-
// business changing is that it is switched on and pointed at the right key.
|
|
542
|
-
if (existing) {
|
|
543
|
-
const existingConfig = isRecord(existing.config) ? existing.config : {};
|
|
544
|
-
entries[entryKey] = {
|
|
545
|
-
...existing,
|
|
546
|
-
enabled: true,
|
|
547
|
-
config: { ...existingConfig, enabled: true, enforceDecision: true, ...keyPathUpdate(existingConfig, home) },
|
|
548
|
-
};
|
|
549
|
-
plugins.entries = entries;
|
|
550
|
-
out.plugins = plugins;
|
|
551
|
-
return out;
|
|
552
|
-
}
|
|
553
|
-
// No entry yet — write the shape the published plugin documents, in full.
|
|
400
|
+
const entryKey = OPENCLAW_LEGACY_ENTRY in entries && !(OPENCLAW_ENTRY in entries)
|
|
401
|
+
? OPENCLAW_LEGACY_ENTRY
|
|
402
|
+
: OPENCLAW_ENTRY;
|
|
554
403
|
const allow = Array.isArray(plugins.allow) ? [...plugins.allow] : [];
|
|
555
404
|
if (!allow.includes(entryKey))
|
|
556
405
|
allow.push(entryKey);
|
|
557
406
|
plugins.allow = allow;
|
|
558
407
|
const load = { ...(isRecord(plugins.load) ? plugins.load : {}) };
|
|
559
|
-
const extensionPath = path.join(home, ...OPENCLAW_EXTENSIONS_REL,
|
|
408
|
+
const extensionPath = path.join(home, ...OPENCLAW_EXTENSIONS_REL, OPENCLAW_ENTRY);
|
|
560
409
|
const paths = Array.isArray(load.paths) ? [...load.paths] : [];
|
|
561
410
|
if (!paths.includes(extensionPath))
|
|
562
411
|
paths.push(extensionPath);
|
|
563
412
|
load.paths = paths;
|
|
564
413
|
plugins.load = load;
|
|
414
|
+
// Preserve any unrelated fields the owner set on the entry (debug, custom
|
|
415
|
+
// hooks); only the fields Atbash owns are asserted.
|
|
416
|
+
const existing = isRecord(entries[entryKey]) ? entries[entryKey] : {};
|
|
417
|
+
const existingConfig = isRecord(existing.config) ? existing.config : {};
|
|
418
|
+
const existingHooks = isRecord(existing.hooks) ? existing.hooks : {};
|
|
565
419
|
entries[entryKey] = {
|
|
420
|
+
...existing,
|
|
566
421
|
enabled: true,
|
|
567
|
-
config: {
|
|
568
|
-
|
|
422
|
+
config: {
|
|
423
|
+
...existingConfig,
|
|
424
|
+
enabled: true,
|
|
425
|
+
enforceDecision: true,
|
|
426
|
+
// The path, not the key. This is the whole point of the canonical location.
|
|
427
|
+
chromiaSecretPath: `~/${KEY_FILE_REL.join("/")}`,
|
|
428
|
+
},
|
|
429
|
+
hooks: {
|
|
430
|
+
...existingHooks,
|
|
431
|
+
allowConversationAccess: true,
|
|
432
|
+
allowPromptInjection: true,
|
|
433
|
+
},
|
|
569
434
|
};
|
|
570
435
|
plugins.entries = entries;
|
|
571
436
|
out.plugins = plugins;
|
|
572
437
|
return out;
|
|
573
438
|
}
|
|
574
|
-
/**
|
|
575
|
-
* The key-path field, but only when it actually needs changing.
|
|
576
|
-
*
|
|
577
|
-
* `/Users/me/.config/atbash/guard-client-key` and `~/.config/atbash/guard-client-key`
|
|
578
|
-
* are the same file, and the plugin expands `~`. Rewriting one into the other is
|
|
579
|
-
* a diff the operator has to read and approve for no behavioural change, so an
|
|
580
|
-
* existing value that already resolves to the canonical key file is left exactly
|
|
581
|
-
* as they wrote it.
|
|
582
|
-
*/
|
|
583
|
-
function keyPathUpdate(existingConfig, home) {
|
|
584
|
-
const canonical = path.join(home, ...KEY_FILE_REL);
|
|
585
|
-
const current = existingConfig.chromiaSecretPath;
|
|
586
|
-
if (typeof current === "string" && path.resolve(expandHome(current.trim(), home)) === path.resolve(canonical)) {
|
|
587
|
-
return {};
|
|
588
|
-
}
|
|
589
|
-
return { chromiaSecretPath: `~/${KEY_FILE_REL.join("/")}` };
|
|
590
|
-
}
|
|
591
439
|
function isRecord(v) {
|
|
592
440
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
593
441
|
}
|
|
594
|
-
/**
|
|
595
|
-
* Detect the indentation a JSON file already uses, so a merge does not reformat
|
|
596
|
-
* the parts it did not touch.
|
|
597
|
-
*
|
|
598
|
-
* Without this, `JSON.stringify(obj, null, 2)` re-indents a tab-indented or
|
|
599
|
-
* 4-space config from top to bottom. The RESULT is still correct, but the diff
|
|
600
|
-
* shown for approval becomes every line in the file, which buries the two lines
|
|
601
|
-
* that actually changed — and the operator's own formatting choice is collateral
|
|
602
|
-
* damage in a file we were asked to make one addition to.
|
|
603
|
-
*
|
|
604
|
-
* Falls back to two spaces, which is what the published docs show.
|
|
605
|
-
*/
|
|
606
|
-
function detectIndent(text) {
|
|
607
|
-
if (!text)
|
|
608
|
-
return 2;
|
|
609
|
-
// First line that is indented under an opening brace/bracket tells us the unit.
|
|
610
|
-
const match = text.match(/\n([ \t]+)\S/);
|
|
611
|
-
if (!match)
|
|
612
|
-
return 2;
|
|
613
|
-
const indent = match[1];
|
|
614
|
-
return indent.startsWith("\t") ? "\t" : indent.length;
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* Serialize a merged config the way the file was already written: same
|
|
618
|
-
* indentation, and a trailing newline only if the original had one.
|
|
619
|
-
*/
|
|
620
|
-
function serializeLike(original, value) {
|
|
621
|
-
const body = JSON.stringify(value, null, detectIndent(original));
|
|
622
|
-
// A file that ended without a newline keeps ending without one. Trivial, but it
|
|
623
|
-
// is one more line of unexplained diff for someone reviewing the change.
|
|
624
|
-
const trailing = original === null || original.endsWith("\n") ? "\n" : "";
|
|
625
|
-
return body + trailing;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* The MCP server entry setup writes into a client's config.
|
|
629
|
-
*
|
|
630
|
-
* Note what is NOT here: an `env` block. The published `@atbash/mcp` wiring
|
|
631
|
-
* carries the agent's private key in one, because that package reads only
|
|
632
|
-
* ATBASH_AGENT_PRIVKEY. Going through `atbash mcp` instead means the launcher
|
|
633
|
-
* reads the 0600 key file and passes the key to the server in the child process
|
|
634
|
-
* environment, so this entry holds no credential and the client's config file is
|
|
635
|
-
* no more sensitive after setup runs than it was before.
|
|
636
|
-
*
|
|
637
|
-
* Deliberately NOT pinned to an exact CLI version: unlike the one-shot connector
|
|
638
|
-
* command, this entry persists in the operator's config and is re-executed every
|
|
639
|
-
* time the client starts. Pinning here would freeze their MCP server at whatever
|
|
640
|
-
* version happened to be current on the day they ran setup.
|
|
641
|
-
*/
|
|
642
|
-
const MCP_SERVER_ENTRY = { command: "npx", args: ["--yes", "@atbash/cli", "mcp"] };
|
|
643
|
-
const MCP_SERVER_NAME = "atbash";
|
|
644
|
-
/**
|
|
645
|
-
* MCP client configs present under this home directory.
|
|
646
|
-
*
|
|
647
|
-
* Paths come from the shared MCP_CONFIGS so the writer and the scanner cannot
|
|
648
|
-
* drift: a client the scan reports but setup cannot find would look like a bug in
|
|
649
|
-
* whichever of the two the operator happened to trust.
|
|
650
|
-
*/
|
|
651
|
-
function detectMcpClients(home) {
|
|
652
|
-
const out = [];
|
|
653
|
-
const seen = new Set();
|
|
654
|
-
for (const { label, segs } of atbash_targets_1.MCP_CONFIGS) {
|
|
655
|
-
if (seen.has(label))
|
|
656
|
-
continue;
|
|
657
|
-
const file = path.join(home, ...segs);
|
|
658
|
-
if (!exists(file))
|
|
659
|
-
continue;
|
|
660
|
-
seen.add(label);
|
|
661
|
-
// Read which key this file already uses rather than assuming. VS Code's
|
|
662
|
-
// mcp.json uses `servers`; writing `mcpServers` into it would be ignored.
|
|
663
|
-
const existing = readJsonLoose(file);
|
|
664
|
-
const serversKey = existing && isRecord(existing.servers) && !isRecord(existing.mcpServers) ? "servers" : "mcpServers";
|
|
665
|
-
out.push({ label, file, format: "json", serversKey });
|
|
666
|
-
}
|
|
667
|
-
// Claude Code and Codex are special-cased in the scanner too — same paths.
|
|
668
|
-
const claudeCode = path.join(home, ".claude.json");
|
|
669
|
-
if (exists(claudeCode))
|
|
670
|
-
out.push({ label: "Claude Code", file: claudeCode, format: "json", serversKey: "mcpServers" });
|
|
671
|
-
const codex = path.join(home, ".codex", "config.toml");
|
|
672
|
-
if (exists(codex))
|
|
673
|
-
out.push({ label: "Codex", file: codex, format: "toml", serversKey: "mcpServers" });
|
|
674
|
-
return out;
|
|
675
|
-
}
|
|
676
|
-
/** Tolerant read used only to sniff an existing file's shape. */
|
|
677
|
-
function readJsonLoose(file) {
|
|
678
|
-
const text = readTextFile(file);
|
|
679
|
-
if (text === null)
|
|
680
|
-
return null;
|
|
681
|
-
const value = jsonc.parse(text, [], { allowTrailingComma: true, disallowComments: false });
|
|
682
|
-
return isRecord(value) ? value : null;
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Add the Atbash server to a client config's server map, in place.
|
|
686
|
-
*
|
|
687
|
-
* A merge, like the OpenClaw one: every server the operator already configured
|
|
688
|
-
* stays exactly as it is. An existing `atbash` entry is REPLACED rather than
|
|
689
|
-
* merged field-by-field — a stale `env` block carrying a private key from the old
|
|
690
|
-
* hand-written wiring is precisely what we want gone, and preserving it would
|
|
691
|
-
* defeat the point of routing through the launcher.
|
|
692
|
-
*/
|
|
693
|
-
/** The Hermes plugin, and the exact version the wiring is written against. */
|
|
694
|
-
const HERMES_PKG = "atbash-hermes-plugin";
|
|
695
|
-
const HERMES_VERSION = "0.4.5";
|
|
696
|
-
/** The name Hermes lists this plugin under, and the allow-list entry. */
|
|
697
|
-
const HERMES_PLUGIN_ENTRY = "atbash-hermes-plugin";
|
|
698
|
-
/**
|
|
699
|
-
* Find the Python interpreter that actually runs Hermes.
|
|
700
|
-
*
|
|
701
|
-
* This is the difference between installing the plugin and only appearing to.
|
|
702
|
-
* `pip install atbash-hermes-plugin` puts the package wherever the *shell's*
|
|
703
|
-
* `pip` points — commonly a system or conda Python — while Hermes typically runs
|
|
704
|
-
* from its own virtualenv. The install succeeds, prints nothing alarming, and the
|
|
705
|
-
* plugin is invisible to Hermes forever. Nobody can debug that from the output.
|
|
706
|
-
*
|
|
707
|
-
* The launcher knows the answer. A pip-installed console script begins with a
|
|
708
|
-
* shebang naming the interpreter that created it:
|
|
709
|
-
*
|
|
710
|
-
* $ head -1 $(command -v hermes)
|
|
711
|
-
* #!/Users/me/.hermes/hermes-agent/venv/bin/python3
|
|
712
|
-
*
|
|
713
|
-
* So resolve `hermes`, read its first line, and use that interpreter directly via
|
|
714
|
-
* `-m pip`. Falls back to the conventional venv location under ~/.hermes, then to
|
|
715
|
-
* null — and a null becomes a printed command rather than a guess, because a
|
|
716
|
-
* wrong guess here is the silent failure this whole function exists to avoid.
|
|
717
|
-
*/
|
|
718
|
-
function findHermesPython(home) {
|
|
719
|
-
const viable = (candidate) => {
|
|
720
|
-
try {
|
|
721
|
-
return fs.statSync(candidate).isFile();
|
|
722
|
-
}
|
|
723
|
-
catch {
|
|
724
|
-
return false;
|
|
725
|
-
}
|
|
726
|
-
};
|
|
727
|
-
// 1. The launcher's own shebang — authoritative, but only for a real run.
|
|
728
|
-
//
|
|
729
|
-
// `--home <dir>` exists so a dry run can be hermetic (the release checklist
|
|
730
|
-
// depends on it). A PATH lookup ignores it entirely: under `--home /tmp/fake`
|
|
731
|
-
// this would find the operator's ACTUAL hermes and plan an install into their
|
|
732
|
-
// real virtualenv. So the shebang route is skipped whenever `home` is not the
|
|
733
|
-
// machine's own home — the caller then falls through to the venv path under the
|
|
734
|
-
// given home, which is correctly scoped.
|
|
735
|
-
const realHome = process.env.HOME || os.homedir();
|
|
736
|
-
const scoped = path.resolve(home) !== path.resolve(realHome);
|
|
737
|
-
const which = scoped
|
|
738
|
-
? { status: 1, stdout: "" }
|
|
739
|
-
: (0, child_process_1.spawnSync)(process.platform === "win32" ? "where" : "which", ["hermes"], { encoding: "utf8" });
|
|
740
|
-
const launcher = which.status === 0 ? which.stdout.split(/\r?\n/)[0]?.trim() : "";
|
|
741
|
-
if (launcher && viable(launcher)) {
|
|
742
|
-
const firstLine = (readTextFile(launcher) ?? "").split(/\r?\n/)[0] ?? "";
|
|
743
|
-
const shebang = firstLine.startsWith("#!") ? firstLine.slice(2).trim() : "";
|
|
744
|
-
// `#!/usr/bin/env python3` names no path; anything else should be absolute.
|
|
745
|
-
const interpreter = shebang.split(/\s+/).filter((part) => !part.endsWith("/env"))[0] ?? "";
|
|
746
|
-
if (/python[0-9.]*$/.test(interpreter) && viable(interpreter)) {
|
|
747
|
-
return { python: interpreter, how: `shebang of ${launcher}` };
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
// 2. The conventional venv Hermes ships with.
|
|
751
|
-
for (const name of ["python3", "python"]) {
|
|
752
|
-
const candidate = path.join(home, ".hermes", "hermes-agent", "venv", "bin", name);
|
|
753
|
-
if (viable(candidate))
|
|
754
|
-
return { python: candidate, how: "Hermes virtualenv under ~/.hermes" };
|
|
755
|
-
}
|
|
756
|
-
return null;
|
|
757
|
-
}
|
|
758
|
-
/** Same rule as buildPlan's `wanted`: an empty --runtime list means everything. */
|
|
759
|
-
function wantedRuntime(id, only) {
|
|
760
|
-
return only.length === 0 || only.includes(id);
|
|
761
|
-
}
|
|
762
|
-
/**
|
|
763
|
-
* Add the plugin to Hermes' opt-in allow-list at `plugins.enabled` in
|
|
764
|
-
* `~/.hermes/config.yaml`.
|
|
765
|
-
*
|
|
766
|
-
* WHY NOT `hermes plugins enable`: that command cannot accept this plugin, on
|
|
767
|
-
* this version, ever. `_plugin_exists` (hermes_cli/plugins_cmd.py) looks only for
|
|
768
|
-
* a DIRECTORY in the user plugins dir or a bundled dir — it never consults entry
|
|
769
|
-
* points. Meanwhile the runtime loader (`plugins.py:_scan_entry_points`) does
|
|
770
|
-
* discover them. So Hermes will happily LOAD a pip-installed plugin but refuses
|
|
771
|
-
* to put one on the allow-list it requires, and since plugins are opt-in, a
|
|
772
|
-
* package that cannot get onto the list can never load. Running that command
|
|
773
|
-
* exits 1 with "not installed or bundled". Writing the list entry directly is the
|
|
774
|
-
* only route that works.
|
|
775
|
-
*
|
|
776
|
-
* A LINE MERGE, not a parse-and-reserialize. config.yaml is tens of kilobytes of
|
|
777
|
-
* heavily commented configuration; round-tripping it through a YAML emitter would
|
|
778
|
-
* strip every comment and reflow the file. So this inserts the one line needed and
|
|
779
|
-
* leaves every other byte alone — the same discipline as the .env merge.
|
|
780
|
-
*/
|
|
781
|
-
function mergeHermesEnabledPlugins(existing, plugin = HERMES_PLUGIN_ENTRY) {
|
|
782
|
-
const lines = existing === null ? [] : existing.split("\n");
|
|
783
|
-
// Already on the list? Then there is nothing to do.
|
|
784
|
-
const pluginsAt = lines.findIndex((l) => /^plugins:\s*(#.*)?$/.test(l));
|
|
785
|
-
if (pluginsAt !== -1) {
|
|
786
|
-
// Walk the plugins block (indented lines) looking for `enabled:` and its items.
|
|
787
|
-
let enabledAt = -1;
|
|
788
|
-
let end = lines.length;
|
|
789
|
-
for (let i = pluginsAt + 1; i < lines.length; i++) {
|
|
790
|
-
const line = lines[i];
|
|
791
|
-
if (line.trim() === "" || line.startsWith("#"))
|
|
792
|
-
continue;
|
|
793
|
-
if (!/^\s/.test(line)) {
|
|
794
|
-
end = i;
|
|
795
|
-
break;
|
|
796
|
-
} // dedented — block over
|
|
797
|
-
if (/^\s+enabled:\s*(#.*)?$/.test(line))
|
|
798
|
-
enabledAt = i;
|
|
799
|
-
}
|
|
800
|
-
if (enabledAt !== -1) {
|
|
801
|
-
// Collect the list items under `enabled:` and bail if ours is there.
|
|
802
|
-
const itemIndent = (lines[enabledAt].match(/^\s*/)?.[0] ?? " ") + " ";
|
|
803
|
-
let last = enabledAt;
|
|
804
|
-
for (let i = enabledAt + 1; i < end; i++) {
|
|
805
|
-
if (/^\s*-\s+/.test(lines[i])) {
|
|
806
|
-
if (lines[i].replace(/^\s*-\s+/, "").trim().replace(/^["']|["']$/g, "") === plugin)
|
|
807
|
-
return existing;
|
|
808
|
-
last = i;
|
|
809
|
-
}
|
|
810
|
-
else if (lines[i].trim() !== "")
|
|
811
|
-
break;
|
|
812
|
-
}
|
|
813
|
-
lines.splice(last + 1, 0, `${itemIndent}- ${plugin}`);
|
|
814
|
-
return lines.join("\n");
|
|
815
|
-
}
|
|
816
|
-
// A plugins block with no `enabled:` key — add one inside it.
|
|
817
|
-
lines.splice(pluginsAt + 1, 0, " enabled:", ` - ${plugin}`);
|
|
818
|
-
return lines.join("\n");
|
|
819
|
-
}
|
|
820
|
-
// No plugins block at all — which is the default, and means nothing loads.
|
|
821
|
-
const out = existing === null ? [] : [...lines];
|
|
822
|
-
if (out.length && out[out.length - 1].trim() !== "")
|
|
823
|
-
out.push("");
|
|
824
|
-
out.push("# Added by `atbash setup` - Hermes loads only plugins on this allow-list");
|
|
825
|
-
out.push("plugins:", " enabled:", ` - ${plugin}`);
|
|
826
|
-
let text = out.join("\n");
|
|
827
|
-
if (!text.endsWith("\n"))
|
|
828
|
-
text += "\n";
|
|
829
|
-
return text;
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Is a Hermes gateway service running, and therefore restartable?
|
|
833
|
-
*
|
|
834
|
-
* "Restart Hermes" only means something when there is a service to bounce.
|
|
835
|
-
* Hermes has two shapes: `hermes` starts an interactive chat session, and
|
|
836
|
-
* `hermes gateway install` registers a launchd/systemd background service. A
|
|
837
|
-
* setup command must not conflate them —
|
|
838
|
-
*
|
|
839
|
-
* - with a service running, `hermes gateway restart` picks up the new config and
|
|
840
|
-
* is worth doing for the operator;
|
|
841
|
-
* - without one, there is nothing to restart. The plugin loads the next time
|
|
842
|
-
* they run `hermes`, and anything we "restarted" would either be a no-op or,
|
|
843
|
-
* worse, an interactive session someone is in the middle of using.
|
|
844
|
-
*
|
|
845
|
-
* `gateway status` exits 0 either way, so the state comes from its text.
|
|
846
|
-
*/
|
|
847
|
-
function hermesGatewayRunning() {
|
|
848
|
-
const probe = (0, child_process_1.spawnSync)("hermes", ["gateway", "status"], { encoding: "utf8" });
|
|
849
|
-
if (probe.status !== 0 || typeof probe.stdout !== "string")
|
|
850
|
-
return false;
|
|
851
|
-
// "✗ Gateway is not running" vs a running report.
|
|
852
|
-
return !/not\s+running/i.test(probe.stdout);
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Is Hermes CONFIGURED to load the plugin?
|
|
856
|
-
*
|
|
857
|
-
* This used to shell out to `hermes plugins list` and look for an atbash row —
|
|
858
|
-
* a signal that can never be true. `_discover_all_plugins` (plugins_cmd.py) walks
|
|
859
|
-
* plugin DIRECTORIES only: bundled, user, project. It never scans entry points,
|
|
860
|
-
* exactly like the `_plugin_exists` gate behind `plugins enable`. So a
|
|
861
|
-
* pip-installed plugin is invisible to both, and the check reported "not picked
|
|
862
|
-
* up" while everything was in fact correct — then told the operator to run the
|
|
863
|
-
* enable command that cannot work. Advising a known-impossible fix is worse than
|
|
864
|
-
* saying nothing.
|
|
865
|
-
*
|
|
866
|
-
* The two facts that actually decide it are both on disk:
|
|
867
|
-
*
|
|
868
|
-
* 1. the package is importable by the interpreter that runs Hermes, and
|
|
869
|
-
* 2. its name is on the `plugins.enabled` allow-list in config.yaml, which is
|
|
870
|
-
* what the RUNTIME loader (`plugins.py:_scan_entry_points`) honours.
|
|
871
|
-
*
|
|
872
|
-
* "configured" is as far as a setup command can honestly go. Proof of loading is
|
|
873
|
-
* a line in the agent log after Hermes next starts, which is why the caller points
|
|
874
|
-
* at that rather than claiming enforcement.
|
|
875
|
-
*/
|
|
876
|
-
function hermesPluginState(home) {
|
|
877
|
-
const venvBase = path.join(home, ".hermes", "hermes-agent", "venv", "lib");
|
|
878
|
-
let installed = false;
|
|
879
|
-
try {
|
|
880
|
-
installed = fs.readdirSync(venvBase, { withFileTypes: true })
|
|
881
|
-
.filter((e) => e.isDirectory())
|
|
882
|
-
.some((e) => exists(venvBase, e.name, "site-packages", "atbash_hermes_plugin"));
|
|
883
|
-
}
|
|
884
|
-
catch {
|
|
885
|
-
return "unknown";
|
|
886
|
-
}
|
|
887
|
-
const configYaml = readTextFile(path.join(home, ".hermes", "config.yaml"));
|
|
888
|
-
if (configYaml === null)
|
|
889
|
-
return installed ? "not-enabled" : "not-installed";
|
|
890
|
-
let enabled = false;
|
|
891
|
-
try {
|
|
892
|
-
const parsed = (0, yaml_1.parse)(configYaml);
|
|
893
|
-
const list = parsed?.plugins?.enabled;
|
|
894
|
-
enabled = Array.isArray(list) && list.some((n) => String(n).trim() === HERMES_PLUGIN_ENTRY);
|
|
895
|
-
}
|
|
896
|
-
catch {
|
|
897
|
-
return "unknown";
|
|
898
|
-
}
|
|
899
|
-
if (!installed)
|
|
900
|
-
return "not-installed";
|
|
901
|
-
return enabled ? "configured" : "not-enabled";
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* How to install a Python package into a specific interpreter on THIS machine.
|
|
905
|
-
*
|
|
906
|
-
* `<python> -m pip install` is the obvious answer and it is frequently wrong: a
|
|
907
|
-
* venv created by `uv venv` has no pip at all (that is uv's default), so the
|
|
908
|
-
* command fails with
|
|
909
|
-
*
|
|
910
|
-
* /path/venv/bin/python3: No module named pip
|
|
911
|
-
*
|
|
912
|
-
* after setup has already written every config file — which is exactly what
|
|
913
|
-
* happened on a real Hermes box. So probe, in order of what suits the venv:
|
|
914
|
-
*
|
|
915
|
-
* 1. `uv pip install --python <python>` when uv is present. Correct for a
|
|
916
|
-
* uv-created venv and fast; uv is also what created most pip-less venvs.
|
|
917
|
-
* 2. `<python> -m pip install` when pip actually answers.
|
|
918
|
-
* 3. Neither — hand it over, with `ensurepip` named, rather than planning a
|
|
919
|
-
* command that is known in advance to fail.
|
|
920
|
-
*/
|
|
921
|
-
function pythonInstallStrategy(python, pkg) {
|
|
922
|
-
const uv = (0, child_process_1.spawnSync)(process.platform === "win32" ? "where" : "which", ["uv"], { stdio: "ignore" });
|
|
923
|
-
if (uv.status === 0) {
|
|
924
|
-
return {
|
|
925
|
-
kind: "exec",
|
|
926
|
-
command: "uv",
|
|
927
|
-
args: ["pip", "install", "--python", python, pkg],
|
|
928
|
-
how: "uv, targeting the interpreter that runs Hermes",
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
const pip = (0, child_process_1.spawnSync)(python, ["-m", "pip", "--version"], { stdio: "ignore" });
|
|
932
|
-
if (pip.status === 0) {
|
|
933
|
-
return { kind: "exec", command: python, args: ["-m", "pip", "install", pkg], how: "pip in the interpreter that runs Hermes" };
|
|
934
|
-
}
|
|
935
|
-
return {
|
|
936
|
-
kind: "manual",
|
|
937
|
-
why: `${python} has no pip (a venv created by \`uv venv\` has none by default) and uv is not on PATH, so setup cannot install into it. Bootstrap pip, then install:`,
|
|
938
|
-
snippet: [`${python} -m ensurepip --upgrade`, `${python} -m pip install ${pkg}`].join("\n"),
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* The env vars the Hermes plugin documents, merged into an existing `.env`.
|
|
943
|
-
*
|
|
944
|
-
* A `.env` is line-oriented and hand-maintained, so this is a line merge rather
|
|
945
|
-
* than a parse-and-reserialize: keys Atbash owns are replaced in place (keeping
|
|
946
|
-
* their position), keys it does not own are never touched, and anything else in
|
|
947
|
-
* the file — comments, blank lines, unrelated settings, ordering — survives
|
|
948
|
-
* exactly as written. Reformatting someone's .env to add four lines would be a
|
|
949
|
-
* poor trade.
|
|
950
|
-
*
|
|
951
|
-
* Values are from the published plugin README (PyPI atbash-hermes-plugin 0.4.5).
|
|
952
|
-
* `ATBASH_ORG_NAME` is deliberately NOT written: its value is the operator's org,
|
|
953
|
-
* which this command has no reliable way to know, and a wrong org sends the SDK
|
|
954
|
-
* at the wrong chain. It is called out in the manual step instead.
|
|
955
|
-
*/
|
|
956
|
-
function mergeHermesEnv(existing) {
|
|
957
|
-
const desired = {
|
|
958
|
-
ATBASH_KEY_PATH: "$HOME/.config/atbash/guard-client-key",
|
|
959
|
-
ATBASH_ENFORCE_DECISION: "true",
|
|
960
|
-
};
|
|
961
|
-
const lines = existing === null ? [] : existing.split("\n");
|
|
962
|
-
const seen = new Set();
|
|
963
|
-
const out = lines.map((line) => {
|
|
964
|
-
const match = line.match(/^\s*(?:export\s+)?([A-Z_][A-Z0-9_]*)\s*=/);
|
|
965
|
-
const key = match?.[1];
|
|
966
|
-
if (!key || !(key in desired) || seen.has(key))
|
|
967
|
-
return line;
|
|
968
|
-
seen.add(key);
|
|
969
|
-
// Already correct — keep the operator's own formatting rather than rewriting.
|
|
970
|
-
if (line.trim() === `${key}=${desired[key]}`)
|
|
971
|
-
return line;
|
|
972
|
-
return `${key}=${desired[key]}`;
|
|
973
|
-
});
|
|
974
|
-
const missing = Object.entries(desired).filter(([key]) => !seen.has(key));
|
|
975
|
-
if (missing.length) {
|
|
976
|
-
// Separate the block we add from whatever came before it.
|
|
977
|
-
if (out.length && out[out.length - 1].trim() !== "")
|
|
978
|
-
out.push("");
|
|
979
|
-
// ASCII-only comment on purpose: .env files are read by many different
|
|
980
|
-
// parsers and a stray multi-byte dash is a free way to trip a strict one.
|
|
981
|
-
if (existing !== null)
|
|
982
|
-
out.push("# Added by `atbash setup` - Atbash Hermes plugin");
|
|
983
|
-
for (const [key, value] of missing)
|
|
984
|
-
out.push(`${key}=${value}`);
|
|
985
|
-
}
|
|
986
|
-
let text = out.join("\n");
|
|
987
|
-
if (!text.endsWith("\n"))
|
|
988
|
-
text += "\n";
|
|
989
|
-
return text;
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Does this config's existing Atbash entry carry a key in its `env` block?
|
|
993
|
-
*
|
|
994
|
-
* True means the operator hand-wired it from the published docs and their private
|
|
995
|
-
* key is sitting in that file today. Setup takes it out, but the backup it writes
|
|
996
|
-
* first still has it — so this exists to make that sayable rather than silently
|
|
997
|
-
* relocating the leak.
|
|
998
|
-
*/
|
|
999
|
-
function hadInlineKey(config, serversKey = "mcpServers") {
|
|
1000
|
-
const servers = isRecord(config[serversKey]) ? config[serversKey] : undefined;
|
|
1001
|
-
const entry = servers && isRecord(servers[MCP_SERVER_NAME]) ? servers[MCP_SERVER_NAME] : undefined;
|
|
1002
|
-
const env = entry && isRecord(entry.env) ? entry.env : undefined;
|
|
1003
|
-
if (!env)
|
|
1004
|
-
return false;
|
|
1005
|
-
// Any 64-hex value, under any key name — not just the documented one, since a
|
|
1006
|
-
// hand-edited config may well have renamed it.
|
|
1007
|
-
return Object.values(env).some((v) => typeof v === "string" && /^(0x)?[0-9a-fA-F]{64}$/.test(v.trim()));
|
|
1008
|
-
}
|
|
1009
|
-
function mergeMcpServer(config, serversKey = "mcpServers") {
|
|
1010
|
-
const out = { ...config };
|
|
1011
|
-
const servers = { ...(isRecord(out[serversKey]) ? out[serversKey] : {}) };
|
|
1012
|
-
servers[MCP_SERVER_NAME] = { ...MCP_SERVER_ENTRY, args: [...MCP_SERVER_ENTRY.args] };
|
|
1013
|
-
out[serversKey] = servers;
|
|
1014
|
-
return out;
|
|
1015
|
-
}
|
|
1016
442
|
/** Is `openclaw` runnable on this machine? Decides install-for-you vs print-it. */
|
|
1017
443
|
function hasExecutable(command) {
|
|
1018
444
|
const probe = (0, child_process_1.spawnSync)(process.platform === "win32" ? "where" : "which", [command], { stdio: "ignore" });
|
|
@@ -1040,33 +466,7 @@ function buildPlan(args) {
|
|
|
1040
466
|
const alreadyThisKey = currentKeyFile !== null && parseKeyMaterial(currentKeyFile)?.privkey === privkey;
|
|
1041
467
|
if (!alreadyThisKey) {
|
|
1042
468
|
if (currentKeyFile !== null) {
|
|
1043
|
-
|
|
1044
|
-
// governing. A `.atbash-bak` preserves the bytes but not the identity — six
|
|
1045
|
-
// months later nobody knows which agent `guard-client-key.atbash-bak` was.
|
|
1046
|
-
// So archive it under its own public key: recoverable, self-identifying,
|
|
1047
|
-
// and a path a runtime config can point at directly if this box needs to
|
|
1048
|
-
// run two agents (both OpenClaw's `chromiaSecretPath` and Hermes'
|
|
1049
|
-
// `ATBASH_KEY_PATH` take an explicit path).
|
|
1050
|
-
const outgoing = parseKeyMaterial(currentKeyFile);
|
|
1051
|
-
const outgoingPub = outgoing ? (0, sdk_1.derivePublicKey)(outgoing.privkey) : null;
|
|
1052
|
-
if (outgoingPub) {
|
|
1053
|
-
const archive = path.join(home, ".config", "atbash", "keys", `${outgoingPub}.key`);
|
|
1054
|
-
if (!exists(archive)) {
|
|
1055
|
-
steps.push({
|
|
1056
|
-
kind: "write",
|
|
1057
|
-
label: `Archive the agent key already on this machine (${outgoingPub.slice(0, 12)}…)`,
|
|
1058
|
-
file: archive,
|
|
1059
|
-
mode: KEY_MODE,
|
|
1060
|
-
before: null,
|
|
1061
|
-
after: currentKeyFile,
|
|
1062
|
-
secret: true,
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
notes.push(`${keyFile} currently holds a DIFFERENT agent (${outgoingPub.slice(0, 12)}…). It is archived to ~/.config/atbash/keys/${outgoingPub.slice(0, 12)}….key before being replaced, so that agent is recoverable — but every integration on this machine reading the default path will switch to the new agent.`);
|
|
1066
|
-
}
|
|
1067
|
-
else {
|
|
1068
|
-
notes.push(`${keyFile} holds something this command could not parse as an agent key. It will be backed up before being replaced.`);
|
|
1069
|
-
}
|
|
469
|
+
notes.push(`${keyFile} already holds a DIFFERENT agent key. It will be backed up before being replaced — check that you meant to re-point this machine at another agent.`);
|
|
1070
470
|
}
|
|
1071
471
|
steps.push({
|
|
1072
472
|
kind: "write",
|
|
@@ -1122,7 +522,7 @@ function buildPlan(args) {
|
|
|
1122
522
|
notes.push(`${openclawConfigFile} is not valid JSON — it will be backed up and rewritten from scratch, which loses whatever was in it. Fix the file first if it holds configuration you need.`);
|
|
1123
523
|
}
|
|
1124
524
|
}
|
|
1125
|
-
const after =
|
|
525
|
+
const after = JSON.stringify(mergeOpenclawConfig(current, home), null, 2) + "\n";
|
|
1126
526
|
if (raw !== after) {
|
|
1127
527
|
steps.push({
|
|
1128
528
|
kind: "write",
|
|
@@ -1147,188 +547,47 @@ function buildPlan(args) {
|
|
|
1147
547
|
// judged. Setup places the key file and says so; it does not pretend to wire it.
|
|
1148
548
|
if (exists(home, ...HERMES_AGENT_REL)) {
|
|
1149
549
|
found.push("Hermes");
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
// interpreter we install into it directly; when we cannot, we hand the
|
|
1192
|
-
// command over rather than guess, because guessing wrong installs
|
|
1193
|
-
// successfully and governs nothing.
|
|
1194
|
-
if (!noInstall) {
|
|
1195
|
-
const hermesPython = findHermesPython(home);
|
|
1196
|
-
if (hermesPython) {
|
|
1197
|
-
const spec = `${HERMES_PKG}==${HERMES_VERSION}`;
|
|
1198
|
-
const strategy = pythonInstallStrategy(hermesPython.python, spec);
|
|
1199
|
-
if (strategy.kind === "exec") {
|
|
1200
|
-
steps.push({
|
|
1201
|
-
kind: "exec",
|
|
1202
|
-
label: `Install ${HERMES_PKG} via ${strategy.how} (interpreter found via ${hermesPython.how})`,
|
|
1203
|
-
command: strategy.command,
|
|
1204
|
-
args: strategy.args,
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
else {
|
|
1208
|
-
steps.push({
|
|
1209
|
-
kind: "manual",
|
|
1210
|
-
label: "Install the Hermes plugin",
|
|
1211
|
-
detail: strategy.why,
|
|
1212
|
-
snippet: strategy.snippet,
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
// The plugin pins atbash-sdk==0.4.5, which constrains cryptography — on
|
|
1216
|
-
// a venv with a newer one this install is a DOWNGRADE of a shared
|
|
1217
|
-
// dependency. Say so; it is the kind of thing that breaks the host app
|
|
1218
|
-
// and is invisible in a list of file writes.
|
|
1219
|
-
notes.push(`Installing ${HERMES_PKG} may change shared Python dependencies in that venv (it pins atbash-sdk==${HERMES_VERSION}, which constrains cryptography). Check the resolver output before confirming if Hermes depends on newer versions.`);
|
|
1220
|
-
// Installing is not enabling. Hermes keeps plugins off until told
|
|
1221
|
-
// otherwise, so without this the hook is never registered and the
|
|
1222
|
-
// agent is not governed — while every file on disk says it is.
|
|
1223
|
-
// Ordered after the install because `enable` needs the package present.
|
|
1224
|
-
}
|
|
1225
|
-
else {
|
|
1226
|
-
steps.push({
|
|
1227
|
-
kind: "manual",
|
|
1228
|
-
label: "Install the Hermes plugin",
|
|
1229
|
-
detail: [
|
|
1230
|
-
"The `hermes` launcher is not on this machine's PATH, so setup cannot tell which Python interpreter runs Hermes — and installing into the wrong one succeeds while governing nothing.",
|
|
1231
|
-
"",
|
|
1232
|
-
"Run this with the interpreter Hermes uses (if it runs in a virtualenv, that venv's python):",
|
|
1233
|
-
].join("\n"),
|
|
1234
|
-
snippet: `/path/to/hermes/venv/bin/python -m pip install ${HERMES_PKG}==${HERMES_VERSION}`,
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
if (restartable) {
|
|
1239
|
-
steps.push({
|
|
1240
|
-
kind: "exec",
|
|
1241
|
-
label: "Restart the Hermes gateway so it loads the plugin",
|
|
1242
|
-
command: "hermes",
|
|
1243
|
-
args: ["gateway", "restart"],
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
else {
|
|
1247
|
-
notes.push("No Hermes gateway service is running, so there is nothing to restart — the plugin loads the next time you start Hermes. (If you run it as a service, `hermes gateway install` then `hermes gateway restart`.)");
|
|
1248
|
-
}
|
|
1249
|
-
notes.push("Confirm the hook registered after Hermes next starts: `tail -n 50 ~/.hermes/logs/agent.log | grep -i atbash`. `hermes plugins list` will not show it — that listing only walks plugin directories.");
|
|
1250
|
-
notes.push("ATBASH_ENFORCE_DECISION=true is fail-closed: if Atbash cannot be reached, the Hermes tool call is blocked rather than allowed.");
|
|
1251
|
-
notes.push("ATBASH_ORG_NAME is not set for you — it decides which chain the SDK uses, and a wrong value points at the wrong one. Add it to ~/.hermes/.env yourself if your org needs it.");
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
// ── 4. MCP clients.
|
|
1255
|
-
//
|
|
1256
|
-
// This used to be a manual step, and the reason was specific: `@atbash/mcp`
|
|
1257
|
-
// reads its identity from ATBASH_AGENT_PRIVKEY with no key-file fallback, so
|
|
1258
|
-
// the documented wiring puts a raw private key inside the client's own config —
|
|
1259
|
-
// `claude_desktop_config.json` and friends, files that get synced between
|
|
1260
|
-
// machines and pasted into help requests. Automating that would have meant the
|
|
1261
|
-
// automation's whole job was planting a secret somewhere worse.
|
|
1262
|
-
//
|
|
1263
|
-
// `atbash mcp` removes the reason. The client spawns the launcher, which reads
|
|
1264
|
-
// the key from the 0600 file and hands it to the server through the child
|
|
1265
|
-
// environment only. The config entry carries NO credential, so it is safe to
|
|
1266
|
-
// write — and a config with no secret in it is strictly better than the one the
|
|
1267
|
-
// operator would have hand-written from the docs.
|
|
1268
|
-
if (wanted("mcp")) {
|
|
1269
|
-
for (const client of detectMcpClients(home)) {
|
|
1270
|
-
found.push(client.label);
|
|
1271
|
-
if (client.format !== "json") {
|
|
1272
|
-
// TOML (Codex) — @iarna/toml can round-trip values but not comments, and
|
|
1273
|
-
// a config.toml is usually hand-maintained. Print it instead.
|
|
1274
|
-
steps.push({
|
|
1275
|
-
kind: "manual",
|
|
1276
|
-
label: `Add Atbash to ${client.label}`,
|
|
1277
|
-
detail: `${client.file} is TOML, and rewriting it would drop any comments in it. Add this table by hand:`,
|
|
1278
|
-
snippet: ["[mcp_servers.atbash]", 'command = "npx"', 'args = ["--yes", "@atbash/cli", "mcp"]'].join("\n"),
|
|
1279
|
-
});
|
|
1280
|
-
continue;
|
|
1281
|
-
}
|
|
1282
|
-
const raw = readTextFile(client.file);
|
|
1283
|
-
if (raw !== null && isJsonc(raw)) {
|
|
1284
|
-
steps.push({
|
|
1285
|
-
kind: "manual",
|
|
1286
|
-
label: `Add Atbash to ${client.label}`,
|
|
1287
|
-
detail: `${client.file} uses comments or trailing commas, and rewriting it as strict JSON would delete them. Merge this in by hand — note it holds no key, so the file stays as non-secret as it is today:`,
|
|
1288
|
-
snippet: JSON.stringify({ mcpServers: { atbash: MCP_SERVER_ENTRY } }, null, 2),
|
|
1289
|
-
});
|
|
1290
|
-
continue;
|
|
1291
|
-
}
|
|
1292
|
-
let current = {};
|
|
1293
|
-
if (raw !== null) {
|
|
1294
|
-
try {
|
|
1295
|
-
const parsed = JSON.parse(raw);
|
|
1296
|
-
if (isRecord(parsed))
|
|
1297
|
-
current = parsed;
|
|
1298
|
-
}
|
|
1299
|
-
catch {
|
|
1300
|
-
notes.push(`${client.file} is not valid JSON, so it was left alone. Fix the file and re-run to wire ${client.label}.`);
|
|
1301
|
-
continue;
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
const after = serializeLike(raw, mergeMcpServer(current, client.serversKey));
|
|
1305
|
-
if (raw !== after) {
|
|
1306
|
-
// A hand-wired entry from the old documented shape carries the private key
|
|
1307
|
-
// in an `env` block. Replacing it REMOVES that secret from the live config
|
|
1308
|
-
// — good — but the backup we are about to take still contains it, and an
|
|
1309
|
-
// operator who does not know that has simply moved the leak to a new file.
|
|
1310
|
-
if (hadInlineKey(current, client.serversKey)) {
|
|
1311
|
-
notes.push(`${client.file} currently holds your private key in an env block. Setup replaces that entry with the keyless launcher, but the .atbash-bak it leaves behind WILL still contain the key — delete that backup once you have confirmed the client works.`);
|
|
1312
|
-
}
|
|
1313
|
-
steps.push({
|
|
1314
|
-
kind: "write",
|
|
1315
|
-
label: `Add Atbash as an MCP server in ${client.label} (a merge — existing servers are kept${hadInlineKey(current, client.serversKey) ? ", and your key is removed from this file" : ""})`,
|
|
1316
|
-
file: client.file,
|
|
1317
|
-
before: raw,
|
|
1318
|
-
after,
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
else {
|
|
1322
|
-
notes.push(`${client.label} already has the Atbash MCP server — left untouched.`);
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
if (found.some((f) => f !== "OpenClaw" && f !== "Hermes")) {
|
|
1326
|
-
notes.push("Restart any MCP client that was changed — clients read their server list at startup.");
|
|
1327
|
-
// A client whose first launch of the server takes ~12s can report a startup
|
|
1328
|
-
// timeout that looks like a broken config. Say so, so the first thing an
|
|
1329
|
-
// operator does is retry rather than undo the wiring.
|
|
1330
|
-
notes.push("The first time a client starts the Atbash server it takes ~10-15s while npx caches the package; after that it is about a second. If a client reports a startup timeout on the very first try, start it again.");
|
|
1331
|
-
}
|
|
550
|
+
notes.push("Hermes is installed here. It shares this agent's skills and signing key, but the Atbash hook lives in the OpenClaw gateway — actions driven through the Hermes API are NOT judged, even while the OpenClaw side reports enforcing. Route that work through OpenClaw, or guard it in code with @atbash/sdk.");
|
|
551
|
+
}
|
|
552
|
+
// ── 4. MCP clients: detected and reported, never seeded.
|
|
553
|
+
// The documented @atbash/mcp wiring carries the private key as an
|
|
554
|
+
// ATBASH_AGENT_PRIVKEY env value inside the client's own config file, and that
|
|
555
|
+
// package has no key-file fallback (checked against the published 0.1.3). We
|
|
556
|
+
// will not write a private key into a file people share and sync, so this is
|
|
557
|
+
// the one place setup deliberately stays manual.
|
|
558
|
+
const mcpClients = [];
|
|
559
|
+
const seenClients = new Set();
|
|
560
|
+
for (const { label, segs } of connect_1.MCP_CONFIGS) {
|
|
561
|
+
if (seenClients.has(label))
|
|
562
|
+
continue;
|
|
563
|
+
if (exists(home, ...segs)) {
|
|
564
|
+
seenClients.add(label);
|
|
565
|
+
mcpClients.push(`${label} (${path.join(home, ...segs)})`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
// Claude Code and Codex live outside MCP_CONFIGS in the scanner too — same paths.
|
|
569
|
+
if (exists(home, ".claude.json"))
|
|
570
|
+
mcpClients.push(`Claude Code (${path.join(home, ".claude.json")})`);
|
|
571
|
+
if (exists(home, ".codex", "config.toml"))
|
|
572
|
+
mcpClients.push(`Codex (${path.join(home, ".codex", "config.toml")})`);
|
|
573
|
+
if (mcpClients.length) {
|
|
574
|
+
found.push(`${mcpClients.length} MCP client config${mcpClients.length === 1 ? "" : "s"}`);
|
|
575
|
+
steps.push({
|
|
576
|
+
kind: "manual",
|
|
577
|
+
label: `Optional: expose Atbash as an MCP server to ${mcpClients.length} detected client${mcpClients.length === 1 ? "" : "s"}`,
|
|
578
|
+
detail: [
|
|
579
|
+
`Detected: ${mcpClients.join(", ")}.`,
|
|
580
|
+
"",
|
|
581
|
+
"This step is NOT done for you, on purpose. The published @atbash/mcp wiring takes the agent's private key as an ATBASH_AGENT_PRIVKEY value inside the client's own config file, and that package has no key-file fallback today. Atbash will not write your private key into a file that gets synced, shared and screenshotted.",
|
|
582
|
+
"",
|
|
583
|
+
"If you want it anyway, add this yourself and fill in the key — and treat that config file as a secret from then on:",
|
|
584
|
+
].join("\n"),
|
|
585
|
+
snippet: JSON.stringify({
|
|
586
|
+
mcpServers: {
|
|
587
|
+
atbash: { command: "npx", args: ["-y", "@atbash/mcp"], env: { ATBASH_AGENT_PRIVKEY: "<your agent private key>" } },
|
|
588
|
+
},
|
|
589
|
+
}, null, 2),
|
|
590
|
+
});
|
|
1332
591
|
}
|
|
1333
592
|
if (!found.length) {
|
|
1334
593
|
notes.push("No OpenClaw, Hermes or MCP client configuration was found under this home directory. The key file is still placed, so an SDK-level integration in your own code will find it — but nothing on this machine is wired to a runtime.");
|
|
@@ -1512,27 +771,10 @@ function applyPlan(plan) {
|
|
|
1512
771
|
continue;
|
|
1513
772
|
const label = `${step.command} ${step.args.join(" ")}`;
|
|
1514
773
|
const run = (0, child_process_1.spawnSync)(step.command, step.args, { stdio: "inherit" });
|
|
1515
|
-
|
|
1516
|
-
// message. `spawnSync` reports a binary it could not launch via `.error` with
|
|
1517
|
-
// `status` left null — so an ENOENT printed "exited on a signal", which reads
|
|
1518
|
-
// like the plugin installer crashed rather than "that command is not here".
|
|
1519
|
-
// The distinction matters because only one of them is the operator's to fix,
|
|
1520
|
-
// and the fix is to run it somewhere the CLI exists.
|
|
1521
|
-
if (run.error) {
|
|
1522
|
-
const missing = run.error.code === "ENOENT";
|
|
1523
|
-
result.failures.push(missing
|
|
1524
|
-
? `${step.command} is not on this machine's PATH, so \`${label}\` did not run. Everything else above was applied — run that one command wherever the ${step.command} CLI lives.`
|
|
1525
|
-
: `${label} could not start: ${run.error.message}`);
|
|
1526
|
-
}
|
|
1527
|
-
else if (run.status === 0) {
|
|
774
|
+
if (run.status === 0)
|
|
1528
775
|
result.ran.push(label);
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
result.failures.push(`${label} was killed by ${run.signal}`);
|
|
1532
|
-
}
|
|
1533
|
-
else {
|
|
1534
|
-
result.failures.push(`${label} exited with code ${run.status}`);
|
|
1535
|
-
}
|
|
776
|
+
else
|
|
777
|
+
result.failures.push(`${label} exited ${run.status ?? "on a signal"}`);
|
|
1536
778
|
}
|
|
1537
779
|
return result;
|
|
1538
780
|
}
|
|
@@ -1546,26 +788,23 @@ function applyPlan(plan) {
|
|
|
1546
788
|
*/
|
|
1547
789
|
async function verifyRegistration(privkey, endpoint) {
|
|
1548
790
|
try {
|
|
1549
|
-
const atbash = new sdk_1.Atbash(privkey, {
|
|
791
|
+
const atbash = new sdk_1.Atbash(privkey, {
|
|
792
|
+
endpoint,
|
|
793
|
+
blockchainRid: (0, sdk_1.resolve)("blockchainRid") || undefined,
|
|
794
|
+
orgName: (0, sdk_1.resolve)("orgName") || undefined,
|
|
795
|
+
});
|
|
1550
796
|
return (await atbash.checkAgentExists()) ? { state: "registered" } : { state: "unregistered" };
|
|
1551
797
|
}
|
|
1552
798
|
catch (err) {
|
|
1553
799
|
return { state: "unknown", reason: err instanceof Error ? err.message : String(err) };
|
|
1554
800
|
}
|
|
1555
801
|
}
|
|
1556
|
-
/**
|
|
1557
|
-
|
|
1558
|
-
* except where `defaultYes` is set, which is only for questions where the safe
|
|
1559
|
-
* answer is also the common one (reusing the key already on this machine).
|
|
1560
|
-
*/
|
|
1561
|
-
async function confirm(question, defaultYes = false) {
|
|
802
|
+
/** y/N confirmation. Anything but an explicit yes is a no. */
|
|
803
|
+
async function confirm(question) {
|
|
1562
804
|
const { createInterface } = await Promise.resolve().then(() => __importStar(require("node:readline")));
|
|
1563
805
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1564
806
|
const answer = await new Promise((r) => rl.question(question, (a) => { rl.close(); r(a); }));
|
|
1565
|
-
|
|
1566
|
-
if (!trimmed)
|
|
1567
|
-
return defaultYes;
|
|
1568
|
-
return /^y(es)?$/i.test(trimmed);
|
|
807
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
1569
808
|
}
|
|
1570
809
|
// ── The command ─────────────────────────────────────────────────────────────
|
|
1571
810
|
function registerSetupCommand(program) {
|
|
@@ -1617,7 +856,7 @@ function registerSetupCommand(program) {
|
|
|
1617
856
|
console.log(chalk_1.default.dim(`\n Agent key source: ${keySource.from}`));
|
|
1618
857
|
// ── Registration check. Only the public key crosses the network.
|
|
1619
858
|
if (!opts.skipVerify) {
|
|
1620
|
-
const endpoint = (opts.host || (0, sdk_1.resolve)("judgeEndpoint") ||
|
|
859
|
+
const endpoint = (opts.host || (0, sdk_1.resolve)("judgeEndpoint") || connect_1.DEFAULT_HOST || sdk_1.DEFAULT_ENDPOINT).replace(/\/$/, "");
|
|
1621
860
|
let hostname = "";
|
|
1622
861
|
try {
|
|
1623
862
|
hostname = new URL(endpoint).hostname.toLowerCase();
|
|
@@ -1629,8 +868,7 @@ function registerSetupCommand(program) {
|
|
|
1629
868
|
// An unrecognized host could answer "registered" for any key, which is
|
|
1630
869
|
// exactly the confirmation this check exists to provide. Exact hostname
|
|
1631
870
|
// match, never a suffix — "atbash.ai.evil.com" must not pass.
|
|
1632
|
-
|
|
1633
|
-
if (!recognizedHost && !opts.allowUnrecognizedHost) {
|
|
871
|
+
if (!connect_1.KNOWN_HOSTS.has(hostname) && !opts.allowUnrecognizedHost) {
|
|
1634
872
|
console.error(chalk_1.default.red(`\n ${hostname} is not a recognized Atbash deployment.`) +
|
|
1635
873
|
chalk_1.default.dim("\n Re-run with --allow-unrecognized-host if you meant to point at a self-hosted instance,\n or with --skip-verify to configure this machine without any network call.\n"));
|
|
1636
874
|
process.exit(1);
|
|
@@ -1638,21 +876,7 @@ function registerSetupCommand(program) {
|
|
|
1638
876
|
const verdict = await verifyRegistration(privkey, endpoint);
|
|
1639
877
|
if (verdict.state === "unregistered") {
|
|
1640
878
|
console.error(chalk_1.default.red("\n That agent is not registered on this deployment.") +
|
|
1641
|
-
chalk_1.default.dim(`\n Public key:
|
|
1642
|
-
// The likeliest cause is not "you skipped onboarding" — it is "this is a
|
|
1643
|
-
// key you did not choose". Say so when the key was found rather than
|
|
1644
|
-
// supplied, because the fix is completely different.
|
|
1645
|
-
if (/existing key file|atbash config/.test(keySource.from)) {
|
|
1646
|
-
console.error(chalk_1.default.yellow(" This is a key that was already on this machine, not one you supplied.") +
|
|
1647
|
-
chalk_1.default.dim("\n If you are onboarding a DIFFERENT agent, pass its key explicitly:" +
|
|
1648
|
-
"\n --key <64-hex> the key shown in the browser" +
|
|
1649
|
-
"\n --keys-dir ~/Downloads the key file you saved" +
|
|
1650
|
-
"\n Or re-run and answer 'n' when asked whether to use the existing key.\n"));
|
|
1651
|
-
}
|
|
1652
|
-
else {
|
|
1653
|
-
console.error(chalk_1.default.dim(" Finish onboarding first — wiring a runtime to an unregistered agent leaves it\n" +
|
|
1654
|
-
" looking governed while the plugin can never get a verdict.\n"));
|
|
1655
|
-
}
|
|
879
|
+
chalk_1.default.dim(`\n Public key: ${pubkey}\n Finish onboarding first — wiring a runtime to an unregistered agent leaves it\n looking governed while the plugin can never get a verdict.\n`));
|
|
1656
880
|
process.exit(1);
|
|
1657
881
|
}
|
|
1658
882
|
if (verdict.state === "unknown") {
|
|
@@ -1663,21 +887,8 @@ function registerSetupCommand(program) {
|
|
|
1663
887
|
return;
|
|
1664
888
|
}
|
|
1665
889
|
}
|
|
1666
|
-
else if (recognizedHost) {
|
|
1667
|
-
console.log(chalk_1.default.green(` Agent is registered on ${hostname}.`));
|
|
1668
|
-
}
|
|
1669
890
|
else {
|
|
1670
|
-
|
|
1671
|
-
// property is that the check still PRINTS a reassuring answer. A host
|
|
1672
|
-
// chosen by an attacker returns "registered" for any key at all, so a
|
|
1673
|
-
// "✓ registered" line here would be the attacker's own claim wearing
|
|
1674
|
-
// Atbash's voice. Never let that line stand unqualified: say the answer
|
|
1675
|
-
// came from an unvouched-for server, so a talked-into-it operator sees
|
|
1676
|
-
// the one thing that would tell them something is wrong.
|
|
1677
|
-
console.log(chalk_1.default.yellow(` ${hostname} answered "registered" — but this is NOT a recognized Atbash deployment.`));
|
|
1678
|
-
console.log(chalk_1.default.yellow(" A registration check against an unrecognized host proves nothing: any server") +
|
|
1679
|
-
chalk_1.default.yellow("\n can answer \"registered\" for any key. Treat this as UNVERIFIED."));
|
|
1680
|
-
console.log(chalk_1.default.dim(` Recognized deployments: ${[...atbash_targets_1.KNOWN_HOSTS].join(", ")}`));
|
|
891
|
+
console.log(chalk_1.default.green(` Agent is registered on ${hostname}.`));
|
|
1681
892
|
}
|
|
1682
893
|
}
|
|
1683
894
|
// ── Plan, show, then (maybe) apply.
|
|
@@ -1726,36 +937,6 @@ function registerSetupCommand(program) {
|
|
|
1726
937
|
process.exitCode = 1;
|
|
1727
938
|
return;
|
|
1728
939
|
}
|
|
1729
|
-
// ── Check, do not assume.
|
|
1730
|
-
//
|
|
1731
|
-
// Every step reporting success is not the same as the runtime having
|
|
1732
|
-
// picked the plugin up, and this command used to print "Done" on the
|
|
1733
|
-
// strength of the former. On a real machine the install succeeded, the
|
|
1734
|
-
// entry point was correct, and Hermes still listed nothing — so the agent
|
|
1735
|
-
// was ungoverned behind a green summary. Where a runtime can be asked, ask.
|
|
1736
|
-
if (plan.found.includes("Hermes") && wantedRuntime("hermes", opts.runtime ?? [])) {
|
|
1737
|
-
const state = hermesPluginState(home);
|
|
1738
|
-
if (state === "configured") {
|
|
1739
|
-
console.log(chalk_1.default.green("\n Hermes is configured to load the plugin.") +
|
|
1740
|
-
chalk_1.default.dim("\n It takes effect on the next Hermes start. Confirm the hook registered:") +
|
|
1741
|
-
chalk_1.default.dim("\n tail -n 50 ~/.hermes/logs/agent.log | grep -i atbash") +
|
|
1742
|
-
chalk_1.default.dim("\n (`hermes plugins list` will NOT show it — that listing only walks plugin") +
|
|
1743
|
-
chalk_1.default.dim("\n directories and cannot see a pip-installed one.)\n"));
|
|
1744
|
-
}
|
|
1745
|
-
else if (state === "not-enabled") {
|
|
1746
|
-
console.log(chalk_1.default.yellow("\n The plugin is installed but NOT on Hermes' enabled allow-list — this agent is not governed.") +
|
|
1747
|
-
chalk_1.default.dim("\n Hermes loads only what is listed. Add it to ~/.hermes/config.yaml:") +
|
|
1748
|
-
chalk_1.default.dim("\n plugins:\n enabled:\n - " + HERMES_PLUGIN_ENTRY + "\n"));
|
|
1749
|
-
process.exitCode = 1;
|
|
1750
|
-
return;
|
|
1751
|
-
}
|
|
1752
|
-
else if (state === "not-installed") {
|
|
1753
|
-
console.log(chalk_1.default.yellow("\n The plugin is not installed in the interpreter that runs Hermes — this agent is not governed.\n"));
|
|
1754
|
-
process.exitCode = 1;
|
|
1755
|
-
return;
|
|
1756
|
-
}
|
|
1757
|
-
// "unknown": nothing readable to judge by, so claim nothing.
|
|
1758
|
-
}
|
|
1759
940
|
console.log(chalk_1.default.green("\n Done.") + chalk_1.default.dim(" Restart the runtime so it loads the hook, then re-scan this machine"));
|
|
1760
941
|
console.log(chalk_1.default.dim(" from the agent's page in the dashboard to confirm it reports as enforcing.\n"));
|
|
1761
942
|
});
|