@haven_ai/connect 0.9.0-alpha.0 → 0.10.0-alpha.0
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 +73 -24
- package/dist/cli.cjs +847 -568
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +847 -568
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +849 -568
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -7
- package/dist/index.d.ts +36 -7
- package/dist/index.js +848 -569
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
var crypto = require('crypto');
|
|
5
5
|
var ethers = require('ethers');
|
|
6
|
-
var promises = require('fs/promises');
|
|
7
|
-
var os = require('os');
|
|
8
|
-
var path = require('path');
|
|
9
6
|
var mcp = require('@haven_ai/mcp');
|
|
10
7
|
var signer = require('@haven_ai/signer');
|
|
11
8
|
var sdk = require('@haven_ai/sdk');
|
|
12
|
-
var yaml = require('yaml');
|
|
13
9
|
var child_process = require('child_process');
|
|
10
|
+
var promises = require('fs/promises');
|
|
11
|
+
var os = require('os');
|
|
12
|
+
var path = require('path');
|
|
14
13
|
var util = require('util');
|
|
14
|
+
var yaml = require('yaml');
|
|
15
15
|
var readline = require('readline');
|
|
16
16
|
var fs = require('fs');
|
|
17
17
|
var url = require('url');
|
|
@@ -72,6 +72,25 @@ function createConnectApiClient(baseUrl, fetchImpl = fetch, clientIdentity) {
|
|
|
72
72
|
method: "GET",
|
|
73
73
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
74
74
|
}),
|
|
75
|
+
reportRetiredAgents: async (input) => {
|
|
76
|
+
try {
|
|
77
|
+
const body = await send(
|
|
78
|
+
`${root}/agent-connection-setups/${encodeURIComponent(input.setupId)}/retired-agents`,
|
|
79
|
+
{
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { Authorization: `Bearer ${input.apiKey}` },
|
|
82
|
+
body: JSON.stringify({ retired_agent_ids: input.retiredAgentIds })
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
const recorded = body?.recorded_agent_ids;
|
|
86
|
+
return {
|
|
87
|
+
recordedAgentIds: Array.isArray(recorded) ? recorded.filter((id) => typeof id === "string") : []
|
|
88
|
+
};
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if (err instanceof ConnectRequestError && err.status === 404) return null;
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
75
94
|
updateInstallStatus: async (setupId, apiKey, input) => {
|
|
76
95
|
await send(`${root}/agent-connection-setups/${encodeURIComponent(setupId)}/install-status`, {
|
|
77
96
|
method: "POST",
|
|
@@ -166,81 +185,574 @@ var init_key = __esm({
|
|
|
166
185
|
}
|
|
167
186
|
});
|
|
168
187
|
|
|
169
|
-
// src/redact.ts
|
|
170
|
-
function redactSecrets(value) {
|
|
171
|
-
return value.replace(API_KEY_RE, "sk_agent_[redacted]").replace(PRIVATE_KEY_RE, "0x[redacted-private-key]");
|
|
188
|
+
// src/redact.ts
|
|
189
|
+
function redactSecrets(value) {
|
|
190
|
+
return value.replace(API_KEY_RE, "sk_agent_[redacted]").replace(PRIVATE_KEY_RE, "0x[redacted-private-key]");
|
|
191
|
+
}
|
|
192
|
+
function redactForAutomation(value) {
|
|
193
|
+
return redactSecrets(value).replace(/(?:~|\/)[^\s`"']*\/(?:identity|signer|agent)\.json\b/g, "[credential-file-redacted]").replace(/(?:~|\/)[^\s`"']*\/\.env\b/g, "[credential-env-redacted]");
|
|
194
|
+
}
|
|
195
|
+
function withoutUserinfo(url) {
|
|
196
|
+
try {
|
|
197
|
+
const parsed = new URL(url);
|
|
198
|
+
parsed.username = "";
|
|
199
|
+
parsed.password = "";
|
|
200
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
201
|
+
} catch {
|
|
202
|
+
return url;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function shortAddress(address) {
|
|
206
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) return address;
|
|
207
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
208
|
+
}
|
|
209
|
+
var API_KEY_RE, PRIVATE_KEY_RE;
|
|
210
|
+
var init_redact = __esm({
|
|
211
|
+
"src/redact.ts"() {
|
|
212
|
+
API_KEY_RE = /sk_agent_[A-Za-z0-9]+/g;
|
|
213
|
+
PRIVATE_KEY_RE = /0x[0-9a-fA-F]{64}/g;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// src/server-names.ts
|
|
218
|
+
function assertValidServerSlug(slug) {
|
|
219
|
+
if (slug.length === 0 || slug.length > 32 || !SLUG_RE.test(slug)) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Invalid server name ${JSON.stringify(slug)}: use 1-32 lowercase letters, digits, and single hyphens (e.g. "research").`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (slug === "haven" || slug === "haven-signer") {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Invalid server name ${JSON.stringify(slug)}: "haven" and "haven-signer" are the unnamed pair's own names \u2014 omit --name for the bare pair.`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (slug === "signer" || slug.startsWith("signer-")) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`Invalid server name ${JSON.stringify(slug)}: "signer" and "signer-*" are reserved \u2014 they would collide with another pair's haven-signer-* entry.`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function serverNamesFor(slug) {
|
|
236
|
+
if (slug === void 0) {
|
|
237
|
+
return {
|
|
238
|
+
hosted: "haven",
|
|
239
|
+
signer: "haven-signer",
|
|
240
|
+
// Historical Codex table names — every wired Codex host has these.
|
|
241
|
+
codexHosted: "haven",
|
|
242
|
+
codexSigner: "haven_signer",
|
|
243
|
+
hermesEnvKey: "MCP_HAVEN_API_KEY"
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
assertValidServerSlug(slug);
|
|
247
|
+
return {
|
|
248
|
+
hosted: `haven-${slug}`,
|
|
249
|
+
signer: `haven-signer-${slug}`,
|
|
250
|
+
// Hyphens are valid TOML bare keys, so named Codex tables match the
|
|
251
|
+
// JSON/YAML names instead of inheriting the legacy underscore.
|
|
252
|
+
codexHosted: `haven-${slug}`,
|
|
253
|
+
codexSigner: `haven-signer-${slug}`,
|
|
254
|
+
hermesEnvKey: `MCP_HAVEN_${slug.toUpperCase().replace(/-/g, "_")}_API_KEY`
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
var SLUG_RE;
|
|
258
|
+
var init_server_names = __esm({
|
|
259
|
+
"src/server-names.ts"() {
|
|
260
|
+
SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
function mcpPackageSpec() {
|
|
264
|
+
return `${MCP_RUNTIME_MANIFEST.mcpPackage}@${MCP_RUNTIME_MANIFEST.mcpVersion}`;
|
|
265
|
+
}
|
|
266
|
+
function sdkPackageSpec() {
|
|
267
|
+
return `${MCP_RUNTIME_MANIFEST.sdkPackage}@${MCP_RUNTIME_MANIFEST.sdkVersion}`;
|
|
268
|
+
}
|
|
269
|
+
function signerPackageSpec() {
|
|
270
|
+
return `${MCP_RUNTIME_MANIFEST.signerPackage}@${MCP_RUNTIME_MANIFEST.signerVersion}`;
|
|
271
|
+
}
|
|
272
|
+
var MCP_RUNTIME_MANIFEST;
|
|
273
|
+
var init_runtime_manifest = __esm({
|
|
274
|
+
"src/runtime-manifest.ts"() {
|
|
275
|
+
MCP_RUNTIME_MANIFEST = {
|
|
276
|
+
mcpPackage: "@haven_ai/mcp",
|
|
277
|
+
mcpVersion: mcp.MCP_VERSION,
|
|
278
|
+
sdkPackage: "@haven_ai/sdk",
|
|
279
|
+
sdkVersion: "0.10.0-alpha.0",
|
|
280
|
+
signerPackage: "@haven_ai/signer",
|
|
281
|
+
signerVersion: "0.10.0-alpha.0",
|
|
282
|
+
// Sourced from the SDK, never a literal (#1161). This field read '20.0.0'
|
|
283
|
+
// while every package's `engines` said `>=24` and the docs said `>=24.0.0`,
|
|
284
|
+
// so the guard that was supposed to enforce the floor waved Node v23 through
|
|
285
|
+
// — including on the `--local` path where it does run. A hand-maintained
|
|
286
|
+
// second copy of a number is a drift waiting to happen; a guard test pins
|
|
287
|
+
// this against `package.json`'s `engines.node`.
|
|
288
|
+
minimumNodeVersion: sdk.HAVEN_MINIMUM_NODE_VERSION,
|
|
289
|
+
supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
|
|
290
|
+
requiredTools: mcp.registeredToolNames(),
|
|
291
|
+
/**
|
|
292
|
+
* The signer MCP's tool surface, DERIVED from the pinned @haven_ai/signer
|
|
293
|
+
* package (#1587) — same anti-drift rule as `requiredTools` above: a
|
|
294
|
+
* literal list here would rot the first time the signer gains a tool.
|
|
295
|
+
* The handshake probe requires all of them.
|
|
296
|
+
*/
|
|
297
|
+
requiredSignerTools: Object.keys(signer.toolSchemas)
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
function resolveRuntimeSpecOverride(env) {
|
|
302
|
+
const override = {};
|
|
303
|
+
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
304
|
+
const variable = RUNTIME_SPEC_ENV[pkg];
|
|
305
|
+
const raw = env[variable];
|
|
306
|
+
if (raw === void 0) continue;
|
|
307
|
+
override[pkg] = validateSpec(variable, raw);
|
|
308
|
+
}
|
|
309
|
+
return Object.keys(override).length > 0 ? override : void 0;
|
|
310
|
+
}
|
|
311
|
+
function validateSpec(variable, raw) {
|
|
312
|
+
if (raw.length === 0 || raw.trim().length === 0) {
|
|
313
|
+
throw new RuntimeSpecOverrideError(variable, "it is empty");
|
|
314
|
+
}
|
|
315
|
+
if (/\s/.test(raw)) {
|
|
316
|
+
throw new RuntimeSpecOverrideError(variable, "it contains whitespace");
|
|
317
|
+
}
|
|
318
|
+
if (/[\u0000-\u001f\u007f]/.test(raw)) {
|
|
319
|
+
throw new RuntimeSpecOverrideError(variable, "it contains a control character");
|
|
320
|
+
}
|
|
321
|
+
const meta = SHELL_METACHARACTERS.exec(raw);
|
|
322
|
+
if (meta) {
|
|
323
|
+
throw new RuntimeSpecOverrideError(variable, `it contains the shell metacharacter ${JSON.stringify(meta[0])}`);
|
|
324
|
+
}
|
|
325
|
+
return raw;
|
|
326
|
+
}
|
|
327
|
+
function runtimeSpecOverrideDirectoryKey(resolvedSpecs) {
|
|
328
|
+
const digest = crypto.createHash("sha256").update(resolvedSpecs.join("\n")).digest("hex");
|
|
329
|
+
return `override-${digest.slice(0, 12)}`;
|
|
330
|
+
}
|
|
331
|
+
function overrideApplies(override, packages) {
|
|
332
|
+
return override !== void 0 && packages.some((pkg) => override[pkg] !== void 0);
|
|
333
|
+
}
|
|
334
|
+
function runtimeSpecOverrideNotice(runtimeLabel, override, pinned, runtimeDirectory) {
|
|
335
|
+
const lines = [`RUNTIME SPEC OVERRIDE ACTIVE for the local Haven ${runtimeLabel} \u2014 this is NOT the pinned manifest.`];
|
|
336
|
+
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
337
|
+
const spec = override[pkg];
|
|
338
|
+
if (spec === void 0) continue;
|
|
339
|
+
const pin = pinned[pkg];
|
|
340
|
+
lines.push(` ${RUNTIME_SPEC_ENV[pkg]}=${spec}${pin ? ` (instead of ${pin})` : ""}`);
|
|
341
|
+
}
|
|
342
|
+
lines.push(` Installing into ${runtimeDirectory} \u2014 the pinned runtime directory is untouched.`);
|
|
343
|
+
lines.push(" Unset the variable(s) and re-run to return to the pinned manifest.");
|
|
344
|
+
return lines;
|
|
345
|
+
}
|
|
346
|
+
function describeRuntimeSpecOverride(override) {
|
|
347
|
+
return Object.keys(RUNTIME_SPEC_ENV).filter((pkg) => override[pkg] !== void 0).map((pkg) => `${RUNTIME_SPEC_ENV[pkg]}=${override[pkg]}`).join(" ");
|
|
348
|
+
}
|
|
349
|
+
var RUNTIME_SPEC_ENV, SHELL_METACHARACTERS, RuntimeSpecOverrideError;
|
|
350
|
+
var init_runtime_spec_override = __esm({
|
|
351
|
+
"src/runtime-spec-override.ts"() {
|
|
352
|
+
RUNTIME_SPEC_ENV = {
|
|
353
|
+
signer: "HAVEN_SIGNER_SPEC",
|
|
354
|
+
sdk: "HAVEN_SDK_SPEC",
|
|
355
|
+
mcp: "HAVEN_MCP_SPEC"
|
|
356
|
+
};
|
|
357
|
+
SHELL_METACHARACTERS = /[;&|<>$`'"()!#*?[\]{}\\]/;
|
|
358
|
+
RuntimeSpecOverrideError = class extends Error {
|
|
359
|
+
code = "runtime_spec_override_invalid";
|
|
360
|
+
variable;
|
|
361
|
+
constructor(variable, reason) {
|
|
362
|
+
super(`${variable} is set but not usable as an npm package spec: ${reason}. Unset it, or set it to a spec npm install accepts (file:/abs/path, a .tgz, or @haven_ai/<pkg>@<version>).`);
|
|
363
|
+
this.name = "RuntimeSpecOverrideError";
|
|
364
|
+
this.variable = variable;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
async function prepareSignerRuntime(input, deps = {}) {
|
|
370
|
+
const homeDir = input.homeDir ?? os.homedir();
|
|
371
|
+
const override = resolveSignerRuntimeOverride(deps.env ?? process.env);
|
|
372
|
+
const signerSpec = override?.signer ?? signerPackageSpec();
|
|
373
|
+
const sdkSpec = override?.sdk ?? sdkPackageSpec();
|
|
374
|
+
const resolvedSpecs = [signerSpec, sdkSpec];
|
|
375
|
+
const overrideRecord = override ? { specs: override, resolved_specs: resolvedSpecs, directory_key: runtimeSpecOverrideDirectoryKey(resolvedSpecs) } : void 0;
|
|
376
|
+
const runtimeDirectory = path.resolve(
|
|
377
|
+
homeDir,
|
|
378
|
+
".haven",
|
|
379
|
+
"signer-runtime",
|
|
380
|
+
overrideRecord ? overrideRecord.directory_key : MCP_RUNTIME_MANIFEST.signerVersion
|
|
381
|
+
);
|
|
382
|
+
const npmCacheDirectory = path.resolve(homeDir, ".haven", "npm-cache");
|
|
383
|
+
const cliPath = path.join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "dist", "cli.js");
|
|
384
|
+
const messages = [];
|
|
385
|
+
if (override) {
|
|
386
|
+
messages.push(...runtimeSpecOverrideNotice(
|
|
387
|
+
"signer runtime",
|
|
388
|
+
override,
|
|
389
|
+
{ signer: signerPackageSpec(), sdk: sdkPackageSpec() },
|
|
390
|
+
runtimeDirectory
|
|
391
|
+
));
|
|
392
|
+
}
|
|
393
|
+
await promises.mkdir(runtimeDirectory, { recursive: true, mode: 448 });
|
|
394
|
+
await promises.chmod(runtimeDirectory, 448).catch(() => void 0);
|
|
395
|
+
await promises.mkdir(npmCacheDirectory, { recursive: true, mode: 448 });
|
|
396
|
+
await promises.chmod(npmCacheDirectory, 448).catch(() => void 0);
|
|
397
|
+
if (override) {
|
|
398
|
+
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
399
|
+
messages.push(`Installed local Haven signer runtime from override (${resolvedSpecs.join(" ")}).`);
|
|
400
|
+
} else if (await installedRuntimeMatches(runtimeDirectory, cliPath)) {
|
|
401
|
+
messages.push(`Using existing local Haven signer runtime ${signerPackageSpec()}.`);
|
|
402
|
+
} else {
|
|
403
|
+
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
404
|
+
messages.push(`Installed local Haven signer runtime ${signerPackageSpec()}.`);
|
|
405
|
+
}
|
|
406
|
+
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
407
|
+
const installedVersions = override ? await readInstalledVersions(runtimeDirectory) : void 0;
|
|
408
|
+
const wrapperPath = path.join(input.credentialDirectory, "bin", "haven-signer.mjs");
|
|
409
|
+
await writeWrapper({
|
|
410
|
+
wrapperPath,
|
|
411
|
+
cliPath,
|
|
412
|
+
signerPath: input.signerPath,
|
|
413
|
+
overrideComment: override ? describeRuntimeSpecOverride(override) : void 0
|
|
414
|
+
});
|
|
415
|
+
await writeRuntimeSidecar({
|
|
416
|
+
path: path.join(input.credentialDirectory, "signer-runtime.json"),
|
|
417
|
+
wrapperPath,
|
|
418
|
+
runtimeDirectory,
|
|
419
|
+
npmCacheDirectory,
|
|
420
|
+
cliPath,
|
|
421
|
+
serverName: input.serverName,
|
|
422
|
+
override: overrideRecord,
|
|
423
|
+
installedVersions
|
|
424
|
+
});
|
|
425
|
+
messages.push(`Prepared stable local Haven signer wrapper: ${wrapperPath}`);
|
|
426
|
+
return {
|
|
427
|
+
command: wrapperPath,
|
|
428
|
+
args: [],
|
|
429
|
+
wrapperPath,
|
|
430
|
+
runtimeDirectory,
|
|
431
|
+
npmCacheDirectory,
|
|
432
|
+
cliPath,
|
|
433
|
+
messages,
|
|
434
|
+
...overrideRecord ? { runtimeSpecOverride: overrideRecord } : {}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function resolveSignerRuntimeOverride(env) {
|
|
438
|
+
const override = resolveRuntimeSpecOverride(env);
|
|
439
|
+
if (!overrideApplies(override, ["signer", "sdk"])) return void 0;
|
|
440
|
+
const { signer, sdk } = override;
|
|
441
|
+
return { ...signer !== void 0 ? { signer } : {}, ...sdk !== void 0 ? { sdk } : {} };
|
|
442
|
+
}
|
|
443
|
+
async function installRuntimePackages(runtimeDirectory, npmCacheDirectory, packageSpecs, deps) {
|
|
444
|
+
const { runCommand, onProgress } = deps;
|
|
445
|
+
const baseArgs = [
|
|
446
|
+
"install",
|
|
447
|
+
"--prefix",
|
|
448
|
+
runtimeDirectory,
|
|
449
|
+
"--no-audit",
|
|
450
|
+
"--no-fund",
|
|
451
|
+
"--omit=dev",
|
|
452
|
+
"--prefer-offline",
|
|
453
|
+
...packageSpecs
|
|
454
|
+
];
|
|
455
|
+
const run = async (args) => {
|
|
456
|
+
const startedAt = Date.now();
|
|
457
|
+
const heartbeat = setInterval(() => {
|
|
458
|
+
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
459
|
+
onProgress?.(`Still installing the local Haven signer runtime\u2026 (${seconds}s \u2014 a cold cache can take several minutes)`);
|
|
460
|
+
}, SIGNER_INSTALL_HEARTBEAT_MS);
|
|
461
|
+
heartbeat.unref?.();
|
|
462
|
+
try {
|
|
463
|
+
if (runCommand) await runCommand("npm", args);
|
|
464
|
+
else await execFileAsync("npm", args, { timeout: SIGNER_INSTALL_TIMEOUT_MS, maxBuffer: 1024 * 1024 });
|
|
465
|
+
} finally {
|
|
466
|
+
clearInterval(heartbeat);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
try {
|
|
470
|
+
await run(baseArgs);
|
|
471
|
+
} catch {
|
|
472
|
+
try {
|
|
473
|
+
await run([...baseArgs, "--cache", npmCacheDirectory]);
|
|
474
|
+
} catch (err) {
|
|
475
|
+
throw new Error(
|
|
476
|
+
`Could not install local Haven signer runtime ${packageSpecs.join(" ")}: ${err instanceof Error ? err.message : String(err)}`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
async function installedRuntimeMatches(runtimeDirectory, cliPath) {
|
|
482
|
+
return installedRuntimeMatchesVersions(runtimeDirectory, cliPath, {
|
|
483
|
+
signerVersion: MCP_RUNTIME_MANIFEST.signerVersion,
|
|
484
|
+
sdkVersion: MCP_RUNTIME_MANIFEST.sdkVersion
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
async function installedRuntimeMatchesVersions(runtimeDirectory, cliPath, expected) {
|
|
488
|
+
try {
|
|
489
|
+
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
490
|
+
const installed = await readInstalledVersions(runtimeDirectory);
|
|
491
|
+
return installed.signerVersion === expected.signerVersion && installed.sdkVersion === expected.sdkVersion;
|
|
492
|
+
} catch {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
async function readInstalledVersions(runtimeDirectory) {
|
|
497
|
+
const [signerPackage, sdkPackage] = await Promise.all([
|
|
498
|
+
readPackageJson(path.join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "package.json")),
|
|
499
|
+
readPackageJson(path.join(runtimeDirectory, "node_modules", "@haven_ai", "sdk", "package.json"))
|
|
500
|
+
]);
|
|
501
|
+
return { signerVersion: signerPackage.version ?? "", sdkVersion: sdkPackage.version ?? "" };
|
|
502
|
+
}
|
|
503
|
+
async function readPackageJson(path) {
|
|
504
|
+
return JSON.parse(await promises.readFile(path, "utf8"));
|
|
505
|
+
}
|
|
506
|
+
async function writeWrapper(input) {
|
|
507
|
+
await promises.mkdir(path.dirname(input.wrapperPath), { recursive: true, mode: 448 });
|
|
508
|
+
await promises.chmod(path.dirname(input.wrapperPath), 448).catch(() => void 0);
|
|
509
|
+
const source = [
|
|
510
|
+
"#!/usr/bin/env node",
|
|
511
|
+
...input.overrideComment ? [`// HAVEN RUNTIME SPEC OVERRIDE (#2424): ${input.overrideComment} \u2014 this wrapper launches a NON-pinned signer build.`] : [],
|
|
512
|
+
"import { spawn } from 'node:child_process'",
|
|
513
|
+
"",
|
|
514
|
+
`const cliPath = ${JSON.stringify(input.cliPath)}`,
|
|
515
|
+
`const signerPath = ${JSON.stringify(input.signerPath)}`,
|
|
516
|
+
"",
|
|
517
|
+
"const child = spawn(process.execPath, [cliPath, '--credentials', signerPath, ...process.argv.slice(2)], {",
|
|
518
|
+
" stdio: 'inherit',",
|
|
519
|
+
"})",
|
|
520
|
+
"",
|
|
521
|
+
"child.on('exit', (code, signal) => {",
|
|
522
|
+
" if (signal) process.kill(process.pid, signal)",
|
|
523
|
+
" else process.exit(code ?? 1)",
|
|
524
|
+
"})",
|
|
525
|
+
""
|
|
526
|
+
].join("\n");
|
|
527
|
+
await promises.writeFile(input.wrapperPath, source, { mode: 448 });
|
|
528
|
+
await promises.chmod(input.wrapperPath, 448).catch(() => void 0);
|
|
529
|
+
}
|
|
530
|
+
async function readRuntimeSidecar(credentialDirectory) {
|
|
531
|
+
try {
|
|
532
|
+
return JSON.parse(
|
|
533
|
+
await promises.readFile(path.join(credentialDirectory, "signer-runtime.json"), "utf8")
|
|
534
|
+
);
|
|
535
|
+
} catch {
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
async function writeRuntimeSidecar(input) {
|
|
540
|
+
const value = {
|
|
541
|
+
...input.serverName ? { server_name: input.serverName } : {},
|
|
542
|
+
signer_package: MCP_RUNTIME_MANIFEST.signerPackage,
|
|
543
|
+
signer_version: input.installedVersions?.signerVersion ?? MCP_RUNTIME_MANIFEST.signerVersion,
|
|
544
|
+
sdk_package: MCP_RUNTIME_MANIFEST.sdkPackage,
|
|
545
|
+
sdk_version: input.installedVersions?.sdkVersion ?? MCP_RUNTIME_MANIFEST.sdkVersion,
|
|
546
|
+
wrapper_path: input.wrapperPath,
|
|
547
|
+
runtime_directory: input.runtimeDirectory,
|
|
548
|
+
npm_cache_directory: input.npmCacheDirectory,
|
|
549
|
+
cli_path: input.cliPath,
|
|
550
|
+
...input.override ? { runtime_spec_override: input.override } : {}
|
|
551
|
+
};
|
|
552
|
+
await promises.writeFile(input.path, `${JSON.stringify(value, null, 2)}
|
|
553
|
+
`, { mode: 384 });
|
|
554
|
+
await promises.chmod(input.path, 384).catch(() => void 0);
|
|
555
|
+
}
|
|
556
|
+
async function assertFileExists(path, label) {
|
|
557
|
+
try {
|
|
558
|
+
await promises.access(path);
|
|
559
|
+
} catch {
|
|
560
|
+
throw new Error(`Missing ${label}: ${path}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
var execFileAsync, SIGNER_INSTALL_TIMEOUT_MS, SIGNER_INSTALL_HEARTBEAT_MS;
|
|
564
|
+
var init_signer_runtime = __esm({
|
|
565
|
+
"src/signer-runtime.ts"() {
|
|
566
|
+
init_runtime_manifest();
|
|
567
|
+
init_runtime_spec_override();
|
|
568
|
+
execFileAsync = util.promisify(child_process.execFile);
|
|
569
|
+
SIGNER_INSTALL_TIMEOUT_MS = 6e5;
|
|
570
|
+
SIGNER_INSTALL_HEARTBEAT_MS = 15e3;
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// src/connect-error.ts
|
|
575
|
+
function isConnectError(err) {
|
|
576
|
+
return err instanceof ConnectError;
|
|
577
|
+
}
|
|
578
|
+
var ConnectError;
|
|
579
|
+
var init_connect_error = __esm({
|
|
580
|
+
"src/connect-error.ts"() {
|
|
581
|
+
ConnectError = class extends Error {
|
|
582
|
+
code;
|
|
583
|
+
nextAction;
|
|
584
|
+
details;
|
|
585
|
+
constructor(code, message, nextAction2, details = {}) {
|
|
586
|
+
super(message);
|
|
587
|
+
this.name = "ConnectError";
|
|
588
|
+
this.code = code;
|
|
589
|
+
this.nextAction = nextAction2;
|
|
590
|
+
this.details = details;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
// src/tombstone.ts
|
|
597
|
+
var tombstone_exports = {};
|
|
598
|
+
__export(tombstone_exports, {
|
|
599
|
+
ROOT_TOMBSTONES_DIRNAME: () => ROOT_TOMBSTONES_DIRNAME,
|
|
600
|
+
TOMBSTONE_FILENAME: () => TOMBSTONE_FILENAME,
|
|
601
|
+
TOMBSTONE_MARKER: () => TOMBSTONE_MARKER,
|
|
602
|
+
defaultTombstonesDir: () => defaultTombstonesDir,
|
|
603
|
+
readAgentTombstone: () => readAgentTombstone,
|
|
604
|
+
readTombstoneRecords: () => readTombstoneRecords,
|
|
605
|
+
tombstonesDirForAgentDirectory: () => tombstonesDirForAgentDirectory,
|
|
606
|
+
tombstonesDirForCredentialRoot: () => tombstonesDirForCredentialRoot,
|
|
607
|
+
writeAgentTombstone: () => writeAgentTombstone
|
|
608
|
+
});
|
|
609
|
+
function defaultTombstonesDir(baseDir) {
|
|
610
|
+
return path.join(baseDir ?? path.join(os.homedir(), ".haven"), "tombstones");
|
|
172
611
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
612
|
+
function tombstonesDirForCredentialRoot(credentialRoot, homeDir = os.homedir()) {
|
|
613
|
+
if (!credentialRoot) return defaultTombstonesDir(path.join(homeDir, ".haven"));
|
|
614
|
+
const root = path.resolve(credentialRoot);
|
|
615
|
+
if (root === path.resolve(homeDir, ".haven", "agents")) return defaultTombstonesDir(path.join(homeDir, ".haven"));
|
|
616
|
+
return path.join(root, ROOT_TOMBSTONES_DIRNAME);
|
|
175
617
|
}
|
|
176
|
-
function
|
|
618
|
+
function tombstonesDirForAgentDirectory(directory, homeDir = os.homedir()) {
|
|
619
|
+
return tombstonesDirForCredentialRoot(path.dirname(path.resolve(directory)), homeDir);
|
|
620
|
+
}
|
|
621
|
+
async function readTombstoneRecords(tombstonesDir) {
|
|
622
|
+
const root = tombstonesDir ?? defaultTombstonesDir();
|
|
623
|
+
let entries = [];
|
|
177
624
|
try {
|
|
178
|
-
|
|
179
|
-
parsed.username = "";
|
|
180
|
-
parsed.password = "";
|
|
181
|
-
return parsed.toString().replace(/\/+$/, "");
|
|
625
|
+
entries = await promises.readdir(root);
|
|
182
626
|
} catch {
|
|
183
|
-
return
|
|
627
|
+
return [];
|
|
628
|
+
}
|
|
629
|
+
const records = [];
|
|
630
|
+
for (const entry of entries) {
|
|
631
|
+
if (!entry.endsWith(".json")) continue;
|
|
632
|
+
const recordPath = path.join(root, entry);
|
|
633
|
+
try {
|
|
634
|
+
const parsed = JSON.parse(await promises.readFile(recordPath, "utf8"));
|
|
635
|
+
if (typeof parsed?.agent_id === "string") {
|
|
636
|
+
records.push({ ...parsed, recordPath });
|
|
637
|
+
}
|
|
638
|
+
} catch {
|
|
639
|
+
}
|
|
184
640
|
}
|
|
641
|
+
return records;
|
|
185
642
|
}
|
|
186
|
-
function
|
|
187
|
-
|
|
188
|
-
|
|
643
|
+
function tombstoneScript(info) {
|
|
644
|
+
const lines = [
|
|
645
|
+
`${TOMBSTONE_MARKER}: this Haven agent was retired.`,
|
|
646
|
+
"",
|
|
647
|
+
` agent: ${info.agent_id}`,
|
|
648
|
+
` retired at: ${info.retired_at}`,
|
|
649
|
+
` reason: ${info.reason}`,
|
|
650
|
+
...info.replaced_by ? [` replaced by: ${info.replaced_by}`] : [],
|
|
651
|
+
"",
|
|
652
|
+
"This process is running with a wiring snapshot that predates the",
|
|
653
|
+
"retirement \u2014 it loaded its MCP config at startup and has kept it since.",
|
|
654
|
+
"Restart THIS host to pick up the current wiring. If several long-lived",
|
|
655
|
+
"hosts are running (a gateway, a TUI worker, an editor), restart EVERY",
|
|
656
|
+
"one of them: each holds the snapshot from its own start time, so after",
|
|
657
|
+
"a chain of recreations each can be parked on a DIFFERENT old agent.",
|
|
658
|
+
"",
|
|
659
|
+
`Then verify with: ${sdk.connectorRerunCommand("--doctor --runtime <runtime>")}`
|
|
660
|
+
];
|
|
661
|
+
return [
|
|
662
|
+
"#!/usr/bin/env node",
|
|
663
|
+
`// ${TOMBSTONE_MARKER} \u2014 written by @haven_ai/connect (#1681). Safe to delete`,
|
|
664
|
+
"// once every long-lived MCP host on this machine has been restarted.",
|
|
665
|
+
`process.stderr.write(${JSON.stringify(lines.join("\n") + "\n")})`,
|
|
666
|
+
"process.exit(1)",
|
|
667
|
+
""
|
|
668
|
+
].join("\n");
|
|
189
669
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// src/server-names.ts
|
|
199
|
-
function assertValidServerSlug(slug) {
|
|
200
|
-
if (slug.length === 0 || slug.length > 32 || !SLUG_RE.test(slug)) {
|
|
201
|
-
throw new Error(
|
|
202
|
-
`Invalid server name ${JSON.stringify(slug)}: use 1-32 lowercase letters, digits, and single hyphens (e.g. "research").`
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
if (slug === "haven" || slug === "haven-signer") {
|
|
206
|
-
throw new Error(
|
|
207
|
-
`Invalid server name ${JSON.stringify(slug)}: "haven" and "haven-signer" are the unnamed pair's own names \u2014 omit --name for the bare pair.`
|
|
670
|
+
async function writeAgentTombstone(input) {
|
|
671
|
+
const dirStat = await promises.stat(input.directory).catch(() => null);
|
|
672
|
+
if (!dirStat?.isDirectory()) {
|
|
673
|
+
throw new ConnectError(
|
|
674
|
+
"tombstone_directory_not_found",
|
|
675
|
+
`Not a directory: ${input.directory} \u2014 nothing to tombstone. Agent directories are named by their wiring SLUG when the agent has one, and by the agent id otherwise \u2014 so a path built from an agent id will not exist for a named agent. List ~/.haven/agents (or read the directories from --doctor --json) and pass one of those.`,
|
|
676
|
+
"retry_with_an_existing_agent_directory"
|
|
208
677
|
);
|
|
209
678
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
679
|
+
const info = {
|
|
680
|
+
// reason / replaced_by are persisted to disk and re-emitted to the host's
|
|
681
|
+
// MCP stderr log on EVERY stale probe, potentially for months — redact
|
|
682
|
+
// like every other output path, at the write layer so any future caller
|
|
683
|
+
// inherits it. (#1681 review, finding 1)
|
|
684
|
+
agent_id: input.agentId,
|
|
685
|
+
retired_at: input.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
686
|
+
reason: redactSecrets(input.reason),
|
|
687
|
+
...input.replacedBy ? { replaced_by: redactSecrets(input.replacedBy) } : {}
|
|
688
|
+
};
|
|
689
|
+
const binDir = path.join(input.directory, "bin");
|
|
690
|
+
await promises.mkdir(binDir, { recursive: true });
|
|
691
|
+
const wrapperPath = path.join(binDir, "haven-signer.mjs");
|
|
692
|
+
await promises.writeFile(wrapperPath, tombstoneScript(info), "utf8");
|
|
693
|
+
await promises.chmod(wrapperPath, 493);
|
|
694
|
+
const record = JSON.stringify(info, null, 2) + "\n";
|
|
695
|
+
await promises.writeFile(path.join(input.directory, TOMBSTONE_FILENAME), record, "utf8");
|
|
696
|
+
const root = input.tombstonesDir ?? defaultTombstonesDir();
|
|
697
|
+
const recordPath = path.join(root, `${info.agent_id}.json`);
|
|
698
|
+
try {
|
|
699
|
+
await promises.mkdir(root, { recursive: true, mode: 448 });
|
|
700
|
+
await promises.writeFile(recordPath, record, { mode: MIRROR_MODE });
|
|
701
|
+
} catch (err) {
|
|
702
|
+
const code = err?.code;
|
|
703
|
+
return { ...info, recordPath: null, mirrorError: typeof code === "string" && /^E[A-Z]+$/.test(code) ? code : "mirror_write_failed" };
|
|
214
704
|
}
|
|
705
|
+
return { ...info, recordPath };
|
|
215
706
|
}
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
codexSigner: "haven_signer",
|
|
224
|
-
hermesEnvKey: "MCP_HAVEN_API_KEY"
|
|
225
|
-
};
|
|
707
|
+
async function readAgentTombstone(directory) {
|
|
708
|
+
try {
|
|
709
|
+
const parsed = JSON.parse(await promises.readFile(path.join(directory, TOMBSTONE_FILENAME), "utf8"));
|
|
710
|
+
if (typeof parsed?.agent_id !== "string") return null;
|
|
711
|
+
return parsed;
|
|
712
|
+
} catch {
|
|
713
|
+
return null;
|
|
226
714
|
}
|
|
227
|
-
assertValidServerSlug(slug);
|
|
228
|
-
return {
|
|
229
|
-
hosted: `haven-${slug}`,
|
|
230
|
-
signer: `haven-signer-${slug}`,
|
|
231
|
-
// Hyphens are valid TOML bare keys, so named Codex tables match the
|
|
232
|
-
// JSON/YAML names instead of inheriting the legacy underscore.
|
|
233
|
-
codexHosted: `haven-${slug}`,
|
|
234
|
-
codexSigner: `haven-signer-${slug}`,
|
|
235
|
-
hermesEnvKey: `MCP_HAVEN_${slug.toUpperCase().replace(/-/g, "_")}_API_KEY`
|
|
236
|
-
};
|
|
237
715
|
}
|
|
238
|
-
var
|
|
239
|
-
var
|
|
240
|
-
"src/
|
|
241
|
-
|
|
716
|
+
var TOMBSTONE_FILENAME, ROOT_TOMBSTONES_DIRNAME, MIRROR_MODE, TOMBSTONE_MARKER;
|
|
717
|
+
var init_tombstone = __esm({
|
|
718
|
+
"src/tombstone.ts"() {
|
|
719
|
+
init_redact();
|
|
720
|
+
init_connect_error();
|
|
721
|
+
TOMBSTONE_FILENAME = "TOMBSTONE.json";
|
|
722
|
+
ROOT_TOMBSTONES_DIRNAME = ".tombstones";
|
|
723
|
+
MIRROR_MODE = 384;
|
|
724
|
+
TOMBSTONE_MARKER = "HAVEN-TOMBSTONE";
|
|
242
725
|
}
|
|
243
726
|
});
|
|
727
|
+
|
|
728
|
+
// src/storage.ts
|
|
729
|
+
var storage_exports = {};
|
|
730
|
+
__export(storage_exports, {
|
|
731
|
+
CONNECT_OUTCOME_FILENAME: () => CONNECT_OUTCOME_FILENAME,
|
|
732
|
+
MCP_SERVER_BINDING_FILENAME: () => MCP_SERVER_BINDING_FILENAME,
|
|
733
|
+
REKEY_PENDING_FILENAME: () => REKEY_PENDING_FILENAME,
|
|
734
|
+
REKEY_PENDING_TTL_MS: () => REKEY_PENDING_TTL_MS,
|
|
735
|
+
assertDirectoryRecordsSlug: () => assertDirectoryRecordsSlug,
|
|
736
|
+
assertServerSlugAvailable: () => assertServerSlugAvailable,
|
|
737
|
+
clearMcpServerBinding: () => clearMcpServerBinding,
|
|
738
|
+
clearRekeyPending: () => clearRekeyPending,
|
|
739
|
+
defaultAgentDirectory: () => defaultAgentDirectory,
|
|
740
|
+
defaultCredentialRoot: () => defaultCredentialRoot,
|
|
741
|
+
inspectRekeyPending: () => inspectRekeyPending,
|
|
742
|
+
listMcpServerBindings: () => listMcpServerBindings,
|
|
743
|
+
preflightCredentialStorage: () => preflightCredentialStorage,
|
|
744
|
+
readConnectOutcomeRuntime: () => readConnectOutcomeRuntime,
|
|
745
|
+
readMcpServerBinding: () => readMcpServerBinding,
|
|
746
|
+
readRekeyPending: () => readRekeyPending,
|
|
747
|
+
readStoredAccountAddress: () => readStoredAccountAddress,
|
|
748
|
+
readStoredCredentials: () => readStoredCredentials,
|
|
749
|
+
resolveAgentDirectoryBySlug: () => resolveAgentDirectoryBySlug,
|
|
750
|
+
rewriteCredentialFiles: () => rewriteCredentialFiles,
|
|
751
|
+
writeConnectOutcomeRecord: () => writeConnectOutcomeRecord,
|
|
752
|
+
writeCredentialFiles: () => writeCredentialFiles,
|
|
753
|
+
writeMcpServerBinding: () => writeMcpServerBinding,
|
|
754
|
+
writeRekeyPending: () => writeRekeyPending
|
|
755
|
+
});
|
|
244
756
|
async function preflightCredentialStorage(input = {}) {
|
|
245
757
|
const directory = defaultCredentialRoot(input.baseDir);
|
|
246
758
|
await promises.mkdir(directory, { recursive: true, mode: 448 });
|
|
@@ -317,8 +829,7 @@ function agentPayload(input) {
|
|
|
317
829
|
};
|
|
318
830
|
}
|
|
319
831
|
async function readStoredCredentials(serverName, agentIdOrSlug, baseDir) {
|
|
320
|
-
const
|
|
321
|
-
const directory = key ? defaultAgentDirectory(key, baseDir) : await discoverSoleAgentDirectory(baseDir);
|
|
832
|
+
const directory = serverName ? await resolveAgentDirectoryBySlug(serverName, { root: baseDir }) : agentIdOrSlug ? defaultAgentDirectory(agentIdOrSlug, baseDir) : await discoverSoleAgentDirectory(baseDir);
|
|
322
833
|
const identity = await readJsonFile(path.join(directory, "identity.json"));
|
|
323
834
|
if (!identity) {
|
|
324
835
|
throw new Error(
|
|
@@ -326,7 +837,7 @@ async function readStoredCredentials(serverName, agentIdOrSlug, baseDir) {
|
|
|
326
837
|
);
|
|
327
838
|
}
|
|
328
839
|
let discoveredSlug;
|
|
329
|
-
if (!
|
|
840
|
+
if (!serverName && !agentIdOrSlug) {
|
|
330
841
|
const binding = await readJsonFile(path.join(directory, "mcp-server-binding.json"));
|
|
331
842
|
const hostedName = binding && typeof binding === "object" ? asString(binding.server_name) : void 0;
|
|
332
843
|
if (hostedName && hostedName.startsWith("haven-")) {
|
|
@@ -397,6 +908,65 @@ async function discoverSoleAgentDirectory(baseDir) {
|
|
|
397
908
|
` + candidates.map((d) => ` ${d}`).join("\n") + "\nRe-run with --name <slug> to pick one."
|
|
398
909
|
);
|
|
399
910
|
}
|
|
911
|
+
async function assertDirectoryRecordsSlug(directory, slug) {
|
|
912
|
+
assertValidServerSlug(slug);
|
|
913
|
+
const sidecar = await readRuntimeSidecar(directory);
|
|
914
|
+
const bindingRecord = await readJsonFile(path.join(directory, "mcp-server-binding.json"));
|
|
915
|
+
const bindingSlug = bindingRecord ? asString(bindingRecord.server_name) : void 0;
|
|
916
|
+
const claimed = sidecar?.server_name ?? bindingSlug;
|
|
917
|
+
if (claimed === slug) return;
|
|
918
|
+
if (!claimed && path.basename(directory) === slug) return;
|
|
919
|
+
throw new Error(
|
|
920
|
+
`--name ${slug} and --credentials-dir ${directory} disagree: that directory records ` + (claimed ? `the pair 'haven-${claimed}'` : "no named pair") + `. Pass one of them, not both \u2014 or point --credentials-dir at the directory that records 'haven-${slug}'.`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
async function resolveAgentDirectoryBySlug(slug, opts = {}) {
|
|
924
|
+
assertValidServerSlug(slug);
|
|
925
|
+
const root = defaultCredentialRoot(opts.root);
|
|
926
|
+
let entries = [];
|
|
927
|
+
try {
|
|
928
|
+
entries = await promises.readdir(root);
|
|
929
|
+
} catch {
|
|
930
|
+
throw new Error(
|
|
931
|
+
`No agent directories under ${root} \u2014 nothing records the pair 'haven-${slug}'. Connect this agent first, or pass --credentials-dir <path> for the exact directory.`
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
const claims = [];
|
|
935
|
+
const recordedSlugs = [];
|
|
936
|
+
let barePairCount = 0;
|
|
937
|
+
let legacyFolder;
|
|
938
|
+
for (const entry of entries.sort()) {
|
|
939
|
+
const directory = path.join(root, entry);
|
|
940
|
+
const retired = await readJsonFile(path.join(directory, TOMBSTONE_FILENAME)) !== null;
|
|
941
|
+
const sidecar = await readRuntimeSidecar(directory);
|
|
942
|
+
const bindingRecord = await readJsonFile(path.join(directory, "mcp-server-binding.json"));
|
|
943
|
+
const bindingSlug = bindingRecord ? asString(bindingRecord.server_name) : void 0;
|
|
944
|
+
const claimedSlug = sidecar?.server_name ?? bindingSlug;
|
|
945
|
+
if (claimedSlug && !recordedSlugs.includes(claimedSlug)) recordedSlugs.push(claimedSlug);
|
|
946
|
+
if (sidecar && !sidecar.server_name) barePairCount++;
|
|
947
|
+
if (retired && !opts.allowRetired) continue;
|
|
948
|
+
if (claimedSlug === slug) {
|
|
949
|
+
const identity = await readJsonFile(path.join(directory, "identity.json"));
|
|
950
|
+
claims.push({ directory, agentId: identity ? asString(identity.agent_id) ?? null : null, retired });
|
|
951
|
+
}
|
|
952
|
+
if (!claimedSlug && !retired && entry === slug) legacyFolder = directory;
|
|
953
|
+
}
|
|
954
|
+
if (claims.length > 1) {
|
|
955
|
+
throw new Error(
|
|
956
|
+
`${claims.length} agent directories on this machine record the pair 'haven-${slug}' \u2014 the MCP server name changed hands (mcp_server_name_rebound):
|
|
957
|
+
` + claims.map((c) => ` \u2022 ${c.agentId ? `agent ${c.agentId}` : "agent (no agent_id recorded)"} \u2014 ${c.directory}${c.retired ? " (retired)" : ""}`).join("\n") + "\nRetire the earlier one with --unwire, or name the directory exactly with --credentials-dir <path>. Nothing was changed."
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
if (claims.length === 1) return claims[0].directory;
|
|
961
|
+
if (legacyFolder) return legacyFolder;
|
|
962
|
+
const known = [
|
|
963
|
+
...recordedSlugs.map((s) => `'haven-${s}'`),
|
|
964
|
+
...barePairCount > 0 ? [`${barePairCount} unnamed 'haven' / 'haven-signer' pair${barePairCount === 1 ? "" : "s"} (no --name)`] : []
|
|
965
|
+
];
|
|
966
|
+
throw new Error(
|
|
967
|
+
`No agent directory on this machine records the pair 'haven-${slug}'.` + (known.length > 0 ? ` Directories under ${root} record: ${known.join(", ")}.` : ` Nothing under ${root} records a named pair.`) + " Check the agent id against the Haven agent page, or name the directory exactly with --credentials-dir <path>."
|
|
968
|
+
);
|
|
969
|
+
}
|
|
400
970
|
async function rewriteCredentialFiles(input) {
|
|
401
971
|
const directory = defaultAgentDirectory(input.serverName ?? input.agentId, input.baseDir);
|
|
402
972
|
const identityPath = path.join(directory, "identity.json");
|
|
@@ -606,6 +1176,7 @@ async function listMcpServerBindings(baseDir, excludeDirectory) {
|
|
|
606
1176
|
const out = [];
|
|
607
1177
|
for (const entry of entries) {
|
|
608
1178
|
const directory = path.join(root, entry);
|
|
1179
|
+
if (excludeDirectory && directory === excludeDirectory) continue;
|
|
609
1180
|
const binding = await readMcpServerBinding(directory);
|
|
610
1181
|
if (binding) out.push({ directory, binding });
|
|
611
1182
|
}
|
|
@@ -615,48 +1186,12 @@ var REKEY_PENDING_FILENAME, REKEY_PENDING_TTL_MS, CONNECT_OUTCOME_FILENAME, MCP_
|
|
|
615
1186
|
var init_storage = __esm({
|
|
616
1187
|
"src/storage.ts"() {
|
|
617
1188
|
init_server_names();
|
|
1189
|
+
init_signer_runtime();
|
|
1190
|
+
init_tombstone();
|
|
618
1191
|
REKEY_PENDING_FILENAME = "rekey-pending.json";
|
|
619
1192
|
REKEY_PENDING_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
620
1193
|
CONNECT_OUTCOME_FILENAME = "last-connect-outcome.json";
|
|
621
|
-
MCP_SERVER_BINDING_FILENAME = "mcp-server-binding.json";
|
|
622
|
-
}
|
|
623
|
-
});
|
|
624
|
-
function mcpPackageSpec() {
|
|
625
|
-
return `${MCP_RUNTIME_MANIFEST.mcpPackage}@${MCP_RUNTIME_MANIFEST.mcpVersion}`;
|
|
626
|
-
}
|
|
627
|
-
function sdkPackageSpec() {
|
|
628
|
-
return `${MCP_RUNTIME_MANIFEST.sdkPackage}@${MCP_RUNTIME_MANIFEST.sdkVersion}`;
|
|
629
|
-
}
|
|
630
|
-
function signerPackageSpec() {
|
|
631
|
-
return `${MCP_RUNTIME_MANIFEST.signerPackage}@${MCP_RUNTIME_MANIFEST.signerVersion}`;
|
|
632
|
-
}
|
|
633
|
-
var MCP_RUNTIME_MANIFEST;
|
|
634
|
-
var init_runtime_manifest = __esm({
|
|
635
|
-
"src/runtime-manifest.ts"() {
|
|
636
|
-
MCP_RUNTIME_MANIFEST = {
|
|
637
|
-
mcpPackage: "@haven_ai/mcp",
|
|
638
|
-
mcpVersion: mcp.MCP_VERSION,
|
|
639
|
-
sdkPackage: "@haven_ai/sdk",
|
|
640
|
-
sdkVersion: "0.9.0-alpha.0",
|
|
641
|
-
signerPackage: "@haven_ai/signer",
|
|
642
|
-
signerVersion: "0.9.0-alpha.0",
|
|
643
|
-
// Sourced from the SDK, never a literal (#1161). This field read '20.0.0'
|
|
644
|
-
// while every package's `engines` said `>=24` and the docs said `>=24.0.0`,
|
|
645
|
-
// so the guard that was supposed to enforce the floor waved Node v23 through
|
|
646
|
-
// — including on the `--local` path where it does run. A hand-maintained
|
|
647
|
-
// second copy of a number is a drift waiting to happen; a guard test pins
|
|
648
|
-
// this against `package.json`'s `engines.node`.
|
|
649
|
-
minimumNodeVersion: sdk.HAVEN_MINIMUM_NODE_VERSION,
|
|
650
|
-
supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
|
|
651
|
-
requiredTools: mcp.registeredToolNames(),
|
|
652
|
-
/**
|
|
653
|
-
* The signer MCP's tool surface, DERIVED from the pinned @haven_ai/signer
|
|
654
|
-
* package (#1587) — same anti-drift rule as `requiredTools` above: a
|
|
655
|
-
* literal list here would rot the first time the signer gains a tool.
|
|
656
|
-
* The handshake probe requires all of them.
|
|
657
|
-
*/
|
|
658
|
-
requiredSignerTools: Object.keys(signer.toolSchemas)
|
|
659
|
-
};
|
|
1194
|
+
MCP_SERVER_BINDING_FILENAME = "mcp-server-binding.json";
|
|
660
1195
|
}
|
|
661
1196
|
});
|
|
662
1197
|
async function writeRuntimeConfig(input, deps = {}) {
|
|
@@ -1693,295 +2228,23 @@ function parseJsonRpcPayload(raw) {
|
|
|
1693
2228
|
const dataLines = trimmed.split(/\r?\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim());
|
|
1694
2229
|
for (let i = dataLines.length - 1; i >= 0; i -= 1) {
|
|
1695
2230
|
try {
|
|
1696
|
-
return JSON.parse(dataLines[i]);
|
|
1697
|
-
} catch {
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
return null;
|
|
1701
|
-
}
|
|
1702
|
-
async function fetchWithTimeout(fetchImpl, url, init) {
|
|
1703
|
-
const controller = new AbortController();
|
|
1704
|
-
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
1705
|
-
try {
|
|
1706
|
-
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
1707
|
-
} finally {
|
|
1708
|
-
clearTimeout(timeout);
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
var init_probes = __esm({
|
|
1712
|
-
"src/probes.ts"() {
|
|
1713
|
-
}
|
|
1714
|
-
});
|
|
1715
|
-
function resolveRuntimeSpecOverride(env) {
|
|
1716
|
-
const override = {};
|
|
1717
|
-
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
1718
|
-
const variable = RUNTIME_SPEC_ENV[pkg];
|
|
1719
|
-
const raw = env[variable];
|
|
1720
|
-
if (raw === void 0) continue;
|
|
1721
|
-
override[pkg] = validateSpec(variable, raw);
|
|
1722
|
-
}
|
|
1723
|
-
return Object.keys(override).length > 0 ? override : void 0;
|
|
1724
|
-
}
|
|
1725
|
-
function validateSpec(variable, raw) {
|
|
1726
|
-
if (raw.length === 0 || raw.trim().length === 0) {
|
|
1727
|
-
throw new RuntimeSpecOverrideError(variable, "it is empty");
|
|
1728
|
-
}
|
|
1729
|
-
if (/\s/.test(raw)) {
|
|
1730
|
-
throw new RuntimeSpecOverrideError(variable, "it contains whitespace");
|
|
1731
|
-
}
|
|
1732
|
-
if (/[\u0000-\u001f\u007f]/.test(raw)) {
|
|
1733
|
-
throw new RuntimeSpecOverrideError(variable, "it contains a control character");
|
|
1734
|
-
}
|
|
1735
|
-
const meta = SHELL_METACHARACTERS.exec(raw);
|
|
1736
|
-
if (meta) {
|
|
1737
|
-
throw new RuntimeSpecOverrideError(variable, `it contains the shell metacharacter ${JSON.stringify(meta[0])}`);
|
|
1738
|
-
}
|
|
1739
|
-
return raw;
|
|
1740
|
-
}
|
|
1741
|
-
function runtimeSpecOverrideDirectoryKey(resolvedSpecs) {
|
|
1742
|
-
const digest = crypto.createHash("sha256").update(resolvedSpecs.join("\n")).digest("hex");
|
|
1743
|
-
return `override-${digest.slice(0, 12)}`;
|
|
1744
|
-
}
|
|
1745
|
-
function overrideApplies(override, packages) {
|
|
1746
|
-
return override !== void 0 && packages.some((pkg) => override[pkg] !== void 0);
|
|
1747
|
-
}
|
|
1748
|
-
function runtimeSpecOverrideNotice(runtimeLabel, override, pinned, runtimeDirectory) {
|
|
1749
|
-
const lines = [`RUNTIME SPEC OVERRIDE ACTIVE for the local Haven ${runtimeLabel} \u2014 this is NOT the pinned manifest.`];
|
|
1750
|
-
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
1751
|
-
const spec = override[pkg];
|
|
1752
|
-
if (spec === void 0) continue;
|
|
1753
|
-
const pin = pinned[pkg];
|
|
1754
|
-
lines.push(` ${RUNTIME_SPEC_ENV[pkg]}=${spec}${pin ? ` (instead of ${pin})` : ""}`);
|
|
1755
|
-
}
|
|
1756
|
-
lines.push(` Installing into ${runtimeDirectory} \u2014 the pinned runtime directory is untouched.`);
|
|
1757
|
-
lines.push(" Unset the variable(s) and re-run to return to the pinned manifest.");
|
|
1758
|
-
return lines;
|
|
1759
|
-
}
|
|
1760
|
-
function describeRuntimeSpecOverride(override) {
|
|
1761
|
-
return Object.keys(RUNTIME_SPEC_ENV).filter((pkg) => override[pkg] !== void 0).map((pkg) => `${RUNTIME_SPEC_ENV[pkg]}=${override[pkg]}`).join(" ");
|
|
1762
|
-
}
|
|
1763
|
-
var RUNTIME_SPEC_ENV, SHELL_METACHARACTERS, RuntimeSpecOverrideError;
|
|
1764
|
-
var init_runtime_spec_override = __esm({
|
|
1765
|
-
"src/runtime-spec-override.ts"() {
|
|
1766
|
-
RUNTIME_SPEC_ENV = {
|
|
1767
|
-
signer: "HAVEN_SIGNER_SPEC",
|
|
1768
|
-
sdk: "HAVEN_SDK_SPEC",
|
|
1769
|
-
mcp: "HAVEN_MCP_SPEC"
|
|
1770
|
-
};
|
|
1771
|
-
SHELL_METACHARACTERS = /[;&|<>$`'"()!#*?[\]{}\\]/;
|
|
1772
|
-
RuntimeSpecOverrideError = class extends Error {
|
|
1773
|
-
code = "runtime_spec_override_invalid";
|
|
1774
|
-
variable;
|
|
1775
|
-
constructor(variable, reason) {
|
|
1776
|
-
super(`${variable} is set but not usable as an npm package spec: ${reason}. Unset it, or set it to a spec npm install accepts (file:/abs/path, a .tgz, or @haven_ai/<pkg>@<version>).`);
|
|
1777
|
-
this.name = "RuntimeSpecOverrideError";
|
|
1778
|
-
this.variable = variable;
|
|
1779
|
-
}
|
|
1780
|
-
};
|
|
1781
|
-
}
|
|
1782
|
-
});
|
|
1783
|
-
async function prepareSignerRuntime(input, deps = {}) {
|
|
1784
|
-
const homeDir = input.homeDir ?? os.homedir();
|
|
1785
|
-
const override = resolveSignerRuntimeOverride(deps.env ?? process.env);
|
|
1786
|
-
const signerSpec = override?.signer ?? signerPackageSpec();
|
|
1787
|
-
const sdkSpec = override?.sdk ?? sdkPackageSpec();
|
|
1788
|
-
const resolvedSpecs = [signerSpec, sdkSpec];
|
|
1789
|
-
const overrideRecord = override ? { specs: override, resolved_specs: resolvedSpecs, directory_key: runtimeSpecOverrideDirectoryKey(resolvedSpecs) } : void 0;
|
|
1790
|
-
const runtimeDirectory = path.resolve(
|
|
1791
|
-
homeDir,
|
|
1792
|
-
".haven",
|
|
1793
|
-
"signer-runtime",
|
|
1794
|
-
overrideRecord ? overrideRecord.directory_key : MCP_RUNTIME_MANIFEST.signerVersion
|
|
1795
|
-
);
|
|
1796
|
-
const npmCacheDirectory = path.resolve(homeDir, ".haven", "npm-cache");
|
|
1797
|
-
const cliPath = path.join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "dist", "cli.js");
|
|
1798
|
-
const messages = [];
|
|
1799
|
-
if (override) {
|
|
1800
|
-
messages.push(...runtimeSpecOverrideNotice(
|
|
1801
|
-
"signer runtime",
|
|
1802
|
-
override,
|
|
1803
|
-
{ signer: signerPackageSpec(), sdk: sdkPackageSpec() },
|
|
1804
|
-
runtimeDirectory
|
|
1805
|
-
));
|
|
1806
|
-
}
|
|
1807
|
-
await promises.mkdir(runtimeDirectory, { recursive: true, mode: 448 });
|
|
1808
|
-
await promises.chmod(runtimeDirectory, 448).catch(() => void 0);
|
|
1809
|
-
await promises.mkdir(npmCacheDirectory, { recursive: true, mode: 448 });
|
|
1810
|
-
await promises.chmod(npmCacheDirectory, 448).catch(() => void 0);
|
|
1811
|
-
if (override) {
|
|
1812
|
-
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
1813
|
-
messages.push(`Installed local Haven signer runtime from override (${resolvedSpecs.join(" ")}).`);
|
|
1814
|
-
} else if (await installedRuntimeMatches(runtimeDirectory, cliPath)) {
|
|
1815
|
-
messages.push(`Using existing local Haven signer runtime ${signerPackageSpec()}.`);
|
|
1816
|
-
} else {
|
|
1817
|
-
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
1818
|
-
messages.push(`Installed local Haven signer runtime ${signerPackageSpec()}.`);
|
|
1819
|
-
}
|
|
1820
|
-
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
1821
|
-
const installedVersions = override ? await readInstalledVersions(runtimeDirectory) : void 0;
|
|
1822
|
-
const wrapperPath = path.join(input.credentialDirectory, "bin", "haven-signer.mjs");
|
|
1823
|
-
await writeWrapper({
|
|
1824
|
-
wrapperPath,
|
|
1825
|
-
cliPath,
|
|
1826
|
-
signerPath: input.signerPath,
|
|
1827
|
-
overrideComment: override ? describeRuntimeSpecOverride(override) : void 0
|
|
1828
|
-
});
|
|
1829
|
-
await writeRuntimeSidecar({
|
|
1830
|
-
path: path.join(input.credentialDirectory, "signer-runtime.json"),
|
|
1831
|
-
wrapperPath,
|
|
1832
|
-
runtimeDirectory,
|
|
1833
|
-
npmCacheDirectory,
|
|
1834
|
-
cliPath,
|
|
1835
|
-
serverName: input.serverName,
|
|
1836
|
-
override: overrideRecord,
|
|
1837
|
-
installedVersions
|
|
1838
|
-
});
|
|
1839
|
-
messages.push(`Prepared stable local Haven signer wrapper: ${wrapperPath}`);
|
|
1840
|
-
return {
|
|
1841
|
-
command: wrapperPath,
|
|
1842
|
-
args: [],
|
|
1843
|
-
wrapperPath,
|
|
1844
|
-
runtimeDirectory,
|
|
1845
|
-
npmCacheDirectory,
|
|
1846
|
-
cliPath,
|
|
1847
|
-
messages,
|
|
1848
|
-
...overrideRecord ? { runtimeSpecOverride: overrideRecord } : {}
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
|
-
function resolveSignerRuntimeOverride(env) {
|
|
1852
|
-
const override = resolveRuntimeSpecOverride(env);
|
|
1853
|
-
if (!overrideApplies(override, ["signer", "sdk"])) return void 0;
|
|
1854
|
-
const { signer, sdk } = override;
|
|
1855
|
-
return { ...signer !== void 0 ? { signer } : {}, ...sdk !== void 0 ? { sdk } : {} };
|
|
1856
|
-
}
|
|
1857
|
-
async function installRuntimePackages(runtimeDirectory, npmCacheDirectory, packageSpecs, deps) {
|
|
1858
|
-
const { runCommand, onProgress } = deps;
|
|
1859
|
-
const baseArgs = [
|
|
1860
|
-
"install",
|
|
1861
|
-
"--prefix",
|
|
1862
|
-
runtimeDirectory,
|
|
1863
|
-
"--no-audit",
|
|
1864
|
-
"--no-fund",
|
|
1865
|
-
"--omit=dev",
|
|
1866
|
-
"--prefer-offline",
|
|
1867
|
-
...packageSpecs
|
|
1868
|
-
];
|
|
1869
|
-
const run = async (args) => {
|
|
1870
|
-
const startedAt = Date.now();
|
|
1871
|
-
const heartbeat = setInterval(() => {
|
|
1872
|
-
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
1873
|
-
onProgress?.(`Still installing the local Haven signer runtime\u2026 (${seconds}s \u2014 a cold cache can take several minutes)`);
|
|
1874
|
-
}, SIGNER_INSTALL_HEARTBEAT_MS);
|
|
1875
|
-
heartbeat.unref?.();
|
|
1876
|
-
try {
|
|
1877
|
-
if (runCommand) await runCommand("npm", args);
|
|
1878
|
-
else await execFileAsync("npm", args, { timeout: SIGNER_INSTALL_TIMEOUT_MS, maxBuffer: 1024 * 1024 });
|
|
1879
|
-
} finally {
|
|
1880
|
-
clearInterval(heartbeat);
|
|
1881
|
-
}
|
|
1882
|
-
};
|
|
1883
|
-
try {
|
|
1884
|
-
await run(baseArgs);
|
|
1885
|
-
} catch {
|
|
1886
|
-
try {
|
|
1887
|
-
await run([...baseArgs, "--cache", npmCacheDirectory]);
|
|
1888
|
-
} catch (err) {
|
|
1889
|
-
throw new Error(
|
|
1890
|
-
`Could not install local Haven signer runtime ${packageSpecs.join(" ")}: ${err instanceof Error ? err.message : String(err)}`
|
|
1891
|
-
);
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
async function installedRuntimeMatches(runtimeDirectory, cliPath) {
|
|
1896
|
-
return installedRuntimeMatchesVersions(runtimeDirectory, cliPath, {
|
|
1897
|
-
signerVersion: MCP_RUNTIME_MANIFEST.signerVersion,
|
|
1898
|
-
sdkVersion: MCP_RUNTIME_MANIFEST.sdkVersion
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
async function installedRuntimeMatchesVersions(runtimeDirectory, cliPath, expected) {
|
|
1902
|
-
try {
|
|
1903
|
-
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
1904
|
-
const installed = await readInstalledVersions(runtimeDirectory);
|
|
1905
|
-
return installed.signerVersion === expected.signerVersion && installed.sdkVersion === expected.sdkVersion;
|
|
1906
|
-
} catch {
|
|
1907
|
-
return false;
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
async function readInstalledVersions(runtimeDirectory) {
|
|
1911
|
-
const [signerPackage, sdkPackage] = await Promise.all([
|
|
1912
|
-
readPackageJson(path.join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "package.json")),
|
|
1913
|
-
readPackageJson(path.join(runtimeDirectory, "node_modules", "@haven_ai", "sdk", "package.json"))
|
|
1914
|
-
]);
|
|
1915
|
-
return { signerVersion: signerPackage.version ?? "", sdkVersion: sdkPackage.version ?? "" };
|
|
1916
|
-
}
|
|
1917
|
-
async function readPackageJson(path) {
|
|
1918
|
-
return JSON.parse(await promises.readFile(path, "utf8"));
|
|
1919
|
-
}
|
|
1920
|
-
async function writeWrapper(input) {
|
|
1921
|
-
await promises.mkdir(path.dirname(input.wrapperPath), { recursive: true, mode: 448 });
|
|
1922
|
-
await promises.chmod(path.dirname(input.wrapperPath), 448).catch(() => void 0);
|
|
1923
|
-
const source = [
|
|
1924
|
-
"#!/usr/bin/env node",
|
|
1925
|
-
...input.overrideComment ? [`// HAVEN RUNTIME SPEC OVERRIDE (#2424): ${input.overrideComment} \u2014 this wrapper launches a NON-pinned signer build.`] : [],
|
|
1926
|
-
"import { spawn } from 'node:child_process'",
|
|
1927
|
-
"",
|
|
1928
|
-
`const cliPath = ${JSON.stringify(input.cliPath)}`,
|
|
1929
|
-
`const signerPath = ${JSON.stringify(input.signerPath)}`,
|
|
1930
|
-
"",
|
|
1931
|
-
"const child = spawn(process.execPath, [cliPath, '--credentials', signerPath, ...process.argv.slice(2)], {",
|
|
1932
|
-
" stdio: 'inherit',",
|
|
1933
|
-
"})",
|
|
1934
|
-
"",
|
|
1935
|
-
"child.on('exit', (code, signal) => {",
|
|
1936
|
-
" if (signal) process.kill(process.pid, signal)",
|
|
1937
|
-
" else process.exit(code ?? 1)",
|
|
1938
|
-
"})",
|
|
1939
|
-
""
|
|
1940
|
-
].join("\n");
|
|
1941
|
-
await promises.writeFile(input.wrapperPath, source, { mode: 448 });
|
|
1942
|
-
await promises.chmod(input.wrapperPath, 448).catch(() => void 0);
|
|
1943
|
-
}
|
|
1944
|
-
async function readRuntimeSidecar(credentialDirectory) {
|
|
1945
|
-
try {
|
|
1946
|
-
return JSON.parse(
|
|
1947
|
-
await promises.readFile(path.join(credentialDirectory, "signer-runtime.json"), "utf8")
|
|
1948
|
-
);
|
|
1949
|
-
} catch {
|
|
1950
|
-
return null;
|
|
2231
|
+
return JSON.parse(dataLines[i]);
|
|
2232
|
+
} catch {
|
|
2233
|
+
}
|
|
1951
2234
|
}
|
|
2235
|
+
return null;
|
|
1952
2236
|
}
|
|
1953
|
-
async function
|
|
1954
|
-
const
|
|
1955
|
-
|
|
1956
|
-
signer_package: MCP_RUNTIME_MANIFEST.signerPackage,
|
|
1957
|
-
signer_version: input.installedVersions?.signerVersion ?? MCP_RUNTIME_MANIFEST.signerVersion,
|
|
1958
|
-
sdk_package: MCP_RUNTIME_MANIFEST.sdkPackage,
|
|
1959
|
-
sdk_version: input.installedVersions?.sdkVersion ?? MCP_RUNTIME_MANIFEST.sdkVersion,
|
|
1960
|
-
wrapper_path: input.wrapperPath,
|
|
1961
|
-
runtime_directory: input.runtimeDirectory,
|
|
1962
|
-
npm_cache_directory: input.npmCacheDirectory,
|
|
1963
|
-
cli_path: input.cliPath,
|
|
1964
|
-
...input.override ? { runtime_spec_override: input.override } : {}
|
|
1965
|
-
};
|
|
1966
|
-
await promises.writeFile(input.path, `${JSON.stringify(value, null, 2)}
|
|
1967
|
-
`, { mode: 384 });
|
|
1968
|
-
await promises.chmod(input.path, 384).catch(() => void 0);
|
|
1969
|
-
}
|
|
1970
|
-
async function assertFileExists(path, label) {
|
|
2237
|
+
async function fetchWithTimeout(fetchImpl, url, init) {
|
|
2238
|
+
const controller = new AbortController();
|
|
2239
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
1971
2240
|
try {
|
|
1972
|
-
await
|
|
1973
|
-
}
|
|
1974
|
-
|
|
2241
|
+
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
2242
|
+
} finally {
|
|
2243
|
+
clearTimeout(timeout);
|
|
1975
2244
|
}
|
|
1976
2245
|
}
|
|
1977
|
-
var
|
|
1978
|
-
|
|
1979
|
-
"src/signer-runtime.ts"() {
|
|
1980
|
-
init_runtime_manifest();
|
|
1981
|
-
init_runtime_spec_override();
|
|
1982
|
-
execFileAsync = util.promisify(child_process.execFile);
|
|
1983
|
-
SIGNER_INSTALL_TIMEOUT_MS = 6e5;
|
|
1984
|
-
SIGNER_INSTALL_HEARTBEAT_MS = 15e3;
|
|
2246
|
+
var init_probes = __esm({
|
|
2247
|
+
"src/probes.ts"() {
|
|
1985
2248
|
}
|
|
1986
2249
|
});
|
|
1987
2250
|
async function prepareLocalMcpRuntime(input, deps = {}) {
|
|
@@ -2299,28 +2562,6 @@ var init_skill_install = __esm({
|
|
|
2299
2562
|
}
|
|
2300
2563
|
});
|
|
2301
2564
|
|
|
2302
|
-
// src/connect-error.ts
|
|
2303
|
-
function isConnectError(err) {
|
|
2304
|
-
return err instanceof ConnectError;
|
|
2305
|
-
}
|
|
2306
|
-
var ConnectError;
|
|
2307
|
-
var init_connect_error = __esm({
|
|
2308
|
-
"src/connect-error.ts"() {
|
|
2309
|
-
ConnectError = class extends Error {
|
|
2310
|
-
code;
|
|
2311
|
-
nextAction;
|
|
2312
|
-
details;
|
|
2313
|
-
constructor(code, message, nextAction2, details = {}) {
|
|
2314
|
-
super(message);
|
|
2315
|
-
this.name = "ConnectError";
|
|
2316
|
-
this.code = code;
|
|
2317
|
-
this.nextAction = nextAction2;
|
|
2318
|
-
this.details = details;
|
|
2319
|
-
}
|
|
2320
|
-
};
|
|
2321
|
-
}
|
|
2322
|
-
});
|
|
2323
|
-
|
|
2324
2565
|
// src/runtime-registry.ts
|
|
2325
2566
|
function runtimeProfile(runtime, env = process.env) {
|
|
2326
2567
|
return RUNTIME_PROFILES[normalizeRuntime(runtime, env)];
|
|
@@ -3242,138 +3483,6 @@ var init_installed_clients = __esm({
|
|
|
3242
3483
|
MAX_PROMPT_ATTEMPTS = 3;
|
|
3243
3484
|
}
|
|
3244
3485
|
});
|
|
3245
|
-
|
|
3246
|
-
// src/tombstone.ts
|
|
3247
|
-
var tombstone_exports = {};
|
|
3248
|
-
__export(tombstone_exports, {
|
|
3249
|
-
ROOT_TOMBSTONES_DIRNAME: () => ROOT_TOMBSTONES_DIRNAME,
|
|
3250
|
-
TOMBSTONE_FILENAME: () => TOMBSTONE_FILENAME,
|
|
3251
|
-
TOMBSTONE_MARKER: () => TOMBSTONE_MARKER,
|
|
3252
|
-
defaultTombstonesDir: () => defaultTombstonesDir,
|
|
3253
|
-
readAgentTombstone: () => readAgentTombstone,
|
|
3254
|
-
readTombstoneRecords: () => readTombstoneRecords,
|
|
3255
|
-
tombstonesDirForAgentDirectory: () => tombstonesDirForAgentDirectory,
|
|
3256
|
-
tombstonesDirForCredentialRoot: () => tombstonesDirForCredentialRoot,
|
|
3257
|
-
writeAgentTombstone: () => writeAgentTombstone
|
|
3258
|
-
});
|
|
3259
|
-
function defaultTombstonesDir(baseDir) {
|
|
3260
|
-
return path.join(baseDir ?? path.join(os.homedir(), ".haven"), "tombstones");
|
|
3261
|
-
}
|
|
3262
|
-
function tombstonesDirForCredentialRoot(credentialRoot, homeDir = os.homedir()) {
|
|
3263
|
-
if (!credentialRoot) return defaultTombstonesDir(path.join(homeDir, ".haven"));
|
|
3264
|
-
const root = path.resolve(credentialRoot);
|
|
3265
|
-
if (root === path.resolve(homeDir, ".haven", "agents")) return defaultTombstonesDir(path.join(homeDir, ".haven"));
|
|
3266
|
-
return path.join(root, ROOT_TOMBSTONES_DIRNAME);
|
|
3267
|
-
}
|
|
3268
|
-
function tombstonesDirForAgentDirectory(directory, homeDir = os.homedir()) {
|
|
3269
|
-
return tombstonesDirForCredentialRoot(path.dirname(path.resolve(directory)), homeDir);
|
|
3270
|
-
}
|
|
3271
|
-
async function readTombstoneRecords(tombstonesDir) {
|
|
3272
|
-
const root = tombstonesDir ?? defaultTombstonesDir();
|
|
3273
|
-
let entries = [];
|
|
3274
|
-
try {
|
|
3275
|
-
entries = await promises.readdir(root);
|
|
3276
|
-
} catch {
|
|
3277
|
-
return [];
|
|
3278
|
-
}
|
|
3279
|
-
const records = [];
|
|
3280
|
-
for (const entry of entries) {
|
|
3281
|
-
if (!entry.endsWith(".json")) continue;
|
|
3282
|
-
const recordPath = path.join(root, entry);
|
|
3283
|
-
try {
|
|
3284
|
-
const parsed = JSON.parse(await promises.readFile(recordPath, "utf8"));
|
|
3285
|
-
if (typeof parsed?.agent_id === "string") {
|
|
3286
|
-
records.push({ ...parsed, recordPath });
|
|
3287
|
-
}
|
|
3288
|
-
} catch {
|
|
3289
|
-
}
|
|
3290
|
-
}
|
|
3291
|
-
return records;
|
|
3292
|
-
}
|
|
3293
|
-
function tombstoneScript(info) {
|
|
3294
|
-
const lines = [
|
|
3295
|
-
`${TOMBSTONE_MARKER}: this Haven agent was retired.`,
|
|
3296
|
-
"",
|
|
3297
|
-
` agent: ${info.agent_id}`,
|
|
3298
|
-
` retired at: ${info.retired_at}`,
|
|
3299
|
-
` reason: ${info.reason}`,
|
|
3300
|
-
...info.replaced_by ? [` replaced by: ${info.replaced_by}`] : [],
|
|
3301
|
-
"",
|
|
3302
|
-
"This process is running with a wiring snapshot that predates the",
|
|
3303
|
-
"retirement \u2014 it loaded its MCP config at startup and has kept it since.",
|
|
3304
|
-
"Restart THIS host to pick up the current wiring. If several long-lived",
|
|
3305
|
-
"hosts are running (a gateway, a TUI worker, an editor), restart EVERY",
|
|
3306
|
-
"one of them: each holds the snapshot from its own start time, so after",
|
|
3307
|
-
"a chain of recreations each can be parked on a DIFFERENT old agent.",
|
|
3308
|
-
"",
|
|
3309
|
-
`Then verify with: ${sdk.connectorRerunCommand("--doctor --runtime <runtime>")}`
|
|
3310
|
-
];
|
|
3311
|
-
return [
|
|
3312
|
-
"#!/usr/bin/env node",
|
|
3313
|
-
`// ${TOMBSTONE_MARKER} \u2014 written by @haven_ai/connect (#1681). Safe to delete`,
|
|
3314
|
-
"// once every long-lived MCP host on this machine has been restarted.",
|
|
3315
|
-
`process.stderr.write(${JSON.stringify(lines.join("\n") + "\n")})`,
|
|
3316
|
-
"process.exit(1)",
|
|
3317
|
-
""
|
|
3318
|
-
].join("\n");
|
|
3319
|
-
}
|
|
3320
|
-
async function writeAgentTombstone(input) {
|
|
3321
|
-
const dirStat = await promises.stat(input.directory).catch(() => null);
|
|
3322
|
-
if (!dirStat?.isDirectory()) {
|
|
3323
|
-
throw new ConnectError(
|
|
3324
|
-
"tombstone_directory_not_found",
|
|
3325
|
-
`Not a directory: ${input.directory} \u2014 nothing to tombstone. Agent directories are named by their wiring SLUG when the agent has one, and by the agent id otherwise \u2014 so a path built from an agent id will not exist for a named agent. List ~/.haven/agents (or read the directories from --doctor --json) and pass one of those.`,
|
|
3326
|
-
"retry_with_an_existing_agent_directory"
|
|
3327
|
-
);
|
|
3328
|
-
}
|
|
3329
|
-
const info = {
|
|
3330
|
-
// reason / replaced_by are persisted to disk and re-emitted to the host's
|
|
3331
|
-
// MCP stderr log on EVERY stale probe, potentially for months — redact
|
|
3332
|
-
// like every other output path, at the write layer so any future caller
|
|
3333
|
-
// inherits it. (#1681 review, finding 1)
|
|
3334
|
-
agent_id: input.agentId,
|
|
3335
|
-
retired_at: input.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
3336
|
-
reason: redactSecrets(input.reason),
|
|
3337
|
-
...input.replacedBy ? { replaced_by: redactSecrets(input.replacedBy) } : {}
|
|
3338
|
-
};
|
|
3339
|
-
const binDir = path.join(input.directory, "bin");
|
|
3340
|
-
await promises.mkdir(binDir, { recursive: true });
|
|
3341
|
-
const wrapperPath = path.join(binDir, "haven-signer.mjs");
|
|
3342
|
-
await promises.writeFile(wrapperPath, tombstoneScript(info), "utf8");
|
|
3343
|
-
await promises.chmod(wrapperPath, 493);
|
|
3344
|
-
const record = JSON.stringify(info, null, 2) + "\n";
|
|
3345
|
-
await promises.writeFile(path.join(input.directory, TOMBSTONE_FILENAME), record, "utf8");
|
|
3346
|
-
const root = input.tombstonesDir ?? defaultTombstonesDir();
|
|
3347
|
-
const recordPath = path.join(root, `${info.agent_id}.json`);
|
|
3348
|
-
try {
|
|
3349
|
-
await promises.mkdir(root, { recursive: true, mode: 448 });
|
|
3350
|
-
await promises.writeFile(recordPath, record, { mode: MIRROR_MODE });
|
|
3351
|
-
} catch (err) {
|
|
3352
|
-
const code = err?.code;
|
|
3353
|
-
return { ...info, recordPath: null, mirrorError: typeof code === "string" && /^E[A-Z]+$/.test(code) ? code : "mirror_write_failed" };
|
|
3354
|
-
}
|
|
3355
|
-
return { ...info, recordPath };
|
|
3356
|
-
}
|
|
3357
|
-
async function readAgentTombstone(directory) {
|
|
3358
|
-
try {
|
|
3359
|
-
const parsed = JSON.parse(await promises.readFile(path.join(directory, TOMBSTONE_FILENAME), "utf8"));
|
|
3360
|
-
if (typeof parsed?.agent_id !== "string") return null;
|
|
3361
|
-
return parsed;
|
|
3362
|
-
} catch {
|
|
3363
|
-
return null;
|
|
3364
|
-
}
|
|
3365
|
-
}
|
|
3366
|
-
var TOMBSTONE_FILENAME, ROOT_TOMBSTONES_DIRNAME, MIRROR_MODE, TOMBSTONE_MARKER;
|
|
3367
|
-
var init_tombstone = __esm({
|
|
3368
|
-
"src/tombstone.ts"() {
|
|
3369
|
-
init_redact();
|
|
3370
|
-
init_connect_error();
|
|
3371
|
-
TOMBSTONE_FILENAME = "TOMBSTONE.json";
|
|
3372
|
-
ROOT_TOMBSTONES_DIRNAME = ".tombstones";
|
|
3373
|
-
MIRROR_MODE = 384;
|
|
3374
|
-
TOMBSTONE_MARKER = "HAVEN-TOMBSTONE";
|
|
3375
|
-
}
|
|
3376
|
-
});
|
|
3377
3486
|
async function detectWiringCollision(input) {
|
|
3378
3487
|
const root = defaultCredentialRoot(input.credentialsDir);
|
|
3379
3488
|
let entries = [];
|
|
@@ -4089,10 +4198,10 @@ async function executeConnect(options, deps, trace) {
|
|
|
4089
4198
|
} else if (supersededAgentIds.length > 0) {
|
|
4090
4199
|
log("");
|
|
4091
4200
|
log(
|
|
4092
|
-
`Heads-up:
|
|
4201
|
+
`Heads-up: other agent directories on this machine \u2014 ${supersededAgentIds.join(", ")}. This setup created a NEW agent and revoked none of them; any not revoked in Haven keep their own keys and any budgets.`
|
|
4093
4202
|
);
|
|
4094
4203
|
log(
|
|
4095
|
-
`
|
|
4204
|
+
`To retire one you no longer use: use Remove agent\u2026 on its Haven agent page (it ends its live budget), restart any long-lived host (gateways, TUI workers, editors) still wired to it \u2014 each holds the MCP wiring snapshot from its own start time \u2014 and remove its directory under ~/.haven/agents (or ${RERUN_HINT} --tombstone <dir> to leave a diagnostic in its place). To rewire the bare haven / haven-signer pair instead of adding an agent, re-run with --replace. Run ${RERUN_HINT} --doctor to check which keys are still live.`
|
|
4096
4205
|
);
|
|
4097
4206
|
}
|
|
4098
4207
|
} catch {
|
|
@@ -4123,6 +4232,18 @@ async function executeConnect(options, deps, trace) {
|
|
|
4123
4232
|
} catch (err) {
|
|
4124
4233
|
log(`Could not report install status to Haven: ${err instanceof Error ? err.message : String(err)}`);
|
|
4125
4234
|
}
|
|
4235
|
+
const reportableRetiredIds = [...new Set(retiredAgentIds.filter((id) => UUID_SHAPE.test(id)))];
|
|
4236
|
+
if (reportableRetiredIds.length > 0 && api.reportRetiredAgents) {
|
|
4237
|
+
try {
|
|
4238
|
+
await api.reportRetiredAgents({
|
|
4239
|
+
setupId: registration.setup_id,
|
|
4240
|
+
apiKey: localApiKey,
|
|
4241
|
+
retiredAgentIds: reportableRetiredIds
|
|
4242
|
+
});
|
|
4243
|
+
} catch (err) {
|
|
4244
|
+
log(`Could not tell Haven which agents were retired: ${err instanceof Error ? err.message : String(err)}`);
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4126
4247
|
let approval;
|
|
4127
4248
|
const narrateApprovalWait = options.waitForApproval === true || options.waitForApproval === void 0 && (deps.isStdoutTty ?? Boolean(process.stdout.isTTY));
|
|
4128
4249
|
if (narrateApprovalWait && !runtimeInstall.errorCode) {
|
|
@@ -4565,7 +4686,7 @@ async function listOtherAgentIds(baseDir, currentDirectory) {
|
|
|
4565
4686
|
function printNextSteps(result, log, approval, approvalUrl) {
|
|
4566
4687
|
for (const line of completionHandoffLines(result, approval, approvalUrl)) log(line);
|
|
4567
4688
|
}
|
|
4568
|
-
var CONNECTOR_VERSION, PRODUCTION_CHAIN_ID, CONNECTOR_CLIENT_IDENTITY, CONNECT_OUTCOME_SCHEMA_VERSION, failureOutcomesByError, RERUN_HINT;
|
|
4689
|
+
var CONNECTOR_VERSION, PRODUCTION_CHAIN_ID, UUID_SHAPE, CONNECTOR_CLIENT_IDENTITY, CONNECT_OUTCOME_SCHEMA_VERSION, failureOutcomesByError, RERUN_HINT;
|
|
4569
4690
|
var init_runtime = __esm({
|
|
4570
4691
|
"src/runtime.ts"() {
|
|
4571
4692
|
init_api();
|
|
@@ -4582,8 +4703,9 @@ var init_runtime = __esm({
|
|
|
4582
4703
|
init_tombstone();
|
|
4583
4704
|
init_local_mcp_runtime();
|
|
4584
4705
|
init_runtime_manifest();
|
|
4585
|
-
CONNECTOR_VERSION = "0.
|
|
4706
|
+
CONNECTOR_VERSION = "0.10.0-alpha.0";
|
|
4586
4707
|
PRODUCTION_CHAIN_ID = 8453;
|
|
4708
|
+
UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4587
4709
|
CONNECTOR_CLIENT_IDENTITY = `@haven_ai/connect/${CONNECTOR_VERSION}`;
|
|
4588
4710
|
CONNECT_OUTCOME_SCHEMA_VERSION = 1;
|
|
4589
4711
|
failureOutcomesByError = /* @__PURE__ */ new WeakMap();
|
|
@@ -5064,6 +5186,40 @@ function rollUpLevel(checks) {
|
|
|
5064
5186
|
if (checks.some((check) => check.level === "advisory")) return "advisory";
|
|
5065
5187
|
return "ok";
|
|
5066
5188
|
}
|
|
5189
|
+
function runWrapperAck(wrapperPath, timeoutMs = 3e4) {
|
|
5190
|
+
return new Promise((resolve11, reject) => {
|
|
5191
|
+
const child = child_process.spawn(wrapperPath, ["--ack"], { stdio: ["ignore", "pipe", "pipe"] });
|
|
5192
|
+
let stdout = "";
|
|
5193
|
+
let settled = false;
|
|
5194
|
+
const timer = setTimeout(() => {
|
|
5195
|
+
if (settled) return;
|
|
5196
|
+
settled = true;
|
|
5197
|
+
child.kill();
|
|
5198
|
+
reject(new Error(`signer --ack timed out after ${Math.round(timeoutMs / 1e3)}s`));
|
|
5199
|
+
}, timeoutMs);
|
|
5200
|
+
child.stdout?.on("data", (chunk) => {
|
|
5201
|
+
stdout += chunk.toString("utf8");
|
|
5202
|
+
});
|
|
5203
|
+
child.on("error", (err) => {
|
|
5204
|
+
if (settled) return;
|
|
5205
|
+
settled = true;
|
|
5206
|
+
clearTimeout(timer);
|
|
5207
|
+
reject(err);
|
|
5208
|
+
});
|
|
5209
|
+
child.on("close", (code) => {
|
|
5210
|
+
if (settled) return;
|
|
5211
|
+
settled = true;
|
|
5212
|
+
clearTimeout(timer);
|
|
5213
|
+
if (code === 0) resolve11({ stdout });
|
|
5214
|
+
else reject(new Error(`signer --ack exited ${code ?? "abnormally"}`));
|
|
5215
|
+
});
|
|
5216
|
+
});
|
|
5217
|
+
}
|
|
5218
|
+
function repairCommandNamedFor(runtime, slug) {
|
|
5219
|
+
const nameFlag = ` --name ${slug}`;
|
|
5220
|
+
if (normalizeRuntimeName(runtime)) return `Run: ${RERUN} --doctor --repair --runtime ${runtime}${nameFlag}`;
|
|
5221
|
+
return `Run: ${RERUN} --doctor --repair --runtime <runtime>${nameFlag} \u2014 --repair needs the runtime named; one of: ${RUNTIME_FLAG_VALUE_LIST.join(", ")}.`;
|
|
5222
|
+
}
|
|
5067
5223
|
function runtimeFlagFor(runtime) {
|
|
5068
5224
|
return normalizeRuntimeName(runtime) ? ` --runtime ${runtime}` : "";
|
|
5069
5225
|
}
|
|
@@ -5145,6 +5301,35 @@ async function discoverCredentialDirectory(homeDir, explicit) {
|
|
|
5145
5301
|
identityDirectories
|
|
5146
5302
|
};
|
|
5147
5303
|
}
|
|
5304
|
+
async function readClaudeCodeWiringEvidence(homeDir) {
|
|
5305
|
+
let parsed;
|
|
5306
|
+
try {
|
|
5307
|
+
parsed = JSON.parse(await promises.readFile(path.join(homeDir, ".claude.json"), "utf8"));
|
|
5308
|
+
} catch {
|
|
5309
|
+
return null;
|
|
5310
|
+
}
|
|
5311
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
5312
|
+
const blocks = [parsed.mcpServers];
|
|
5313
|
+
const projects = parsed.projects;
|
|
5314
|
+
if (typeof projects === "object" && projects !== null) {
|
|
5315
|
+
for (const project of Object.values(projects)) {
|
|
5316
|
+
if (typeof project === "object" && project !== null) blocks.push(project.mcpServers);
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
const lines = [];
|
|
5320
|
+
for (const block of blocks) {
|
|
5321
|
+
if (typeof block !== "object" || block === null) continue;
|
|
5322
|
+
for (const [name, server] of Object.entries(block)) {
|
|
5323
|
+
const entry = typeof server === "object" && server !== null ? server : {};
|
|
5324
|
+
const parts = [JSON.stringify(name) + ":"];
|
|
5325
|
+
if (typeof entry.command === "string") parts.push(entry.command);
|
|
5326
|
+
if (Array.isArray(entry.args)) parts.push(...entry.args.filter((arg) => typeof arg === "string"));
|
|
5327
|
+
if (typeof entry.url === "string") parts.push(entry.url);
|
|
5328
|
+
lines.push(parts.join(" "));
|
|
5329
|
+
}
|
|
5330
|
+
}
|
|
5331
|
+
return lines.length > 0 ? lines.join("\n") : null;
|
|
5332
|
+
}
|
|
5148
5333
|
function agentIsWired(configText, names, slug, identity, sidecar, isPrimary, bareOwnerExists) {
|
|
5149
5334
|
if (configText === null) return isPrimary;
|
|
5150
5335
|
if (slug) {
|
|
@@ -5390,8 +5575,11 @@ async function verdictsForAgent(entry, input, deps) {
|
|
|
5390
5575
|
id: "signer_process",
|
|
5391
5576
|
label: "Signer stdio handshake",
|
|
5392
5577
|
level: "failed",
|
|
5393
|
-
|
|
5394
|
-
|
|
5578
|
+
// #3799: honest about what the mismatch does and does not prove. The
|
|
5579
|
+
// stored ack covers a tool SET; a doctor bundled with a newer signer
|
|
5580
|
+
// reports exactly this against an older, still-working install.
|
|
5581
|
+
detail: "The stored local-tools consent does not match the tool set this connector bundles \u2014 by design a signer with a different tool set refuses to start. This does not prove the currently running signer is broken: a doctor newer than the installed signer reports exactly this mismatch.",
|
|
5582
|
+
repair: `Run: ${sidecar.wrapper_path} --ack < /dev/null \u2014 re-acknowledge consent with the installed signer, no setup token needed. Or re-run repair with --ack-local-tools: ${repairCommandFor(input.runtime, " --ack-local-tools", input.repairDir)}.`
|
|
5395
5583
|
});
|
|
5396
5584
|
} else {
|
|
5397
5585
|
const probe = await (deps.probeSignerTools ?? probeLocalMcpTools)(
|
|
@@ -5422,12 +5610,21 @@ async function verdictsForAgent(entry, input, deps) {
|
|
|
5422
5610
|
}
|
|
5423
5611
|
return { checks, ...signerCapabilities ? { signerCapabilities } : {} };
|
|
5424
5612
|
}
|
|
5613
|
+
async function resolveNamedDirectory(input, homeDir) {
|
|
5614
|
+
if (!input.serverName) return input.credentialsDir;
|
|
5615
|
+
if (input.credentialsDir) {
|
|
5616
|
+
await assertDirectoryRecordsSlug(input.credentialsDir, input.serverName);
|
|
5617
|
+
return input.credentialsDir;
|
|
5618
|
+
}
|
|
5619
|
+
return resolveAgentDirectoryBySlug(input.serverName, { root: path.join(homeDir, ".haven", "agents") });
|
|
5620
|
+
}
|
|
5425
5621
|
async function runDoctor(input, deps = {}) {
|
|
5426
5622
|
const homeDir = deps.homeDir ?? os.homedir();
|
|
5427
5623
|
const checks = [];
|
|
5428
5624
|
let signerCapabilities;
|
|
5429
|
-
const
|
|
5430
|
-
const
|
|
5625
|
+
const namedDir = await resolveNamedDirectory(input, homeDir);
|
|
5626
|
+
const { directory, others, parkedOnly, identityDirectories } = await discoverCredentialDirectory(homeDir, namedDir);
|
|
5627
|
+
const nameRepairDir = identityDirectories.length > 1 || Boolean(namedDir);
|
|
5431
5628
|
const resolution = await resolveDoctorRuntime(input, directory);
|
|
5432
5629
|
const runtime = resolution.runtime;
|
|
5433
5630
|
const input2 = { ...input, runtime };
|
|
@@ -5441,6 +5638,7 @@ async function runDoctor(input, deps = {}) {
|
|
|
5441
5638
|
configText = null;
|
|
5442
5639
|
}
|
|
5443
5640
|
}
|
|
5641
|
+
const claudeCodeWiring = configText === null && normalizedRuntime === "claude-code" ? await readClaudeCodeWiringEvidence(homeDir) : null;
|
|
5444
5642
|
const allDirectories = directory ? [directory, ...others] : others;
|
|
5445
5643
|
let bareOwnerExists = false;
|
|
5446
5644
|
for (const dir of allDirectories) {
|
|
@@ -5474,7 +5672,10 @@ async function runDoctor(input, deps = {}) {
|
|
|
5474
5672
|
});
|
|
5475
5673
|
continue;
|
|
5476
5674
|
}
|
|
5477
|
-
const wired = agentIsWired(configText, names, slug, identity, sidecar, dir === directory, bareOwnerExists)
|
|
5675
|
+
const wired = agentIsWired(configText, names, slug, identity, sidecar, dir === directory, bareOwnerExists) || // Additive only: a name or wrapper path in ~/.claude.json proves this
|
|
5676
|
+
// directory is wired; its absence proves nothing (#3830), so the
|
|
5677
|
+
// fallback verdict above is never downgraded.
|
|
5678
|
+
claudeCodeWiring !== null && agentIsWired(claudeCodeWiring, names, slug, identity, sidecar, false, false);
|
|
5478
5679
|
const entry = {
|
|
5479
5680
|
...slug ? { slug } : {},
|
|
5480
5681
|
...identity.agent_id ? { agentId: identity.agent_id } : {},
|
|
@@ -5542,15 +5743,20 @@ async function runDoctor(input, deps = {}) {
|
|
|
5542
5743
|
id: "runtime_config",
|
|
5543
5744
|
label: "Runtime MCP config",
|
|
5544
5745
|
level: "failed",
|
|
5545
|
-
detail: `Runtime is unknown \u2014 no runtime flag was given and the connector's record in ${primaryDirectory ??
|
|
5746
|
+
detail: `Runtime is unknown \u2014 no runtime flag was given and the connector's record in ${primaryDirectory ?? namedDir ?? "~/.haven/agents"} carries no resolvable ${CONNECT_OUTCOME_FILENAME} runtime. The runtime config was NOT checked. Re-run the doctor naming the runtime \u2014 one of: ${RUNTIME_FLAG_VALUE_LIST.join(", ")}.`,
|
|
5546
5747
|
repair: `Re-run the doctor naming the runtime \u2014 one of: ${RUNTIME_FLAG_VALUE_LIST.join(", ")}.`
|
|
5547
5748
|
});
|
|
5548
5749
|
} else if (configPath === null) {
|
|
5750
|
+
const claudePairSuffix = input2.runtime === "claude-code" && primaryDirectory ? await (async () => {
|
|
5751
|
+
const sidecar = await readRuntimeSidecar(primaryDirectory);
|
|
5752
|
+
const names = serverNamesFor(sidecar?.server_name);
|
|
5753
|
+
return ` The MCP pair recorded for this folder is ${names.hosted} / ${names.signer} \u2014 confirm with \`claude mcp get ${names.signer}\`.`;
|
|
5754
|
+
})() : "";
|
|
5549
5755
|
checks.push({
|
|
5550
5756
|
id: "runtime_config",
|
|
5551
5757
|
label: "Runtime MCP config",
|
|
5552
5758
|
level: "ok",
|
|
5553
|
-
detail: `Runtime '${input2.runtime}' is configured through its own CLI or by hand (${input2.runtime === "other" ? "manual runtime" : "CLI-managed"}) and has no file-based config the connector owns \u2014 skipping the file check
|
|
5759
|
+
detail: `Runtime '${input2.runtime}' is configured through its own CLI or by hand (${input2.runtime === "other" ? "manual runtime" : "CLI-managed"}) and has no file-based config the connector owns \u2014 skipping the file check.${claudePairSuffix}`
|
|
5554
5760
|
});
|
|
5555
5761
|
} else if (configText === null) {
|
|
5556
5762
|
checks.push({
|
|
@@ -5624,9 +5830,13 @@ async function runDoctor(input, deps = {}) {
|
|
|
5624
5830
|
const supersededLevel = supersededLive.length === 0 ? "ok" : classificationUnreliable ? "advisory" : "failed";
|
|
5625
5831
|
checks.push({
|
|
5626
5832
|
id: "superseded_agents",
|
|
5627
|
-
|
|
5833
|
+
// #3830: an advisory means the connector could not tell wired from
|
|
5834
|
+
// superseded, so its label must not assert "superseded" either. The
|
|
5835
|
+
// inventory `classification` stays as is (#3121 decision 5); the label
|
|
5836
|
+
// is what a person reads.
|
|
5837
|
+
label: supersededLevel === "advisory" ? "Other agent credentials (wiring not verifiable)" : "Superseded agent credentials",
|
|
5628
5838
|
level: supersededLevel,
|
|
5629
|
-
detail: supersededLevel === "failed" ? `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}. A host started before your latest setup keeps authenticating (and spending) as the old agent.` : supersededLevel === "advisory" ? `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}. Runtime '${input2.runtime}' has no config file the connector can read, so which of
|
|
5839
|
+
detail: supersededLevel === "failed" ? `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}. A host started before your latest setup keeps authenticating (and spending) as the old agent.` : supersededLevel === "advisory" ? `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}. Runtime '${input2.runtime}' has no config file the connector writes, and none it can read names these agents, so which of them are wired cannot be verified from this machine: a live key here may be an agent you use deliberately, or one a host started before your latest setup is still spending as.` : `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}.`,
|
|
5630
5840
|
...supersededLevel === "failed" ? {
|
|
5631
5841
|
repair: `Use Remove agent\u2026 on the Haven agent page for ${supersededLive.join(", ")} (it ends each one\u2019s live budgets), then remove the old director(y/ies) under ~/.haven/agents. Connect never revokes or deletes for you.`
|
|
5632
5842
|
} : supersededLevel === "advisory" ? {
|
|
@@ -5655,7 +5865,7 @@ async function runDoctor(input, deps = {}) {
|
|
|
5655
5865
|
label: "MCP server names bound more than once",
|
|
5656
5866
|
level: "advisory",
|
|
5657
5867
|
detail: `${rebound.length} MCP server name${rebound.length === 1 ? "" : "s"} changed hands on this machine (locally recorded bindings; the backend's own record is the authority for the same backend): ${parts.join("; ")}. A saved session, script or document naming the server may still mean the earlier agent.`,
|
|
5658
|
-
repair: `Retire the earlier director(y/ies) with ${RERUN} --unwire <dir> to release the name, or keep both and address them by --name.`
|
|
5868
|
+
repair: `Retire the earlier director(y/ies) with ${RERUN} --unwire <dir> to release the name, or keep both and address them by --name \u2014 --doctor --repair --name <slug> now selects the pair directly.`
|
|
5659
5869
|
});
|
|
5660
5870
|
}
|
|
5661
5871
|
const parkedElsewhere = inventory.filter((entry) => entry.directory !== primaryDirectory && entry.rekeyPending).map((entry) => ({ entry, pending: entry.rekeyPending }));
|
|
@@ -5715,20 +5925,24 @@ async function runDoctor(input, deps = {}) {
|
|
|
5715
5925
|
async function runRepair(input, deps = {}) {
|
|
5716
5926
|
const homeDir = deps.homeDir ?? os.homedir();
|
|
5717
5927
|
const messages = [];
|
|
5718
|
-
const
|
|
5719
|
-
|
|
5928
|
+
const namedDir = await resolveNamedDirectory(input, homeDir);
|
|
5929
|
+
const { directory, others, identityDirectories } = await discoverCredentialDirectory(homeDir, namedDir);
|
|
5930
|
+
if (!namedDir && identityDirectories.length > 1) {
|
|
5720
5931
|
const lines = await Promise.all(
|
|
5721
5932
|
identityDirectories.map(async (dir) => {
|
|
5722
5933
|
const identity2 = await readIdentity(dir);
|
|
5723
5934
|
const who = identity2?.agent_id ? `agent ${identity2.agent_id}` : "agent (no agent_id recorded)";
|
|
5724
5935
|
const retired = !identity2?.api_key || await pathExists3(path.join(dir, TOMBSTONE_FILENAME));
|
|
5725
|
-
|
|
5936
|
+
const sidecar = await readRuntimeSidecar(dir);
|
|
5937
|
+
const slug = sidecar?.server_name;
|
|
5938
|
+
const pair = slug ? `${serverNamesFor(slug).hosted} / ${serverNamesFor(slug).signer}` : "the bare haven / haven-signer pair";
|
|
5939
|
+
return retired ? ` \u2022 ${who} \u2014 ${pair} (${dir}): retired \u2014 not a repair target` : slug ? ` \u2022 ${who} \u2014 owns ${pair}: ${repairCommandNamedFor(input.runtime, slug).replace(/^Run: /, "")}` : ` \u2022 ${who} \u2014 owns ${pair}: ${repairCommandFor(input.runtime, "", dir).replace(/^Run: /, "")}`;
|
|
5726
5940
|
})
|
|
5727
5941
|
);
|
|
5728
5942
|
return {
|
|
5729
5943
|
ok: false,
|
|
5730
5944
|
messages: [
|
|
5731
|
-
`${identityDirectories.length} agent credential directories exist on this machine, and a repair rewrites the runtime config from ONE of them. Name the agent to repair with --credentials-dir \u2014 nothing was changed:`,
|
|
5945
|
+
`${identityDirectories.length} agent credential directories exist on this machine, and a repair rewrites the runtime config from ONE of them. Name the agent to repair with --name <slug> (its recorded pair) or --credentials-dir \u2014 nothing was changed:`,
|
|
5732
5946
|
...lines,
|
|
5733
5947
|
"Not sure which agent is which? Compare the agent ids against the Haven agent page, or run --doctor first."
|
|
5734
5948
|
]
|
|
@@ -5786,13 +6000,62 @@ async function runRepair(input, deps = {}) {
|
|
|
5786
6000
|
const existingSidecar = await readRuntimeSidecar(directory);
|
|
5787
6001
|
const serverName = existingSidecar?.server_name;
|
|
5788
6002
|
const signerPath = path.join(directory, "signer.json");
|
|
6003
|
+
const consent = await getLocalSignerConsentStatus(signerPath);
|
|
6004
|
+
const consentMismatch = !consent.acknowledged && (consent.reason === "ack_file_missing" || consent.reason === "ack_file_mismatch");
|
|
6005
|
+
if (consentMismatch && !input.ackLocalTools) {
|
|
6006
|
+
const wrapperPath = existingSidecar?.wrapper_path ?? path.join(directory, "bin", "haven-signer.mjs");
|
|
6007
|
+
return {
|
|
6008
|
+
ok: false,
|
|
6009
|
+
messages: [
|
|
6010
|
+
"Repair stopped before writing anything: the signer it installs would refuse to start until local-tools consent is re-acknowledged \u2014 the stored acknowledgement does not match the tool set of the signer this connector pins.",
|
|
6011
|
+
"The mismatch does not prove the currently running signer is broken; a newer tool set is enough to explain it.",
|
|
6012
|
+
`Re-consent without a setup token, produced by the installed signer: ${wrapperPath} --ack < /dev/null`,
|
|
6013
|
+
`Or re-run repair with --ack-local-tools to re-consent during the repair: ${repairCommandFor(input2.runtime, " --ack-local-tools", directory)}`
|
|
6014
|
+
]
|
|
6015
|
+
};
|
|
6016
|
+
}
|
|
5789
6017
|
const prepared = await prepareSignerRuntime(
|
|
5790
6018
|
{ credentialDirectory: directory, signerPath, homeDir, serverName },
|
|
5791
6019
|
{ runCommand: deps.runCommand, env: deps.env }
|
|
5792
6020
|
);
|
|
5793
6021
|
messages.push(...prepared.messages);
|
|
5794
6022
|
const names = serverNamesFor(serverName);
|
|
5795
|
-
|
|
6023
|
+
const rewritesConfig = runtimeConfigPathFor(normalizeRuntimeName(input2.runtime) ?? input2.runtime, homeDir) !== null;
|
|
6024
|
+
if (rewritesConfig) {
|
|
6025
|
+
messages.push(`Rewriting MCP entries ${names.hosted} / ${names.signer}${serverName ? ` (agent "${serverName}")` : " (unnamed pair)"} \u2014 no other pair is touched.`);
|
|
6026
|
+
} else {
|
|
6027
|
+
messages.push(
|
|
6028
|
+
`Re-pointed ${prepared.wrapperPath} at signer ${signerPackageSpec()}. ` + (input2.runtime === "claude-code" ? `Claude Code's MCP entries were not touched \u2014 the entry that launches this wrapper uses the new signer after a restart. Confirm with \`claude mcp get ${names.signer}\`.` : `No MCP config was written \u2014 '${input2.runtime}' is configured through its own CLI or by hand; the entry that launches this wrapper uses the new signer after a restart.`)
|
|
6029
|
+
);
|
|
6030
|
+
}
|
|
6031
|
+
if (consentMismatch && input.ackLocalTools) {
|
|
6032
|
+
messages.push(`Re-acknowledging local-tools consent with the installed signer (${signerPackageSpec()}):`);
|
|
6033
|
+
try {
|
|
6034
|
+
const ack = await (deps.runSignerAck ?? runWrapperAck)(prepared.wrapperPath);
|
|
6035
|
+
for (const line of ack.stdout.split("\n")) {
|
|
6036
|
+
if (line.trim()) messages.push(` ${line}`);
|
|
6037
|
+
}
|
|
6038
|
+
} catch (err) {
|
|
6039
|
+
return {
|
|
6040
|
+
ok: false,
|
|
6041
|
+
messages: [
|
|
6042
|
+
...messages,
|
|
6043
|
+
`The re-acknowledgement failed: ${err instanceof Error ? err.message : String(err)} \u2014 consent was NOT written; the runtime config was not rewritten.`
|
|
6044
|
+
]
|
|
6045
|
+
};
|
|
6046
|
+
}
|
|
6047
|
+
const after = await getLocalSignerConsentStatus(signerPath);
|
|
6048
|
+
if (!after.acknowledged) {
|
|
6049
|
+
return {
|
|
6050
|
+
ok: false,
|
|
6051
|
+
messages: [
|
|
6052
|
+
...messages,
|
|
6053
|
+
`Consent still does not match after the re-acknowledgement (${after.reason ?? after.error}). The runtime config was not rewritten.`
|
|
6054
|
+
]
|
|
6055
|
+
};
|
|
6056
|
+
}
|
|
6057
|
+
messages.push("Local-tools consent acknowledged for the installed signer.");
|
|
6058
|
+
}
|
|
5796
6059
|
const configResult = await writeRuntimeConfig({
|
|
5797
6060
|
// Normalized for the WRITE too (#3145 review round 3): `writeRuntimeConfig`
|
|
5798
6061
|
// switches on the id, and the raw alias fell to its "manual runtime" arm
|
|
@@ -6012,6 +6275,11 @@ function parseArgs(argv, env = process.env) {
|
|
|
6012
6275
|
"--repair needs --runtime <runtime>: it rewrites that runtime's config, so the runtime is named explicitly rather than inherited from the setup record. --doctor alone resolves it from the record."
|
|
6013
6276
|
);
|
|
6014
6277
|
}
|
|
6278
|
+
if (options.ackLocalTools && !repair) {
|
|
6279
|
+
throw new Error(
|
|
6280
|
+
"--ack-local-tools does nothing with --doctor alone: the doctor is read-only. Re-consent during a repair (--repair --ack-local-tools), or token-free with the recorded wrapper: <agent dir>/bin/haven-signer.mjs --ack"
|
|
6281
|
+
);
|
|
6282
|
+
}
|
|
6015
6283
|
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
6016
6284
|
}
|
|
6017
6285
|
if (!options.setupToken) {
|
|
@@ -6063,7 +6331,9 @@ function helpText() {
|
|
|
6063
6331
|
" agents can run side by side in one runtime. 1-32 lowercase letters, digits,",
|
|
6064
6332
|
" single hyphens; immutable once wired. Without it the pair is named from the",
|
|
6065
6333
|
" agent's display name; --bare wires the bare haven / haven-signer pair.",
|
|
6066
|
-
" --ack-local-tools Write the
|
|
6334
|
+
" --ack-local-tools Write the local Haven tools acknowledgement: during setup, or (with --repair)",
|
|
6335
|
+
" re-acknowledge consent for the signer the repair installs \u2014 no setup token.",
|
|
6336
|
+
" With a bare --doctor it is refused: --doctor is read-only.",
|
|
6067
6337
|
" --ack-signer Backward-compatible alias for --ack-local-tools.",
|
|
6068
6338
|
" --local Advanced: install the fully-local Haven MCP (no hosted dependency).",
|
|
6069
6339
|
" Only available for Claude Code and Codex. Default is hosted MCP + local signer.",
|
|
@@ -6072,10 +6342,13 @@ function helpText() {
|
|
|
6072
6342
|
" signer runtime, hosted MCP, and a live signer handshake. Exits non-zero only on a failed check; an advisory (!) exits 0.",
|
|
6073
6343
|
" --runtime is optional: without it the doctor checks the runtime the setup recorded,",
|
|
6074
6344
|
" and reports a failure (not a pass) when no record names one.",
|
|
6345
|
+
" --name <slug> selects the agent directory by its recorded MCP pair.",
|
|
6075
6346
|
" --repair Repair, then re-diagnose (implies --doctor): reinstall the pinned signer",
|
|
6076
6347
|
" runtime, rewrite the wrapper and runtime config from stored credentials.",
|
|
6077
6348
|
" Hosted topology only (refuses to touch a --local config). No keys, no token.",
|
|
6078
6349
|
" Requires --runtime <runtime>: it rewrites that config, so the runtime is never inherited.",
|
|
6350
|
+
" --name <slug> selects the agent to repair by its recorded pair; --ack-local-tools",
|
|
6351
|
+
" re-consents the installed signer (the old token-free path: <agent dir>/bin/haven-signer.mjs --ack).",
|
|
6079
6352
|
" --rekey Replace this agent's signing key (no token). Generates a fresh keypair HERE and",
|
|
6080
6353
|
" prints its public address to paste into the Haven agent page. Nothing changes",
|
|
6081
6354
|
" until you finish; the agent keeps working on its old key throughout.",
|
|
@@ -6236,11 +6509,12 @@ async function runCli(argv, io = {
|
|
|
6236
6509
|
if (parsed.unwire) {
|
|
6237
6510
|
const { unwireAgent: unwireAgent2 } = await Promise.resolve().then(() => (init_unwire(), unwire_exports));
|
|
6238
6511
|
const { tombstonesDirForAgentDirectory: tombstonesDirForAgentDirectory2 } = await Promise.resolve().then(() => (init_tombstone(), tombstone_exports));
|
|
6512
|
+
const { resolveAgentDirectoryBySlug: resolveAgentDirectoryBySlug2 } = await Promise.resolve().then(() => (init_storage(), storage_exports));
|
|
6239
6513
|
const { homedir: homedir11 } = await import('os');
|
|
6240
6514
|
const { join: join13 } = await import('path');
|
|
6241
6515
|
const homeDir = homedir11();
|
|
6242
6516
|
const root = parsed.options.credentialsDir ?? join13(homeDir, ".haven", "agents");
|
|
6243
|
-
const directory = parsed.unwireDir ?? (parsed.options.serverName ?
|
|
6517
|
+
const directory = parsed.unwireDir ?? (parsed.options.serverName ? await resolveAgentDirectoryBySlug2(parsed.options.serverName, { root, allowRetired: true }) : root);
|
|
6244
6518
|
const ledgerDir = tombstonesDirForAgentDirectory2(directory, homeDir);
|
|
6245
6519
|
try {
|
|
6246
6520
|
const result = await unwireAgent2({
|
|
@@ -6442,14 +6716,16 @@ async function runCli(argv, io = {
|
|
|
6442
6716
|
const { runDoctor: runDoctor2, runRepair: runRepair2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
6443
6717
|
const runtime = parsed.options.runtime ?? "";
|
|
6444
6718
|
const credentialsDir = parsed.options.credentialsDir;
|
|
6719
|
+
const serverName = parsed.options.serverName;
|
|
6720
|
+
const ackLocalTools = parsed.options.ackLocalTools === true;
|
|
6445
6721
|
try {
|
|
6446
6722
|
if (parsed.repair) {
|
|
6447
|
-
const repair = await runRepair2({ runtime, credentialsDir });
|
|
6723
|
+
const repair = await runRepair2({ runtime, credentialsDir, serverName, ackLocalTools });
|
|
6448
6724
|
for (const message of repair.messages) io.stderr(`${redactSecrets(message)}
|
|
6449
6725
|
`);
|
|
6450
6726
|
if (!repair.ok) return 1;
|
|
6451
6727
|
}
|
|
6452
|
-
const report = await runDoctor2({ runtime, credentialsDir });
|
|
6728
|
+
const report = await runDoctor2({ runtime, credentialsDir, serverName });
|
|
6453
6729
|
if (parsed.json) {
|
|
6454
6730
|
io.stdout(`${redactSecrets(JSON.stringify(report))}
|
|
6455
6731
|
`);
|
|
@@ -6461,13 +6737,16 @@ async function runCli(argv, io = {
|
|
|
6461
6737
|
`));
|
|
6462
6738
|
}
|
|
6463
6739
|
const otherAgents = report.agents.filter((agent) => agent.directory !== report.credentialDirectory);
|
|
6740
|
+
const wiringUnverifiable = report.checks.some(
|
|
6741
|
+
(check) => check.id === "superseded_agents" && check.level === "advisory"
|
|
6742
|
+
);
|
|
6464
6743
|
if (otherAgents.length > 0) {
|
|
6465
6744
|
io.stdout("\nOther agents on this machine:\n");
|
|
6466
6745
|
for (const agent of otherAgents) {
|
|
6467
6746
|
const name = agent.slug ? `${agent.slug} (${agent.agentId ?? "unknown"})` : agent.agentId ?? "unknown";
|
|
6468
6747
|
const failed = agent.checks.filter((check) => check.level === "failed");
|
|
6469
6748
|
const advised = agent.checks.filter((check) => check.level === "advisory");
|
|
6470
|
-
const verdict = agent.classification === "wired" ? failed.length > 0 ? `wired, ${failed.length} check(s) FAILED` : advised.length > 0 ? `wired, ${advised.length} advisory finding(s)` : "wired, all checks passed" : agent.classification === "parked" ? "parked re-key only \u2014 no identity.json in this directory, but key material is still there" : agent.classification;
|
|
6749
|
+
const verdict = agent.classification === "wired" ? failed.length > 0 ? `wired, ${failed.length} check(s) FAILED` : advised.length > 0 ? `wired, ${advised.length} advisory finding(s)` : "wired, all checks passed" : agent.classification === "parked" ? "parked re-key only \u2014 no identity.json in this directory, but key material is still there" : agent.classification === "superseded" && wiringUnverifiable ? "not verified as wired \u2014 no config the connector can read names it" : agent.classification;
|
|
6471
6750
|
io.stdout(redactSecrets(` ${failed.length > 0 ? "\u2717" : advised.length > 0 ? "!" : "\u2022"} ${name}: ${verdict}
|
|
6472
6751
|
`));
|
|
6473
6752
|
for (const check of [...failed, ...advised]) {
|