@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.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import crypto, { createHash } from 'crypto';
|
|
3
3
|
import { Wallet } from 'ethers';
|
|
4
|
-
import { mkdir, rm, stat, readdir, readFile, writeFile, chmod, access, unlink, realpath, rename } from 'fs/promises';
|
|
5
|
-
import { homedir, platform } from 'os';
|
|
6
|
-
import { join, resolve, dirname, basename } from 'path';
|
|
7
4
|
import { MCP_VERSION, registeredToolNames, ensureConsent, computeConsentHash, loadCredentials, consentInputFromClient } from '@haven_ai/mcp';
|
|
8
5
|
import { toolSchemas, ensureSignerConsent, computeSignerConsentHash, loadSignerCredentials, createEdgeSigner } from '@haven_ai/signer';
|
|
9
6
|
import { connectorRerunCommand, HAVEN_MINIMUM_NODE_VERSION, isSupportedNodeVersion, SKILL_FOLDER_NAME, resolveTokenFromAddress, HAVEN_SKILL_MD, HAVEN_SKILL_BODY_MD, unsupportedNodeVersionMessage } from '@haven_ai/sdk';
|
|
10
|
-
import { parseDocument, isMap, stringify } from 'yaml';
|
|
11
7
|
import { execFile, spawn } from 'child_process';
|
|
8
|
+
import { mkdir, rm, stat, readdir, readFile, writeFile, chmod, access, unlink, rename, realpath } from 'fs/promises';
|
|
9
|
+
import { homedir, platform } from 'os';
|
|
10
|
+
import { join, resolve, dirname, basename } from 'path';
|
|
12
11
|
import { promisify } from 'util';
|
|
12
|
+
import { parseDocument, isMap, stringify } from 'yaml';
|
|
13
13
|
import { createInterface } from 'readline';
|
|
14
14
|
import { realpathSync } from 'fs';
|
|
15
15
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
@@ -65,6 +65,25 @@ function createConnectApiClient(baseUrl, fetchImpl = fetch, clientIdentity) {
|
|
|
65
65
|
method: "GET",
|
|
66
66
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
67
67
|
}),
|
|
68
|
+
reportRetiredAgents: async (input) => {
|
|
69
|
+
try {
|
|
70
|
+
const body = await send(
|
|
71
|
+
`${root}/agent-connection-setups/${encodeURIComponent(input.setupId)}/retired-agents`,
|
|
72
|
+
{
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: { Authorization: `Bearer ${input.apiKey}` },
|
|
75
|
+
body: JSON.stringify({ retired_agent_ids: input.retiredAgentIds })
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
const recorded = body?.recorded_agent_ids;
|
|
79
|
+
return {
|
|
80
|
+
recordedAgentIds: Array.isArray(recorded) ? recorded.filter((id) => typeof id === "string") : []
|
|
81
|
+
};
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (err instanceof ConnectRequestError && err.status === 404) return null;
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
68
87
|
updateInstallStatus: async (setupId, apiKey, input) => {
|
|
69
88
|
await send(`${root}/agent-connection-setups/${encodeURIComponent(setupId)}/install-status`, {
|
|
70
89
|
method: "POST",
|
|
@@ -159,81 +178,574 @@ var init_key = __esm({
|
|
|
159
178
|
}
|
|
160
179
|
});
|
|
161
180
|
|
|
162
|
-
// src/redact.ts
|
|
163
|
-
function redactSecrets(value) {
|
|
164
|
-
return value.replace(API_KEY_RE, "sk_agent_[redacted]").replace(PRIVATE_KEY_RE, "0x[redacted-private-key]");
|
|
181
|
+
// src/redact.ts
|
|
182
|
+
function redactSecrets(value) {
|
|
183
|
+
return value.replace(API_KEY_RE, "sk_agent_[redacted]").replace(PRIVATE_KEY_RE, "0x[redacted-private-key]");
|
|
184
|
+
}
|
|
185
|
+
function redactForAutomation(value) {
|
|
186
|
+
return redactSecrets(value).replace(/(?:~|\/)[^\s`"']*\/(?:identity|signer|agent)\.json\b/g, "[credential-file-redacted]").replace(/(?:~|\/)[^\s`"']*\/\.env\b/g, "[credential-env-redacted]");
|
|
187
|
+
}
|
|
188
|
+
function withoutUserinfo(url) {
|
|
189
|
+
try {
|
|
190
|
+
const parsed = new URL(url);
|
|
191
|
+
parsed.username = "";
|
|
192
|
+
parsed.password = "";
|
|
193
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
194
|
+
} catch {
|
|
195
|
+
return url;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function shortAddress(address) {
|
|
199
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) return address;
|
|
200
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
201
|
+
}
|
|
202
|
+
var API_KEY_RE, PRIVATE_KEY_RE;
|
|
203
|
+
var init_redact = __esm({
|
|
204
|
+
"src/redact.ts"() {
|
|
205
|
+
API_KEY_RE = /sk_agent_[A-Za-z0-9]+/g;
|
|
206
|
+
PRIVATE_KEY_RE = /0x[0-9a-fA-F]{64}/g;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// src/server-names.ts
|
|
211
|
+
function assertValidServerSlug(slug) {
|
|
212
|
+
if (slug.length === 0 || slug.length > 32 || !SLUG_RE.test(slug)) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
`Invalid server name ${JSON.stringify(slug)}: use 1-32 lowercase letters, digits, and single hyphens (e.g. "research").`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (slug === "haven" || slug === "haven-signer") {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Invalid server name ${JSON.stringify(slug)}: "haven" and "haven-signer" are the unnamed pair's own names \u2014 omit --name for the bare pair.`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
if (slug === "signer" || slug.startsWith("signer-")) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Invalid server name ${JSON.stringify(slug)}: "signer" and "signer-*" are reserved \u2014 they would collide with another pair's haven-signer-* entry.`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function serverNamesFor(slug) {
|
|
229
|
+
if (slug === void 0) {
|
|
230
|
+
return {
|
|
231
|
+
hosted: "haven",
|
|
232
|
+
signer: "haven-signer",
|
|
233
|
+
// Historical Codex table names — every wired Codex host has these.
|
|
234
|
+
codexHosted: "haven",
|
|
235
|
+
codexSigner: "haven_signer",
|
|
236
|
+
hermesEnvKey: "MCP_HAVEN_API_KEY"
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
assertValidServerSlug(slug);
|
|
240
|
+
return {
|
|
241
|
+
hosted: `haven-${slug}`,
|
|
242
|
+
signer: `haven-signer-${slug}`,
|
|
243
|
+
// Hyphens are valid TOML bare keys, so named Codex tables match the
|
|
244
|
+
// JSON/YAML names instead of inheriting the legacy underscore.
|
|
245
|
+
codexHosted: `haven-${slug}`,
|
|
246
|
+
codexSigner: `haven-signer-${slug}`,
|
|
247
|
+
hermesEnvKey: `MCP_HAVEN_${slug.toUpperCase().replace(/-/g, "_")}_API_KEY`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
var SLUG_RE;
|
|
251
|
+
var init_server_names = __esm({
|
|
252
|
+
"src/server-names.ts"() {
|
|
253
|
+
SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
function mcpPackageSpec() {
|
|
257
|
+
return `${MCP_RUNTIME_MANIFEST.mcpPackage}@${MCP_RUNTIME_MANIFEST.mcpVersion}`;
|
|
258
|
+
}
|
|
259
|
+
function sdkPackageSpec() {
|
|
260
|
+
return `${MCP_RUNTIME_MANIFEST.sdkPackage}@${MCP_RUNTIME_MANIFEST.sdkVersion}`;
|
|
261
|
+
}
|
|
262
|
+
function signerPackageSpec() {
|
|
263
|
+
return `${MCP_RUNTIME_MANIFEST.signerPackage}@${MCP_RUNTIME_MANIFEST.signerVersion}`;
|
|
264
|
+
}
|
|
265
|
+
var MCP_RUNTIME_MANIFEST;
|
|
266
|
+
var init_runtime_manifest = __esm({
|
|
267
|
+
"src/runtime-manifest.ts"() {
|
|
268
|
+
MCP_RUNTIME_MANIFEST = {
|
|
269
|
+
mcpPackage: "@haven_ai/mcp",
|
|
270
|
+
mcpVersion: MCP_VERSION,
|
|
271
|
+
sdkPackage: "@haven_ai/sdk",
|
|
272
|
+
sdkVersion: "0.10.0-alpha.0",
|
|
273
|
+
signerPackage: "@haven_ai/signer",
|
|
274
|
+
signerVersion: "0.10.0-alpha.0",
|
|
275
|
+
// Sourced from the SDK, never a literal (#1161). This field read '20.0.0'
|
|
276
|
+
// while every package's `engines` said `>=24` and the docs said `>=24.0.0`,
|
|
277
|
+
// so the guard that was supposed to enforce the floor waved Node v23 through
|
|
278
|
+
// — including on the `--local` path where it does run. A hand-maintained
|
|
279
|
+
// second copy of a number is a drift waiting to happen; a guard test pins
|
|
280
|
+
// this against `package.json`'s `engines.node`.
|
|
281
|
+
minimumNodeVersion: HAVEN_MINIMUM_NODE_VERSION,
|
|
282
|
+
supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
|
|
283
|
+
requiredTools: registeredToolNames(),
|
|
284
|
+
/**
|
|
285
|
+
* The signer MCP's tool surface, DERIVED from the pinned @haven_ai/signer
|
|
286
|
+
* package (#1587) — same anti-drift rule as `requiredTools` above: a
|
|
287
|
+
* literal list here would rot the first time the signer gains a tool.
|
|
288
|
+
* The handshake probe requires all of them.
|
|
289
|
+
*/
|
|
290
|
+
requiredSignerTools: Object.keys(toolSchemas)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
function resolveRuntimeSpecOverride(env) {
|
|
295
|
+
const override = {};
|
|
296
|
+
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
297
|
+
const variable = RUNTIME_SPEC_ENV[pkg];
|
|
298
|
+
const raw = env[variable];
|
|
299
|
+
if (raw === void 0) continue;
|
|
300
|
+
override[pkg] = validateSpec(variable, raw);
|
|
301
|
+
}
|
|
302
|
+
return Object.keys(override).length > 0 ? override : void 0;
|
|
303
|
+
}
|
|
304
|
+
function validateSpec(variable, raw) {
|
|
305
|
+
if (raw.length === 0 || raw.trim().length === 0) {
|
|
306
|
+
throw new RuntimeSpecOverrideError(variable, "it is empty");
|
|
307
|
+
}
|
|
308
|
+
if (/\s/.test(raw)) {
|
|
309
|
+
throw new RuntimeSpecOverrideError(variable, "it contains whitespace");
|
|
310
|
+
}
|
|
311
|
+
if (/[\u0000-\u001f\u007f]/.test(raw)) {
|
|
312
|
+
throw new RuntimeSpecOverrideError(variable, "it contains a control character");
|
|
313
|
+
}
|
|
314
|
+
const meta = SHELL_METACHARACTERS.exec(raw);
|
|
315
|
+
if (meta) {
|
|
316
|
+
throw new RuntimeSpecOverrideError(variable, `it contains the shell metacharacter ${JSON.stringify(meta[0])}`);
|
|
317
|
+
}
|
|
318
|
+
return raw;
|
|
319
|
+
}
|
|
320
|
+
function runtimeSpecOverrideDirectoryKey(resolvedSpecs) {
|
|
321
|
+
const digest = createHash("sha256").update(resolvedSpecs.join("\n")).digest("hex");
|
|
322
|
+
return `override-${digest.slice(0, 12)}`;
|
|
323
|
+
}
|
|
324
|
+
function overrideApplies(override, packages) {
|
|
325
|
+
return override !== void 0 && packages.some((pkg) => override[pkg] !== void 0);
|
|
326
|
+
}
|
|
327
|
+
function runtimeSpecOverrideNotice(runtimeLabel, override, pinned, runtimeDirectory) {
|
|
328
|
+
const lines = [`RUNTIME SPEC OVERRIDE ACTIVE for the local Haven ${runtimeLabel} \u2014 this is NOT the pinned manifest.`];
|
|
329
|
+
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
330
|
+
const spec = override[pkg];
|
|
331
|
+
if (spec === void 0) continue;
|
|
332
|
+
const pin = pinned[pkg];
|
|
333
|
+
lines.push(` ${RUNTIME_SPEC_ENV[pkg]}=${spec}${pin ? ` (instead of ${pin})` : ""}`);
|
|
334
|
+
}
|
|
335
|
+
lines.push(` Installing into ${runtimeDirectory} \u2014 the pinned runtime directory is untouched.`);
|
|
336
|
+
lines.push(" Unset the variable(s) and re-run to return to the pinned manifest.");
|
|
337
|
+
return lines;
|
|
338
|
+
}
|
|
339
|
+
function describeRuntimeSpecOverride(override) {
|
|
340
|
+
return Object.keys(RUNTIME_SPEC_ENV).filter((pkg) => override[pkg] !== void 0).map((pkg) => `${RUNTIME_SPEC_ENV[pkg]}=${override[pkg]}`).join(" ");
|
|
341
|
+
}
|
|
342
|
+
var RUNTIME_SPEC_ENV, SHELL_METACHARACTERS, RuntimeSpecOverrideError;
|
|
343
|
+
var init_runtime_spec_override = __esm({
|
|
344
|
+
"src/runtime-spec-override.ts"() {
|
|
345
|
+
RUNTIME_SPEC_ENV = {
|
|
346
|
+
signer: "HAVEN_SIGNER_SPEC",
|
|
347
|
+
sdk: "HAVEN_SDK_SPEC",
|
|
348
|
+
mcp: "HAVEN_MCP_SPEC"
|
|
349
|
+
};
|
|
350
|
+
SHELL_METACHARACTERS = /[;&|<>$`'"()!#*?[\]{}\\]/;
|
|
351
|
+
RuntimeSpecOverrideError = class extends Error {
|
|
352
|
+
code = "runtime_spec_override_invalid";
|
|
353
|
+
variable;
|
|
354
|
+
constructor(variable, reason) {
|
|
355
|
+
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>).`);
|
|
356
|
+
this.name = "RuntimeSpecOverrideError";
|
|
357
|
+
this.variable = variable;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
async function prepareSignerRuntime(input, deps = {}) {
|
|
363
|
+
const homeDir = input.homeDir ?? homedir();
|
|
364
|
+
const override = resolveSignerRuntimeOverride(deps.env ?? process.env);
|
|
365
|
+
const signerSpec = override?.signer ?? signerPackageSpec();
|
|
366
|
+
const sdkSpec = override?.sdk ?? sdkPackageSpec();
|
|
367
|
+
const resolvedSpecs = [signerSpec, sdkSpec];
|
|
368
|
+
const overrideRecord = override ? { specs: override, resolved_specs: resolvedSpecs, directory_key: runtimeSpecOverrideDirectoryKey(resolvedSpecs) } : void 0;
|
|
369
|
+
const runtimeDirectory = resolve(
|
|
370
|
+
homeDir,
|
|
371
|
+
".haven",
|
|
372
|
+
"signer-runtime",
|
|
373
|
+
overrideRecord ? overrideRecord.directory_key : MCP_RUNTIME_MANIFEST.signerVersion
|
|
374
|
+
);
|
|
375
|
+
const npmCacheDirectory = resolve(homeDir, ".haven", "npm-cache");
|
|
376
|
+
const cliPath = join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "dist", "cli.js");
|
|
377
|
+
const messages = [];
|
|
378
|
+
if (override) {
|
|
379
|
+
messages.push(...runtimeSpecOverrideNotice(
|
|
380
|
+
"signer runtime",
|
|
381
|
+
override,
|
|
382
|
+
{ signer: signerPackageSpec(), sdk: sdkPackageSpec() },
|
|
383
|
+
runtimeDirectory
|
|
384
|
+
));
|
|
385
|
+
}
|
|
386
|
+
await mkdir(runtimeDirectory, { recursive: true, mode: 448 });
|
|
387
|
+
await chmod(runtimeDirectory, 448).catch(() => void 0);
|
|
388
|
+
await mkdir(npmCacheDirectory, { recursive: true, mode: 448 });
|
|
389
|
+
await chmod(npmCacheDirectory, 448).catch(() => void 0);
|
|
390
|
+
if (override) {
|
|
391
|
+
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
392
|
+
messages.push(`Installed local Haven signer runtime from override (${resolvedSpecs.join(" ")}).`);
|
|
393
|
+
} else if (await installedRuntimeMatches(runtimeDirectory, cliPath)) {
|
|
394
|
+
messages.push(`Using existing local Haven signer runtime ${signerPackageSpec()}.`);
|
|
395
|
+
} else {
|
|
396
|
+
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
397
|
+
messages.push(`Installed local Haven signer runtime ${signerPackageSpec()}.`);
|
|
398
|
+
}
|
|
399
|
+
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
400
|
+
const installedVersions = override ? await readInstalledVersions(runtimeDirectory) : void 0;
|
|
401
|
+
const wrapperPath = join(input.credentialDirectory, "bin", "haven-signer.mjs");
|
|
402
|
+
await writeWrapper({
|
|
403
|
+
wrapperPath,
|
|
404
|
+
cliPath,
|
|
405
|
+
signerPath: input.signerPath,
|
|
406
|
+
overrideComment: override ? describeRuntimeSpecOverride(override) : void 0
|
|
407
|
+
});
|
|
408
|
+
await writeRuntimeSidecar({
|
|
409
|
+
path: join(input.credentialDirectory, "signer-runtime.json"),
|
|
410
|
+
wrapperPath,
|
|
411
|
+
runtimeDirectory,
|
|
412
|
+
npmCacheDirectory,
|
|
413
|
+
cliPath,
|
|
414
|
+
serverName: input.serverName,
|
|
415
|
+
override: overrideRecord,
|
|
416
|
+
installedVersions
|
|
417
|
+
});
|
|
418
|
+
messages.push(`Prepared stable local Haven signer wrapper: ${wrapperPath}`);
|
|
419
|
+
return {
|
|
420
|
+
command: wrapperPath,
|
|
421
|
+
args: [],
|
|
422
|
+
wrapperPath,
|
|
423
|
+
runtimeDirectory,
|
|
424
|
+
npmCacheDirectory,
|
|
425
|
+
cliPath,
|
|
426
|
+
messages,
|
|
427
|
+
...overrideRecord ? { runtimeSpecOverride: overrideRecord } : {}
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function resolveSignerRuntimeOverride(env) {
|
|
431
|
+
const override = resolveRuntimeSpecOverride(env);
|
|
432
|
+
if (!overrideApplies(override, ["signer", "sdk"])) return void 0;
|
|
433
|
+
const { signer, sdk } = override;
|
|
434
|
+
return { ...signer !== void 0 ? { signer } : {}, ...sdk !== void 0 ? { sdk } : {} };
|
|
435
|
+
}
|
|
436
|
+
async function installRuntimePackages(runtimeDirectory, npmCacheDirectory, packageSpecs, deps) {
|
|
437
|
+
const { runCommand, onProgress } = deps;
|
|
438
|
+
const baseArgs = [
|
|
439
|
+
"install",
|
|
440
|
+
"--prefix",
|
|
441
|
+
runtimeDirectory,
|
|
442
|
+
"--no-audit",
|
|
443
|
+
"--no-fund",
|
|
444
|
+
"--omit=dev",
|
|
445
|
+
"--prefer-offline",
|
|
446
|
+
...packageSpecs
|
|
447
|
+
];
|
|
448
|
+
const run = async (args) => {
|
|
449
|
+
const startedAt = Date.now();
|
|
450
|
+
const heartbeat = setInterval(() => {
|
|
451
|
+
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
452
|
+
onProgress?.(`Still installing the local Haven signer runtime\u2026 (${seconds}s \u2014 a cold cache can take several minutes)`);
|
|
453
|
+
}, SIGNER_INSTALL_HEARTBEAT_MS);
|
|
454
|
+
heartbeat.unref?.();
|
|
455
|
+
try {
|
|
456
|
+
if (runCommand) await runCommand("npm", args);
|
|
457
|
+
else await execFileAsync("npm", args, { timeout: SIGNER_INSTALL_TIMEOUT_MS, maxBuffer: 1024 * 1024 });
|
|
458
|
+
} finally {
|
|
459
|
+
clearInterval(heartbeat);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
try {
|
|
463
|
+
await run(baseArgs);
|
|
464
|
+
} catch {
|
|
465
|
+
try {
|
|
466
|
+
await run([...baseArgs, "--cache", npmCacheDirectory]);
|
|
467
|
+
} catch (err) {
|
|
468
|
+
throw new Error(
|
|
469
|
+
`Could not install local Haven signer runtime ${packageSpecs.join(" ")}: ${err instanceof Error ? err.message : String(err)}`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async function installedRuntimeMatches(runtimeDirectory, cliPath) {
|
|
475
|
+
return installedRuntimeMatchesVersions(runtimeDirectory, cliPath, {
|
|
476
|
+
signerVersion: MCP_RUNTIME_MANIFEST.signerVersion,
|
|
477
|
+
sdkVersion: MCP_RUNTIME_MANIFEST.sdkVersion
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
async function installedRuntimeMatchesVersions(runtimeDirectory, cliPath, expected) {
|
|
481
|
+
try {
|
|
482
|
+
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
483
|
+
const installed = await readInstalledVersions(runtimeDirectory);
|
|
484
|
+
return installed.signerVersion === expected.signerVersion && installed.sdkVersion === expected.sdkVersion;
|
|
485
|
+
} catch {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async function readInstalledVersions(runtimeDirectory) {
|
|
490
|
+
const [signerPackage, sdkPackage] = await Promise.all([
|
|
491
|
+
readPackageJson(join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "package.json")),
|
|
492
|
+
readPackageJson(join(runtimeDirectory, "node_modules", "@haven_ai", "sdk", "package.json"))
|
|
493
|
+
]);
|
|
494
|
+
return { signerVersion: signerPackage.version ?? "", sdkVersion: sdkPackage.version ?? "" };
|
|
495
|
+
}
|
|
496
|
+
async function readPackageJson(path) {
|
|
497
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
498
|
+
}
|
|
499
|
+
async function writeWrapper(input) {
|
|
500
|
+
await mkdir(dirname(input.wrapperPath), { recursive: true, mode: 448 });
|
|
501
|
+
await chmod(dirname(input.wrapperPath), 448).catch(() => void 0);
|
|
502
|
+
const source = [
|
|
503
|
+
"#!/usr/bin/env node",
|
|
504
|
+
...input.overrideComment ? [`// HAVEN RUNTIME SPEC OVERRIDE (#2424): ${input.overrideComment} \u2014 this wrapper launches a NON-pinned signer build.`] : [],
|
|
505
|
+
"import { spawn } from 'node:child_process'",
|
|
506
|
+
"",
|
|
507
|
+
`const cliPath = ${JSON.stringify(input.cliPath)}`,
|
|
508
|
+
`const signerPath = ${JSON.stringify(input.signerPath)}`,
|
|
509
|
+
"",
|
|
510
|
+
"const child = spawn(process.execPath, [cliPath, '--credentials', signerPath, ...process.argv.slice(2)], {",
|
|
511
|
+
" stdio: 'inherit',",
|
|
512
|
+
"})",
|
|
513
|
+
"",
|
|
514
|
+
"child.on('exit', (code, signal) => {",
|
|
515
|
+
" if (signal) process.kill(process.pid, signal)",
|
|
516
|
+
" else process.exit(code ?? 1)",
|
|
517
|
+
"})",
|
|
518
|
+
""
|
|
519
|
+
].join("\n");
|
|
520
|
+
await writeFile(input.wrapperPath, source, { mode: 448 });
|
|
521
|
+
await chmod(input.wrapperPath, 448).catch(() => void 0);
|
|
522
|
+
}
|
|
523
|
+
async function readRuntimeSidecar(credentialDirectory) {
|
|
524
|
+
try {
|
|
525
|
+
return JSON.parse(
|
|
526
|
+
await readFile(join(credentialDirectory, "signer-runtime.json"), "utf8")
|
|
527
|
+
);
|
|
528
|
+
} catch {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
async function writeRuntimeSidecar(input) {
|
|
533
|
+
const value = {
|
|
534
|
+
...input.serverName ? { server_name: input.serverName } : {},
|
|
535
|
+
signer_package: MCP_RUNTIME_MANIFEST.signerPackage,
|
|
536
|
+
signer_version: input.installedVersions?.signerVersion ?? MCP_RUNTIME_MANIFEST.signerVersion,
|
|
537
|
+
sdk_package: MCP_RUNTIME_MANIFEST.sdkPackage,
|
|
538
|
+
sdk_version: input.installedVersions?.sdkVersion ?? MCP_RUNTIME_MANIFEST.sdkVersion,
|
|
539
|
+
wrapper_path: input.wrapperPath,
|
|
540
|
+
runtime_directory: input.runtimeDirectory,
|
|
541
|
+
npm_cache_directory: input.npmCacheDirectory,
|
|
542
|
+
cli_path: input.cliPath,
|
|
543
|
+
...input.override ? { runtime_spec_override: input.override } : {}
|
|
544
|
+
};
|
|
545
|
+
await writeFile(input.path, `${JSON.stringify(value, null, 2)}
|
|
546
|
+
`, { mode: 384 });
|
|
547
|
+
await chmod(input.path, 384).catch(() => void 0);
|
|
548
|
+
}
|
|
549
|
+
async function assertFileExists(path, label) {
|
|
550
|
+
try {
|
|
551
|
+
await access(path);
|
|
552
|
+
} catch {
|
|
553
|
+
throw new Error(`Missing ${label}: ${path}`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
var execFileAsync, SIGNER_INSTALL_TIMEOUT_MS, SIGNER_INSTALL_HEARTBEAT_MS;
|
|
557
|
+
var init_signer_runtime = __esm({
|
|
558
|
+
"src/signer-runtime.ts"() {
|
|
559
|
+
init_runtime_manifest();
|
|
560
|
+
init_runtime_spec_override();
|
|
561
|
+
execFileAsync = promisify(execFile);
|
|
562
|
+
SIGNER_INSTALL_TIMEOUT_MS = 6e5;
|
|
563
|
+
SIGNER_INSTALL_HEARTBEAT_MS = 15e3;
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// src/connect-error.ts
|
|
568
|
+
function isConnectError(err) {
|
|
569
|
+
return err instanceof ConnectError;
|
|
570
|
+
}
|
|
571
|
+
var ConnectError;
|
|
572
|
+
var init_connect_error = __esm({
|
|
573
|
+
"src/connect-error.ts"() {
|
|
574
|
+
ConnectError = class extends Error {
|
|
575
|
+
code;
|
|
576
|
+
nextAction;
|
|
577
|
+
details;
|
|
578
|
+
constructor(code, message, nextAction2, details = {}) {
|
|
579
|
+
super(message);
|
|
580
|
+
this.name = "ConnectError";
|
|
581
|
+
this.code = code;
|
|
582
|
+
this.nextAction = nextAction2;
|
|
583
|
+
this.details = details;
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// src/tombstone.ts
|
|
590
|
+
var tombstone_exports = {};
|
|
591
|
+
__export(tombstone_exports, {
|
|
592
|
+
ROOT_TOMBSTONES_DIRNAME: () => ROOT_TOMBSTONES_DIRNAME,
|
|
593
|
+
TOMBSTONE_FILENAME: () => TOMBSTONE_FILENAME,
|
|
594
|
+
TOMBSTONE_MARKER: () => TOMBSTONE_MARKER,
|
|
595
|
+
defaultTombstonesDir: () => defaultTombstonesDir,
|
|
596
|
+
readAgentTombstone: () => readAgentTombstone,
|
|
597
|
+
readTombstoneRecords: () => readTombstoneRecords,
|
|
598
|
+
tombstonesDirForAgentDirectory: () => tombstonesDirForAgentDirectory,
|
|
599
|
+
tombstonesDirForCredentialRoot: () => tombstonesDirForCredentialRoot,
|
|
600
|
+
writeAgentTombstone: () => writeAgentTombstone
|
|
601
|
+
});
|
|
602
|
+
function defaultTombstonesDir(baseDir) {
|
|
603
|
+
return join(baseDir ?? join(homedir(), ".haven"), "tombstones");
|
|
165
604
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
605
|
+
function tombstonesDirForCredentialRoot(credentialRoot, homeDir = homedir()) {
|
|
606
|
+
if (!credentialRoot) return defaultTombstonesDir(join(homeDir, ".haven"));
|
|
607
|
+
const root = resolve(credentialRoot);
|
|
608
|
+
if (root === resolve(homeDir, ".haven", "agents")) return defaultTombstonesDir(join(homeDir, ".haven"));
|
|
609
|
+
return join(root, ROOT_TOMBSTONES_DIRNAME);
|
|
168
610
|
}
|
|
169
|
-
function
|
|
611
|
+
function tombstonesDirForAgentDirectory(directory, homeDir = homedir()) {
|
|
612
|
+
return tombstonesDirForCredentialRoot(dirname(resolve(directory)), homeDir);
|
|
613
|
+
}
|
|
614
|
+
async function readTombstoneRecords(tombstonesDir) {
|
|
615
|
+
const root = tombstonesDir ?? defaultTombstonesDir();
|
|
616
|
+
let entries = [];
|
|
170
617
|
try {
|
|
171
|
-
|
|
172
|
-
parsed.username = "";
|
|
173
|
-
parsed.password = "";
|
|
174
|
-
return parsed.toString().replace(/\/+$/, "");
|
|
618
|
+
entries = await readdir(root);
|
|
175
619
|
} catch {
|
|
176
|
-
return
|
|
620
|
+
return [];
|
|
621
|
+
}
|
|
622
|
+
const records = [];
|
|
623
|
+
for (const entry of entries) {
|
|
624
|
+
if (!entry.endsWith(".json")) continue;
|
|
625
|
+
const recordPath = join(root, entry);
|
|
626
|
+
try {
|
|
627
|
+
const parsed = JSON.parse(await readFile(recordPath, "utf8"));
|
|
628
|
+
if (typeof parsed?.agent_id === "string") {
|
|
629
|
+
records.push({ ...parsed, recordPath });
|
|
630
|
+
}
|
|
631
|
+
} catch {
|
|
632
|
+
}
|
|
177
633
|
}
|
|
634
|
+
return records;
|
|
178
635
|
}
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
636
|
+
function tombstoneScript(info) {
|
|
637
|
+
const lines = [
|
|
638
|
+
`${TOMBSTONE_MARKER}: this Haven agent was retired.`,
|
|
639
|
+
"",
|
|
640
|
+
` agent: ${info.agent_id}`,
|
|
641
|
+
` retired at: ${info.retired_at}`,
|
|
642
|
+
` reason: ${info.reason}`,
|
|
643
|
+
...info.replaced_by ? [` replaced by: ${info.replaced_by}`] : [],
|
|
644
|
+
"",
|
|
645
|
+
"This process is running with a wiring snapshot that predates the",
|
|
646
|
+
"retirement \u2014 it loaded its MCP config at startup and has kept it since.",
|
|
647
|
+
"Restart THIS host to pick up the current wiring. If several long-lived",
|
|
648
|
+
"hosts are running (a gateway, a TUI worker, an editor), restart EVERY",
|
|
649
|
+
"one of them: each holds the snapshot from its own start time, so after",
|
|
650
|
+
"a chain of recreations each can be parked on a DIFFERENT old agent.",
|
|
651
|
+
"",
|
|
652
|
+
`Then verify with: ${connectorRerunCommand("--doctor --runtime <runtime>")}`
|
|
653
|
+
];
|
|
654
|
+
return [
|
|
655
|
+
"#!/usr/bin/env node",
|
|
656
|
+
`// ${TOMBSTONE_MARKER} \u2014 written by @haven_ai/connect (#1681). Safe to delete`,
|
|
657
|
+
"// once every long-lived MCP host on this machine has been restarted.",
|
|
658
|
+
`process.stderr.write(${JSON.stringify(lines.join("\n") + "\n")})`,
|
|
659
|
+
"process.exit(1)",
|
|
660
|
+
""
|
|
661
|
+
].join("\n");
|
|
182
662
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
// src/server-names.ts
|
|
192
|
-
function assertValidServerSlug(slug) {
|
|
193
|
-
if (slug.length === 0 || slug.length > 32 || !SLUG_RE.test(slug)) {
|
|
194
|
-
throw new Error(
|
|
195
|
-
`Invalid server name ${JSON.stringify(slug)}: use 1-32 lowercase letters, digits, and single hyphens (e.g. "research").`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
if (slug === "haven" || slug === "haven-signer") {
|
|
199
|
-
throw new Error(
|
|
200
|
-
`Invalid server name ${JSON.stringify(slug)}: "haven" and "haven-signer" are the unnamed pair's own names \u2014 omit --name for the bare pair.`
|
|
663
|
+
async function writeAgentTombstone(input) {
|
|
664
|
+
const dirStat = await stat(input.directory).catch(() => null);
|
|
665
|
+
if (!dirStat?.isDirectory()) {
|
|
666
|
+
throw new ConnectError(
|
|
667
|
+
"tombstone_directory_not_found",
|
|
668
|
+
`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.`,
|
|
669
|
+
"retry_with_an_existing_agent_directory"
|
|
201
670
|
);
|
|
202
671
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
672
|
+
const info = {
|
|
673
|
+
// reason / replaced_by are persisted to disk and re-emitted to the host's
|
|
674
|
+
// MCP stderr log on EVERY stale probe, potentially for months — redact
|
|
675
|
+
// like every other output path, at the write layer so any future caller
|
|
676
|
+
// inherits it. (#1681 review, finding 1)
|
|
677
|
+
agent_id: input.agentId,
|
|
678
|
+
retired_at: input.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
679
|
+
reason: redactSecrets(input.reason),
|
|
680
|
+
...input.replacedBy ? { replaced_by: redactSecrets(input.replacedBy) } : {}
|
|
681
|
+
};
|
|
682
|
+
const binDir = join(input.directory, "bin");
|
|
683
|
+
await mkdir(binDir, { recursive: true });
|
|
684
|
+
const wrapperPath = join(binDir, "haven-signer.mjs");
|
|
685
|
+
await writeFile(wrapperPath, tombstoneScript(info), "utf8");
|
|
686
|
+
await chmod(wrapperPath, 493);
|
|
687
|
+
const record = JSON.stringify(info, null, 2) + "\n";
|
|
688
|
+
await writeFile(join(input.directory, TOMBSTONE_FILENAME), record, "utf8");
|
|
689
|
+
const root = input.tombstonesDir ?? defaultTombstonesDir();
|
|
690
|
+
const recordPath = join(root, `${info.agent_id}.json`);
|
|
691
|
+
try {
|
|
692
|
+
await mkdir(root, { recursive: true, mode: 448 });
|
|
693
|
+
await writeFile(recordPath, record, { mode: MIRROR_MODE });
|
|
694
|
+
} catch (err) {
|
|
695
|
+
const code = err?.code;
|
|
696
|
+
return { ...info, recordPath: null, mirrorError: typeof code === "string" && /^E[A-Z]+$/.test(code) ? code : "mirror_write_failed" };
|
|
207
697
|
}
|
|
698
|
+
return { ...info, recordPath };
|
|
208
699
|
}
|
|
209
|
-
function
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
codexSigner: "haven_signer",
|
|
217
|
-
hermesEnvKey: "MCP_HAVEN_API_KEY"
|
|
218
|
-
};
|
|
700
|
+
async function readAgentTombstone(directory) {
|
|
701
|
+
try {
|
|
702
|
+
const parsed = JSON.parse(await readFile(join(directory, TOMBSTONE_FILENAME), "utf8"));
|
|
703
|
+
if (typeof parsed?.agent_id !== "string") return null;
|
|
704
|
+
return parsed;
|
|
705
|
+
} catch {
|
|
706
|
+
return null;
|
|
219
707
|
}
|
|
220
|
-
assertValidServerSlug(slug);
|
|
221
|
-
return {
|
|
222
|
-
hosted: `haven-${slug}`,
|
|
223
|
-
signer: `haven-signer-${slug}`,
|
|
224
|
-
// Hyphens are valid TOML bare keys, so named Codex tables match the
|
|
225
|
-
// JSON/YAML names instead of inheriting the legacy underscore.
|
|
226
|
-
codexHosted: `haven-${slug}`,
|
|
227
|
-
codexSigner: `haven-signer-${slug}`,
|
|
228
|
-
hermesEnvKey: `MCP_HAVEN_${slug.toUpperCase().replace(/-/g, "_")}_API_KEY`
|
|
229
|
-
};
|
|
230
708
|
}
|
|
231
|
-
var
|
|
232
|
-
var
|
|
233
|
-
"src/
|
|
234
|
-
|
|
709
|
+
var TOMBSTONE_FILENAME, ROOT_TOMBSTONES_DIRNAME, MIRROR_MODE, TOMBSTONE_MARKER;
|
|
710
|
+
var init_tombstone = __esm({
|
|
711
|
+
"src/tombstone.ts"() {
|
|
712
|
+
init_redact();
|
|
713
|
+
init_connect_error();
|
|
714
|
+
TOMBSTONE_FILENAME = "TOMBSTONE.json";
|
|
715
|
+
ROOT_TOMBSTONES_DIRNAME = ".tombstones";
|
|
716
|
+
MIRROR_MODE = 384;
|
|
717
|
+
TOMBSTONE_MARKER = "HAVEN-TOMBSTONE";
|
|
235
718
|
}
|
|
236
719
|
});
|
|
720
|
+
|
|
721
|
+
// src/storage.ts
|
|
722
|
+
var storage_exports = {};
|
|
723
|
+
__export(storage_exports, {
|
|
724
|
+
CONNECT_OUTCOME_FILENAME: () => CONNECT_OUTCOME_FILENAME,
|
|
725
|
+
MCP_SERVER_BINDING_FILENAME: () => MCP_SERVER_BINDING_FILENAME,
|
|
726
|
+
REKEY_PENDING_FILENAME: () => REKEY_PENDING_FILENAME,
|
|
727
|
+
REKEY_PENDING_TTL_MS: () => REKEY_PENDING_TTL_MS,
|
|
728
|
+
assertDirectoryRecordsSlug: () => assertDirectoryRecordsSlug,
|
|
729
|
+
assertServerSlugAvailable: () => assertServerSlugAvailable,
|
|
730
|
+
clearMcpServerBinding: () => clearMcpServerBinding,
|
|
731
|
+
clearRekeyPending: () => clearRekeyPending,
|
|
732
|
+
defaultAgentDirectory: () => defaultAgentDirectory,
|
|
733
|
+
defaultCredentialRoot: () => defaultCredentialRoot,
|
|
734
|
+
inspectRekeyPending: () => inspectRekeyPending,
|
|
735
|
+
listMcpServerBindings: () => listMcpServerBindings,
|
|
736
|
+
preflightCredentialStorage: () => preflightCredentialStorage,
|
|
737
|
+
readConnectOutcomeRuntime: () => readConnectOutcomeRuntime,
|
|
738
|
+
readMcpServerBinding: () => readMcpServerBinding,
|
|
739
|
+
readRekeyPending: () => readRekeyPending,
|
|
740
|
+
readStoredAccountAddress: () => readStoredAccountAddress,
|
|
741
|
+
readStoredCredentials: () => readStoredCredentials,
|
|
742
|
+
resolveAgentDirectoryBySlug: () => resolveAgentDirectoryBySlug,
|
|
743
|
+
rewriteCredentialFiles: () => rewriteCredentialFiles,
|
|
744
|
+
writeConnectOutcomeRecord: () => writeConnectOutcomeRecord,
|
|
745
|
+
writeCredentialFiles: () => writeCredentialFiles,
|
|
746
|
+
writeMcpServerBinding: () => writeMcpServerBinding,
|
|
747
|
+
writeRekeyPending: () => writeRekeyPending
|
|
748
|
+
});
|
|
237
749
|
async function preflightCredentialStorage(input = {}) {
|
|
238
750
|
const directory = defaultCredentialRoot(input.baseDir);
|
|
239
751
|
await mkdir(directory, { recursive: true, mode: 448 });
|
|
@@ -310,8 +822,7 @@ function agentPayload(input) {
|
|
|
310
822
|
};
|
|
311
823
|
}
|
|
312
824
|
async function readStoredCredentials(serverName, agentIdOrSlug, baseDir) {
|
|
313
|
-
const
|
|
314
|
-
const directory = key ? defaultAgentDirectory(key, baseDir) : await discoverSoleAgentDirectory(baseDir);
|
|
825
|
+
const directory = serverName ? await resolveAgentDirectoryBySlug(serverName, { root: baseDir }) : agentIdOrSlug ? defaultAgentDirectory(agentIdOrSlug, baseDir) : await discoverSoleAgentDirectory(baseDir);
|
|
315
826
|
const identity = await readJsonFile(join(directory, "identity.json"));
|
|
316
827
|
if (!identity) {
|
|
317
828
|
throw new Error(
|
|
@@ -319,7 +830,7 @@ async function readStoredCredentials(serverName, agentIdOrSlug, baseDir) {
|
|
|
319
830
|
);
|
|
320
831
|
}
|
|
321
832
|
let discoveredSlug;
|
|
322
|
-
if (!
|
|
833
|
+
if (!serverName && !agentIdOrSlug) {
|
|
323
834
|
const binding = await readJsonFile(join(directory, "mcp-server-binding.json"));
|
|
324
835
|
const hostedName = binding && typeof binding === "object" ? asString(binding.server_name) : void 0;
|
|
325
836
|
if (hostedName && hostedName.startsWith("haven-")) {
|
|
@@ -390,6 +901,65 @@ async function discoverSoleAgentDirectory(baseDir) {
|
|
|
390
901
|
` + candidates.map((d) => ` ${d}`).join("\n") + "\nRe-run with --name <slug> to pick one."
|
|
391
902
|
);
|
|
392
903
|
}
|
|
904
|
+
async function assertDirectoryRecordsSlug(directory, slug) {
|
|
905
|
+
assertValidServerSlug(slug);
|
|
906
|
+
const sidecar = await readRuntimeSidecar(directory);
|
|
907
|
+
const bindingRecord = await readJsonFile(join(directory, "mcp-server-binding.json"));
|
|
908
|
+
const bindingSlug = bindingRecord ? asString(bindingRecord.server_name) : void 0;
|
|
909
|
+
const claimed = sidecar?.server_name ?? bindingSlug;
|
|
910
|
+
if (claimed === slug) return;
|
|
911
|
+
if (!claimed && basename(directory) === slug) return;
|
|
912
|
+
throw new Error(
|
|
913
|
+
`--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}'.`
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
async function resolveAgentDirectoryBySlug(slug, opts = {}) {
|
|
917
|
+
assertValidServerSlug(slug);
|
|
918
|
+
const root = defaultCredentialRoot(opts.root);
|
|
919
|
+
let entries = [];
|
|
920
|
+
try {
|
|
921
|
+
entries = await readdir(root);
|
|
922
|
+
} catch {
|
|
923
|
+
throw new Error(
|
|
924
|
+
`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.`
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
const claims = [];
|
|
928
|
+
const recordedSlugs = [];
|
|
929
|
+
let barePairCount = 0;
|
|
930
|
+
let legacyFolder;
|
|
931
|
+
for (const entry of entries.sort()) {
|
|
932
|
+
const directory = join(root, entry);
|
|
933
|
+
const retired = await readJsonFile(join(directory, TOMBSTONE_FILENAME)) !== null;
|
|
934
|
+
const sidecar = await readRuntimeSidecar(directory);
|
|
935
|
+
const bindingRecord = await readJsonFile(join(directory, "mcp-server-binding.json"));
|
|
936
|
+
const bindingSlug = bindingRecord ? asString(bindingRecord.server_name) : void 0;
|
|
937
|
+
const claimedSlug = sidecar?.server_name ?? bindingSlug;
|
|
938
|
+
if (claimedSlug && !recordedSlugs.includes(claimedSlug)) recordedSlugs.push(claimedSlug);
|
|
939
|
+
if (sidecar && !sidecar.server_name) barePairCount++;
|
|
940
|
+
if (retired && !opts.allowRetired) continue;
|
|
941
|
+
if (claimedSlug === slug) {
|
|
942
|
+
const identity = await readJsonFile(join(directory, "identity.json"));
|
|
943
|
+
claims.push({ directory, agentId: identity ? asString(identity.agent_id) ?? null : null, retired });
|
|
944
|
+
}
|
|
945
|
+
if (!claimedSlug && !retired && entry === slug) legacyFolder = directory;
|
|
946
|
+
}
|
|
947
|
+
if (claims.length > 1) {
|
|
948
|
+
throw new Error(
|
|
949
|
+
`${claims.length} agent directories on this machine record the pair 'haven-${slug}' \u2014 the MCP server name changed hands (mcp_server_name_rebound):
|
|
950
|
+
` + 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."
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
if (claims.length === 1) return claims[0].directory;
|
|
954
|
+
if (legacyFolder) return legacyFolder;
|
|
955
|
+
const known = [
|
|
956
|
+
...recordedSlugs.map((s) => `'haven-${s}'`),
|
|
957
|
+
...barePairCount > 0 ? [`${barePairCount} unnamed 'haven' / 'haven-signer' pair${barePairCount === 1 ? "" : "s"} (no --name)`] : []
|
|
958
|
+
];
|
|
959
|
+
throw new Error(
|
|
960
|
+
`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>."
|
|
961
|
+
);
|
|
962
|
+
}
|
|
393
963
|
async function rewriteCredentialFiles(input) {
|
|
394
964
|
const directory = defaultAgentDirectory(input.serverName ?? input.agentId, input.baseDir);
|
|
395
965
|
const identityPath = join(directory, "identity.json");
|
|
@@ -599,6 +1169,7 @@ async function listMcpServerBindings(baseDir, excludeDirectory) {
|
|
|
599
1169
|
const out = [];
|
|
600
1170
|
for (const entry of entries) {
|
|
601
1171
|
const directory = join(root, entry);
|
|
1172
|
+
if (excludeDirectory && directory === excludeDirectory) continue;
|
|
602
1173
|
const binding = await readMcpServerBinding(directory);
|
|
603
1174
|
if (binding) out.push({ directory, binding });
|
|
604
1175
|
}
|
|
@@ -608,48 +1179,12 @@ var REKEY_PENDING_FILENAME, REKEY_PENDING_TTL_MS, CONNECT_OUTCOME_FILENAME, MCP_
|
|
|
608
1179
|
var init_storage = __esm({
|
|
609
1180
|
"src/storage.ts"() {
|
|
610
1181
|
init_server_names();
|
|
1182
|
+
init_signer_runtime();
|
|
1183
|
+
init_tombstone();
|
|
611
1184
|
REKEY_PENDING_FILENAME = "rekey-pending.json";
|
|
612
1185
|
REKEY_PENDING_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
613
1186
|
CONNECT_OUTCOME_FILENAME = "last-connect-outcome.json";
|
|
614
|
-
MCP_SERVER_BINDING_FILENAME = "mcp-server-binding.json";
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
function mcpPackageSpec() {
|
|
618
|
-
return `${MCP_RUNTIME_MANIFEST.mcpPackage}@${MCP_RUNTIME_MANIFEST.mcpVersion}`;
|
|
619
|
-
}
|
|
620
|
-
function sdkPackageSpec() {
|
|
621
|
-
return `${MCP_RUNTIME_MANIFEST.sdkPackage}@${MCP_RUNTIME_MANIFEST.sdkVersion}`;
|
|
622
|
-
}
|
|
623
|
-
function signerPackageSpec() {
|
|
624
|
-
return `${MCP_RUNTIME_MANIFEST.signerPackage}@${MCP_RUNTIME_MANIFEST.signerVersion}`;
|
|
625
|
-
}
|
|
626
|
-
var MCP_RUNTIME_MANIFEST;
|
|
627
|
-
var init_runtime_manifest = __esm({
|
|
628
|
-
"src/runtime-manifest.ts"() {
|
|
629
|
-
MCP_RUNTIME_MANIFEST = {
|
|
630
|
-
mcpPackage: "@haven_ai/mcp",
|
|
631
|
-
mcpVersion: MCP_VERSION,
|
|
632
|
-
sdkPackage: "@haven_ai/sdk",
|
|
633
|
-
sdkVersion: "0.9.0-alpha.0",
|
|
634
|
-
signerPackage: "@haven_ai/signer",
|
|
635
|
-
signerVersion: "0.9.0-alpha.0",
|
|
636
|
-
// Sourced from the SDK, never a literal (#1161). This field read '20.0.0'
|
|
637
|
-
// while every package's `engines` said `>=24` and the docs said `>=24.0.0`,
|
|
638
|
-
// so the guard that was supposed to enforce the floor waved Node v23 through
|
|
639
|
-
// — including on the `--local` path where it does run. A hand-maintained
|
|
640
|
-
// second copy of a number is a drift waiting to happen; a guard test pins
|
|
641
|
-
// this against `package.json`'s `engines.node`.
|
|
642
|
-
minimumNodeVersion: HAVEN_MINIMUM_NODE_VERSION,
|
|
643
|
-
supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
|
|
644
|
-
requiredTools: registeredToolNames(),
|
|
645
|
-
/**
|
|
646
|
-
* The signer MCP's tool surface, DERIVED from the pinned @haven_ai/signer
|
|
647
|
-
* package (#1587) — same anti-drift rule as `requiredTools` above: a
|
|
648
|
-
* literal list here would rot the first time the signer gains a tool.
|
|
649
|
-
* The handshake probe requires all of them.
|
|
650
|
-
*/
|
|
651
|
-
requiredSignerTools: Object.keys(toolSchemas)
|
|
652
|
-
};
|
|
1187
|
+
MCP_SERVER_BINDING_FILENAME = "mcp-server-binding.json";
|
|
653
1188
|
}
|
|
654
1189
|
});
|
|
655
1190
|
async function writeRuntimeConfig(input, deps = {}) {
|
|
@@ -1686,295 +2221,23 @@ function parseJsonRpcPayload(raw) {
|
|
|
1686
2221
|
const dataLines = trimmed.split(/\r?\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim());
|
|
1687
2222
|
for (let i = dataLines.length - 1; i >= 0; i -= 1) {
|
|
1688
2223
|
try {
|
|
1689
|
-
return JSON.parse(dataLines[i]);
|
|
1690
|
-
} catch {
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
return null;
|
|
1694
|
-
}
|
|
1695
|
-
async function fetchWithTimeout(fetchImpl, url, init) {
|
|
1696
|
-
const controller = new AbortController();
|
|
1697
|
-
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
1698
|
-
try {
|
|
1699
|
-
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
1700
|
-
} finally {
|
|
1701
|
-
clearTimeout(timeout);
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
var init_probes = __esm({
|
|
1705
|
-
"src/probes.ts"() {
|
|
1706
|
-
}
|
|
1707
|
-
});
|
|
1708
|
-
function resolveRuntimeSpecOverride(env) {
|
|
1709
|
-
const override = {};
|
|
1710
|
-
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
1711
|
-
const variable = RUNTIME_SPEC_ENV[pkg];
|
|
1712
|
-
const raw = env[variable];
|
|
1713
|
-
if (raw === void 0) continue;
|
|
1714
|
-
override[pkg] = validateSpec(variable, raw);
|
|
1715
|
-
}
|
|
1716
|
-
return Object.keys(override).length > 0 ? override : void 0;
|
|
1717
|
-
}
|
|
1718
|
-
function validateSpec(variable, raw) {
|
|
1719
|
-
if (raw.length === 0 || raw.trim().length === 0) {
|
|
1720
|
-
throw new RuntimeSpecOverrideError(variable, "it is empty");
|
|
1721
|
-
}
|
|
1722
|
-
if (/\s/.test(raw)) {
|
|
1723
|
-
throw new RuntimeSpecOverrideError(variable, "it contains whitespace");
|
|
1724
|
-
}
|
|
1725
|
-
if (/[\u0000-\u001f\u007f]/.test(raw)) {
|
|
1726
|
-
throw new RuntimeSpecOverrideError(variable, "it contains a control character");
|
|
1727
|
-
}
|
|
1728
|
-
const meta = SHELL_METACHARACTERS.exec(raw);
|
|
1729
|
-
if (meta) {
|
|
1730
|
-
throw new RuntimeSpecOverrideError(variable, `it contains the shell metacharacter ${JSON.stringify(meta[0])}`);
|
|
1731
|
-
}
|
|
1732
|
-
return raw;
|
|
1733
|
-
}
|
|
1734
|
-
function runtimeSpecOverrideDirectoryKey(resolvedSpecs) {
|
|
1735
|
-
const digest = createHash("sha256").update(resolvedSpecs.join("\n")).digest("hex");
|
|
1736
|
-
return `override-${digest.slice(0, 12)}`;
|
|
1737
|
-
}
|
|
1738
|
-
function overrideApplies(override, packages) {
|
|
1739
|
-
return override !== void 0 && packages.some((pkg) => override[pkg] !== void 0);
|
|
1740
|
-
}
|
|
1741
|
-
function runtimeSpecOverrideNotice(runtimeLabel, override, pinned, runtimeDirectory) {
|
|
1742
|
-
const lines = [`RUNTIME SPEC OVERRIDE ACTIVE for the local Haven ${runtimeLabel} \u2014 this is NOT the pinned manifest.`];
|
|
1743
|
-
for (const pkg of Object.keys(RUNTIME_SPEC_ENV)) {
|
|
1744
|
-
const spec = override[pkg];
|
|
1745
|
-
if (spec === void 0) continue;
|
|
1746
|
-
const pin = pinned[pkg];
|
|
1747
|
-
lines.push(` ${RUNTIME_SPEC_ENV[pkg]}=${spec}${pin ? ` (instead of ${pin})` : ""}`);
|
|
1748
|
-
}
|
|
1749
|
-
lines.push(` Installing into ${runtimeDirectory} \u2014 the pinned runtime directory is untouched.`);
|
|
1750
|
-
lines.push(" Unset the variable(s) and re-run to return to the pinned manifest.");
|
|
1751
|
-
return lines;
|
|
1752
|
-
}
|
|
1753
|
-
function describeRuntimeSpecOverride(override) {
|
|
1754
|
-
return Object.keys(RUNTIME_SPEC_ENV).filter((pkg) => override[pkg] !== void 0).map((pkg) => `${RUNTIME_SPEC_ENV[pkg]}=${override[pkg]}`).join(" ");
|
|
1755
|
-
}
|
|
1756
|
-
var RUNTIME_SPEC_ENV, SHELL_METACHARACTERS, RuntimeSpecOverrideError;
|
|
1757
|
-
var init_runtime_spec_override = __esm({
|
|
1758
|
-
"src/runtime-spec-override.ts"() {
|
|
1759
|
-
RUNTIME_SPEC_ENV = {
|
|
1760
|
-
signer: "HAVEN_SIGNER_SPEC",
|
|
1761
|
-
sdk: "HAVEN_SDK_SPEC",
|
|
1762
|
-
mcp: "HAVEN_MCP_SPEC"
|
|
1763
|
-
};
|
|
1764
|
-
SHELL_METACHARACTERS = /[;&|<>$`'"()!#*?[\]{}\\]/;
|
|
1765
|
-
RuntimeSpecOverrideError = class extends Error {
|
|
1766
|
-
code = "runtime_spec_override_invalid";
|
|
1767
|
-
variable;
|
|
1768
|
-
constructor(variable, reason) {
|
|
1769
|
-
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>).`);
|
|
1770
|
-
this.name = "RuntimeSpecOverrideError";
|
|
1771
|
-
this.variable = variable;
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
|
-
}
|
|
1775
|
-
});
|
|
1776
|
-
async function prepareSignerRuntime(input, deps = {}) {
|
|
1777
|
-
const homeDir = input.homeDir ?? homedir();
|
|
1778
|
-
const override = resolveSignerRuntimeOverride(deps.env ?? process.env);
|
|
1779
|
-
const signerSpec = override?.signer ?? signerPackageSpec();
|
|
1780
|
-
const sdkSpec = override?.sdk ?? sdkPackageSpec();
|
|
1781
|
-
const resolvedSpecs = [signerSpec, sdkSpec];
|
|
1782
|
-
const overrideRecord = override ? { specs: override, resolved_specs: resolvedSpecs, directory_key: runtimeSpecOverrideDirectoryKey(resolvedSpecs) } : void 0;
|
|
1783
|
-
const runtimeDirectory = resolve(
|
|
1784
|
-
homeDir,
|
|
1785
|
-
".haven",
|
|
1786
|
-
"signer-runtime",
|
|
1787
|
-
overrideRecord ? overrideRecord.directory_key : MCP_RUNTIME_MANIFEST.signerVersion
|
|
1788
|
-
);
|
|
1789
|
-
const npmCacheDirectory = resolve(homeDir, ".haven", "npm-cache");
|
|
1790
|
-
const cliPath = join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "dist", "cli.js");
|
|
1791
|
-
const messages = [];
|
|
1792
|
-
if (override) {
|
|
1793
|
-
messages.push(...runtimeSpecOverrideNotice(
|
|
1794
|
-
"signer runtime",
|
|
1795
|
-
override,
|
|
1796
|
-
{ signer: signerPackageSpec(), sdk: sdkPackageSpec() },
|
|
1797
|
-
runtimeDirectory
|
|
1798
|
-
));
|
|
1799
|
-
}
|
|
1800
|
-
await mkdir(runtimeDirectory, { recursive: true, mode: 448 });
|
|
1801
|
-
await chmod(runtimeDirectory, 448).catch(() => void 0);
|
|
1802
|
-
await mkdir(npmCacheDirectory, { recursive: true, mode: 448 });
|
|
1803
|
-
await chmod(npmCacheDirectory, 448).catch(() => void 0);
|
|
1804
|
-
if (override) {
|
|
1805
|
-
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
1806
|
-
messages.push(`Installed local Haven signer runtime from override (${resolvedSpecs.join(" ")}).`);
|
|
1807
|
-
} else if (await installedRuntimeMatches(runtimeDirectory, cliPath)) {
|
|
1808
|
-
messages.push(`Using existing local Haven signer runtime ${signerPackageSpec()}.`);
|
|
1809
|
-
} else {
|
|
1810
|
-
await installRuntimePackages(runtimeDirectory, npmCacheDirectory, resolvedSpecs, deps);
|
|
1811
|
-
messages.push(`Installed local Haven signer runtime ${signerPackageSpec()}.`);
|
|
1812
|
-
}
|
|
1813
|
-
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
1814
|
-
const installedVersions = override ? await readInstalledVersions(runtimeDirectory) : void 0;
|
|
1815
|
-
const wrapperPath = join(input.credentialDirectory, "bin", "haven-signer.mjs");
|
|
1816
|
-
await writeWrapper({
|
|
1817
|
-
wrapperPath,
|
|
1818
|
-
cliPath,
|
|
1819
|
-
signerPath: input.signerPath,
|
|
1820
|
-
overrideComment: override ? describeRuntimeSpecOverride(override) : void 0
|
|
1821
|
-
});
|
|
1822
|
-
await writeRuntimeSidecar({
|
|
1823
|
-
path: join(input.credentialDirectory, "signer-runtime.json"),
|
|
1824
|
-
wrapperPath,
|
|
1825
|
-
runtimeDirectory,
|
|
1826
|
-
npmCacheDirectory,
|
|
1827
|
-
cliPath,
|
|
1828
|
-
serverName: input.serverName,
|
|
1829
|
-
override: overrideRecord,
|
|
1830
|
-
installedVersions
|
|
1831
|
-
});
|
|
1832
|
-
messages.push(`Prepared stable local Haven signer wrapper: ${wrapperPath}`);
|
|
1833
|
-
return {
|
|
1834
|
-
command: wrapperPath,
|
|
1835
|
-
args: [],
|
|
1836
|
-
wrapperPath,
|
|
1837
|
-
runtimeDirectory,
|
|
1838
|
-
npmCacheDirectory,
|
|
1839
|
-
cliPath,
|
|
1840
|
-
messages,
|
|
1841
|
-
...overrideRecord ? { runtimeSpecOverride: overrideRecord } : {}
|
|
1842
|
-
};
|
|
1843
|
-
}
|
|
1844
|
-
function resolveSignerRuntimeOverride(env) {
|
|
1845
|
-
const override = resolveRuntimeSpecOverride(env);
|
|
1846
|
-
if (!overrideApplies(override, ["signer", "sdk"])) return void 0;
|
|
1847
|
-
const { signer, sdk } = override;
|
|
1848
|
-
return { ...signer !== void 0 ? { signer } : {}, ...sdk !== void 0 ? { sdk } : {} };
|
|
1849
|
-
}
|
|
1850
|
-
async function installRuntimePackages(runtimeDirectory, npmCacheDirectory, packageSpecs, deps) {
|
|
1851
|
-
const { runCommand, onProgress } = deps;
|
|
1852
|
-
const baseArgs = [
|
|
1853
|
-
"install",
|
|
1854
|
-
"--prefix",
|
|
1855
|
-
runtimeDirectory,
|
|
1856
|
-
"--no-audit",
|
|
1857
|
-
"--no-fund",
|
|
1858
|
-
"--omit=dev",
|
|
1859
|
-
"--prefer-offline",
|
|
1860
|
-
...packageSpecs
|
|
1861
|
-
];
|
|
1862
|
-
const run = async (args) => {
|
|
1863
|
-
const startedAt = Date.now();
|
|
1864
|
-
const heartbeat = setInterval(() => {
|
|
1865
|
-
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
1866
|
-
onProgress?.(`Still installing the local Haven signer runtime\u2026 (${seconds}s \u2014 a cold cache can take several minutes)`);
|
|
1867
|
-
}, SIGNER_INSTALL_HEARTBEAT_MS);
|
|
1868
|
-
heartbeat.unref?.();
|
|
1869
|
-
try {
|
|
1870
|
-
if (runCommand) await runCommand("npm", args);
|
|
1871
|
-
else await execFileAsync("npm", args, { timeout: SIGNER_INSTALL_TIMEOUT_MS, maxBuffer: 1024 * 1024 });
|
|
1872
|
-
} finally {
|
|
1873
|
-
clearInterval(heartbeat);
|
|
1874
|
-
}
|
|
1875
|
-
};
|
|
1876
|
-
try {
|
|
1877
|
-
await run(baseArgs);
|
|
1878
|
-
} catch {
|
|
1879
|
-
try {
|
|
1880
|
-
await run([...baseArgs, "--cache", npmCacheDirectory]);
|
|
1881
|
-
} catch (err) {
|
|
1882
|
-
throw new Error(
|
|
1883
|
-
`Could not install local Haven signer runtime ${packageSpecs.join(" ")}: ${err instanceof Error ? err.message : String(err)}`
|
|
1884
|
-
);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
async function installedRuntimeMatches(runtimeDirectory, cliPath) {
|
|
1889
|
-
return installedRuntimeMatchesVersions(runtimeDirectory, cliPath, {
|
|
1890
|
-
signerVersion: MCP_RUNTIME_MANIFEST.signerVersion,
|
|
1891
|
-
sdkVersion: MCP_RUNTIME_MANIFEST.sdkVersion
|
|
1892
|
-
});
|
|
1893
|
-
}
|
|
1894
|
-
async function installedRuntimeMatchesVersions(runtimeDirectory, cliPath, expected) {
|
|
1895
|
-
try {
|
|
1896
|
-
await assertFileExists(cliPath, "local Haven signer CLI");
|
|
1897
|
-
const installed = await readInstalledVersions(runtimeDirectory);
|
|
1898
|
-
return installed.signerVersion === expected.signerVersion && installed.sdkVersion === expected.sdkVersion;
|
|
1899
|
-
} catch {
|
|
1900
|
-
return false;
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
async function readInstalledVersions(runtimeDirectory) {
|
|
1904
|
-
const [signerPackage, sdkPackage] = await Promise.all([
|
|
1905
|
-
readPackageJson(join(runtimeDirectory, "node_modules", "@haven_ai", "signer", "package.json")),
|
|
1906
|
-
readPackageJson(join(runtimeDirectory, "node_modules", "@haven_ai", "sdk", "package.json"))
|
|
1907
|
-
]);
|
|
1908
|
-
return { signerVersion: signerPackage.version ?? "", sdkVersion: sdkPackage.version ?? "" };
|
|
1909
|
-
}
|
|
1910
|
-
async function readPackageJson(path) {
|
|
1911
|
-
return JSON.parse(await readFile(path, "utf8"));
|
|
1912
|
-
}
|
|
1913
|
-
async function writeWrapper(input) {
|
|
1914
|
-
await mkdir(dirname(input.wrapperPath), { recursive: true, mode: 448 });
|
|
1915
|
-
await chmod(dirname(input.wrapperPath), 448).catch(() => void 0);
|
|
1916
|
-
const source = [
|
|
1917
|
-
"#!/usr/bin/env node",
|
|
1918
|
-
...input.overrideComment ? [`// HAVEN RUNTIME SPEC OVERRIDE (#2424): ${input.overrideComment} \u2014 this wrapper launches a NON-pinned signer build.`] : [],
|
|
1919
|
-
"import { spawn } from 'node:child_process'",
|
|
1920
|
-
"",
|
|
1921
|
-
`const cliPath = ${JSON.stringify(input.cliPath)}`,
|
|
1922
|
-
`const signerPath = ${JSON.stringify(input.signerPath)}`,
|
|
1923
|
-
"",
|
|
1924
|
-
"const child = spawn(process.execPath, [cliPath, '--credentials', signerPath, ...process.argv.slice(2)], {",
|
|
1925
|
-
" stdio: 'inherit',",
|
|
1926
|
-
"})",
|
|
1927
|
-
"",
|
|
1928
|
-
"child.on('exit', (code, signal) => {",
|
|
1929
|
-
" if (signal) process.kill(process.pid, signal)",
|
|
1930
|
-
" else process.exit(code ?? 1)",
|
|
1931
|
-
"})",
|
|
1932
|
-
""
|
|
1933
|
-
].join("\n");
|
|
1934
|
-
await writeFile(input.wrapperPath, source, { mode: 448 });
|
|
1935
|
-
await chmod(input.wrapperPath, 448).catch(() => void 0);
|
|
1936
|
-
}
|
|
1937
|
-
async function readRuntimeSidecar(credentialDirectory) {
|
|
1938
|
-
try {
|
|
1939
|
-
return JSON.parse(
|
|
1940
|
-
await readFile(join(credentialDirectory, "signer-runtime.json"), "utf8")
|
|
1941
|
-
);
|
|
1942
|
-
} catch {
|
|
1943
|
-
return null;
|
|
2224
|
+
return JSON.parse(dataLines[i]);
|
|
2225
|
+
} catch {
|
|
2226
|
+
}
|
|
1944
2227
|
}
|
|
2228
|
+
return null;
|
|
1945
2229
|
}
|
|
1946
|
-
async function
|
|
1947
|
-
const
|
|
1948
|
-
|
|
1949
|
-
signer_package: MCP_RUNTIME_MANIFEST.signerPackage,
|
|
1950
|
-
signer_version: input.installedVersions?.signerVersion ?? MCP_RUNTIME_MANIFEST.signerVersion,
|
|
1951
|
-
sdk_package: MCP_RUNTIME_MANIFEST.sdkPackage,
|
|
1952
|
-
sdk_version: input.installedVersions?.sdkVersion ?? MCP_RUNTIME_MANIFEST.sdkVersion,
|
|
1953
|
-
wrapper_path: input.wrapperPath,
|
|
1954
|
-
runtime_directory: input.runtimeDirectory,
|
|
1955
|
-
npm_cache_directory: input.npmCacheDirectory,
|
|
1956
|
-
cli_path: input.cliPath,
|
|
1957
|
-
...input.override ? { runtime_spec_override: input.override } : {}
|
|
1958
|
-
};
|
|
1959
|
-
await writeFile(input.path, `${JSON.stringify(value, null, 2)}
|
|
1960
|
-
`, { mode: 384 });
|
|
1961
|
-
await chmod(input.path, 384).catch(() => void 0);
|
|
1962
|
-
}
|
|
1963
|
-
async function assertFileExists(path, label) {
|
|
2230
|
+
async function fetchWithTimeout(fetchImpl, url, init) {
|
|
2231
|
+
const controller = new AbortController();
|
|
2232
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
1964
2233
|
try {
|
|
1965
|
-
await
|
|
1966
|
-
}
|
|
1967
|
-
|
|
2234
|
+
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
2235
|
+
} finally {
|
|
2236
|
+
clearTimeout(timeout);
|
|
1968
2237
|
}
|
|
1969
2238
|
}
|
|
1970
|
-
var
|
|
1971
|
-
|
|
1972
|
-
"src/signer-runtime.ts"() {
|
|
1973
|
-
init_runtime_manifest();
|
|
1974
|
-
init_runtime_spec_override();
|
|
1975
|
-
execFileAsync = promisify(execFile);
|
|
1976
|
-
SIGNER_INSTALL_TIMEOUT_MS = 6e5;
|
|
1977
|
-
SIGNER_INSTALL_HEARTBEAT_MS = 15e3;
|
|
2239
|
+
var init_probes = __esm({
|
|
2240
|
+
"src/probes.ts"() {
|
|
1978
2241
|
}
|
|
1979
2242
|
});
|
|
1980
2243
|
async function prepareLocalMcpRuntime(input, deps = {}) {
|
|
@@ -2292,28 +2555,6 @@ var init_skill_install = __esm({
|
|
|
2292
2555
|
}
|
|
2293
2556
|
});
|
|
2294
2557
|
|
|
2295
|
-
// src/connect-error.ts
|
|
2296
|
-
function isConnectError(err) {
|
|
2297
|
-
return err instanceof ConnectError;
|
|
2298
|
-
}
|
|
2299
|
-
var ConnectError;
|
|
2300
|
-
var init_connect_error = __esm({
|
|
2301
|
-
"src/connect-error.ts"() {
|
|
2302
|
-
ConnectError = class extends Error {
|
|
2303
|
-
code;
|
|
2304
|
-
nextAction;
|
|
2305
|
-
details;
|
|
2306
|
-
constructor(code, message, nextAction2, details = {}) {
|
|
2307
|
-
super(message);
|
|
2308
|
-
this.name = "ConnectError";
|
|
2309
|
-
this.code = code;
|
|
2310
|
-
this.nextAction = nextAction2;
|
|
2311
|
-
this.details = details;
|
|
2312
|
-
}
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
});
|
|
2316
|
-
|
|
2317
2558
|
// src/runtime-registry.ts
|
|
2318
2559
|
function runtimeProfile(runtime, env = process.env) {
|
|
2319
2560
|
return RUNTIME_PROFILES[normalizeRuntime(runtime, env)];
|
|
@@ -3235,138 +3476,6 @@ var init_installed_clients = __esm({
|
|
|
3235
3476
|
MAX_PROMPT_ATTEMPTS = 3;
|
|
3236
3477
|
}
|
|
3237
3478
|
});
|
|
3238
|
-
|
|
3239
|
-
// src/tombstone.ts
|
|
3240
|
-
var tombstone_exports = {};
|
|
3241
|
-
__export(tombstone_exports, {
|
|
3242
|
-
ROOT_TOMBSTONES_DIRNAME: () => ROOT_TOMBSTONES_DIRNAME,
|
|
3243
|
-
TOMBSTONE_FILENAME: () => TOMBSTONE_FILENAME,
|
|
3244
|
-
TOMBSTONE_MARKER: () => TOMBSTONE_MARKER,
|
|
3245
|
-
defaultTombstonesDir: () => defaultTombstonesDir,
|
|
3246
|
-
readAgentTombstone: () => readAgentTombstone,
|
|
3247
|
-
readTombstoneRecords: () => readTombstoneRecords,
|
|
3248
|
-
tombstonesDirForAgentDirectory: () => tombstonesDirForAgentDirectory,
|
|
3249
|
-
tombstonesDirForCredentialRoot: () => tombstonesDirForCredentialRoot,
|
|
3250
|
-
writeAgentTombstone: () => writeAgentTombstone
|
|
3251
|
-
});
|
|
3252
|
-
function defaultTombstonesDir(baseDir) {
|
|
3253
|
-
return join(baseDir ?? join(homedir(), ".haven"), "tombstones");
|
|
3254
|
-
}
|
|
3255
|
-
function tombstonesDirForCredentialRoot(credentialRoot, homeDir = homedir()) {
|
|
3256
|
-
if (!credentialRoot) return defaultTombstonesDir(join(homeDir, ".haven"));
|
|
3257
|
-
const root = resolve(credentialRoot);
|
|
3258
|
-
if (root === resolve(homeDir, ".haven", "agents")) return defaultTombstonesDir(join(homeDir, ".haven"));
|
|
3259
|
-
return join(root, ROOT_TOMBSTONES_DIRNAME);
|
|
3260
|
-
}
|
|
3261
|
-
function tombstonesDirForAgentDirectory(directory, homeDir = homedir()) {
|
|
3262
|
-
return tombstonesDirForCredentialRoot(dirname(resolve(directory)), homeDir);
|
|
3263
|
-
}
|
|
3264
|
-
async function readTombstoneRecords(tombstonesDir) {
|
|
3265
|
-
const root = tombstonesDir ?? defaultTombstonesDir();
|
|
3266
|
-
let entries = [];
|
|
3267
|
-
try {
|
|
3268
|
-
entries = await readdir(root);
|
|
3269
|
-
} catch {
|
|
3270
|
-
return [];
|
|
3271
|
-
}
|
|
3272
|
-
const records = [];
|
|
3273
|
-
for (const entry of entries) {
|
|
3274
|
-
if (!entry.endsWith(".json")) continue;
|
|
3275
|
-
const recordPath = join(root, entry);
|
|
3276
|
-
try {
|
|
3277
|
-
const parsed = JSON.parse(await readFile(recordPath, "utf8"));
|
|
3278
|
-
if (typeof parsed?.agent_id === "string") {
|
|
3279
|
-
records.push({ ...parsed, recordPath });
|
|
3280
|
-
}
|
|
3281
|
-
} catch {
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
return records;
|
|
3285
|
-
}
|
|
3286
|
-
function tombstoneScript(info) {
|
|
3287
|
-
const lines = [
|
|
3288
|
-
`${TOMBSTONE_MARKER}: this Haven agent was retired.`,
|
|
3289
|
-
"",
|
|
3290
|
-
` agent: ${info.agent_id}`,
|
|
3291
|
-
` retired at: ${info.retired_at}`,
|
|
3292
|
-
` reason: ${info.reason}`,
|
|
3293
|
-
...info.replaced_by ? [` replaced by: ${info.replaced_by}`] : [],
|
|
3294
|
-
"",
|
|
3295
|
-
"This process is running with a wiring snapshot that predates the",
|
|
3296
|
-
"retirement \u2014 it loaded its MCP config at startup and has kept it since.",
|
|
3297
|
-
"Restart THIS host to pick up the current wiring. If several long-lived",
|
|
3298
|
-
"hosts are running (a gateway, a TUI worker, an editor), restart EVERY",
|
|
3299
|
-
"one of them: each holds the snapshot from its own start time, so after",
|
|
3300
|
-
"a chain of recreations each can be parked on a DIFFERENT old agent.",
|
|
3301
|
-
"",
|
|
3302
|
-
`Then verify with: ${connectorRerunCommand("--doctor --runtime <runtime>")}`
|
|
3303
|
-
];
|
|
3304
|
-
return [
|
|
3305
|
-
"#!/usr/bin/env node",
|
|
3306
|
-
`// ${TOMBSTONE_MARKER} \u2014 written by @haven_ai/connect (#1681). Safe to delete`,
|
|
3307
|
-
"// once every long-lived MCP host on this machine has been restarted.",
|
|
3308
|
-
`process.stderr.write(${JSON.stringify(lines.join("\n") + "\n")})`,
|
|
3309
|
-
"process.exit(1)",
|
|
3310
|
-
""
|
|
3311
|
-
].join("\n");
|
|
3312
|
-
}
|
|
3313
|
-
async function writeAgentTombstone(input) {
|
|
3314
|
-
const dirStat = await stat(input.directory).catch(() => null);
|
|
3315
|
-
if (!dirStat?.isDirectory()) {
|
|
3316
|
-
throw new ConnectError(
|
|
3317
|
-
"tombstone_directory_not_found",
|
|
3318
|
-
`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.`,
|
|
3319
|
-
"retry_with_an_existing_agent_directory"
|
|
3320
|
-
);
|
|
3321
|
-
}
|
|
3322
|
-
const info = {
|
|
3323
|
-
// reason / replaced_by are persisted to disk and re-emitted to the host's
|
|
3324
|
-
// MCP stderr log on EVERY stale probe, potentially for months — redact
|
|
3325
|
-
// like every other output path, at the write layer so any future caller
|
|
3326
|
-
// inherits it. (#1681 review, finding 1)
|
|
3327
|
-
agent_id: input.agentId,
|
|
3328
|
-
retired_at: input.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
3329
|
-
reason: redactSecrets(input.reason),
|
|
3330
|
-
...input.replacedBy ? { replaced_by: redactSecrets(input.replacedBy) } : {}
|
|
3331
|
-
};
|
|
3332
|
-
const binDir = join(input.directory, "bin");
|
|
3333
|
-
await mkdir(binDir, { recursive: true });
|
|
3334
|
-
const wrapperPath = join(binDir, "haven-signer.mjs");
|
|
3335
|
-
await writeFile(wrapperPath, tombstoneScript(info), "utf8");
|
|
3336
|
-
await chmod(wrapperPath, 493);
|
|
3337
|
-
const record = JSON.stringify(info, null, 2) + "\n";
|
|
3338
|
-
await writeFile(join(input.directory, TOMBSTONE_FILENAME), record, "utf8");
|
|
3339
|
-
const root = input.tombstonesDir ?? defaultTombstonesDir();
|
|
3340
|
-
const recordPath = join(root, `${info.agent_id}.json`);
|
|
3341
|
-
try {
|
|
3342
|
-
await mkdir(root, { recursive: true, mode: 448 });
|
|
3343
|
-
await writeFile(recordPath, record, { mode: MIRROR_MODE });
|
|
3344
|
-
} catch (err) {
|
|
3345
|
-
const code = err?.code;
|
|
3346
|
-
return { ...info, recordPath: null, mirrorError: typeof code === "string" && /^E[A-Z]+$/.test(code) ? code : "mirror_write_failed" };
|
|
3347
|
-
}
|
|
3348
|
-
return { ...info, recordPath };
|
|
3349
|
-
}
|
|
3350
|
-
async function readAgentTombstone(directory) {
|
|
3351
|
-
try {
|
|
3352
|
-
const parsed = JSON.parse(await readFile(join(directory, TOMBSTONE_FILENAME), "utf8"));
|
|
3353
|
-
if (typeof parsed?.agent_id !== "string") return null;
|
|
3354
|
-
return parsed;
|
|
3355
|
-
} catch {
|
|
3356
|
-
return null;
|
|
3357
|
-
}
|
|
3358
|
-
}
|
|
3359
|
-
var TOMBSTONE_FILENAME, ROOT_TOMBSTONES_DIRNAME, MIRROR_MODE, TOMBSTONE_MARKER;
|
|
3360
|
-
var init_tombstone = __esm({
|
|
3361
|
-
"src/tombstone.ts"() {
|
|
3362
|
-
init_redact();
|
|
3363
|
-
init_connect_error();
|
|
3364
|
-
TOMBSTONE_FILENAME = "TOMBSTONE.json";
|
|
3365
|
-
ROOT_TOMBSTONES_DIRNAME = ".tombstones";
|
|
3366
|
-
MIRROR_MODE = 384;
|
|
3367
|
-
TOMBSTONE_MARKER = "HAVEN-TOMBSTONE";
|
|
3368
|
-
}
|
|
3369
|
-
});
|
|
3370
3479
|
async function detectWiringCollision(input) {
|
|
3371
3480
|
const root = defaultCredentialRoot(input.credentialsDir);
|
|
3372
3481
|
let entries = [];
|
|
@@ -4082,10 +4191,10 @@ async function executeConnect(options, deps, trace) {
|
|
|
4082
4191
|
} else if (supersededAgentIds.length > 0) {
|
|
4083
4192
|
log("");
|
|
4084
4193
|
log(
|
|
4085
|
-
`Heads-up:
|
|
4194
|
+
`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.`
|
|
4086
4195
|
);
|
|
4087
4196
|
log(
|
|
4088
|
-
`
|
|
4197
|
+
`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.`
|
|
4089
4198
|
);
|
|
4090
4199
|
}
|
|
4091
4200
|
} catch {
|
|
@@ -4116,6 +4225,18 @@ async function executeConnect(options, deps, trace) {
|
|
|
4116
4225
|
} catch (err) {
|
|
4117
4226
|
log(`Could not report install status to Haven: ${err instanceof Error ? err.message : String(err)}`);
|
|
4118
4227
|
}
|
|
4228
|
+
const reportableRetiredIds = [...new Set(retiredAgentIds.filter((id) => UUID_SHAPE.test(id)))];
|
|
4229
|
+
if (reportableRetiredIds.length > 0 && api.reportRetiredAgents) {
|
|
4230
|
+
try {
|
|
4231
|
+
await api.reportRetiredAgents({
|
|
4232
|
+
setupId: registration.setup_id,
|
|
4233
|
+
apiKey: localApiKey,
|
|
4234
|
+
retiredAgentIds: reportableRetiredIds
|
|
4235
|
+
});
|
|
4236
|
+
} catch (err) {
|
|
4237
|
+
log(`Could not tell Haven which agents were retired: ${err instanceof Error ? err.message : String(err)}`);
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4119
4240
|
let approval;
|
|
4120
4241
|
const narrateApprovalWait = options.waitForApproval === true || options.waitForApproval === void 0 && (deps.isStdoutTty ?? Boolean(process.stdout.isTTY));
|
|
4121
4242
|
if (narrateApprovalWait && !runtimeInstall.errorCode) {
|
|
@@ -4558,7 +4679,7 @@ async function listOtherAgentIds(baseDir, currentDirectory) {
|
|
|
4558
4679
|
function printNextSteps(result, log, approval, approvalUrl) {
|
|
4559
4680
|
for (const line of completionHandoffLines(result, approval, approvalUrl)) log(line);
|
|
4560
4681
|
}
|
|
4561
|
-
var CONNECTOR_VERSION, PRODUCTION_CHAIN_ID, CONNECTOR_CLIENT_IDENTITY, CONNECT_OUTCOME_SCHEMA_VERSION, failureOutcomesByError, RERUN_HINT;
|
|
4682
|
+
var CONNECTOR_VERSION, PRODUCTION_CHAIN_ID, UUID_SHAPE, CONNECTOR_CLIENT_IDENTITY, CONNECT_OUTCOME_SCHEMA_VERSION, failureOutcomesByError, RERUN_HINT;
|
|
4562
4683
|
var init_runtime = __esm({
|
|
4563
4684
|
"src/runtime.ts"() {
|
|
4564
4685
|
init_api();
|
|
@@ -4575,8 +4696,9 @@ var init_runtime = __esm({
|
|
|
4575
4696
|
init_tombstone();
|
|
4576
4697
|
init_local_mcp_runtime();
|
|
4577
4698
|
init_runtime_manifest();
|
|
4578
|
-
CONNECTOR_VERSION = "0.
|
|
4699
|
+
CONNECTOR_VERSION = "0.10.0-alpha.0";
|
|
4579
4700
|
PRODUCTION_CHAIN_ID = 8453;
|
|
4701
|
+
UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4580
4702
|
CONNECTOR_CLIENT_IDENTITY = `@haven_ai/connect/${CONNECTOR_VERSION}`;
|
|
4581
4703
|
CONNECT_OUTCOME_SCHEMA_VERSION = 1;
|
|
4582
4704
|
failureOutcomesByError = /* @__PURE__ */ new WeakMap();
|
|
@@ -5057,6 +5179,40 @@ function rollUpLevel(checks) {
|
|
|
5057
5179
|
if (checks.some((check) => check.level === "advisory")) return "advisory";
|
|
5058
5180
|
return "ok";
|
|
5059
5181
|
}
|
|
5182
|
+
function runWrapperAck(wrapperPath, timeoutMs = 3e4) {
|
|
5183
|
+
return new Promise((resolve11, reject) => {
|
|
5184
|
+
const child = spawn(wrapperPath, ["--ack"], { stdio: ["ignore", "pipe", "pipe"] });
|
|
5185
|
+
let stdout = "";
|
|
5186
|
+
let settled = false;
|
|
5187
|
+
const timer = setTimeout(() => {
|
|
5188
|
+
if (settled) return;
|
|
5189
|
+
settled = true;
|
|
5190
|
+
child.kill();
|
|
5191
|
+
reject(new Error(`signer --ack timed out after ${Math.round(timeoutMs / 1e3)}s`));
|
|
5192
|
+
}, timeoutMs);
|
|
5193
|
+
child.stdout?.on("data", (chunk) => {
|
|
5194
|
+
stdout += chunk.toString("utf8");
|
|
5195
|
+
});
|
|
5196
|
+
child.on("error", (err) => {
|
|
5197
|
+
if (settled) return;
|
|
5198
|
+
settled = true;
|
|
5199
|
+
clearTimeout(timer);
|
|
5200
|
+
reject(err);
|
|
5201
|
+
});
|
|
5202
|
+
child.on("close", (code) => {
|
|
5203
|
+
if (settled) return;
|
|
5204
|
+
settled = true;
|
|
5205
|
+
clearTimeout(timer);
|
|
5206
|
+
if (code === 0) resolve11({ stdout });
|
|
5207
|
+
else reject(new Error(`signer --ack exited ${code ?? "abnormally"}`));
|
|
5208
|
+
});
|
|
5209
|
+
});
|
|
5210
|
+
}
|
|
5211
|
+
function repairCommandNamedFor(runtime, slug) {
|
|
5212
|
+
const nameFlag = ` --name ${slug}`;
|
|
5213
|
+
if (normalizeRuntimeName(runtime)) return `Run: ${RERUN} --doctor --repair --runtime ${runtime}${nameFlag}`;
|
|
5214
|
+
return `Run: ${RERUN} --doctor --repair --runtime <runtime>${nameFlag} \u2014 --repair needs the runtime named; one of: ${RUNTIME_FLAG_VALUE_LIST.join(", ")}.`;
|
|
5215
|
+
}
|
|
5060
5216
|
function runtimeFlagFor(runtime) {
|
|
5061
5217
|
return normalizeRuntimeName(runtime) ? ` --runtime ${runtime}` : "";
|
|
5062
5218
|
}
|
|
@@ -5138,6 +5294,35 @@ async function discoverCredentialDirectory(homeDir, explicit) {
|
|
|
5138
5294
|
identityDirectories
|
|
5139
5295
|
};
|
|
5140
5296
|
}
|
|
5297
|
+
async function readClaudeCodeWiringEvidence(homeDir) {
|
|
5298
|
+
let parsed;
|
|
5299
|
+
try {
|
|
5300
|
+
parsed = JSON.parse(await readFile(join(homeDir, ".claude.json"), "utf8"));
|
|
5301
|
+
} catch {
|
|
5302
|
+
return null;
|
|
5303
|
+
}
|
|
5304
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
5305
|
+
const blocks = [parsed.mcpServers];
|
|
5306
|
+
const projects = parsed.projects;
|
|
5307
|
+
if (typeof projects === "object" && projects !== null) {
|
|
5308
|
+
for (const project of Object.values(projects)) {
|
|
5309
|
+
if (typeof project === "object" && project !== null) blocks.push(project.mcpServers);
|
|
5310
|
+
}
|
|
5311
|
+
}
|
|
5312
|
+
const lines = [];
|
|
5313
|
+
for (const block of blocks) {
|
|
5314
|
+
if (typeof block !== "object" || block === null) continue;
|
|
5315
|
+
for (const [name, server] of Object.entries(block)) {
|
|
5316
|
+
const entry = typeof server === "object" && server !== null ? server : {};
|
|
5317
|
+
const parts = [JSON.stringify(name) + ":"];
|
|
5318
|
+
if (typeof entry.command === "string") parts.push(entry.command);
|
|
5319
|
+
if (Array.isArray(entry.args)) parts.push(...entry.args.filter((arg) => typeof arg === "string"));
|
|
5320
|
+
if (typeof entry.url === "string") parts.push(entry.url);
|
|
5321
|
+
lines.push(parts.join(" "));
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
return lines.length > 0 ? lines.join("\n") : null;
|
|
5325
|
+
}
|
|
5141
5326
|
function agentIsWired(configText, names, slug, identity, sidecar, isPrimary, bareOwnerExists) {
|
|
5142
5327
|
if (configText === null) return isPrimary;
|
|
5143
5328
|
if (slug) {
|
|
@@ -5383,8 +5568,11 @@ async function verdictsForAgent(entry, input, deps) {
|
|
|
5383
5568
|
id: "signer_process",
|
|
5384
5569
|
label: "Signer stdio handshake",
|
|
5385
5570
|
level: "failed",
|
|
5386
|
-
|
|
5387
|
-
|
|
5571
|
+
// #3799: honest about what the mismatch does and does not prove. The
|
|
5572
|
+
// stored ack covers a tool SET; a doctor bundled with a newer signer
|
|
5573
|
+
// reports exactly this against an older, still-working install.
|
|
5574
|
+
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.",
|
|
5575
|
+
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)}.`
|
|
5388
5576
|
});
|
|
5389
5577
|
} else {
|
|
5390
5578
|
const probe = await (deps.probeSignerTools ?? probeLocalMcpTools)(
|
|
@@ -5415,12 +5603,21 @@ async function verdictsForAgent(entry, input, deps) {
|
|
|
5415
5603
|
}
|
|
5416
5604
|
return { checks, ...signerCapabilities ? { signerCapabilities } : {} };
|
|
5417
5605
|
}
|
|
5606
|
+
async function resolveNamedDirectory(input, homeDir) {
|
|
5607
|
+
if (!input.serverName) return input.credentialsDir;
|
|
5608
|
+
if (input.credentialsDir) {
|
|
5609
|
+
await assertDirectoryRecordsSlug(input.credentialsDir, input.serverName);
|
|
5610
|
+
return input.credentialsDir;
|
|
5611
|
+
}
|
|
5612
|
+
return resolveAgentDirectoryBySlug(input.serverName, { root: join(homeDir, ".haven", "agents") });
|
|
5613
|
+
}
|
|
5418
5614
|
async function runDoctor(input, deps = {}) {
|
|
5419
5615
|
const homeDir = deps.homeDir ?? homedir();
|
|
5420
5616
|
const checks = [];
|
|
5421
5617
|
let signerCapabilities;
|
|
5422
|
-
const
|
|
5423
|
-
const
|
|
5618
|
+
const namedDir = await resolveNamedDirectory(input, homeDir);
|
|
5619
|
+
const { directory, others, parkedOnly, identityDirectories } = await discoverCredentialDirectory(homeDir, namedDir);
|
|
5620
|
+
const nameRepairDir = identityDirectories.length > 1 || Boolean(namedDir);
|
|
5424
5621
|
const resolution = await resolveDoctorRuntime(input, directory);
|
|
5425
5622
|
const runtime = resolution.runtime;
|
|
5426
5623
|
const input2 = { ...input, runtime };
|
|
@@ -5434,6 +5631,7 @@ async function runDoctor(input, deps = {}) {
|
|
|
5434
5631
|
configText = null;
|
|
5435
5632
|
}
|
|
5436
5633
|
}
|
|
5634
|
+
const claudeCodeWiring = configText === null && normalizedRuntime === "claude-code" ? await readClaudeCodeWiringEvidence(homeDir) : null;
|
|
5437
5635
|
const allDirectories = directory ? [directory, ...others] : others;
|
|
5438
5636
|
let bareOwnerExists = false;
|
|
5439
5637
|
for (const dir of allDirectories) {
|
|
@@ -5467,7 +5665,10 @@ async function runDoctor(input, deps = {}) {
|
|
|
5467
5665
|
});
|
|
5468
5666
|
continue;
|
|
5469
5667
|
}
|
|
5470
|
-
const wired = agentIsWired(configText, names, slug, identity, sidecar, dir === directory, bareOwnerExists)
|
|
5668
|
+
const wired = agentIsWired(configText, names, slug, identity, sidecar, dir === directory, bareOwnerExists) || // Additive only: a name or wrapper path in ~/.claude.json proves this
|
|
5669
|
+
// directory is wired; its absence proves nothing (#3830), so the
|
|
5670
|
+
// fallback verdict above is never downgraded.
|
|
5671
|
+
claudeCodeWiring !== null && agentIsWired(claudeCodeWiring, names, slug, identity, sidecar, false, false);
|
|
5471
5672
|
const entry = {
|
|
5472
5673
|
...slug ? { slug } : {},
|
|
5473
5674
|
...identity.agent_id ? { agentId: identity.agent_id } : {},
|
|
@@ -5535,15 +5736,20 @@ async function runDoctor(input, deps = {}) {
|
|
|
5535
5736
|
id: "runtime_config",
|
|
5536
5737
|
label: "Runtime MCP config",
|
|
5537
5738
|
level: "failed",
|
|
5538
|
-
detail: `Runtime is unknown \u2014 no runtime flag was given and the connector's record in ${primaryDirectory ??
|
|
5739
|
+
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(", ")}.`,
|
|
5539
5740
|
repair: `Re-run the doctor naming the runtime \u2014 one of: ${RUNTIME_FLAG_VALUE_LIST.join(", ")}.`
|
|
5540
5741
|
});
|
|
5541
5742
|
} else if (configPath === null) {
|
|
5743
|
+
const claudePairSuffix = input2.runtime === "claude-code" && primaryDirectory ? await (async () => {
|
|
5744
|
+
const sidecar = await readRuntimeSidecar(primaryDirectory);
|
|
5745
|
+
const names = serverNamesFor(sidecar?.server_name);
|
|
5746
|
+
return ` The MCP pair recorded for this folder is ${names.hosted} / ${names.signer} \u2014 confirm with \`claude mcp get ${names.signer}\`.`;
|
|
5747
|
+
})() : "";
|
|
5542
5748
|
checks.push({
|
|
5543
5749
|
id: "runtime_config",
|
|
5544
5750
|
label: "Runtime MCP config",
|
|
5545
5751
|
level: "ok",
|
|
5546
|
-
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
|
|
5752
|
+
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}`
|
|
5547
5753
|
});
|
|
5548
5754
|
} else if (configText === null) {
|
|
5549
5755
|
checks.push({
|
|
@@ -5617,9 +5823,13 @@ async function runDoctor(input, deps = {}) {
|
|
|
5617
5823
|
const supersededLevel = supersededLive.length === 0 ? "ok" : classificationUnreliable ? "advisory" : "failed";
|
|
5618
5824
|
checks.push({
|
|
5619
5825
|
id: "superseded_agents",
|
|
5620
|
-
|
|
5826
|
+
// #3830: an advisory means the connector could not tell wired from
|
|
5827
|
+
// superseded, so its label must not assert "superseded" either. The
|
|
5828
|
+
// inventory `classification` stays as is (#3121 decision 5); the label
|
|
5829
|
+
// is what a person reads.
|
|
5830
|
+
label: supersededLevel === "advisory" ? "Other agent credentials (wiring not verifiable)" : "Superseded agent credentials",
|
|
5621
5831
|
level: supersededLevel,
|
|
5622
|
-
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
|
|
5832
|
+
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("; ")}.`,
|
|
5623
5833
|
...supersededLevel === "failed" ? {
|
|
5624
5834
|
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.`
|
|
5625
5835
|
} : supersededLevel === "advisory" ? {
|
|
@@ -5648,7 +5858,7 @@ async function runDoctor(input, deps = {}) {
|
|
|
5648
5858
|
label: "MCP server names bound more than once",
|
|
5649
5859
|
level: "advisory",
|
|
5650
5860
|
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.`,
|
|
5651
|
-
repair: `Retire the earlier director(y/ies) with ${RERUN} --unwire <dir> to release the name, or keep both and address them by --name.`
|
|
5861
|
+
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.`
|
|
5652
5862
|
});
|
|
5653
5863
|
}
|
|
5654
5864
|
const parkedElsewhere = inventory.filter((entry) => entry.directory !== primaryDirectory && entry.rekeyPending).map((entry) => ({ entry, pending: entry.rekeyPending }));
|
|
@@ -5708,20 +5918,24 @@ async function runDoctor(input, deps = {}) {
|
|
|
5708
5918
|
async function runRepair(input, deps = {}) {
|
|
5709
5919
|
const homeDir = deps.homeDir ?? homedir();
|
|
5710
5920
|
const messages = [];
|
|
5711
|
-
const
|
|
5712
|
-
|
|
5921
|
+
const namedDir = await resolveNamedDirectory(input, homeDir);
|
|
5922
|
+
const { directory, others, identityDirectories } = await discoverCredentialDirectory(homeDir, namedDir);
|
|
5923
|
+
if (!namedDir && identityDirectories.length > 1) {
|
|
5713
5924
|
const lines = await Promise.all(
|
|
5714
5925
|
identityDirectories.map(async (dir) => {
|
|
5715
5926
|
const identity2 = await readIdentity(dir);
|
|
5716
5927
|
const who = identity2?.agent_id ? `agent ${identity2.agent_id}` : "agent (no agent_id recorded)";
|
|
5717
5928
|
const retired = !identity2?.api_key || await pathExists3(join(dir, TOMBSTONE_FILENAME));
|
|
5718
|
-
|
|
5929
|
+
const sidecar = await readRuntimeSidecar(dir);
|
|
5930
|
+
const slug = sidecar?.server_name;
|
|
5931
|
+
const pair = slug ? `${serverNamesFor(slug).hosted} / ${serverNamesFor(slug).signer}` : "the bare haven / haven-signer pair";
|
|
5932
|
+
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: /, "")}`;
|
|
5719
5933
|
})
|
|
5720
5934
|
);
|
|
5721
5935
|
return {
|
|
5722
5936
|
ok: false,
|
|
5723
5937
|
messages: [
|
|
5724
|
-
`${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:`,
|
|
5938
|
+
`${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:`,
|
|
5725
5939
|
...lines,
|
|
5726
5940
|
"Not sure which agent is which? Compare the agent ids against the Haven agent page, or run --doctor first."
|
|
5727
5941
|
]
|
|
@@ -5779,13 +5993,62 @@ async function runRepair(input, deps = {}) {
|
|
|
5779
5993
|
const existingSidecar = await readRuntimeSidecar(directory);
|
|
5780
5994
|
const serverName = existingSidecar?.server_name;
|
|
5781
5995
|
const signerPath = join(directory, "signer.json");
|
|
5996
|
+
const consent = await getLocalSignerConsentStatus(signerPath);
|
|
5997
|
+
const consentMismatch = !consent.acknowledged && (consent.reason === "ack_file_missing" || consent.reason === "ack_file_mismatch");
|
|
5998
|
+
if (consentMismatch && !input.ackLocalTools) {
|
|
5999
|
+
const wrapperPath = existingSidecar?.wrapper_path ?? join(directory, "bin", "haven-signer.mjs");
|
|
6000
|
+
return {
|
|
6001
|
+
ok: false,
|
|
6002
|
+
messages: [
|
|
6003
|
+
"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.",
|
|
6004
|
+
"The mismatch does not prove the currently running signer is broken; a newer tool set is enough to explain it.",
|
|
6005
|
+
`Re-consent without a setup token, produced by the installed signer: ${wrapperPath} --ack < /dev/null`,
|
|
6006
|
+
`Or re-run repair with --ack-local-tools to re-consent during the repair: ${repairCommandFor(input2.runtime, " --ack-local-tools", directory)}`
|
|
6007
|
+
]
|
|
6008
|
+
};
|
|
6009
|
+
}
|
|
5782
6010
|
const prepared = await prepareSignerRuntime(
|
|
5783
6011
|
{ credentialDirectory: directory, signerPath, homeDir, serverName },
|
|
5784
6012
|
{ runCommand: deps.runCommand, env: deps.env }
|
|
5785
6013
|
);
|
|
5786
6014
|
messages.push(...prepared.messages);
|
|
5787
6015
|
const names = serverNamesFor(serverName);
|
|
5788
|
-
|
|
6016
|
+
const rewritesConfig = runtimeConfigPathFor(normalizeRuntimeName(input2.runtime) ?? input2.runtime, homeDir) !== null;
|
|
6017
|
+
if (rewritesConfig) {
|
|
6018
|
+
messages.push(`Rewriting MCP entries ${names.hosted} / ${names.signer}${serverName ? ` (agent "${serverName}")` : " (unnamed pair)"} \u2014 no other pair is touched.`);
|
|
6019
|
+
} else {
|
|
6020
|
+
messages.push(
|
|
6021
|
+
`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.`)
|
|
6022
|
+
);
|
|
6023
|
+
}
|
|
6024
|
+
if (consentMismatch && input.ackLocalTools) {
|
|
6025
|
+
messages.push(`Re-acknowledging local-tools consent with the installed signer (${signerPackageSpec()}):`);
|
|
6026
|
+
try {
|
|
6027
|
+
const ack = await (deps.runSignerAck ?? runWrapperAck)(prepared.wrapperPath);
|
|
6028
|
+
for (const line of ack.stdout.split("\n")) {
|
|
6029
|
+
if (line.trim()) messages.push(` ${line}`);
|
|
6030
|
+
}
|
|
6031
|
+
} catch (err) {
|
|
6032
|
+
return {
|
|
6033
|
+
ok: false,
|
|
6034
|
+
messages: [
|
|
6035
|
+
...messages,
|
|
6036
|
+
`The re-acknowledgement failed: ${err instanceof Error ? err.message : String(err)} \u2014 consent was NOT written; the runtime config was not rewritten.`
|
|
6037
|
+
]
|
|
6038
|
+
};
|
|
6039
|
+
}
|
|
6040
|
+
const after = await getLocalSignerConsentStatus(signerPath);
|
|
6041
|
+
if (!after.acknowledged) {
|
|
6042
|
+
return {
|
|
6043
|
+
ok: false,
|
|
6044
|
+
messages: [
|
|
6045
|
+
...messages,
|
|
6046
|
+
`Consent still does not match after the re-acknowledgement (${after.reason ?? after.error}). The runtime config was not rewritten.`
|
|
6047
|
+
]
|
|
6048
|
+
};
|
|
6049
|
+
}
|
|
6050
|
+
messages.push("Local-tools consent acknowledged for the installed signer.");
|
|
6051
|
+
}
|
|
5789
6052
|
const configResult = await writeRuntimeConfig({
|
|
5790
6053
|
// Normalized for the WRITE too (#3145 review round 3): `writeRuntimeConfig`
|
|
5791
6054
|
// switches on the id, and the raw alias fell to its "manual runtime" arm
|
|
@@ -6005,6 +6268,11 @@ function parseArgs(argv, env = process.env) {
|
|
|
6005
6268
|
"--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."
|
|
6006
6269
|
);
|
|
6007
6270
|
}
|
|
6271
|
+
if (options.ackLocalTools && !repair) {
|
|
6272
|
+
throw new Error(
|
|
6273
|
+
"--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"
|
|
6274
|
+
);
|
|
6275
|
+
}
|
|
6008
6276
|
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
6009
6277
|
}
|
|
6010
6278
|
if (!options.setupToken) {
|
|
@@ -6056,7 +6324,9 @@ function helpText() {
|
|
|
6056
6324
|
" agents can run side by side in one runtime. 1-32 lowercase letters, digits,",
|
|
6057
6325
|
" single hyphens; immutable once wired. Without it the pair is named from the",
|
|
6058
6326
|
" agent's display name; --bare wires the bare haven / haven-signer pair.",
|
|
6059
|
-
" --ack-local-tools Write the
|
|
6327
|
+
" --ack-local-tools Write the local Haven tools acknowledgement: during setup, or (with --repair)",
|
|
6328
|
+
" re-acknowledge consent for the signer the repair installs \u2014 no setup token.",
|
|
6329
|
+
" With a bare --doctor it is refused: --doctor is read-only.",
|
|
6060
6330
|
" --ack-signer Backward-compatible alias for --ack-local-tools.",
|
|
6061
6331
|
" --local Advanced: install the fully-local Haven MCP (no hosted dependency).",
|
|
6062
6332
|
" Only available for Claude Code and Codex. Default is hosted MCP + local signer.",
|
|
@@ -6065,10 +6335,13 @@ function helpText() {
|
|
|
6065
6335
|
" signer runtime, hosted MCP, and a live signer handshake. Exits non-zero only on a failed check; an advisory (!) exits 0.",
|
|
6066
6336
|
" --runtime is optional: without it the doctor checks the runtime the setup recorded,",
|
|
6067
6337
|
" and reports a failure (not a pass) when no record names one.",
|
|
6338
|
+
" --name <slug> selects the agent directory by its recorded MCP pair.",
|
|
6068
6339
|
" --repair Repair, then re-diagnose (implies --doctor): reinstall the pinned signer",
|
|
6069
6340
|
" runtime, rewrite the wrapper and runtime config from stored credentials.",
|
|
6070
6341
|
" Hosted topology only (refuses to touch a --local config). No keys, no token.",
|
|
6071
6342
|
" Requires --runtime <runtime>: it rewrites that config, so the runtime is never inherited.",
|
|
6343
|
+
" --name <slug> selects the agent to repair by its recorded pair; --ack-local-tools",
|
|
6344
|
+
" re-consents the installed signer (the old token-free path: <agent dir>/bin/haven-signer.mjs --ack).",
|
|
6072
6345
|
" --rekey Replace this agent's signing key (no token). Generates a fresh keypair HERE and",
|
|
6073
6346
|
" prints its public address to paste into the Haven agent page. Nothing changes",
|
|
6074
6347
|
" until you finish; the agent keeps working on its old key throughout.",
|
|
@@ -6229,11 +6502,12 @@ async function runCli(argv, io = {
|
|
|
6229
6502
|
if (parsed.unwire) {
|
|
6230
6503
|
const { unwireAgent: unwireAgent2 } = await Promise.resolve().then(() => (init_unwire(), unwire_exports));
|
|
6231
6504
|
const { tombstonesDirForAgentDirectory: tombstonesDirForAgentDirectory2 } = await Promise.resolve().then(() => (init_tombstone(), tombstone_exports));
|
|
6505
|
+
const { resolveAgentDirectoryBySlug: resolveAgentDirectoryBySlug2 } = await Promise.resolve().then(() => (init_storage(), storage_exports));
|
|
6232
6506
|
const { homedir: homedir11 } = await import('os');
|
|
6233
6507
|
const { join: join13 } = await import('path');
|
|
6234
6508
|
const homeDir = homedir11();
|
|
6235
6509
|
const root = parsed.options.credentialsDir ?? join13(homeDir, ".haven", "agents");
|
|
6236
|
-
const directory = parsed.unwireDir ?? (parsed.options.serverName ?
|
|
6510
|
+
const directory = parsed.unwireDir ?? (parsed.options.serverName ? await resolveAgentDirectoryBySlug2(parsed.options.serverName, { root, allowRetired: true }) : root);
|
|
6237
6511
|
const ledgerDir = tombstonesDirForAgentDirectory2(directory, homeDir);
|
|
6238
6512
|
try {
|
|
6239
6513
|
const result = await unwireAgent2({
|
|
@@ -6435,14 +6709,16 @@ async function runCli(argv, io = {
|
|
|
6435
6709
|
const { runDoctor: runDoctor2, runRepair: runRepair2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
6436
6710
|
const runtime = parsed.options.runtime ?? "";
|
|
6437
6711
|
const credentialsDir = parsed.options.credentialsDir;
|
|
6712
|
+
const serverName = parsed.options.serverName;
|
|
6713
|
+
const ackLocalTools = parsed.options.ackLocalTools === true;
|
|
6438
6714
|
try {
|
|
6439
6715
|
if (parsed.repair) {
|
|
6440
|
-
const repair = await runRepair2({ runtime, credentialsDir });
|
|
6716
|
+
const repair = await runRepair2({ runtime, credentialsDir, serverName, ackLocalTools });
|
|
6441
6717
|
for (const message of repair.messages) io.stderr(`${redactSecrets(message)}
|
|
6442
6718
|
`);
|
|
6443
6719
|
if (!repair.ok) return 1;
|
|
6444
6720
|
}
|
|
6445
|
-
const report = await runDoctor2({ runtime, credentialsDir });
|
|
6721
|
+
const report = await runDoctor2({ runtime, credentialsDir, serverName });
|
|
6446
6722
|
if (parsed.json) {
|
|
6447
6723
|
io.stdout(`${redactSecrets(JSON.stringify(report))}
|
|
6448
6724
|
`);
|
|
@@ -6454,13 +6730,16 @@ async function runCli(argv, io = {
|
|
|
6454
6730
|
`));
|
|
6455
6731
|
}
|
|
6456
6732
|
const otherAgents = report.agents.filter((agent) => agent.directory !== report.credentialDirectory);
|
|
6733
|
+
const wiringUnverifiable = report.checks.some(
|
|
6734
|
+
(check) => check.id === "superseded_agents" && check.level === "advisory"
|
|
6735
|
+
);
|
|
6457
6736
|
if (otherAgents.length > 0) {
|
|
6458
6737
|
io.stdout("\nOther agents on this machine:\n");
|
|
6459
6738
|
for (const agent of otherAgents) {
|
|
6460
6739
|
const name = agent.slug ? `${agent.slug} (${agent.agentId ?? "unknown"})` : agent.agentId ?? "unknown";
|
|
6461
6740
|
const failed = agent.checks.filter((check) => check.level === "failed");
|
|
6462
6741
|
const advised = agent.checks.filter((check) => check.level === "advisory");
|
|
6463
|
-
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;
|
|
6742
|
+
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;
|
|
6464
6743
|
io.stdout(redactSecrets(` ${failed.length > 0 ? "\u2717" : advised.length > 0 ? "!" : "\u2022"} ${name}: ${verdict}
|
|
6465
6744
|
`));
|
|
6466
6745
|
for (const check of [...failed, ...advised]) {
|