@haven_ai/connect 0.1.29-alpha.0 → 0.1.30-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 +92 -4
- package/dist/cli.cjs +2290 -1621
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2273 -1604
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2293 -1620
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -4
- package/dist/index.d.ts +50 -4
- package/dist/index.js +2299 -1626
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { mkdir, rm, stat, readdir, readFile, chmod, access, writeFile, unlink } from 'fs/promises';
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { Wallet } from 'ethers';
|
|
3
|
+
import { mkdir, rm, stat, readdir, readFile, chmod, access, writeFile, unlink, rename } from 'fs/promises';
|
|
5
4
|
import { homedir, platform } from 'os';
|
|
6
5
|
import { join, resolve, dirname, basename } from 'path';
|
|
6
|
+
import { ensureConsent, computeConsentHash, loadCredentials, consentInputFromClient, registeredToolNames, MCP_VERSION } from '@haven_ai/mcp';
|
|
7
|
+
import { ensureSignerConsent, computeSignerConsentHash, loadSignerCredentials, createEdgeSigner, toolSchemas } from '@haven_ai/signer';
|
|
8
|
+
import { isSupportedNodeVersion, SKILL_FOLDER_NAME, resolveTokenFromAddress, HAVEN_SKILL_MD, HAVEN_SKILL_BODY_MD, HAVEN_MINIMUM_NODE_VERSION, unsupportedNodeVersionMessage } from '@haven_ai/sdk';
|
|
7
9
|
import { parseDocument, isMap, stringify } from 'yaml';
|
|
8
|
-
import {
|
|
10
|
+
import { spawn, execFile } from 'child_process';
|
|
9
11
|
import { promisify } from 'util';
|
|
10
|
-
import crypto from 'crypto';
|
|
11
|
-
import { Wallet } from 'ethers';
|
|
12
12
|
import { createInterface } from 'readline';
|
|
13
13
|
import { realpathSync } from 'fs';
|
|
14
14
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
@@ -23,6 +23,125 @@ var __export = (target, all) => {
|
|
|
23
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
// src/api.ts
|
|
27
|
+
function createConnectApiClient(baseUrl, fetchImpl = fetch) {
|
|
28
|
+
const root = baseUrl.replace(/\/+$/, "");
|
|
29
|
+
return {
|
|
30
|
+
resolveSetup: (input) => request(fetchImpl, `${root}/agent-connection-setups/resolve`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
setup_token: input.setupToken,
|
|
34
|
+
connector_version: input.connectorVersion,
|
|
35
|
+
runtime: input.runtime
|
|
36
|
+
})
|
|
37
|
+
}),
|
|
38
|
+
registerSetup: (input) => request(fetchImpl, `${root}/agent-connection-setups/register`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
setup_token: input.setupToken,
|
|
42
|
+
challenge_id: input.challengeId,
|
|
43
|
+
delegate_address: input.delegateAddress,
|
|
44
|
+
proof_signature: input.proofSignature,
|
|
45
|
+
api_key_hash: input.apiKeyHash,
|
|
46
|
+
api_key_prefix: input.apiKeyPrefix,
|
|
47
|
+
runtime: input.runtime,
|
|
48
|
+
connector_version: input.connectorVersion,
|
|
49
|
+
mcp_server_name: input.mcpServerName,
|
|
50
|
+
connector_context: input.connectorContext,
|
|
51
|
+
install_capabilities: input.installCapabilities && {
|
|
52
|
+
can_write_runtime_config: input.installCapabilities.canWriteRuntimeConfig,
|
|
53
|
+
restart_required: input.installCapabilities.restartRequired
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}),
|
|
57
|
+
getAgentIdentity: (apiKey) => request(fetchImpl, `${root}/machine-payments/agent`, {
|
|
58
|
+
method: "GET",
|
|
59
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
60
|
+
}),
|
|
61
|
+
getConnectorStatus: (setupId, apiKey) => request(fetchImpl, `${root}/agent-connection-setups/${encodeURIComponent(setupId)}/connector-status`, {
|
|
62
|
+
method: "GET",
|
|
63
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
64
|
+
}),
|
|
65
|
+
updateInstallStatus: async (setupId, apiKey, input) => {
|
|
66
|
+
await request(fetchImpl, `${root}/agent-connection-setups/${encodeURIComponent(setupId)}/install-status`, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
runtime: input.runtime,
|
|
71
|
+
connector_version: input.connectorVersion,
|
|
72
|
+
runtime_mcp_mode: input.runtimeMcpMode,
|
|
73
|
+
hosted_mcp_configured: input.hostedMcpConfigured,
|
|
74
|
+
local_signer_configured: input.localSignerConfigured,
|
|
75
|
+
local_mcp_configured: input.localMcpConfigured,
|
|
76
|
+
credential_files_written: input.credentialFilesWritten,
|
|
77
|
+
signer_acknowledged: input.signerAcknowledged,
|
|
78
|
+
local_mcp_acknowledged: input.localMcpAcknowledged,
|
|
79
|
+
activation_command_available: input.activationCommandAvailable,
|
|
80
|
+
skill_installed: input.skillInstalled,
|
|
81
|
+
probe_result: input.probeResult,
|
|
82
|
+
restart_required: input.restartRequired,
|
|
83
|
+
next_user_action: input.nextUserAction,
|
|
84
|
+
error_code: input.errorCode ?? null,
|
|
85
|
+
environment_label: input.environmentLabel
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function request(fetchImpl, url, init) {
|
|
92
|
+
const response = await fetchImpl(url, {
|
|
93
|
+
...init,
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
...init.headers ?? {}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const text = await response.text();
|
|
100
|
+
const body = text ? JSON.parse(text) : null;
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
const message = body?.error ?? body?.message ?? `${response.status} ${response.statusText}`;
|
|
103
|
+
throw new ConnectRequestError(`Haven setup request failed: ${message}`, response.status);
|
|
104
|
+
}
|
|
105
|
+
return body;
|
|
106
|
+
}
|
|
107
|
+
var ConnectRequestError;
|
|
108
|
+
var init_api = __esm({
|
|
109
|
+
"src/api.ts"() {
|
|
110
|
+
ConnectRequestError = class extends Error {
|
|
111
|
+
constructor(message, status) {
|
|
112
|
+
super(message);
|
|
113
|
+
this.status = status;
|
|
114
|
+
this.name = "ConnectRequestError";
|
|
115
|
+
}
|
|
116
|
+
status;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
function generateDelegateKey() {
|
|
121
|
+
return delegateKeyFromPrivateKey(Wallet.createRandom().privateKey);
|
|
122
|
+
}
|
|
123
|
+
function delegateKeyFromPrivateKey(privateKey) {
|
|
124
|
+
const wallet = new Wallet(privateKey);
|
|
125
|
+
return {
|
|
126
|
+
privateKey: wallet.privateKey,
|
|
127
|
+
address: wallet.address,
|
|
128
|
+
signChallenge: (message) => wallet.signMessage(message)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function generateAgentApiKey() {
|
|
132
|
+
return `sk_agent_${crypto.randomBytes(24).toString("hex")}`;
|
|
133
|
+
}
|
|
134
|
+
function hashAgentApiKey(apiKey) {
|
|
135
|
+
return crypto.createHash("sha256").update(apiKey).digest("hex");
|
|
136
|
+
}
|
|
137
|
+
function agentApiKeyPrefix(apiKey) {
|
|
138
|
+
return apiKey.slice(0, 12);
|
|
139
|
+
}
|
|
140
|
+
var init_key = __esm({
|
|
141
|
+
"src/key.ts"() {
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
26
145
|
// src/redact.ts
|
|
27
146
|
function redactSecrets(value) {
|
|
28
147
|
return value.replace(API_KEY_RE, "sk_agent_[redacted]").replace(PRIVATE_KEY_RE, "0x[redacted-private-key]");
|
|
@@ -85,121 +204,417 @@ var init_server_names = __esm({
|
|
|
85
204
|
SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
86
205
|
}
|
|
87
206
|
});
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
207
|
+
async function preflightCredentialStorage(input = {}) {
|
|
208
|
+
const directory = defaultCredentialRoot(input.baseDir);
|
|
209
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
210
|
+
await restrictPermissions(directory, 448, input.warn);
|
|
211
|
+
const probePath = join(directory, `.haven-connect-preflight-${crypto.randomBytes(8).toString("hex")}`);
|
|
212
|
+
try {
|
|
213
|
+
await writeOwnerOnlyJson(probePath, { ok: true }, input.warn);
|
|
214
|
+
} finally {
|
|
215
|
+
await rm(probePath, { force: true }).catch(() => void 0);
|
|
216
|
+
}
|
|
217
|
+
return directory;
|
|
96
218
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
minimumNodeVersion: HAVEN_MINIMUM_NODE_VERSION,
|
|
114
|
-
supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
|
|
115
|
-
requiredTools: registeredToolNames(),
|
|
116
|
-
/**
|
|
117
|
-
* The signer MCP's tool surface, DERIVED from the pinned @haven_ai/signer
|
|
118
|
-
* package (#1587) — same anti-drift rule as `requiredTools` above: a
|
|
119
|
-
* literal list here would rot the first time the signer gains a tool.
|
|
120
|
-
* The handshake probe requires all of them.
|
|
121
|
-
*/
|
|
122
|
-
requiredSignerTools: Object.keys(toolSchemas)
|
|
123
|
-
};
|
|
219
|
+
async function writeCredentialFiles(input) {
|
|
220
|
+
const directory = defaultAgentDirectory(input.serverName ?? input.agentId, input.baseDir);
|
|
221
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
222
|
+
await restrictPermissions(directory, 448, input.warn);
|
|
223
|
+
const identityPath = join(directory, "identity.json");
|
|
224
|
+
const signerPath = join(directory, "signer.json");
|
|
225
|
+
const agentPath = join(directory, "agent.json");
|
|
226
|
+
await assertDoesNotExist(identityPath);
|
|
227
|
+
await assertDoesNotExist(signerPath);
|
|
228
|
+
await assertDoesNotExist(agentPath);
|
|
229
|
+
await writeOwnerOnlyJson(signerPath, signerPayload(input), input.warn);
|
|
230
|
+
try {
|
|
231
|
+
await writeOwnerOnlyJson(identityPath, identityPayload(input), input.warn);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
await rm(signerPath, { force: true }).catch(() => void 0);
|
|
234
|
+
throw err;
|
|
124
235
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return writeJsonRuntimeConfig(input, cursorConfigPath(input.homeDir), "mcpServers");
|
|
133
|
-
case "vscode":
|
|
134
|
-
return writeJsonRuntimeConfig(input, vscodeConfigPath(input.homeDir), "servers");
|
|
135
|
-
case "vscode-insiders":
|
|
136
|
-
return writeJsonRuntimeConfig(input, vscodeInsidersConfigPath(input.homeDir), "servers");
|
|
137
|
-
case "claude-desktop":
|
|
138
|
-
return writeJsonRuntimeConfig(input, claudeDesktopConfigPath(input.homeDir), "mcpServers");
|
|
139
|
-
case "hermes":
|
|
140
|
-
return writeHermesConfig(input, deps);
|
|
141
|
-
default:
|
|
142
|
-
return {
|
|
143
|
-
hostedConfigured: false,
|
|
144
|
-
signerConfigured: false,
|
|
145
|
-
localMcpConfigured: false,
|
|
146
|
-
runtimeMcpMode: "manual",
|
|
147
|
-
target: "manual runtime setup",
|
|
148
|
-
changed: false,
|
|
149
|
-
restartRequired: true,
|
|
150
|
-
messages: ["Runtime config needs to be added manually for this agent environment."],
|
|
151
|
-
errorCode: "manual_runtime_setup_required"
|
|
152
|
-
};
|
|
236
|
+
try {
|
|
237
|
+
await writeOwnerOnlyJson(agentPath, agentPayload(input), input.warn);
|
|
238
|
+
} catch (err) {
|
|
239
|
+
await rm(signerPath, { force: true }).catch(() => void 0);
|
|
240
|
+
await rm(identityPath, { force: true }).catch(() => void 0);
|
|
241
|
+
await rm(agentPath, { force: true }).catch(() => void 0);
|
|
242
|
+
throw err;
|
|
153
243
|
}
|
|
244
|
+
return { directory, identityPath, signerPath, agentPath };
|
|
154
245
|
}
|
|
155
|
-
function
|
|
156
|
-
if (runtime === "vscode" || runtime === "vscode-insiders") {
|
|
157
|
-
return {
|
|
158
|
-
type: "http",
|
|
159
|
-
url: hostedMcpUrl,
|
|
160
|
-
headers: { Authorization: `Bearer ${apiKey}` }
|
|
161
|
-
};
|
|
162
|
-
}
|
|
246
|
+
function signerPayload(input) {
|
|
163
247
|
return {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
248
|
+
delegate_key: input.delegateKey,
|
|
249
|
+
delegate_address: input.delegateAddress,
|
|
250
|
+
agent_id: input.agentId,
|
|
251
|
+
safe_address: input.safeAddress,
|
|
252
|
+
chain_id: input.chainId,
|
|
253
|
+
network: input.network,
|
|
254
|
+
x402_binding_signer: input.x402BindingSigner,
|
|
255
|
+
note: "Local signer credential. Haven backend never receives this private key."
|
|
172
256
|
};
|
|
173
257
|
}
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
258
|
+
function identityPayload(input) {
|
|
259
|
+
return {
|
|
260
|
+
api_key: input.apiKey,
|
|
261
|
+
agent_id: input.agentId,
|
|
262
|
+
safe_address: input.safeAddress,
|
|
263
|
+
chain_id: input.chainId,
|
|
264
|
+
network: input.network,
|
|
265
|
+
api_url: input.apiUrl,
|
|
266
|
+
hosted_mcp_url: input.hostedMcpUrl,
|
|
267
|
+
agent_budget: input.agentBudget,
|
|
268
|
+
note: "Haven API key identifies the agent only. It cannot spend without the local signer key and on-chain Haven wallet rules."
|
|
178
269
|
};
|
|
179
|
-
if (runtime === "vscode" || runtime === "vscode-insiders") return { type: "stdio", ...server };
|
|
180
|
-
return server;
|
|
181
270
|
}
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
271
|
+
function agentPayload(input) {
|
|
272
|
+
return {
|
|
273
|
+
agent_id: input.agentId,
|
|
274
|
+
delegate_address: input.delegateAddress,
|
|
275
|
+
safe_address: input.safeAddress,
|
|
276
|
+
chain_id: input.chainId,
|
|
277
|
+
network: input.network,
|
|
278
|
+
agent_budget: input.agentBudget,
|
|
279
|
+
note: "Non-secret orientation for the agent: public delegate/Haven wallet identity + configured budget. Contains no API key or signing key. For the live remaining budget, call haven_get_allowances."
|
|
190
280
|
};
|
|
191
|
-
return `${JSON.stringify(config, null, 2)}
|
|
192
|
-
`;
|
|
193
281
|
}
|
|
194
|
-
function
|
|
195
|
-
|
|
196
|
-
|
|
282
|
+
async function readStoredCredentials(serverName, agentIdOrSlug, baseDir) {
|
|
283
|
+
const key = serverName ?? agentIdOrSlug;
|
|
284
|
+
const directory = key ? defaultAgentDirectory(key, baseDir) : await discoverSoleAgentDirectory(baseDir);
|
|
285
|
+
const identity = await readJsonFile(join(directory, "identity.json"));
|
|
286
|
+
if (!identity) {
|
|
287
|
+
throw new Error(
|
|
288
|
+
`No Haven credentials at ${directory}. Nothing to re-key \u2014 connect this agent first, or pass the --name you wired it under.`
|
|
289
|
+
);
|
|
197
290
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
291
|
+
const agent = await readJsonFile(join(directory, "agent.json")) ?? {};
|
|
292
|
+
const signer = await readJsonFile(join(directory, "signer.json")) ?? {};
|
|
293
|
+
const agentId = asString(identity.agent_id);
|
|
294
|
+
const apiKey = asString(identity.api_key);
|
|
295
|
+
const apiUrl = asString(identity.api_url);
|
|
296
|
+
const hostedMcpUrl = asString(identity.hosted_mcp_url);
|
|
297
|
+
if (!agentId || !apiKey || !apiUrl || !hostedMcpUrl) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
`The credential set at ${directory} is incomplete (identity.json is missing agent_id, api_key, api_url or hosted_mcp_url). Re-key cannot rebuild it \u2014 reconnect the agent instead.`
|
|
300
|
+
);
|
|
201
301
|
}
|
|
202
|
-
|
|
302
|
+
return {
|
|
303
|
+
directory,
|
|
304
|
+
agentId,
|
|
305
|
+
apiKey,
|
|
306
|
+
apiUrl,
|
|
307
|
+
hostedMcpUrl,
|
|
308
|
+
delegateAddress: asString(agent.delegate_address) ?? asString(signer.delegate_address),
|
|
309
|
+
safeAddress: asString(identity.safe_address) ?? asString(agent.safe_address),
|
|
310
|
+
chainId: typeof identity.chain_id === "number" ? identity.chain_id : void 0,
|
|
311
|
+
network: asString(identity.network),
|
|
312
|
+
x402BindingSigner: asString(signer.x402_binding_signer),
|
|
313
|
+
agentBudget: Array.isArray(identity.agent_budget) ? identity.agent_budget : void 0
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
async function discoverSoleAgentDirectory(baseDir) {
|
|
317
|
+
const root = defaultCredentialRoot(baseDir);
|
|
318
|
+
let entries = [];
|
|
319
|
+
try {
|
|
320
|
+
entries = await readdir(root);
|
|
321
|
+
} catch {
|
|
322
|
+
throw new Error(`No Haven credentials found under ${root}. Connect an agent on this machine first.`);
|
|
323
|
+
}
|
|
324
|
+
const candidates = [];
|
|
325
|
+
for (const entry of entries) {
|
|
326
|
+
const directory = join(root, entry);
|
|
327
|
+
if (!await readJsonFile(join(directory, "identity.json"))) continue;
|
|
328
|
+
if (await readJsonFile(join(directory, "TOMBSTONE.json"))) continue;
|
|
329
|
+
candidates.push(directory);
|
|
330
|
+
}
|
|
331
|
+
if (candidates.length === 1) return candidates[0];
|
|
332
|
+
if (candidates.length === 0) {
|
|
333
|
+
throw new Error(`No Haven credentials found under ${root}. Connect an agent on this machine first.`);
|
|
334
|
+
}
|
|
335
|
+
throw new Error(
|
|
336
|
+
`Several agents are wired on this machine, so --rekey cannot tell which one you mean:
|
|
337
|
+
` + candidates.map((d) => ` ${d}`).join("\n") + "\nRe-run with --name <slug> to pick one."
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
async function rewriteCredentialFiles(input) {
|
|
341
|
+
const directory = defaultAgentDirectory(input.serverName ?? input.agentId, input.baseDir);
|
|
342
|
+
const identityPath = join(directory, "identity.json");
|
|
343
|
+
const signerPath = join(directory, "signer.json");
|
|
344
|
+
const agentPath = join(directory, "agent.json");
|
|
345
|
+
const targets = [
|
|
346
|
+
{ path: signerPath, payload: signerPayload(input) },
|
|
347
|
+
{ path: identityPath, payload: identityPayload(input) },
|
|
348
|
+
{ path: agentPath, payload: agentPayload(input) }
|
|
349
|
+
];
|
|
350
|
+
const originals = /* @__PURE__ */ new Map();
|
|
351
|
+
for (const { path } of targets) {
|
|
352
|
+
originals.set(path, await readRawFile(path));
|
|
353
|
+
}
|
|
354
|
+
const temps = [];
|
|
355
|
+
try {
|
|
356
|
+
for (const { path, payload } of targets) {
|
|
357
|
+
const temp = `${path}.rekey-${crypto.randomBytes(6).toString("hex")}.tmp`;
|
|
358
|
+
await writeOwnerOnlyJson(temp, payload, input.warn);
|
|
359
|
+
temps.push({ from: temp, to: path });
|
|
360
|
+
}
|
|
361
|
+
for (const { from, to } of temps) {
|
|
362
|
+
await rename(from, to);
|
|
363
|
+
}
|
|
364
|
+
} catch (err) {
|
|
365
|
+
for (const { from } of temps) await rm(from, { force: true }).catch(() => void 0);
|
|
366
|
+
for (const [path, contents] of originals) {
|
|
367
|
+
if (contents === null) {
|
|
368
|
+
await rm(path, { force: true }).catch(() => void 0);
|
|
369
|
+
} else {
|
|
370
|
+
await writeFile(path, contents, { mode: 384 }).catch(() => void 0);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
throw err;
|
|
374
|
+
}
|
|
375
|
+
return { directory, identityPath, signerPath, agentPath };
|
|
376
|
+
}
|
|
377
|
+
async function writeRekeyPending(directory, pending, warn) {
|
|
378
|
+
const path = join(directory, REKEY_PENDING_FILENAME);
|
|
379
|
+
await rm(path, { force: true }).catch(() => void 0);
|
|
380
|
+
await writeOwnerOnlyJson(path, { ...pending }, warn);
|
|
381
|
+
return path;
|
|
382
|
+
}
|
|
383
|
+
async function readRekeyPending(directory, now = Date.now()) {
|
|
384
|
+
const path = join(directory, REKEY_PENDING_FILENAME);
|
|
385
|
+
const raw = await readJsonFile(path);
|
|
386
|
+
if (!raw) {
|
|
387
|
+
throw new Error(
|
|
388
|
+
`No re-key in progress at ${directory}. Run the connector with --rekey first \u2014 it prints the new signing address to paste into the Haven agent page.`
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
const pending = raw;
|
|
392
|
+
if (!pending.new_delegate_key || !pending.new_delegate_address || !pending.agent_id) {
|
|
393
|
+
throw new Error(`The pending re-key at ${path} is unreadable. Delete it and start again with --rekey.`);
|
|
394
|
+
}
|
|
395
|
+
if (pending.expires_at && Date.parse(pending.expires_at) < now) {
|
|
396
|
+
throw new Error(
|
|
397
|
+
`The re-key started at ${pending.started_at} has expired. Start again with --rekey \u2014 the address currently shown in your dashboard is no longer the one this machine holds.`
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
return pending;
|
|
401
|
+
}
|
|
402
|
+
async function inspectRekeyPending(directory, now = Date.now()) {
|
|
403
|
+
const path = join(directory, REKEY_PENDING_FILENAME);
|
|
404
|
+
const raw = await readJsonFile(path);
|
|
405
|
+
if (!raw) {
|
|
406
|
+
const present = await readRawFile(path) !== null;
|
|
407
|
+
return present ? { state: "unreadable", path } : null;
|
|
408
|
+
}
|
|
409
|
+
const agentId = asString(raw.agent_id);
|
|
410
|
+
const newDelegateAddress = asString(raw.new_delegate_address);
|
|
411
|
+
const startedAt = asString(raw.started_at);
|
|
412
|
+
const expiresAt = asString(raw.expires_at);
|
|
413
|
+
if (!agentId || !newDelegateAddress) {
|
|
414
|
+
return { state: "unreadable", path, ...startedAt ? { startedAt } : {} };
|
|
415
|
+
}
|
|
416
|
+
const expired = expiresAt !== void 0 && Date.parse(expiresAt) < now;
|
|
417
|
+
return {
|
|
418
|
+
state: expired ? "expired" : "pending",
|
|
419
|
+
path,
|
|
420
|
+
agentId,
|
|
421
|
+
newDelegateAddress,
|
|
422
|
+
...startedAt ? { startedAt } : {},
|
|
423
|
+
...expiresAt ? { expiresAt } : {}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
async function clearRekeyPending(directory) {
|
|
427
|
+
await rm(join(directory, REKEY_PENDING_FILENAME), { force: true }).catch(() => void 0);
|
|
428
|
+
}
|
|
429
|
+
async function readJsonFile(path) {
|
|
430
|
+
const raw = await readRawFile(path);
|
|
431
|
+
if (raw === null) return null;
|
|
432
|
+
try {
|
|
433
|
+
const parsed = JSON.parse(raw);
|
|
434
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
435
|
+
} catch {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
async function readRawFile(path) {
|
|
440
|
+
try {
|
|
441
|
+
return await readFile(path, "utf8");
|
|
442
|
+
} catch {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function asString(value) {
|
|
447
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
448
|
+
}
|
|
449
|
+
async function assertServerSlugAvailable(serverName, baseDir) {
|
|
450
|
+
const directory = defaultAgentDirectory(serverName, baseDir);
|
|
451
|
+
try {
|
|
452
|
+
await stat(join(directory, "identity.json"));
|
|
453
|
+
} catch {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
throw new Error(
|
|
457
|
+
`The name "${serverName}" is already wired on this machine (${directory} holds credentials). Pick a different --name, or revoke and remove that agent first \u2014 connect never overwrites credentials.`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
function defaultAgentDirectory(agentId, baseDir = join(homedir(), ".haven", "agents")) {
|
|
461
|
+
return resolve(defaultCredentialRoot(baseDir), safePathPart(agentId));
|
|
462
|
+
}
|
|
463
|
+
function defaultCredentialRoot(baseDir = join(homedir(), ".haven", "agents")) {
|
|
464
|
+
return resolve(baseDir);
|
|
465
|
+
}
|
|
466
|
+
async function writeOwnerOnlyJson(path, value, warn) {
|
|
467
|
+
const json = JSON.stringify(dropUndefined(value), null, 2);
|
|
468
|
+
await writeFile(path, `${json}
|
|
469
|
+
`, { mode: 384, flag: "wx" });
|
|
470
|
+
await restrictPermissions(path, 384, warn);
|
|
471
|
+
}
|
|
472
|
+
function safePathPart(value) {
|
|
473
|
+
return value.replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
474
|
+
}
|
|
475
|
+
function dropUndefined(value) {
|
|
476
|
+
return Object.fromEntries(Object.entries(value).filter(([, field]) => field !== void 0));
|
|
477
|
+
}
|
|
478
|
+
async function assertDoesNotExist(path) {
|
|
479
|
+
try {
|
|
480
|
+
await access(path);
|
|
481
|
+
} catch (err) {
|
|
482
|
+
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") return;
|
|
483
|
+
throw err;
|
|
484
|
+
}
|
|
485
|
+
throw new Error(`Refusing to overwrite existing Haven credential file: ${path}`);
|
|
486
|
+
}
|
|
487
|
+
async function restrictPermissions(path, mode, warn) {
|
|
488
|
+
try {
|
|
489
|
+
await chmod(path, mode);
|
|
490
|
+
} catch (err) {
|
|
491
|
+
warn?.(
|
|
492
|
+
`Warning: could not restrict permissions on ${path} to ${mode.toString(8)}. Move this credential to a private location or run chmod ${mode.toString(8)} ${path}. ${err instanceof Error ? err.message : String(err)}`
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
var REKEY_PENDING_FILENAME, REKEY_PENDING_TTL_MS;
|
|
497
|
+
var init_storage = __esm({
|
|
498
|
+
"src/storage.ts"() {
|
|
499
|
+
REKEY_PENDING_FILENAME = "rekey-pending.json";
|
|
500
|
+
REKEY_PENDING_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
function mcpPackageSpec() {
|
|
504
|
+
return `${MCP_RUNTIME_MANIFEST.mcpPackage}@${MCP_RUNTIME_MANIFEST.mcpVersion}`;
|
|
505
|
+
}
|
|
506
|
+
function sdkPackageSpec() {
|
|
507
|
+
return `${MCP_RUNTIME_MANIFEST.sdkPackage}@${MCP_RUNTIME_MANIFEST.sdkVersion}`;
|
|
508
|
+
}
|
|
509
|
+
function signerPackageSpec() {
|
|
510
|
+
return `${MCP_RUNTIME_MANIFEST.signerPackage}@${MCP_RUNTIME_MANIFEST.signerVersion}`;
|
|
511
|
+
}
|
|
512
|
+
var MCP_RUNTIME_MANIFEST;
|
|
513
|
+
var init_runtime_manifest = __esm({
|
|
514
|
+
"src/runtime-manifest.ts"() {
|
|
515
|
+
MCP_RUNTIME_MANIFEST = {
|
|
516
|
+
mcpPackage: "@haven_ai/mcp",
|
|
517
|
+
mcpVersion: MCP_VERSION,
|
|
518
|
+
sdkPackage: "@haven_ai/sdk",
|
|
519
|
+
sdkVersion: "0.1.30-alpha.0",
|
|
520
|
+
signerPackage: "@haven_ai/signer",
|
|
521
|
+
signerVersion: "0.1.30-alpha.0",
|
|
522
|
+
// Sourced from the SDK, never a literal (#1161). This field read '20.0.0'
|
|
523
|
+
// while every package's `engines` said `>=24` and the docs said `>=24.0.0`,
|
|
524
|
+
// so the guard that was supposed to enforce the floor waved Node v23 through
|
|
525
|
+
// — including on the `--local` path where it does run. A hand-maintained
|
|
526
|
+
// second copy of a number is a drift waiting to happen; a guard test pins
|
|
527
|
+
// this against `package.json`'s `engines.node`.
|
|
528
|
+
minimumNodeVersion: HAVEN_MINIMUM_NODE_VERSION,
|
|
529
|
+
supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
|
|
530
|
+
requiredTools: registeredToolNames(),
|
|
531
|
+
/**
|
|
532
|
+
* The signer MCP's tool surface, DERIVED from the pinned @haven_ai/signer
|
|
533
|
+
* package (#1587) — same anti-drift rule as `requiredTools` above: a
|
|
534
|
+
* literal list here would rot the first time the signer gains a tool.
|
|
535
|
+
* The handshake probe requires all of them.
|
|
536
|
+
*/
|
|
537
|
+
requiredSignerTools: Object.keys(toolSchemas)
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
async function writeRuntimeConfig(input, deps = {}) {
|
|
542
|
+
switch (input.runtime) {
|
|
543
|
+
case "codex-cli":
|
|
544
|
+
case "codex-desktop":
|
|
545
|
+
return writeCodexConfig(input);
|
|
546
|
+
case "cursor":
|
|
547
|
+
return writeJsonRuntimeConfig(input, cursorConfigPath(input.homeDir), "mcpServers");
|
|
548
|
+
case "vscode":
|
|
549
|
+
return writeJsonRuntimeConfig(input, vscodeConfigPath(input.homeDir), "servers");
|
|
550
|
+
case "vscode-insiders":
|
|
551
|
+
return writeJsonRuntimeConfig(input, vscodeInsidersConfigPath(input.homeDir), "servers");
|
|
552
|
+
case "claude-desktop":
|
|
553
|
+
return writeJsonRuntimeConfig(input, claudeDesktopConfigPath(input.homeDir), "mcpServers");
|
|
554
|
+
case "hermes":
|
|
555
|
+
return writeHermesConfig(input, deps);
|
|
556
|
+
default:
|
|
557
|
+
return {
|
|
558
|
+
hostedConfigured: false,
|
|
559
|
+
signerConfigured: false,
|
|
560
|
+
localMcpConfigured: false,
|
|
561
|
+
runtimeMcpMode: "manual",
|
|
562
|
+
target: "manual runtime setup",
|
|
563
|
+
changed: false,
|
|
564
|
+
restartRequired: true,
|
|
565
|
+
messages: ["Runtime config needs to be added manually for this agent environment."],
|
|
566
|
+
errorCode: "manual_runtime_setup_required"
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function buildHostedServer(hostedMcpUrl, apiKey, runtime) {
|
|
571
|
+
if (runtime === "vscode" || runtime === "vscode-insiders") {
|
|
572
|
+
return {
|
|
573
|
+
type: "http",
|
|
574
|
+
url: hostedMcpUrl,
|
|
575
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
url: hostedMcpUrl,
|
|
580
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function resolveSignerLaunchSpec(input) {
|
|
584
|
+
return input.signerCommand ?? {
|
|
585
|
+
command: "npx",
|
|
586
|
+
args: ["-y", signerPackageSpec(), "--credentials", input.signerPath]
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function buildSignerServer(spec, runtime) {
|
|
590
|
+
const server = {
|
|
591
|
+
command: spec.command,
|
|
592
|
+
args: spec.args
|
|
593
|
+
};
|
|
594
|
+
if (runtime === "vscode" || runtime === "vscode-insiders") return { type: "stdio", ...server };
|
|
595
|
+
return server;
|
|
596
|
+
}
|
|
597
|
+
function mergeJsonMcpConfig(existingJson, serverRoot, hostedServer, signerServer, names = serverNamesFor(), configPath) {
|
|
598
|
+
const config = existingJson?.trim() ? parseJsonObject(existingJson, configPath) : {};
|
|
599
|
+
const existingRoot = config[serverRoot];
|
|
600
|
+
const servers = existingRoot && typeof existingRoot === "object" && !Array.isArray(existingRoot) ? existingRoot : {};
|
|
601
|
+
config[serverRoot] = {
|
|
602
|
+
...servers,
|
|
603
|
+
[names.hosted]: hostedServer,
|
|
604
|
+
[names.signer]: signerServer
|
|
605
|
+
};
|
|
606
|
+
return `${JSON.stringify(config, null, 2)}
|
|
607
|
+
`;
|
|
608
|
+
}
|
|
609
|
+
function mergeHermesYaml(existingYaml, hostedServer, signerServer, names = serverNamesFor(), configPath) {
|
|
610
|
+
if (!existingYaml?.trim()) {
|
|
611
|
+
return renderHermesYaml({ [names.hosted]: hostedServer, [names.signer]: signerServer });
|
|
612
|
+
}
|
|
613
|
+
const doc = parseDocument(existingYaml, { keepSourceTokens: true });
|
|
614
|
+
if (doc.errors.length > 0 || !isMap(doc.contents)) {
|
|
615
|
+
throw new UnreadableRuntimeConfigError(configPath ?? "the Hermes config", "it is not a YAML object");
|
|
616
|
+
}
|
|
617
|
+
const mcpPair = doc.contents.items.find((item) => item.key?.toString() === "mcp_servers");
|
|
203
618
|
const existingServers = mcpPair && isMap(mcpPair.value) ? mcpPair.value.toJSON() : {};
|
|
204
619
|
const servers = isRecord(existingServers) ? existingServers : {};
|
|
205
620
|
const mergedServers = {
|
|
@@ -844,24 +1259,104 @@ var init_config_writers = __esm({
|
|
|
844
1259
|
};
|
|
845
1260
|
}
|
|
846
1261
|
});
|
|
847
|
-
async function
|
|
848
|
-
let response;
|
|
1262
|
+
async function acknowledgeLocalMcpConsent(identityPath, signerPath, log) {
|
|
849
1263
|
try {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1264
|
+
const input = await buildLocalMcpConsentInput(identityPath, signerPath);
|
|
1265
|
+
const decision = await ensureConsent(input, {
|
|
1266
|
+
credentialsPath: identityPath,
|
|
1267
|
+
writeAck: true,
|
|
1268
|
+
out: log ? { write: (chunk) => writeLogChunk(log, chunk) } : void 0
|
|
853
1269
|
});
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
1270
|
+
return {
|
|
1271
|
+
acknowledged: decision.ok,
|
|
1272
|
+
hash: decision.hash,
|
|
1273
|
+
reason: decision.reason
|
|
1274
|
+
};
|
|
1275
|
+
} catch (err) {
|
|
1276
|
+
return {
|
|
1277
|
+
acknowledged: false,
|
|
1278
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
async function getLocalMcpConsentStatus(identityPath, signerPath) {
|
|
1283
|
+
try {
|
|
1284
|
+
const input = await buildLocalMcpConsentInput(identityPath, signerPath);
|
|
1285
|
+
const hash = computeConsentHash(input);
|
|
1286
|
+
const stored = await readLocalMcpAckFile(localMcpAckPath(identityPath));
|
|
1287
|
+
if (stored === hash) {
|
|
1288
|
+
return { acknowledged: true, hash, reason: "ack_file_match" };
|
|
1289
|
+
}
|
|
1290
|
+
return {
|
|
1291
|
+
acknowledged: false,
|
|
1292
|
+
hash,
|
|
1293
|
+
reason: stored ? "ack_file_mismatch" : "ack_file_missing"
|
|
1294
|
+
};
|
|
1295
|
+
} catch (err) {
|
|
1296
|
+
return {
|
|
1297
|
+
acknowledged: false,
|
|
1298
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function localMcpAckPath(identityPath) {
|
|
1303
|
+
return resolve(`${identityPath}.ack.json`);
|
|
1304
|
+
}
|
|
1305
|
+
async function buildLocalMcpConsentInput(identityPath, signerPath) {
|
|
1306
|
+
const credentials = await loadCredentials({ identityPath, signerPath });
|
|
1307
|
+
const unavailableDuringSetup = {
|
|
1308
|
+
getAllowances: async () => {
|
|
1309
|
+
throw new Error("Haven approval is not complete yet.");
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
return consentInputFromClient(
|
|
1313
|
+
unavailableDuringSetup,
|
|
1314
|
+
{
|
|
1315
|
+
apiKey: credentials.apiKey,
|
|
1316
|
+
apiUrl: credentials.apiUrl,
|
|
1317
|
+
agentId: credentials.agentId,
|
|
1318
|
+
safeAddress: credentials.safeAddress,
|
|
1319
|
+
delegateAddress: credentials.delegateAddress,
|
|
1320
|
+
chainId: credentials.chainId,
|
|
1321
|
+
allowanceSummary: credentials.allowanceSummary
|
|
1322
|
+
},
|
|
1323
|
+
registeredToolNames()
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
async function readLocalMcpAckFile(path) {
|
|
1327
|
+
try {
|
|
1328
|
+
const parsed = JSON.parse(await readFile(path, "utf8"));
|
|
1329
|
+
return typeof parsed.ack === "string" ? parsed.ack : null;
|
|
1330
|
+
} catch {
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
function writeLogChunk(log, chunk) {
|
|
1335
|
+
const message = String(chunk).trimEnd();
|
|
1336
|
+
if (message) log(message);
|
|
1337
|
+
}
|
|
1338
|
+
var init_local_mcp_consent = __esm({
|
|
1339
|
+
"src/local-mcp-consent.ts"() {
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
async function probeHostedAgentIdentity(apiKey, apiUrl, fetchImpl = fetch) {
|
|
1343
|
+
let response;
|
|
1344
|
+
try {
|
|
1345
|
+
response = await fetchWithTimeout(fetchImpl, `${apiUrl.replace(/\/+$/, "")}/machine-payments/agent`, {
|
|
1346
|
+
method: "GET",
|
|
1347
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" }
|
|
1348
|
+
});
|
|
1349
|
+
} catch {
|
|
1350
|
+
return { status: "network_error" };
|
|
1351
|
+
}
|
|
1352
|
+
if (response.status === 401 || response.status === 403) return { status: "unauthorized" };
|
|
1353
|
+
if (!response.ok) return { status: "bad_response" };
|
|
1354
|
+
try {
|
|
1355
|
+
const payload = JSON.parse(await response.text());
|
|
1356
|
+
if (typeof payload?.delegate_address !== "string") return { status: "bad_response" };
|
|
1357
|
+
return { status: "ok", agentId: payload.id, delegateAddress: payload.delegate_address };
|
|
1358
|
+
} catch {
|
|
1359
|
+
return { status: "bad_response" };
|
|
865
1360
|
}
|
|
866
1361
|
}
|
|
867
1362
|
async function probeHostedMcpTools(apiKey, hostedMcpUrl, fetchImpl = fetch) {
|
|
@@ -1159,101 +1654,377 @@ var init_signer_runtime = __esm({
|
|
|
1159
1654
|
SIGNER_INSTALL_HEARTBEAT_MS = 15e3;
|
|
1160
1655
|
}
|
|
1161
1656
|
});
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1657
|
+
async function prepareLocalMcpRuntime(input, deps = {}) {
|
|
1658
|
+
assertSupportedNodeVersion(input.nodeVersion);
|
|
1659
|
+
const homeDir = input.homeDir ?? homedir();
|
|
1660
|
+
const runtimeDirectory = resolve(homeDir, ".haven", "mcp-runtime", MCP_RUNTIME_MANIFEST.mcpVersion);
|
|
1661
|
+
const npmCacheDirectory = resolve(homeDir, ".haven", "npm-cache");
|
|
1662
|
+
const cliPath = join(runtimeDirectory, "node_modules", "@haven_ai", "mcp", "dist", "cli.js");
|
|
1663
|
+
const messages = [];
|
|
1664
|
+
await mkdir(runtimeDirectory, { recursive: true, mode: 448 });
|
|
1665
|
+
await chmod(runtimeDirectory, 448).catch(() => void 0);
|
|
1666
|
+
await mkdir(npmCacheDirectory, { recursive: true, mode: 448 });
|
|
1667
|
+
await chmod(npmCacheDirectory, 448).catch(() => void 0);
|
|
1668
|
+
if (await installedRuntimeMatches2(runtimeDirectory, cliPath)) {
|
|
1669
|
+
messages.push(`Using existing local Haven MCP runtime ${mcpPackageSpec()}.`);
|
|
1670
|
+
} else {
|
|
1671
|
+
await installRuntimePackages2(runtimeDirectory, npmCacheDirectory, deps);
|
|
1672
|
+
messages.push(`Installed local Haven MCP runtime ${mcpPackageSpec()}.`);
|
|
1180
1673
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1674
|
+
await assertFileExists2(cliPath, "local Haven MCP CLI");
|
|
1675
|
+
const wrapperPath = join(input.credentialDirectory, "bin", "haven-mcp");
|
|
1676
|
+
await writeWrapper2({
|
|
1677
|
+
wrapperPath,
|
|
1678
|
+
cliPath,
|
|
1679
|
+
identityPath: input.identityPath,
|
|
1680
|
+
signerPath: input.signerPath
|
|
1681
|
+
});
|
|
1682
|
+
await writeRuntimeSidecar2({
|
|
1683
|
+
path: join(input.credentialDirectory, "mcp-runtime.json"),
|
|
1684
|
+
wrapperPath,
|
|
1685
|
+
runtimeDirectory,
|
|
1686
|
+
npmCacheDirectory,
|
|
1687
|
+
cliPath,
|
|
1688
|
+
serverName: input.serverName
|
|
1689
|
+
});
|
|
1690
|
+
messages.push(`Prepared stable local Haven MCP wrapper: ${wrapperPath}`);
|
|
1691
|
+
return {
|
|
1692
|
+
command: wrapperPath,
|
|
1693
|
+
args: [],
|
|
1694
|
+
wrapperPath,
|
|
1695
|
+
runtimeDirectory,
|
|
1696
|
+
npmCacheDirectory,
|
|
1697
|
+
cliPath,
|
|
1698
|
+
messages
|
|
1699
|
+
};
|
|
1186
1700
|
}
|
|
1187
|
-
function
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1701
|
+
function assertSupportedNodeVersion(nodeVersion = process.versions.node, minimumNodeVersion = MCP_RUNTIME_MANIFEST.minimumNodeVersion, subject = "Haven setup") {
|
|
1702
|
+
if (!isSupportedNodeVersion(nodeVersion, minimumNodeVersion)) {
|
|
1703
|
+
throw new UnsupportedNodeVersionError(nodeVersion, minimumNodeVersion, subject);
|
|
1704
|
+
}
|
|
1191
1705
|
}
|
|
1192
|
-
async function
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1706
|
+
async function installRuntimePackages2(runtimeDirectory, npmCacheDirectory, deps) {
|
|
1707
|
+
const { runCommand, onProgress } = deps;
|
|
1708
|
+
const baseArgs = [
|
|
1709
|
+
"install",
|
|
1710
|
+
"--prefix",
|
|
1711
|
+
runtimeDirectory,
|
|
1712
|
+
"--no-audit",
|
|
1713
|
+
"--no-fund",
|
|
1714
|
+
"--omit=dev",
|
|
1715
|
+
"--prefer-offline",
|
|
1716
|
+
mcpPackageSpec(),
|
|
1717
|
+
sdkPackageSpec()
|
|
1718
|
+
];
|
|
1719
|
+
const run = async (args) => {
|
|
1720
|
+
const startedAt = Date.now();
|
|
1721
|
+
const heartbeat = setInterval(() => {
|
|
1722
|
+
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
1723
|
+
onProgress?.(`Still installing the local Haven MCP runtime\u2026 (${seconds}s \u2014 a cold cache can take several minutes)`);
|
|
1724
|
+
}, SIGNER_INSTALL_HEARTBEAT_MS);
|
|
1725
|
+
heartbeat.unref?.();
|
|
1726
|
+
try {
|
|
1727
|
+
if (runCommand) await runCommand("npm", args);
|
|
1728
|
+
else await execFileAsync2("npm", args, { timeout: SIGNER_INSTALL_TIMEOUT_MS, maxBuffer: 1024 * 1024 });
|
|
1729
|
+
} finally {
|
|
1730
|
+
clearInterval(heartbeat);
|
|
1202
1731
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
throw new
|
|
1211
|
-
"runtime_unrecognized",
|
|
1212
|
-
`"${supplied}" is not an agent runtime Haven knows. Valid values: ${RUNTIME_FLAG_VALUES} (the aliases cowork, codex and openclaw are accepted too). Re-run with one of those, or --runtime other to store credentials and finish the MCP setup by hand. Nothing was written and the Haven setup token is still unused.`,
|
|
1213
|
-
"rerun_connect_with_a_valid_runtime_name"
|
|
1214
|
-
);
|
|
1732
|
+
};
|
|
1733
|
+
try {
|
|
1734
|
+
await run(baseArgs);
|
|
1735
|
+
} catch {
|
|
1736
|
+
try {
|
|
1737
|
+
await run([...baseArgs, "--cache", npmCacheDirectory]);
|
|
1738
|
+
} catch (err) {
|
|
1739
|
+
throw new Error(`Could not install local Haven MCP runtime ${mcpPackageSpec()}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1215
1740
|
}
|
|
1216
|
-
return { runtime: detected, source: "detected", discardedHint: supplied };
|
|
1217
|
-
}
|
|
1218
|
-
if (detected && hint && detected !== hint) {
|
|
1219
|
-
return { runtime: detected, source: "detected", overrodeHint: hint };
|
|
1220
|
-
}
|
|
1221
|
-
if (hint) return { runtime: hint, source: "explicit" };
|
|
1222
|
-
if (detected) return { runtime: detected, source: "detected" };
|
|
1223
|
-
if (options.promptForRuntime) {
|
|
1224
|
-
return { runtime: await options.promptForRuntime(), source: "prompted" };
|
|
1225
1741
|
}
|
|
1226
|
-
return { runtime: null, source: "none" };
|
|
1227
|
-
}
|
|
1228
|
-
function restartRequiredForRuntime(runtime, env = process.env) {
|
|
1229
|
-
const mode = runtimeProfile(runtime, env).restartMode;
|
|
1230
|
-
return mode === "restart-session" || mode === "restart-app";
|
|
1231
|
-
}
|
|
1232
|
-
function runtimeVerificationInstruction(runtime) {
|
|
1233
|
-
const label = RUNTIME_PROFILES[runtime].label;
|
|
1234
|
-
return `In ${label}, run the read-only \`haven_get_agent\` and \`haven_get_allowances\` tools to confirm the Haven wallet and live budget. Do not sign, fund, or create a payment to verify setup.`;
|
|
1235
1742
|
}
|
|
1236
|
-
function
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1743
|
+
async function installedRuntimeMatches2(runtimeDirectory, cliPath) {
|
|
1744
|
+
try {
|
|
1745
|
+
await assertFileExists2(cliPath, "local Haven MCP CLI");
|
|
1746
|
+
const [mcpPackage, sdkPackage] = await Promise.all([
|
|
1747
|
+
readPackageJson2(join(runtimeDirectory, "node_modules", "@haven_ai", "mcp", "package.json")),
|
|
1748
|
+
readPackageJson2(join(runtimeDirectory, "node_modules", "@haven_ai", "sdk", "package.json"))
|
|
1749
|
+
]);
|
|
1750
|
+
return mcpPackage.version === MCP_RUNTIME_MANIFEST.mcpVersion && sdkPackage.version === MCP_RUNTIME_MANIFEST.sdkVersion;
|
|
1751
|
+
} catch {
|
|
1752
|
+
return false;
|
|
1753
|
+
}
|
|
1240
1754
|
}
|
|
1241
|
-
function
|
|
1242
|
-
|
|
1243
|
-
if (env.CODEX_SANDBOX || env.CODEX_HOME || env.CODEX_CWD) return "codex-cli";
|
|
1244
|
-
if (env.VSCODE_CWD || env.VSCODE_IPC_HOOK_CLI || env.TERM_PROGRAM === "vscode") return "vscode";
|
|
1245
|
-
if (env.HERMES_HOME || env.HERMES_AGENT) return "hermes";
|
|
1246
|
-
return null;
|
|
1755
|
+
async function readPackageJson2(path) {
|
|
1756
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
1247
1757
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1758
|
+
async function writeWrapper2(input) {
|
|
1759
|
+
await mkdir(dirname(input.wrapperPath), { recursive: true, mode: 448 });
|
|
1760
|
+
await chmod(dirname(input.wrapperPath), 448).catch(() => void 0);
|
|
1761
|
+
const source = [
|
|
1762
|
+
"#!/usr/bin/env node",
|
|
1763
|
+
"import { spawn } from 'node:child_process'",
|
|
1764
|
+
"",
|
|
1765
|
+
`const cliPath = ${JSON.stringify(input.cliPath)}`,
|
|
1766
|
+
`const identityPath = ${JSON.stringify(input.identityPath)}`,
|
|
1767
|
+
`const signerPath = ${JSON.stringify(input.signerPath)}`,
|
|
1768
|
+
"",
|
|
1769
|
+
"const child = spawn(process.execPath, [cliPath, '--identity', identityPath, '--signer', signerPath, ...process.argv.slice(2)], {",
|
|
1770
|
+
" stdio: 'inherit',",
|
|
1771
|
+
"})",
|
|
1772
|
+
"",
|
|
1773
|
+
"child.on('exit', (code, signal) => {",
|
|
1774
|
+
" if (signal) process.kill(process.pid, signal)",
|
|
1775
|
+
" else process.exit(code ?? 1)",
|
|
1776
|
+
"})",
|
|
1777
|
+
""
|
|
1778
|
+
].join("\n");
|
|
1779
|
+
await writeFile(input.wrapperPath, source, { mode: 448 });
|
|
1780
|
+
await chmod(input.wrapperPath, 448).catch(() => void 0);
|
|
1781
|
+
}
|
|
1782
|
+
async function writeRuntimeSidecar2(input) {
|
|
1783
|
+
const value = {
|
|
1784
|
+
...input.serverName ? { server_name: input.serverName } : {},
|
|
1785
|
+
mcp_package: MCP_RUNTIME_MANIFEST.mcpPackage,
|
|
1786
|
+
mcp_version: MCP_RUNTIME_MANIFEST.mcpVersion,
|
|
1787
|
+
sdk_package: MCP_RUNTIME_MANIFEST.sdkPackage,
|
|
1788
|
+
sdk_version: MCP_RUNTIME_MANIFEST.sdkVersion,
|
|
1789
|
+
minimum_node_version: MCP_RUNTIME_MANIFEST.minimumNodeVersion,
|
|
1790
|
+
wrapper_path: input.wrapperPath,
|
|
1791
|
+
runtime_directory: input.runtimeDirectory,
|
|
1792
|
+
npm_cache_directory: input.npmCacheDirectory,
|
|
1793
|
+
cli_path: input.cliPath
|
|
1794
|
+
};
|
|
1795
|
+
await writeFile(input.path, `${JSON.stringify(value, null, 2)}
|
|
1796
|
+
`, { mode: 384 });
|
|
1797
|
+
await chmod(input.path, 384).catch(() => void 0);
|
|
1798
|
+
}
|
|
1799
|
+
async function assertFileExists2(path, label) {
|
|
1800
|
+
try {
|
|
1801
|
+
await access(path);
|
|
1802
|
+
} catch {
|
|
1803
|
+
throw new Error(`Missing ${label}: ${path}`);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
var execFileAsync2, UnsupportedNodeVersionError;
|
|
1807
|
+
var init_local_mcp_runtime = __esm({
|
|
1808
|
+
"src/local-mcp-runtime.ts"() {
|
|
1809
|
+
init_signer_runtime();
|
|
1810
|
+
init_runtime_manifest();
|
|
1811
|
+
execFileAsync2 = promisify(execFile);
|
|
1812
|
+
UnsupportedNodeVersionError = class extends Error {
|
|
1813
|
+
code = "local_mcp_unsupported_node_version";
|
|
1814
|
+
nodeVersion;
|
|
1815
|
+
minimumNodeVersion;
|
|
1816
|
+
constructor(nodeVersion, minimumNodeVersion, subject = "Haven setup") {
|
|
1817
|
+
super(unsupportedNodeVersionMessage({ subject, nodeVersion, minimumNodeVersion }));
|
|
1818
|
+
this.name = "UnsupportedNodeVersionError";
|
|
1819
|
+
this.nodeVersion = nodeVersion;
|
|
1820
|
+
this.minimumNodeVersion = minimumNodeVersion;
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
});
|
|
1825
|
+
async function installSkillForRuntime(runtime, deps = {}) {
|
|
1826
|
+
switch (runtime) {
|
|
1827
|
+
case "claude-code":
|
|
1828
|
+
return installSkillFile(
|
|
1829
|
+
resolve(deps.homeDir ?? homedir(), ".claude", "skills", SKILL_FOLDER_NAME),
|
|
1830
|
+
"~/.claude/skills/haven-pay"
|
|
1831
|
+
);
|
|
1832
|
+
case "hermes":
|
|
1833
|
+
return installSkillFile(
|
|
1834
|
+
join(hermesHome(deps), "skills", SKILL_FOLDER_NAME),
|
|
1835
|
+
"the Hermes skills folder"
|
|
1836
|
+
);
|
|
1837
|
+
case "codex-cli":
|
|
1838
|
+
case "codex-desktop":
|
|
1839
|
+
return installCodexAgentsSection(deps);
|
|
1840
|
+
default:
|
|
1841
|
+
return void 0;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
async function installSkillFile(skillDir, label) {
|
|
1845
|
+
try {
|
|
1846
|
+
await mkdir(skillDir, { recursive: true });
|
|
1847
|
+
const target = join(skillDir, "SKILL.md");
|
|
1848
|
+
await writeFile(target, HAVEN_SKILL_MD, "utf8");
|
|
1849
|
+
return {
|
|
1850
|
+
installed: true,
|
|
1851
|
+
target,
|
|
1852
|
+
messages: [`Installed the generic Haven payment skill (${label}). It contains no secrets.`]
|
|
1853
|
+
};
|
|
1854
|
+
} catch (err) {
|
|
1855
|
+
return {
|
|
1856
|
+
installed: false,
|
|
1857
|
+
messages: [
|
|
1858
|
+
`Could not install the Haven payment skill: ${err instanceof Error ? err.message : String(err)}. Download it from the Haven dashboard instead.`
|
|
1859
|
+
]
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
async function installCodexAgentsSection(deps) {
|
|
1864
|
+
try {
|
|
1865
|
+
const codexDir = resolve(deps.homeDir ?? homedir(), ".codex");
|
|
1866
|
+
const target = join(codexDir, "AGENTS.md");
|
|
1867
|
+
await mkdir(codexDir, { recursive: true });
|
|
1868
|
+
const existing = await readFile(target, "utf8").catch(() => null);
|
|
1869
|
+
const next = upsertManagedSection(existing, codexManagedSection());
|
|
1870
|
+
if (next !== existing) {
|
|
1871
|
+
await writeFile(target, next, "utf8");
|
|
1872
|
+
}
|
|
1873
|
+
return {
|
|
1874
|
+
installed: true,
|
|
1875
|
+
target,
|
|
1876
|
+
messages: [
|
|
1877
|
+
"Installed the generic Haven payment guidance as a managed section in ~/.codex/AGENTS.md (Codex reads it as global instructions). It contains no secrets; your own content in that file is untouched."
|
|
1878
|
+
]
|
|
1879
|
+
};
|
|
1880
|
+
} catch (err) {
|
|
1881
|
+
return {
|
|
1882
|
+
installed: false,
|
|
1883
|
+
messages: [
|
|
1884
|
+
`Could not install the Haven payment guidance into ~/.codex/AGENTS.md: ${err instanceof Error ? err.message : String(err)}. Download the skill from the Haven dashboard instead.`
|
|
1885
|
+
]
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
function codexManagedSection() {
|
|
1890
|
+
return `${CODEX_AGENTS_BEGIN_MARKER}
|
|
1891
|
+
|
|
1892
|
+
${HAVEN_SKILL_BODY_MD.trimEnd()}
|
|
1893
|
+
|
|
1894
|
+
${CODEX_AGENTS_END_MARKER}
|
|
1895
|
+
`;
|
|
1896
|
+
}
|
|
1897
|
+
function upsertManagedSection(existing, section) {
|
|
1898
|
+
if (existing === null || existing.trim() === "") return section;
|
|
1899
|
+
const begins = markerLineIndexes(existing, CODEX_AGENTS_BEGIN_MARKER);
|
|
1900
|
+
const ends = markerLineIndexes(existing, CODEX_AGENTS_END_MARKER);
|
|
1901
|
+
if (begins.length === 1 && ends.length === 1 && ends[0] > begins[0]) {
|
|
1902
|
+
const afterEnd = ends[0] + CODEX_AGENTS_END_MARKER.length;
|
|
1903
|
+
const tail = existing.startsWith("\r\n", afterEnd) ? existing.slice(afterEnd + 2) : existing.startsWith("\n", afterEnd) ? existing.slice(afterEnd + 1) : existing.slice(afterEnd);
|
|
1904
|
+
return existing.slice(0, begins[0]) + section + tail;
|
|
1905
|
+
}
|
|
1906
|
+
if (begins.length > 0 || ends.length > 0) {
|
|
1907
|
+
throw new Error(
|
|
1908
|
+
"found a damaged Haven marker section (orphaned or duplicated markers); remove the leftover marker lines and re-run setup"
|
|
1909
|
+
);
|
|
1910
|
+
}
|
|
1911
|
+
return `${existing.replace(/\n*$/, "\n\n")}${section}`;
|
|
1912
|
+
}
|
|
1913
|
+
function markerLineIndexes(text, marker) {
|
|
1914
|
+
const indexes = [];
|
|
1915
|
+
for (let from = 0; ; ) {
|
|
1916
|
+
const at = text.indexOf(marker, from);
|
|
1917
|
+
if (at === -1) return indexes;
|
|
1918
|
+
if (at === 0 || text[at - 1] === "\n") indexes.push(at);
|
|
1919
|
+
from = at + marker.length;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
function hermesHome(deps) {
|
|
1923
|
+
const env = deps.env ?? process.env;
|
|
1924
|
+
return env.HERMES_HOME ?? join(deps.homeDir ?? homedir(), ".hermes");
|
|
1925
|
+
}
|
|
1926
|
+
var CODEX_AGENTS_BEGIN_MARKER, CODEX_AGENTS_END_MARKER;
|
|
1927
|
+
var init_skill_install = __esm({
|
|
1928
|
+
"src/skill-install.ts"() {
|
|
1929
|
+
CODEX_AGENTS_BEGIN_MARKER = "<!-- BEGIN haven-pay (managed by @haven_ai/connect; edits inside this section are overwritten on re-setup) -->";
|
|
1930
|
+
CODEX_AGENTS_END_MARKER = "<!-- END haven-pay -->";
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
|
|
1934
|
+
// src/connect-error.ts
|
|
1935
|
+
function isConnectError(err) {
|
|
1936
|
+
return err instanceof ConnectError;
|
|
1937
|
+
}
|
|
1938
|
+
var ConnectError;
|
|
1939
|
+
var init_connect_error = __esm({
|
|
1940
|
+
"src/connect-error.ts"() {
|
|
1941
|
+
ConnectError = class extends Error {
|
|
1942
|
+
code;
|
|
1943
|
+
nextAction;
|
|
1944
|
+
constructor(code, message, nextAction2) {
|
|
1945
|
+
super(message);
|
|
1946
|
+
this.name = "ConnectError";
|
|
1947
|
+
this.code = code;
|
|
1948
|
+
this.nextAction = nextAction2;
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1953
|
+
|
|
1954
|
+
// src/runtime-registry.ts
|
|
1955
|
+
function runtimeProfile(runtime, env = process.env) {
|
|
1956
|
+
return RUNTIME_PROFILES[normalizeRuntime(runtime, env)];
|
|
1957
|
+
}
|
|
1958
|
+
function normalizeRuntime(runtime, env = process.env) {
|
|
1959
|
+
const explicit = normalizeRuntimeName(runtime);
|
|
1960
|
+
if (explicit) return explicit;
|
|
1961
|
+
return detectRuntime(env) ?? "other";
|
|
1962
|
+
}
|
|
1963
|
+
async function resolveRuntimeSelection(explicit, force, options = {}) {
|
|
1964
|
+
const env = options.env ?? process.env;
|
|
1965
|
+
if (force !== void 0) {
|
|
1966
|
+
const forced = normalizeRuntimeName(force);
|
|
1967
|
+
if (!forced) {
|
|
1968
|
+
throw new ConnectError(
|
|
1969
|
+
"runtime_force_unrecognized",
|
|
1970
|
+
`Unknown --runtime-force value "${force}". Valid values: ${RUNTIME_FLAG_VALUES}.`,
|
|
1971
|
+
"rerun_connect_with_a_valid_runtime_name"
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
return { runtime: forced, source: "force" };
|
|
1975
|
+
}
|
|
1976
|
+
const detected = detectRuntime(env);
|
|
1977
|
+
const supplied = explicit?.trim() || options.selfReported?.trim() || void 0;
|
|
1978
|
+
const hint = normalizeRuntimeName(supplied);
|
|
1979
|
+
if (supplied && !hint) {
|
|
1980
|
+
if (!detected) {
|
|
1981
|
+
throw new ConnectError(
|
|
1982
|
+
"runtime_unrecognized",
|
|
1983
|
+
`"${supplied}" is not an agent runtime Haven knows. Valid values: ${RUNTIME_FLAG_VALUES} (the aliases cowork, codex and openclaw are accepted too). Re-run with one of those, or --runtime other to store credentials and finish the MCP setup by hand. Nothing was written and the Haven setup token is still unused.`,
|
|
1984
|
+
"rerun_connect_with_a_valid_runtime_name"
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
return { runtime: detected, source: "detected", discardedHint: supplied };
|
|
1988
|
+
}
|
|
1989
|
+
if (detected && hint && detected !== hint) {
|
|
1990
|
+
return { runtime: detected, source: "detected", overrodeHint: hint };
|
|
1991
|
+
}
|
|
1992
|
+
if (hint) return { runtime: hint, source: "explicit" };
|
|
1993
|
+
if (detected) return { runtime: detected, source: "detected" };
|
|
1994
|
+
if (options.promptForRuntime) {
|
|
1995
|
+
return { runtime: await options.promptForRuntime(), source: "prompted" };
|
|
1996
|
+
}
|
|
1997
|
+
return { runtime: null, source: "none" };
|
|
1998
|
+
}
|
|
1999
|
+
function restartRequiredForRuntime(runtime, env = process.env) {
|
|
2000
|
+
const mode = runtimeProfile(runtime, env).restartMode;
|
|
2001
|
+
return mode === "restart-session" || mode === "restart-app";
|
|
2002
|
+
}
|
|
2003
|
+
function runtimeVerificationInstruction(runtime) {
|
|
2004
|
+
const label = RUNTIME_PROFILES[runtime].label;
|
|
2005
|
+
return `In ${label}, run the read-only \`haven_get_agent\` and \`haven_get_allowances\` tools to confirm the Haven wallet and live budget. Do not sign, fund, or create a payment to verify setup.`;
|
|
2006
|
+
}
|
|
2007
|
+
function normalizeRuntimeName(runtime) {
|
|
2008
|
+
const key = runtime?.trim().toLowerCase();
|
|
2009
|
+
if (!key) return null;
|
|
2010
|
+
return RUNTIME_ALIASES[key.replace(/\s+/g, "-")] ?? null;
|
|
2011
|
+
}
|
|
2012
|
+
function detectRuntime(env) {
|
|
2013
|
+
if (env.CLAUDECODE || env.CLAUDE_CODE || env.CLAUDECODE_CWD) return "claude-code";
|
|
2014
|
+
if (env.CODEX_SANDBOX || env.CODEX_HOME || env.CODEX_CWD) return "codex-cli";
|
|
2015
|
+
if (env.VSCODE_CWD || env.VSCODE_IPC_HOOK_CLI || env.TERM_PROGRAM === "vscode") return "vscode";
|
|
2016
|
+
if (env.HERMES_HOME || env.HERMES_AGENT) return "hermes";
|
|
2017
|
+
return null;
|
|
2018
|
+
}
|
|
2019
|
+
var RUNTIME_PROFILES, RUNTIME_ALIASES, RUNTIME_FLAG_VALUES;
|
|
2020
|
+
var init_runtime_registry = __esm({
|
|
2021
|
+
"src/runtime-registry.ts"() {
|
|
2022
|
+
init_connect_error();
|
|
2023
|
+
RUNTIME_PROFILES = {
|
|
2024
|
+
"claude-code": {
|
|
2025
|
+
id: "claude-code",
|
|
2026
|
+
label: "Claude Code",
|
|
2027
|
+
restartMode: "restart-session",
|
|
1257
2028
|
canWriteRuntimeConfig: true,
|
|
1258
2029
|
activationInstruction: "Start a new Claude Code session so it loads the Haven MCP entries."
|
|
1259
2030
|
},
|
|
@@ -1440,1519 +2211,1319 @@ var init_signer_consent = __esm({
|
|
|
1440
2211
|
"src/signer-consent.ts"() {
|
|
1441
2212
|
}
|
|
1442
2213
|
});
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
].join("\n");
|
|
1478
|
-
}
|
|
1479
|
-
async function writeAgentTombstone(input) {
|
|
1480
|
-
const dirStat = await stat(input.directory).catch(() => null);
|
|
1481
|
-
if (!dirStat?.isDirectory()) {
|
|
1482
|
-
throw new Error(`Not a directory: ${input.directory} \u2014 nothing to tombstone.`);
|
|
1483
|
-
}
|
|
1484
|
-
const info = {
|
|
1485
|
-
// reason / replaced_by are persisted to disk and re-emitted to the host's
|
|
1486
|
-
// MCP stderr log on EVERY stale probe, potentially for months — redact
|
|
1487
|
-
// like every other output path, at the write layer so any future caller
|
|
1488
|
-
// inherits it. (#1681 review, finding 1)
|
|
1489
|
-
agent_id: input.agentId,
|
|
1490
|
-
retired_at: input.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1491
|
-
reason: redactSecrets(input.reason),
|
|
1492
|
-
...input.replacedBy ? { replaced_by: redactSecrets(input.replacedBy) } : {}
|
|
1493
|
-
};
|
|
1494
|
-
const binDir = join(input.directory, "bin");
|
|
1495
|
-
await mkdir(binDir, { recursive: true });
|
|
1496
|
-
const wrapperPath = join(binDir, "haven-signer.mjs");
|
|
1497
|
-
await writeFile(wrapperPath, tombstoneScript(info), "utf8");
|
|
1498
|
-
await chmod(wrapperPath, 493);
|
|
1499
|
-
await writeFile(join(input.directory, TOMBSTONE_FILENAME), JSON.stringify(info, null, 2) + "\n", "utf8");
|
|
1500
|
-
return info;
|
|
1501
|
-
}
|
|
1502
|
-
async function readAgentTombstone(directory) {
|
|
1503
|
-
try {
|
|
1504
|
-
const parsed = JSON.parse(await readFile(join(directory, TOMBSTONE_FILENAME), "utf8"));
|
|
1505
|
-
if (typeof parsed?.agent_id !== "string") return null;
|
|
1506
|
-
return parsed;
|
|
1507
|
-
} catch {
|
|
1508
|
-
return null;
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
var TOMBSTONE_FILENAME, TOMBSTONE_MARKER;
|
|
1512
|
-
var init_tombstone = __esm({
|
|
1513
|
-
"src/tombstone.ts"() {
|
|
1514
|
-
init_redact();
|
|
1515
|
-
TOMBSTONE_FILENAME = "TOMBSTONE.json";
|
|
1516
|
-
TOMBSTONE_MARKER = "HAVEN-TOMBSTONE";
|
|
1517
|
-
}
|
|
1518
|
-
});
|
|
1519
|
-
|
|
1520
|
-
// src/doctor.ts
|
|
1521
|
-
var doctor_exports = {};
|
|
1522
|
-
__export(doctor_exports, {
|
|
1523
|
-
runDoctor: () => runDoctor,
|
|
1524
|
-
runRepair: () => runRepair
|
|
1525
|
-
});
|
|
1526
|
-
async function discoverCredentialDirectory(homeDir, explicit) {
|
|
1527
|
-
const root = explicit ? dirname(explicit) : join(homeDir, ".haven", "agents");
|
|
1528
|
-
let entries = [];
|
|
1529
|
-
try {
|
|
1530
|
-
entries = await readdir(root);
|
|
1531
|
-
} catch {
|
|
1532
|
-
return explicit ? { directory: explicit, others: [] } : { others: [] };
|
|
2214
|
+
async function installRuntime(input, deps = {}) {
|
|
2215
|
+
const runtime = normalizeRuntime(input.runtime, deps.env);
|
|
2216
|
+
const profile = runtimeProfile(runtime, deps.env);
|
|
2217
|
+
const progress = deps.onProgress ?? (() => void 0);
|
|
2218
|
+
const localRuntime = input.localMcp === true && supportsLocalMcp(runtime);
|
|
2219
|
+
const consentMessages = [];
|
|
2220
|
+
const localMcpConsent = localRuntime ? await resolveLocalMcpConsent(input, consentMessages) : void 0;
|
|
2221
|
+
const signerConsent = localRuntime ? void 0 : await resolveSignerConsent(input, consentMessages);
|
|
2222
|
+
if (runtime === "other") {
|
|
2223
|
+
const signerCredentialReady2 = await probeLocalSignerCredential(input.signerPath);
|
|
2224
|
+
const signerReady = signerCredentialReady2 && signerConsent?.acknowledged;
|
|
2225
|
+
return {
|
|
2226
|
+
runtime,
|
|
2227
|
+
runtimeMcpMode: "manual",
|
|
2228
|
+
hostedMcpConfigured: false,
|
|
2229
|
+
localSignerConfigured: false,
|
|
2230
|
+
localMcpConfigured: false,
|
|
2231
|
+
probeResult: signerReady ? "manual_runtime_setup_required_local_signer_ready" : "manual_runtime_setup_required_local_signer_unavailable",
|
|
2232
|
+
restartRequired: true,
|
|
2233
|
+
nextUserAction: "return_to_haven_for_wallet_approval_then_configure_runtime",
|
|
2234
|
+
errorCode: "manual_runtime_setup_required",
|
|
2235
|
+
configTarget: "manual runtime setup",
|
|
2236
|
+
signerAcknowledged: signerConsent?.acknowledged,
|
|
2237
|
+
localMcpAcknowledged: false,
|
|
2238
|
+
messages: [
|
|
2239
|
+
...consentMessages,
|
|
2240
|
+
"Custom runtime: Haven did not auto-configure it. Your credentials are on disk (chmod 600) \u2014 read them at runtime; never paste a key into the agent prompt, memory, or logs.",
|
|
2241
|
+
` identity (hosted MCP Bearer): ${input.identityPath}`,
|
|
2242
|
+
` signer (local signing key): ${input.signerPath}`,
|
|
2243
|
+
"After wallet approval, wire the runtime to Haven by reference:",
|
|
2244
|
+
` Hosted MCP + local signer: point your MCP client at ${input.hostedMcpUrl} with the api_key from identity.json, then run npx -y ${signerPackageSpec()} --credentials ${input.signerPath}`,
|
|
2245
|
+
` Fully local MCP (no hosted dependency): npx -y ${mcpPackageSpec()} --identity ${input.identityPath} --signer ${input.signerPath}`
|
|
2246
|
+
]
|
|
2247
|
+
};
|
|
1533
2248
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
const directory = join(root, entry);
|
|
2249
|
+
let localRuntimeInstall;
|
|
2250
|
+
let localRuntimeError;
|
|
2251
|
+
if (localRuntime) {
|
|
1538
2252
|
try {
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
try {
|
|
1543
|
-
await stat(join(directory, TOMBSTONE_FILENAME));
|
|
1544
|
-
tombstonedOnly.push(directory);
|
|
1545
|
-
} catch {
|
|
1546
|
-
}
|
|
2253
|
+
localRuntimeInstall = await prepareRuntimeForLocalMcp(input, deps);
|
|
2254
|
+
} catch (err) {
|
|
2255
|
+
localRuntimeError = err;
|
|
1547
2256
|
}
|
|
1548
2257
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
2258
|
+
if (localRuntimeError) {
|
|
2259
|
+
const errorCode2 = localRuntimePrepareErrorCode(localRuntimeError);
|
|
1551
2260
|
return {
|
|
1552
|
-
|
|
1553
|
-
|
|
2261
|
+
runtime,
|
|
2262
|
+
runtimeMcpMode: "local_stdio",
|
|
2263
|
+
hostedMcpConfigured: false,
|
|
2264
|
+
localSignerConfigured: false,
|
|
2265
|
+
localMcpConfigured: false,
|
|
2266
|
+
probeResult: errorCode2 === "local_mcp_unsupported_node_version" ? "local_stdio_mcp_unsupported_node_version" : "local_stdio_mcp_runtime_install_failed",
|
|
2267
|
+
restartRequired: true,
|
|
2268
|
+
nextUserAction: nextAction(runtime, profile.restartMode, errorCode2),
|
|
2269
|
+
errorCode: errorCode2,
|
|
2270
|
+
configTarget: profile.label,
|
|
2271
|
+
signerAcknowledged: signerConsent?.acknowledged,
|
|
2272
|
+
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2273
|
+
activationCommand: void 0,
|
|
2274
|
+
messages: [
|
|
2275
|
+
...consentMessages,
|
|
2276
|
+
`Could not prepare local Haven MCP runtime: ${localRuntimeError instanceof Error ? localRuntimeError.message : String(localRuntimeError)}`
|
|
2277
|
+
]
|
|
1554
2278
|
};
|
|
1555
2279
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
2280
|
+
let signerCommand;
|
|
2281
|
+
if (!localRuntime) {
|
|
2282
|
+
progress("Getting the signer ready\u2026");
|
|
2283
|
+
try {
|
|
2284
|
+
const signerRuntime = await prepareSignerForRuntime(input, deps);
|
|
2285
|
+
signerCommand = { command: signerRuntime.command, args: signerRuntime.args };
|
|
2286
|
+
consentMessages.push(...signerRuntime.messages);
|
|
2287
|
+
} catch (err) {
|
|
2288
|
+
return {
|
|
2289
|
+
runtime,
|
|
2290
|
+
runtimeMcpMode: "hosted_plus_signer",
|
|
2291
|
+
hostedMcpConfigured: false,
|
|
2292
|
+
localSignerConfigured: false,
|
|
2293
|
+
localMcpConfigured: false,
|
|
2294
|
+
probeResult: "signer_runtime_install_failed",
|
|
2295
|
+
restartRequired: false,
|
|
2296
|
+
nextUserAction: "The local Haven signer runtime could not be installed, so no configuration was written. Check your network (a cold install downloads the signer package set) and re-run: npx @haven_ai/connect@alpha",
|
|
2297
|
+
errorCode: "signer_runtime_install_failed",
|
|
2298
|
+
configTarget: profile.label,
|
|
2299
|
+
signerAcknowledged: signerConsent?.acknowledged,
|
|
2300
|
+
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2301
|
+
activationCommand: void 0,
|
|
2302
|
+
signerRuntimePrepared: false,
|
|
2303
|
+
messages: [
|
|
2304
|
+
...consentMessages,
|
|
2305
|
+
`Could not pre-install the local Haven signer: ${err instanceof Error ? err.message : String(err)}`,
|
|
2306
|
+
"No runtime configuration was written (fail-closed): a config pointing at an uninstalled signer looks wired but cannot start.",
|
|
2307
|
+
"Re-run `npx @haven_ai/connect@alpha` to retry the setup."
|
|
2308
|
+
]
|
|
2309
|
+
};
|
|
1567
2310
|
}
|
|
1568
|
-
return false;
|
|
1569
|
-
}
|
|
1570
|
-
if (sidecar?.wrapper_path && configText.includes(sidecar.wrapper_path)) return true;
|
|
1571
|
-
if (bareOwnerExists) return false;
|
|
1572
|
-
return isPrimary && Boolean(identity?.hosted_mcp_url && configText.includes(identity.hosted_mcp_url));
|
|
1573
|
-
}
|
|
1574
|
-
async function readIdentity(directory) {
|
|
1575
|
-
try {
|
|
1576
|
-
return JSON.parse(await readFile(join(directory, "identity.json"), "utf8"));
|
|
1577
|
-
} catch {
|
|
1578
|
-
return void 0;
|
|
1579
2311
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
2312
|
+
const signerRuntimePrepared = localRuntime ? void 0 : signerCommand !== void 0;
|
|
2313
|
+
progress("Setting up your Haven tools\u2026");
|
|
2314
|
+
const configResult = localRuntime ? runtime === "claude-code" ? await configureClaudeCode(deps, localRuntimeInstall?.command ?? "", input.serverName) : await writeRuntimeConfig({
|
|
2315
|
+
runtime,
|
|
2316
|
+
hostedMcpUrl: input.hostedMcpUrl,
|
|
2317
|
+
apiKey: input.apiKey,
|
|
2318
|
+
identityPath: input.identityPath,
|
|
2319
|
+
signerPath: input.signerPath,
|
|
2320
|
+
serverName: input.serverName,
|
|
2321
|
+
credentialDirectory: input.credentialDirectory,
|
|
2322
|
+
localMcpCommand: localRuntimeInstall?.command,
|
|
2323
|
+
signerCommand,
|
|
2324
|
+
homeDir: deps.homeDir,
|
|
2325
|
+
mode: "local"
|
|
2326
|
+
}) : await writeHostedRuntimeConfig(deps, { ...input, runtime }, signerCommand);
|
|
2327
|
+
if (deps.onRuntimeConfigured) {
|
|
2328
|
+
const signerCredentialOnDisk = await probeLocalSignerCredential(input.signerPath);
|
|
2329
|
+
const earlyLocalMcpOk = configResult.runtimeMcpMode === "local_stdio" && configResult.localMcpConfigured && signerCredentialOnDisk && Boolean(localMcpConsent?.acknowledged);
|
|
2330
|
+
const earlySignerOk = configResult.runtimeMcpMode === "local_stdio" ? earlyLocalMcpOk : configResult.signerConfigured && signerCredentialOnDisk && Boolean(signerConsent?.acknowledged);
|
|
2331
|
+
try {
|
|
2332
|
+
await deps.onRuntimeConfigured({
|
|
2333
|
+
runtime,
|
|
2334
|
+
runtimeMcpMode: configResult.runtimeMcpMode,
|
|
2335
|
+
hostedMcpConfigured: configResult.hostedConfigured,
|
|
2336
|
+
localSignerConfigured: earlySignerOk,
|
|
2337
|
+
localMcpConfigured: earlyLocalMcpOk,
|
|
2338
|
+
signerAcknowledged: signerConsent?.acknowledged,
|
|
2339
|
+
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2340
|
+
restartRequired: configResult.restartRequired || restartRequiredForRuntime(runtime, deps.env),
|
|
2341
|
+
nextUserAction: nextAction(runtime, profile.restartMode, configResult.errorCode),
|
|
2342
|
+
errorCode: configResult.errorCode
|
|
2343
|
+
});
|
|
2344
|
+
} catch {
|
|
2345
|
+
}
|
|
1591
2346
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
detail: "No stored API key / hosted MCP URL to probe with.",
|
|
1638
|
-
repair: `Re-run the full setup: ${RERUN} --setup <token>.`
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
const localDelegate = typeof signerFile?.delegate_address === "string" ? signerFile.delegate_address : void 0;
|
|
1642
|
-
if (identity?.api_key && identity.api_url) {
|
|
1643
|
-
const probe = await (deps.probeHostedIdentity ?? probeHostedAgentIdentity)(
|
|
1644
|
-
identity.api_key,
|
|
1645
|
-
identity.api_url,
|
|
1646
|
-
deps.fetch
|
|
1647
|
-
);
|
|
1648
|
-
if (probe.status !== "ok") {
|
|
1649
|
-
checks.push({
|
|
1650
|
-
id: "identity_match",
|
|
1651
|
-
label: "Hosted identity matches the local signing key",
|
|
1652
|
-
ok: false,
|
|
1653
|
-
detail: probe.status === "unauthorized" ? "The stored API key was rejected, so the agent it authenticates as cannot be compared with the local signing key." : `Could not read the hosted identity (${probe.status}) \u2014 the comparison did not happen, so it cannot be reported as a match.`,
|
|
1654
|
-
repair: probe.status === "unauthorized" ? `Re-run the full setup with a fresh token: ${RERUN} --setup <token>.` : `Restore network access to the Haven API, then re-run: ${RERUN} --doctor --runtime ${input.runtime}`
|
|
1655
|
-
});
|
|
1656
|
-
} else if (!localDelegate) {
|
|
1657
|
-
checks.push({
|
|
1658
|
-
id: "identity_match",
|
|
1659
|
-
label: "Hosted identity matches the local signing key",
|
|
1660
|
-
ok: false,
|
|
1661
|
-
detail: "signer.json holds no delegate_address to compare against the hosted identity.",
|
|
1662
|
-
repair: `Re-run the full setup with a fresh token: ${RERUN} --setup <token>.`
|
|
1663
|
-
});
|
|
1664
|
-
} else {
|
|
1665
|
-
const same = probe.delegateAddress?.toLowerCase() === localDelegate.toLowerCase();
|
|
1666
|
-
checks.push({
|
|
1667
|
-
id: "identity_match",
|
|
1668
|
-
label: "Hosted identity matches the local signing key",
|
|
1669
|
-
ok: same,
|
|
1670
|
-
detail: same ? `The stored API key authenticates as the agent whose signing key is in this directory (${shortAddress(localDelegate)}).` : `MISMATCH: the stored API key authenticates as agent ${probe.agentId ?? "unknown"} with delegate ${shortAddress(probe.delegateAddress ?? "unknown")}, but signer.json here holds ${shortAddress(localDelegate)}. This runtime would quote as one agent and sign as another.`,
|
|
1671
|
-
...same ? {} : {
|
|
1672
|
-
repair: `Re-run setup for this agent so its API key and signing key come from one run: ${RERUN} --setup <token>. Do not hand-edit either file.`
|
|
1673
|
-
}
|
|
1674
|
-
});
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
if (sidecar) {
|
|
1678
|
-
const consent = await getLocalSignerConsentStatus(join(directory, "signer.json"));
|
|
1679
|
-
if (!consent.acknowledged) {
|
|
1680
|
-
checks.push({
|
|
1681
|
-
id: "signer_process",
|
|
1682
|
-
label: "Signer stdio handshake",
|
|
1683
|
-
ok: false,
|
|
1684
|
-
detail: "The local-tools consent is not acknowledged, so the signer refuses to start (by design).",
|
|
1685
|
-
repair: `Run: ${RERUN} --ack-local-tools --setup <token> (or re-run your original setup command with --ack-local-tools).`
|
|
1686
|
-
});
|
|
1687
|
-
} else {
|
|
1688
|
-
const probe = await (deps.probeSignerTools ?? probeLocalMcpTools)(
|
|
1689
|
-
sidecar.wrapper_path,
|
|
1690
|
-
[],
|
|
1691
|
-
MCP_RUNTIME_MANIFEST.requiredSignerTools
|
|
1692
|
-
);
|
|
1693
|
-
const experimental = probe.capabilities?.experimental ?? probe.capabilities;
|
|
1694
|
-
const compat = experimental?.["haven/signer-compatibility"];
|
|
1695
|
-
signerCapabilities = compat ? { "haven/signer-compatibility": compat } : void 0;
|
|
1696
|
-
const compatDetail = compat ? ` Compat: x402 expected-context v${JSON.stringify(compat.x402_expected_context_versions ?? "?")}.` : "";
|
|
1697
|
-
checks.push({
|
|
1698
|
-
id: "signer_process",
|
|
1699
|
-
label: "Signer stdio handshake",
|
|
1700
|
-
ok: probe.status === "ok",
|
|
1701
|
-
detail: probe.status === "ok" ? `Signer started, listed ${probe.toolNames?.length ?? 0} tools${probe.serverInfo?.version ? ` (v${probe.serverInfo.version})` : ""}.${compatDetail}` : `Handshake failed: ${probe.status}.`,
|
|
1702
|
-
...probe.status === "ok" ? {} : { repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}` }
|
|
1703
|
-
});
|
|
1704
|
-
}
|
|
1705
|
-
} else {
|
|
1706
|
-
checks.push({
|
|
1707
|
-
id: "signer_process",
|
|
1708
|
-
label: "Signer stdio handshake",
|
|
1709
|
-
ok: false,
|
|
1710
|
-
detail: "Skipped \u2014 no prepared signer runtime to probe.",
|
|
1711
|
-
repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}`
|
|
1712
|
-
});
|
|
1713
|
-
}
|
|
1714
|
-
return { checks, ...signerCapabilities ? { signerCapabilities } : {} };
|
|
2347
|
+
progress("Almost there \u2014 just confirming everything connects\u2026");
|
|
2348
|
+
const localProbePromise = configResult.runtimeMcpMode === "local_stdio" && localRuntimeInstall ? runLocalMcpProbe(localRuntimeInstall, deps) : Promise.resolve(void 0);
|
|
2349
|
+
const signerProbePromise = configResult.runtimeMcpMode !== "local_stdio" && signerCommand ? (deps.probeSignerTools ?? probeLocalMcpTools)(
|
|
2350
|
+
signerCommand.command,
|
|
2351
|
+
signerCommand.args,
|
|
2352
|
+
MCP_RUNTIME_MANIFEST.requiredSignerTools
|
|
2353
|
+
) : Promise.resolve(void 0);
|
|
2354
|
+
const [hostedProbe, signerCredentialReady, localMcpProbe, signerProbe] = await Promise.all([
|
|
2355
|
+
configResult.hostedConfigured ? probeHostedMcpTools(input.apiKey, input.hostedMcpUrl, deps.fetch) : Promise.resolve({ status: "bad_response" }),
|
|
2356
|
+
probeLocalSignerCredential(input.signerPath),
|
|
2357
|
+
localProbePromise,
|
|
2358
|
+
signerProbePromise
|
|
2359
|
+
]);
|
|
2360
|
+
const hostedOk = configResult.hostedConfigured && hostedProbe.status === "ok";
|
|
2361
|
+
const localMcpOk = configResult.runtimeMcpMode === "local_stdio" && configResult.localMcpConfigured && signerCredentialReady && Boolean(localMcpConsent?.acknowledged) && localMcpProbe?.status === "ok";
|
|
2362
|
+
const signerOk = configResult.runtimeMcpMode === "local_stdio" ? localMcpOk : configResult.signerConfigured && signerCredentialReady && Boolean(signerConsent?.acknowledged) && // #1587: no handshake, no green. A signer command that was registered
|
|
2363
|
+
// but not probed (manual topology) keeps the old semantics.
|
|
2364
|
+
(signerProbe === void 0 || signerProbe.status === "ok");
|
|
2365
|
+
const restartRequired = configResult.restartRequired || restartRequiredForRuntime(runtime, deps.env);
|
|
2366
|
+
const errorCode = configResult.errorCode ?? (configResult.runtimeMcpMode === "local_stdio" ? localMcpErrorCode(signerCredentialReady, localMcpConsent, localMcpProbe?.status) : hostedMcpErrorCode(configResult.hostedConfigured, hostedProbe.status) ?? signerConsentErrorCode(signerCredentialReady, signerConsent) ?? signerProbeErrorCode(signerProbe));
|
|
2367
|
+
const hostedProbeMessages = configResult.hostedConfigured && hostedProbe.status !== "ok" ? [`Hosted Haven MCP probe failed: ${hostedProbe.status}.`] : configResult.hostedConfigured ? ["Verified hosted Haven MCP tools with a read-only handshake."] : [];
|
|
2368
|
+
const signerProbeMessages = signerProbe ? signerProbe.status === "ok" ? ["Verified local Haven signer with a stdio handshake."] : [
|
|
2369
|
+
`Local Haven signer handshake failed: ${signerProbe.status}.`,
|
|
2370
|
+
"Re-run `npx @haven_ai/connect@alpha` to repair the signer setup."
|
|
2371
|
+
] : [];
|
|
2372
|
+
const localProbeMessages = localMcpProbe && localMcpProbe.status !== "ok" ? [`Local Haven MCP handshake failed: ${localMcpProbe.status}.`] : localMcpProbe?.status === "ok" ? ["Verified local Haven MCP tools with a stdio handshake."] : [];
|
|
2373
|
+
const skillInstall = !configResult.errorCode ? await installSkillForRuntime(runtime, { homeDir: deps.homeDir, env: deps.env }) : void 0;
|
|
2374
|
+
return {
|
|
2375
|
+
runtime,
|
|
2376
|
+
runtimeMcpMode: configResult.runtimeMcpMode,
|
|
2377
|
+
hostedMcpConfigured: hostedOk,
|
|
2378
|
+
localSignerConfigured: signerOk,
|
|
2379
|
+
localMcpConfigured: localMcpOk,
|
|
2380
|
+
probeResult: buildProbeResult(configResult.runtimeMcpMode, configResult.hostedConfigured, hostedProbe.status, signerOk, localMcpOk, localMcpProbe?.status),
|
|
2381
|
+
restartRequired,
|
|
2382
|
+
nextUserAction: nextAction(runtime, profile.restartMode, errorCode),
|
|
2383
|
+
errorCode,
|
|
2384
|
+
configTarget: configResult.target,
|
|
2385
|
+
signerAcknowledged: signerConsent?.acknowledged,
|
|
2386
|
+
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2387
|
+
activationCommand: configResult.activationCommand,
|
|
2388
|
+
skillInstalled: skillInstall?.installed,
|
|
2389
|
+
signerRuntimePrepared,
|
|
2390
|
+
messages: [...consentMessages, ...localRuntimeInstall?.messages ?? [], ...configResult.messages, ...hostedProbeMessages, ...signerProbeMessages, ...localProbeMessages, ...skillInstall?.messages ?? []]
|
|
2391
|
+
};
|
|
1715
2392
|
}
|
|
1716
|
-
|
|
1717
|
-
const
|
|
1718
|
-
const checks = [];
|
|
1719
|
-
let signerCapabilities;
|
|
1720
|
-
const { directory, others } = await discoverCredentialDirectory(homeDir, input.credentialsDir);
|
|
1721
|
-
const configPath = runtimeConfigPathFor(input.runtime, homeDir);
|
|
1722
|
-
let configText = null;
|
|
1723
|
-
if (configPath !== null) {
|
|
1724
|
-
try {
|
|
1725
|
-
configText = await readFile(configPath, "utf8");
|
|
1726
|
-
} catch {
|
|
1727
|
-
configText = null;
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
const allDirectories = directory ? [directory, ...others] : others;
|
|
1731
|
-
let bareOwnerExists = false;
|
|
1732
|
-
for (const dir of allDirectories) {
|
|
1733
|
-
const sidecar = await readRuntimeSidecar(dir);
|
|
1734
|
-
if (!sidecar?.server_name && sidecar?.wrapper_path && configText?.includes(sidecar.wrapper_path)) {
|
|
1735
|
-
bareOwnerExists = true;
|
|
1736
|
-
break;
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
const inventory = [];
|
|
1740
|
-
const capabilitiesByDirectory = /* @__PURE__ */ new Map();
|
|
1741
|
-
const primaryChecksById = /* @__PURE__ */ new Map();
|
|
1742
|
-
for (const dir of allDirectories) {
|
|
1743
|
-
const identity = await readIdentity(dir);
|
|
1744
|
-
const sidecar = await readRuntimeSidecar(dir);
|
|
1745
|
-
const tombstone = await readAgentTombstone(dir);
|
|
1746
|
-
const slug = sidecar?.server_name;
|
|
1747
|
-
const names = serverNamesFor(slug);
|
|
1748
|
-
if (!identity?.api_key) {
|
|
1749
|
-
inventory.push({
|
|
1750
|
-
...slug ? { slug } : {},
|
|
1751
|
-
...tombstone?.agent_id ? { agentId: tombstone.agent_id } : {},
|
|
1752
|
-
directory: dir,
|
|
1753
|
-
classification: tombstone ? "retired" : "orphaned",
|
|
1754
|
-
checks: []
|
|
1755
|
-
});
|
|
1756
|
-
continue;
|
|
1757
|
-
}
|
|
1758
|
-
const wired = agentIsWired(configText, names, slug, identity, sidecar, dir === directory, bareOwnerExists);
|
|
1759
|
-
const entry = {
|
|
1760
|
-
...slug ? { slug } : {},
|
|
1761
|
-
...identity.agent_id ? { agentId: identity.agent_id } : {},
|
|
1762
|
-
directory: dir,
|
|
1763
|
-
classification: wired ? "wired" : "superseded",
|
|
1764
|
-
checks: []
|
|
1765
|
-
};
|
|
1766
|
-
if (wired) {
|
|
1767
|
-
const result = await checksForAgent({ directory: dir, identity, sidecar }, input, deps);
|
|
1768
|
-
entry.checks = result.checks;
|
|
1769
|
-
capabilitiesByDirectory.set(dir, result.signerCapabilities);
|
|
1770
|
-
}
|
|
1771
|
-
inventory.push(entry);
|
|
1772
|
-
}
|
|
1773
|
-
const wiredDirectories = inventory.filter((entry) => entry.classification === "wired").map((entry) => entry.directory);
|
|
1774
|
-
const primaryDirectory = input.credentialsDir ? directory : wiredDirectories.includes(directory ?? "") ? directory : wiredDirectories[0] ?? directory;
|
|
1775
|
-
if (primaryDirectory) {
|
|
1776
|
-
const primaryEntry = inventory.find((entry) => entry.directory === primaryDirectory);
|
|
1777
|
-
signerCapabilities = capabilitiesByDirectory.get(primaryDirectory);
|
|
1778
|
-
for (const check of primaryEntry?.checks ?? []) primaryChecksById.set(check.id, check);
|
|
1779
|
-
}
|
|
1780
|
-
if (!primaryDirectory) {
|
|
1781
|
-
checks.push({
|
|
1782
|
-
id: "credentials",
|
|
1783
|
-
label: "Agent credentials",
|
|
1784
|
-
ok: false,
|
|
1785
|
-
detail: "No agent credential directory with an identity.json under ~/.haven/agents.",
|
|
1786
|
-
repair: `Run the full setup once: ${RERUN} --setup <token from the Haven dashboard>.`
|
|
1787
|
-
});
|
|
1788
|
-
} else {
|
|
1789
|
-
const primaryIdentity = await readIdentity(primaryDirectory);
|
|
1790
|
-
const primarySidecar = await readRuntimeSidecar(primaryDirectory);
|
|
1791
|
-
if (primaryChecksById.size === 0) {
|
|
1792
|
-
const result = await checksForAgent(
|
|
1793
|
-
{ directory: primaryDirectory, identity: primaryIdentity, sidecar: primarySidecar },
|
|
1794
|
-
input,
|
|
1795
|
-
deps
|
|
1796
|
-
);
|
|
1797
|
-
signerCapabilities = result.signerCapabilities;
|
|
1798
|
-
for (const check of result.checks) primaryChecksById.set(check.id, check);
|
|
1799
|
-
}
|
|
1800
|
-
for (const id of ["credentials", "signer_runtime"]) {
|
|
1801
|
-
const check = primaryChecksById.get(id);
|
|
1802
|
-
if (check) checks.push(check);
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
if (configPath === null) {
|
|
1806
|
-
checks.push({
|
|
1807
|
-
id: "runtime_config",
|
|
1808
|
-
label: "Runtime MCP config",
|
|
1809
|
-
ok: true,
|
|
1810
|
-
detail: `Runtime '${input.runtime}' has no file-based config the connector owns (CLI-managed) \u2014 skipping the file check.`
|
|
1811
|
-
});
|
|
1812
|
-
} else if (configText === null) {
|
|
1813
|
-
checks.push({
|
|
1814
|
-
id: "runtime_config",
|
|
1815
|
-
label: "Runtime MCP config",
|
|
1816
|
-
ok: false,
|
|
1817
|
-
detail: `No runtime config at ${configPath}.`,
|
|
1818
|
-
repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}`
|
|
1819
|
-
});
|
|
1820
|
-
} else {
|
|
1821
|
-
const primaryIdentity = await readIdentity(primaryDirectory ?? "");
|
|
1822
|
-
const primarySidecar = primaryDirectory ? await readRuntimeSidecar(primaryDirectory) : null;
|
|
1823
|
-
const hasHaven = primaryIdentity?.hosted_mcp_url ? configText.includes(primaryIdentity.hosted_mcp_url) : configText.includes("haven");
|
|
1824
|
-
const signerViaNpx = configText.includes("@haven_ai/signer");
|
|
1825
|
-
const wrapperReferenced = primarySidecar ? configText.includes(primarySidecar.wrapper_path) : false;
|
|
1826
|
-
const ok = hasHaven && !signerViaNpx && (primarySidecar ? wrapperReferenced : true);
|
|
1827
|
-
checks.push({
|
|
1828
|
-
id: "runtime_config",
|
|
1829
|
-
label: "Runtime MCP config",
|
|
1830
|
-
ok,
|
|
1831
|
-
detail: ok ? `Config at ${configPath} references the hosted server and the prepared signer wrapper.` : signerViaNpx ? `Config at ${configPath} still launches the signer via npx \u2014 the pre-#1586 shape that cannot start under a 120s startup timeout.` : `Config at ${configPath} is missing the Haven entries${primarySidecar && !wrapperReferenced ? " (or references a different signer wrapper)" : ""}.`,
|
|
1832
|
-
...ok ? {} : { repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}` }
|
|
1833
|
-
});
|
|
1834
|
-
}
|
|
1835
|
-
for (const id of ["hosted_mcp", "identity_match"]) {
|
|
1836
|
-
const check = primaryChecksById.get(id);
|
|
1837
|
-
if (check) checks.push(check);
|
|
1838
|
-
}
|
|
1839
|
-
const otherEntries = inventory.filter((entry) => entry.directory !== primaryDirectory);
|
|
1840
|
-
if (otherEntries.length > 0) {
|
|
1841
|
-
const live = [];
|
|
1842
|
-
const revoked = [];
|
|
1843
|
-
const unverifiable = [];
|
|
1844
|
-
const retired = [];
|
|
1845
|
-
for (const entry of otherEntries) {
|
|
1846
|
-
const identity = await readIdentity(entry.directory);
|
|
1847
|
-
const tombstone = await readAgentTombstone(entry.directory);
|
|
1848
|
-
const otherAgent = identity?.agent_id ?? tombstone?.agent_id ?? basename(entry.directory);
|
|
1849
|
-
const otherUrl = identity?.hosted_mcp_url ?? (identity?.api_url ? `${identity.api_url}/mcp` : void 0);
|
|
1850
|
-
if (!identity?.api_key || !otherUrl) {
|
|
1851
|
-
if (tombstone) retired.push(`${otherAgent} (retired ${tombstone.retired_at})`);
|
|
1852
|
-
else unverifiable.push(`${otherAgent} (no stored key/URL to probe)`);
|
|
1853
|
-
continue;
|
|
1854
|
-
}
|
|
1855
|
-
const suffix = tombstone ? " [tombstoned \u2014 key material still present]" : "";
|
|
1856
|
-
const probe = await (deps.probeHosted ?? probeHostedMcpTools)(identity.api_key, otherUrl, deps.fetch);
|
|
1857
|
-
if (probe.status === "ok") live.push({ label: `${otherAgent}${suffix}`, entry });
|
|
1858
|
-
else if (probe.status === "unauthorized") revoked.push(`${otherAgent}${suffix}`);
|
|
1859
|
-
else unverifiable.push(`${otherAgent} (${probe.status})${suffix}`);
|
|
1860
|
-
}
|
|
1861
|
-
const parts = [];
|
|
1862
|
-
if (live.length > 0) parts.push(`STILL SPEND-CAPABLE: ${live.map((item) => item.label).join(", ")}`);
|
|
1863
|
-
if (revoked.length > 0) parts.push(`already revoked: ${revoked.join(", ")}`);
|
|
1864
|
-
if (retired.length > 0) parts.push(`tombstoned (keys removed): ${retired.join(", ")}`);
|
|
1865
|
-
if (unverifiable.length > 0) parts.push(`could not verify: ${unverifiable.join(", ")}`);
|
|
1866
|
-
const supersededLive = live.filter((item) => item.entry.classification !== "wired").map((item) => item.label);
|
|
1867
|
-
checks.push({
|
|
1868
|
-
id: "superseded_agents",
|
|
1869
|
-
label: "Superseded agent credentials",
|
|
1870
|
-
ok: supersededLive.length === 0,
|
|
1871
|
-
detail: supersededLive.length > 0 ? `${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.` : `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}.`,
|
|
1872
|
-
...supersededLive.length > 0 ? {
|
|
1873
|
-
repair: `Revoke ${supersededLive.join(", ")} on the Haven agent page, then remove the old director(y/ies) under ~/.haven/agents. Connect never revokes or deletes for you.`
|
|
1874
|
-
} : {}
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
1877
|
-
const signerProcess = primaryChecksById.get("signer_process");
|
|
1878
|
-
if (signerProcess) checks.push(signerProcess);
|
|
1879
|
-
const restart = restartRequiredForRuntime(input.runtime, deps.env);
|
|
1880
|
-
checks.push({
|
|
1881
|
-
id: "restart",
|
|
1882
|
-
label: "Runtime restart",
|
|
1883
|
-
ok: true,
|
|
1884
|
-
detail: restart ? "This runtime loads MCP config at startup \u2014 restart it after any repair before expecting the tools to appear." : "No restart requirement known for this runtime."
|
|
1885
|
-
});
|
|
1886
|
-
const wiredOk = inventory.filter((entry) => entry.classification === "wired").every((entry) => entry.checks.every((check) => check.ok));
|
|
2393
|
+
function runtimeInstallCapabilities(runtime, env = process.env) {
|
|
2394
|
+
const profile = runtimeProfile(runtime, env);
|
|
1887
2395
|
return {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
runtime: input.runtime,
|
|
1891
|
-
credentialDirectory: primaryDirectory,
|
|
1892
|
-
checks,
|
|
1893
|
-
agents: inventory,
|
|
1894
|
-
...signerCapabilities ? { signerCapabilities } : {}
|
|
2396
|
+
canWriteRuntimeConfig: profile.canWriteRuntimeConfig,
|
|
2397
|
+
restartRequired: restartRequiredForRuntime(runtime, env)
|
|
1895
2398
|
};
|
|
1896
2399
|
}
|
|
1897
|
-
async function
|
|
1898
|
-
const
|
|
1899
|
-
const
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
2400
|
+
async function configureClaudeCode(deps, localMcpCommand, serverName) {
|
|
2401
|
+
const runCommand = deps.runCommand ?? defaultRunCommand;
|
|
2402
|
+
const serverJson = JSON.stringify({
|
|
2403
|
+
type: "stdio",
|
|
2404
|
+
command: localMcpCommand,
|
|
2405
|
+
args: [],
|
|
2406
|
+
env: {}
|
|
2407
|
+
});
|
|
2408
|
+
try {
|
|
2409
|
+
if (!localMcpCommand) throw new Error("local MCP wrapper command is required");
|
|
2410
|
+
const names = serverNamesFor(serverName);
|
|
2411
|
+
await runCommand("claude", ["mcp", "remove", names.hosted]).catch(() => void 0);
|
|
2412
|
+
await runCommand("claude", ["mcp", "remove", names.signer]).catch(() => void 0);
|
|
2413
|
+
await runCommand("claude", ["mcp", "add-json", names.hosted, serverJson, "--scope", "user"]).catch(async () => {
|
|
2414
|
+
await runCommand("claude", ["mcp", "add", names.hosted, "--scope", "user", "--", localMcpCommand]);
|
|
2415
|
+
});
|
|
2416
|
+
const verified = await runCommand("claude", ["mcp", "get", names.hosted]).then(() => true).catch(() => false);
|
|
1905
2417
|
return {
|
|
1906
|
-
|
|
1907
|
-
|
|
2418
|
+
hostedConfigured: false,
|
|
2419
|
+
signerConfigured: true,
|
|
2420
|
+
localMcpConfigured: true,
|
|
2421
|
+
runtimeMcpMode: "local_stdio",
|
|
2422
|
+
target: "Claude Code MCP config",
|
|
2423
|
+
changed: true,
|
|
2424
|
+
restartRequired: true,
|
|
2425
|
+
messages: [
|
|
2426
|
+
"Updated local Haven MCP entry with Claude Code.",
|
|
2427
|
+
...verified ? ["Verified Claude Code MCP entry."] : []
|
|
2428
|
+
]
|
|
1908
2429
|
};
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
ok: false,
|
|
1926
|
-
messages: [
|
|
1927
|
-
`The config at ${configPath} is the LOCAL-stdio topology (--local). Repair currently rewrites only the hosted+signer shape and will not touch it.`,
|
|
1928
|
-
"Re-run your original setup command (with --local) to repair a local-stdio install."
|
|
1929
|
-
]
|
|
1930
|
-
};
|
|
1931
|
-
}
|
|
1932
|
-
} catch {
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
const signerPath = join(directory, "signer.json");
|
|
1936
|
-
const prepared = await prepareSignerRuntime(
|
|
1937
|
-
{ credentialDirectory: directory, signerPath, homeDir },
|
|
1938
|
-
{ runCommand: deps.runCommand }
|
|
1939
|
-
);
|
|
1940
|
-
messages.push(...prepared.messages);
|
|
1941
|
-
const configResult = await writeRuntimeConfig({
|
|
1942
|
-
runtime: input.runtime,
|
|
1943
|
-
hostedMcpUrl: identity.hosted_mcp_url ?? `${identity.api_url}/mcp`,
|
|
1944
|
-
apiKey: identity.api_key,
|
|
1945
|
-
identityPath: join(directory, "identity.json"),
|
|
1946
|
-
signerPath,
|
|
1947
|
-
credentialDirectory: directory,
|
|
1948
|
-
signerCommand: { command: prepared.command, args: prepared.args },
|
|
1949
|
-
homeDir,
|
|
1950
|
-
mode: "hosted"
|
|
1951
|
-
});
|
|
1952
|
-
messages.push(...configResult.messages);
|
|
1953
|
-
messages.push("Repair complete \u2014 restart the runtime, then verify with --doctor.");
|
|
1954
|
-
return { ok: true, messages };
|
|
1955
|
-
}
|
|
1956
|
-
var RERUN;
|
|
1957
|
-
var init_doctor = __esm({
|
|
1958
|
-
"src/doctor.ts"() {
|
|
1959
|
-
init_runtime_manifest();
|
|
1960
|
-
init_probes();
|
|
1961
|
-
init_signer_runtime();
|
|
1962
|
-
init_config_writers();
|
|
1963
|
-
init_runtime_registry();
|
|
1964
|
-
init_signer_consent();
|
|
1965
|
-
init_tombstone();
|
|
1966
|
-
init_server_names();
|
|
1967
|
-
init_redact();
|
|
1968
|
-
RERUN = "npx @haven_ai/connect@alpha";
|
|
1969
|
-
}
|
|
1970
|
-
});
|
|
1971
|
-
|
|
1972
|
-
// src/api.ts
|
|
1973
|
-
function createConnectApiClient(baseUrl, fetchImpl = fetch) {
|
|
1974
|
-
const root = baseUrl.replace(/\/+$/, "");
|
|
1975
|
-
return {
|
|
1976
|
-
resolveSetup: (input) => request(fetchImpl, `${root}/agent-connection-setups/resolve`, {
|
|
1977
|
-
method: "POST",
|
|
1978
|
-
body: JSON.stringify({
|
|
1979
|
-
setup_token: input.setupToken,
|
|
1980
|
-
connector_version: input.connectorVersion,
|
|
1981
|
-
runtime: input.runtime
|
|
1982
|
-
})
|
|
1983
|
-
}),
|
|
1984
|
-
registerSetup: (input) => request(fetchImpl, `${root}/agent-connection-setups/register`, {
|
|
1985
|
-
method: "POST",
|
|
1986
|
-
body: JSON.stringify({
|
|
1987
|
-
setup_token: input.setupToken,
|
|
1988
|
-
challenge_id: input.challengeId,
|
|
1989
|
-
delegate_address: input.delegateAddress,
|
|
1990
|
-
proof_signature: input.proofSignature,
|
|
1991
|
-
api_key_hash: input.apiKeyHash,
|
|
1992
|
-
api_key_prefix: input.apiKeyPrefix,
|
|
1993
|
-
runtime: input.runtime,
|
|
1994
|
-
connector_version: input.connectorVersion,
|
|
1995
|
-
connector_context: input.connectorContext,
|
|
1996
|
-
install_capabilities: input.installCapabilities && {
|
|
1997
|
-
can_write_runtime_config: input.installCapabilities.canWriteRuntimeConfig,
|
|
1998
|
-
restart_required: input.installCapabilities.restartRequired
|
|
1999
|
-
}
|
|
2000
|
-
})
|
|
2001
|
-
}),
|
|
2002
|
-
getConnectorStatus: (setupId, apiKey) => request(fetchImpl, `${root}/agent-connection-setups/${encodeURIComponent(setupId)}/connector-status`, {
|
|
2003
|
-
method: "GET",
|
|
2004
|
-
headers: { Authorization: `Bearer ${apiKey}` }
|
|
2005
|
-
}),
|
|
2006
|
-
updateInstallStatus: async (setupId, apiKey, input) => {
|
|
2007
|
-
await request(fetchImpl, `${root}/agent-connection-setups/${encodeURIComponent(setupId)}/install-status`, {
|
|
2008
|
-
method: "POST",
|
|
2009
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
2010
|
-
body: JSON.stringify({
|
|
2011
|
-
runtime: input.runtime,
|
|
2012
|
-
connector_version: input.connectorVersion,
|
|
2013
|
-
runtime_mcp_mode: input.runtimeMcpMode,
|
|
2014
|
-
hosted_mcp_configured: input.hostedMcpConfigured,
|
|
2015
|
-
local_signer_configured: input.localSignerConfigured,
|
|
2016
|
-
local_mcp_configured: input.localMcpConfigured,
|
|
2017
|
-
credential_files_written: input.credentialFilesWritten,
|
|
2018
|
-
signer_acknowledged: input.signerAcknowledged,
|
|
2019
|
-
local_mcp_acknowledged: input.localMcpAcknowledged,
|
|
2020
|
-
activation_command_available: input.activationCommandAvailable,
|
|
2021
|
-
skill_installed: input.skillInstalled,
|
|
2022
|
-
probe_result: input.probeResult,
|
|
2023
|
-
restart_required: input.restartRequired,
|
|
2024
|
-
next_user_action: input.nextUserAction,
|
|
2025
|
-
error_code: input.errorCode ?? null,
|
|
2026
|
-
environment_label: input.environmentLabel
|
|
2027
|
-
})
|
|
2028
|
-
});
|
|
2029
|
-
}
|
|
2030
|
-
};
|
|
2430
|
+
} catch (err) {
|
|
2431
|
+
return {
|
|
2432
|
+
hostedConfigured: false,
|
|
2433
|
+
signerConfigured: false,
|
|
2434
|
+
localMcpConfigured: false,
|
|
2435
|
+
runtimeMcpMode: "local_stdio",
|
|
2436
|
+
target: "Claude Code MCP config",
|
|
2437
|
+
changed: false,
|
|
2438
|
+
restartRequired: true,
|
|
2439
|
+
messages: [
|
|
2440
|
+
`Could not update Claude Code MCP config: ${err instanceof Error ? err.message : String(err)}`,
|
|
2441
|
+
"Install Claude Code or rerun the Haven setup command inside a Claude Code terminal."
|
|
2442
|
+
],
|
|
2443
|
+
errorCode: "claude_code_config_failed"
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2031
2446
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
this.status = status;
|
|
2036
|
-
this.name = "ConnectRequestError";
|
|
2447
|
+
async function writeHostedRuntimeConfig(deps, input, signerCommand) {
|
|
2448
|
+
if (input.runtime === "claude-code") {
|
|
2449
|
+
return configureClaudeCodeHosted(deps, input, signerCommand);
|
|
2037
2450
|
}
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2451
|
+
return writeRuntimeConfig({
|
|
2452
|
+
runtime: input.runtime,
|
|
2453
|
+
hostedMcpUrl: input.hostedMcpUrl,
|
|
2454
|
+
apiKey: input.apiKey,
|
|
2455
|
+
identityPath: input.identityPath,
|
|
2456
|
+
signerPath: input.signerPath,
|
|
2457
|
+
serverName: input.serverName,
|
|
2458
|
+
credentialDirectory: input.credentialDirectory,
|
|
2459
|
+
signerCommand,
|
|
2460
|
+
homeDir: deps.homeDir,
|
|
2461
|
+
mode: "hosted"
|
|
2047
2462
|
});
|
|
2048
|
-
const text = await response.text();
|
|
2049
|
-
const body = text ? JSON.parse(text) : null;
|
|
2050
|
-
if (!response.ok) {
|
|
2051
|
-
const message = body?.error ?? body?.message ?? `${response.status} ${response.statusText}`;
|
|
2052
|
-
throw new ConnectRequestError(`Haven setup request failed: ${message}`, response.status);
|
|
2053
|
-
}
|
|
2054
|
-
return body;
|
|
2055
|
-
}
|
|
2056
|
-
function generateDelegateKey() {
|
|
2057
|
-
return delegateKeyFromPrivateKey(Wallet.createRandom().privateKey);
|
|
2058
|
-
}
|
|
2059
|
-
function delegateKeyFromPrivateKey(privateKey) {
|
|
2060
|
-
const wallet = new Wallet(privateKey);
|
|
2061
|
-
return {
|
|
2062
|
-
privateKey: wallet.privateKey,
|
|
2063
|
-
address: wallet.address,
|
|
2064
|
-
signChallenge: (message) => wallet.signMessage(message)
|
|
2065
|
-
};
|
|
2066
|
-
}
|
|
2067
|
-
function generateAgentApiKey() {
|
|
2068
|
-
return `sk_agent_${crypto.randomBytes(24).toString("hex")}`;
|
|
2069
|
-
}
|
|
2070
|
-
function hashAgentApiKey(apiKey) {
|
|
2071
|
-
return crypto.createHash("sha256").update(apiKey).digest("hex");
|
|
2072
|
-
}
|
|
2073
|
-
function agentApiKeyPrefix(apiKey) {
|
|
2074
|
-
return apiKey.slice(0, 12);
|
|
2075
2463
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2464
|
+
async function configureClaudeCodeHosted(deps, input, signerCommand) {
|
|
2465
|
+
const runCommand = deps.runCommand ?? defaultRunCommand;
|
|
2466
|
+
const hostedJson = JSON.stringify({
|
|
2467
|
+
type: "http",
|
|
2468
|
+
url: input.hostedMcpUrl,
|
|
2469
|
+
headers: { Authorization: `Bearer ${input.apiKey}` }
|
|
2470
|
+
});
|
|
2471
|
+
const signerJson = JSON.stringify({
|
|
2472
|
+
type: "stdio",
|
|
2473
|
+
command: signerCommand?.command ?? "npx",
|
|
2474
|
+
args: signerCommand?.args ?? ["-y", signerPackageSpec(), "--credentials", input.signerPath],
|
|
2475
|
+
env: {}
|
|
2476
|
+
});
|
|
2085
2477
|
try {
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
await
|
|
2478
|
+
const names = serverNamesFor(input.serverName);
|
|
2479
|
+
await runCommand("claude", ["mcp", "remove", names.hosted]).catch(() => void 0);
|
|
2480
|
+
await runCommand("claude", ["mcp", "remove", names.signer]).catch(() => void 0);
|
|
2481
|
+
await runCommand("claude", ["mcp", "add-json", names.hosted, hostedJson, "--scope", "user"]);
|
|
2482
|
+
await runCommand("claude", ["mcp", "add-json", names.signer, signerJson, "--scope", "user"]);
|
|
2483
|
+
const verified = await runCommand("claude", ["mcp", "get", names.hosted]).then(() => true).catch(() => false);
|
|
2484
|
+
return {
|
|
2485
|
+
hostedConfigured: true,
|
|
2486
|
+
signerConfigured: true,
|
|
2487
|
+
localMcpConfigured: false,
|
|
2488
|
+
runtimeMcpMode: "hosted_plus_signer",
|
|
2489
|
+
target: "Claude Code MCP config",
|
|
2490
|
+
changed: true,
|
|
2491
|
+
restartRequired: true,
|
|
2492
|
+
messages: [
|
|
2493
|
+
"Updated hosted Haven MCP and local signer entries with Claude Code.",
|
|
2494
|
+
...verified ? ["Verified Claude Code MCP entry."] : []
|
|
2495
|
+
]
|
|
2496
|
+
};
|
|
2497
|
+
} catch (err) {
|
|
2498
|
+
return {
|
|
2499
|
+
hostedConfigured: false,
|
|
2500
|
+
signerConfigured: false,
|
|
2501
|
+
localMcpConfigured: false,
|
|
2502
|
+
runtimeMcpMode: "hosted_plus_signer",
|
|
2503
|
+
target: "Claude Code MCP config",
|
|
2504
|
+
changed: false,
|
|
2505
|
+
restartRequired: true,
|
|
2506
|
+
messages: [
|
|
2507
|
+
`Could not update Claude Code MCP config: ${err instanceof Error ? err.message : String(err)}`,
|
|
2508
|
+
"Install Claude Code or rerun the Haven setup command inside a Claude Code terminal."
|
|
2509
|
+
],
|
|
2510
|
+
errorCode: "claude_code_config_failed"
|
|
2511
|
+
};
|
|
2089
2512
|
}
|
|
2090
|
-
return directory;
|
|
2091
2513
|
}
|
|
2092
|
-
async function
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
await assertDoesNotExist(identityPath);
|
|
2100
|
-
await assertDoesNotExist(signerPath);
|
|
2101
|
-
await assertDoesNotExist(agentPath);
|
|
2102
|
-
await writeOwnerOnlyJson(
|
|
2103
|
-
signerPath,
|
|
2104
|
-
{
|
|
2105
|
-
delegate_key: input.delegateKey,
|
|
2106
|
-
delegate_address: input.delegateAddress,
|
|
2107
|
-
agent_id: input.agentId,
|
|
2108
|
-
safe_address: input.safeAddress,
|
|
2109
|
-
chain_id: input.chainId,
|
|
2110
|
-
network: input.network,
|
|
2111
|
-
x402_binding_signer: input.x402BindingSigner,
|
|
2112
|
-
note: "Local signer credential. Haven backend never receives this private key."
|
|
2113
|
-
},
|
|
2114
|
-
input.warn
|
|
2115
|
-
);
|
|
2116
|
-
try {
|
|
2117
|
-
await writeOwnerOnlyJson(
|
|
2118
|
-
identityPath,
|
|
2119
|
-
{
|
|
2120
|
-
api_key: input.apiKey,
|
|
2121
|
-
agent_id: input.agentId,
|
|
2122
|
-
safe_address: input.safeAddress,
|
|
2123
|
-
chain_id: input.chainId,
|
|
2124
|
-
network: input.network,
|
|
2125
|
-
api_url: input.apiUrl,
|
|
2126
|
-
hosted_mcp_url: input.hostedMcpUrl,
|
|
2127
|
-
agent_budget: input.agentBudget,
|
|
2128
|
-
note: "Haven API key identifies the agent only. It cannot spend without the local signer key and on-chain Haven wallet rules."
|
|
2129
|
-
},
|
|
2130
|
-
input.warn
|
|
2131
|
-
);
|
|
2132
|
-
} catch (err) {
|
|
2133
|
-
await rm(signerPath, { force: true }).catch(() => void 0);
|
|
2134
|
-
throw err;
|
|
2514
|
+
async function defaultRunCommand(command, args) {
|
|
2515
|
+
await execFileAsync3(command, args, { timeout: 1e4 });
|
|
2516
|
+
}
|
|
2517
|
+
function buildProbeResult(mode, hostedConfigured, hostedStatus, signerReady, localMcpReady, localMcpProbeStatus) {
|
|
2518
|
+
if (mode === "local_stdio") {
|
|
2519
|
+
if (localMcpReady) return "local_stdio_mcp_ready";
|
|
2520
|
+
return localMcpProbeStatus ? `local_stdio_mcp_${localMcpProbeStatus}` : "local_stdio_mcp_unavailable";
|
|
2135
2521
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
);
|
|
2150
|
-
} catch (err) {
|
|
2151
|
-
await rm(signerPath, { force: true }).catch(() => void 0);
|
|
2152
|
-
await rm(identityPath, { force: true }).catch(() => void 0);
|
|
2153
|
-
await rm(agentPath, { force: true }).catch(() => void 0);
|
|
2154
|
-
throw err;
|
|
2522
|
+
const hostedPart = hostedConfigured ? `hosted_${hostedStatus}` : "hosted_not_configured";
|
|
2523
|
+
const signerPart = signerReady ? "local_signer_ready" : "local_signer_unavailable";
|
|
2524
|
+
return `${hostedPart}_${signerPart}`.slice(0, 120);
|
|
2525
|
+
}
|
|
2526
|
+
async function resolveLocalMcpConsent(input, messages) {
|
|
2527
|
+
if (input.ackLocalTools || input.ackSigner) {
|
|
2528
|
+
const status = await acknowledgeLocalMcpConsent(input.identityPath, input.signerPath, (message) => messages.push(message));
|
|
2529
|
+
if (status.acknowledged) {
|
|
2530
|
+
messages.push("Prepared the local Haven tools acknowledgement.");
|
|
2531
|
+
} else {
|
|
2532
|
+
messages.push("Local Haven tools acknowledgement still needs attention.");
|
|
2533
|
+
}
|
|
2534
|
+
return status;
|
|
2155
2535
|
}
|
|
2156
|
-
return
|
|
2536
|
+
return getLocalMcpConsentStatus(input.identityPath, input.signerPath);
|
|
2157
2537
|
}
|
|
2158
|
-
async function
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2538
|
+
async function resolveSignerConsent(input, messages) {
|
|
2539
|
+
if (input.ackSigner || input.ackLocalTools) {
|
|
2540
|
+
const status = await acknowledgeLocalSignerConsent(input.signerPath, (message) => messages.push(message));
|
|
2541
|
+
if (status.acknowledged) {
|
|
2542
|
+
messages.push("Prepared the local Haven signer acknowledgement.");
|
|
2543
|
+
} else {
|
|
2544
|
+
messages.push("Local Haven signer acknowledgement still needs attention.");
|
|
2545
|
+
}
|
|
2546
|
+
return status;
|
|
2164
2547
|
}
|
|
2165
|
-
|
|
2166
|
-
`The name "${serverName}" is already wired on this machine (${directory} holds credentials). Pick a different --name, or revoke and remove that agent first \u2014 connect never overwrites credentials.`
|
|
2167
|
-
);
|
|
2548
|
+
return getLocalSignerConsentStatus(input.signerPath);
|
|
2168
2549
|
}
|
|
2169
|
-
function
|
|
2170
|
-
|
|
2550
|
+
function signerConsentErrorCode(signerCredentialReady, signerConsent) {
|
|
2551
|
+
if (!signerCredentialReady) return "local_signer_credential_unavailable";
|
|
2552
|
+
if (!signerConsent?.acknowledged) return "local_signer_ack_required";
|
|
2553
|
+
return void 0;
|
|
2171
2554
|
}
|
|
2172
|
-
function
|
|
2173
|
-
|
|
2555
|
+
function signerProbeErrorCode(probe) {
|
|
2556
|
+
if (!probe || probe.status === "ok") return void 0;
|
|
2557
|
+
return `local_signer_probe_${probe.status}`;
|
|
2174
2558
|
}
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
`, { mode: 384, flag: "wx" });
|
|
2179
|
-
await restrictPermissions(path, 384, warn);
|
|
2559
|
+
function hostedMcpErrorCode(hostedConfigured, hostedProbeStatus) {
|
|
2560
|
+
if (!hostedConfigured || hostedProbeStatus === "ok") return void 0;
|
|
2561
|
+
return `hosted_mcp_probe_${hostedProbeStatus}`;
|
|
2180
2562
|
}
|
|
2181
|
-
function
|
|
2182
|
-
|
|
2563
|
+
function localMcpErrorCode(signerCredentialReady, localMcpConsent, localMcpProbeStatus) {
|
|
2564
|
+
if (!signerCredentialReady) return "local_signer_credential_unavailable";
|
|
2565
|
+
if (!localMcpConsent?.acknowledged) return "local_mcp_ack_required";
|
|
2566
|
+
if (localMcpProbeStatus && localMcpProbeStatus !== "ok") return `local_mcp_probe_${localMcpProbeStatus}`;
|
|
2567
|
+
return void 0;
|
|
2183
2568
|
}
|
|
2184
|
-
function
|
|
2185
|
-
|
|
2569
|
+
function nextAction(runtime, restartMode, errorCode) {
|
|
2570
|
+
if (errorCode) return "return_to_haven_for_wallet_approval_then_finish_runtime_setup";
|
|
2571
|
+
if (restartMode === "hot-reload") return "return_to_haven_for_wallet_approval";
|
|
2572
|
+
if (runtime === "codex-cli" || runtime === "codex-desktop") return "return_to_haven_for_wallet_approval_then_restart_codex";
|
|
2573
|
+
if (runtime === "claude-code") return "return_to_haven_for_wallet_approval_then_restart_claude_code";
|
|
2574
|
+
if (restartMode === "restart-app") return "return_to_haven_for_wallet_approval_then_restart_app";
|
|
2575
|
+
if (restartMode === "restart-session") return "return_to_haven_for_wallet_approval_then_restart_agent_session";
|
|
2576
|
+
return "return_to_haven_for_wallet_approval_then_configure_runtime";
|
|
2577
|
+
}
|
|
2578
|
+
function supportsLocalMcp(runtime) {
|
|
2579
|
+
return runtime === "codex-cli" || runtime === "codex-desktop" || runtime === "claude-code";
|
|
2580
|
+
}
|
|
2581
|
+
async function prepareRuntimeForLocalMcp(input, deps) {
|
|
2582
|
+
const prepare = deps.prepareLocalMcpRuntime ?? ((runtimeInput) => prepareLocalMcpRuntime(runtimeInput, { runCommand: deps.runCommand, onProgress: deps.onProgress }));
|
|
2583
|
+
return prepare({
|
|
2584
|
+
credentialDirectory: input.credentialDirectory,
|
|
2585
|
+
identityPath: input.identityPath,
|
|
2586
|
+
signerPath: input.signerPath,
|
|
2587
|
+
homeDir: deps.homeDir,
|
|
2588
|
+
serverName: input.serverName
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
async function prepareSignerForRuntime(input, deps) {
|
|
2592
|
+
const prepare = deps.prepareSignerRuntime ?? ((runtimeInput) => (
|
|
2593
|
+
// onProgress threaded through on purpose (#1586 review): without it the
|
|
2594
|
+
// install heartbeat was dead code in production and the console still
|
|
2595
|
+
// went silent for the whole cold install — the exact symptom the issue
|
|
2596
|
+
// set out to remove, at a longer timeout.
|
|
2597
|
+
prepareSignerRuntime(runtimeInput, { runCommand: deps.runCommand, onProgress: deps.onProgress })
|
|
2598
|
+
));
|
|
2599
|
+
return prepare({
|
|
2600
|
+
credentialDirectory: input.credentialDirectory,
|
|
2601
|
+
signerPath: input.signerPath,
|
|
2602
|
+
homeDir: deps.homeDir,
|
|
2603
|
+
serverName: input.serverName
|
|
2604
|
+
});
|
|
2186
2605
|
}
|
|
2187
|
-
async function
|
|
2606
|
+
async function runLocalMcpProbe(runtimeInstall, deps) {
|
|
2607
|
+
const probe = deps.probeLocalMcpTools ?? probeLocalMcpTools;
|
|
2188
2608
|
try {
|
|
2189
|
-
await
|
|
2190
|
-
} catch
|
|
2191
|
-
|
|
2192
|
-
throw err;
|
|
2609
|
+
return await probe(runtimeInstall.command, runtimeInstall.args, MCP_RUNTIME_MANIFEST.requiredTools);
|
|
2610
|
+
} catch {
|
|
2611
|
+
return { status: "process_error" };
|
|
2193
2612
|
}
|
|
2194
|
-
throw new Error(`Refusing to overwrite existing Haven credential file: ${path}`);
|
|
2195
2613
|
}
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
} catch (err) {
|
|
2200
|
-
warn?.(
|
|
2201
|
-
`Warning: could not restrict permissions on ${path} to ${mode.toString(8)}. Move this credential to a private location or run chmod ${mode.toString(8)} ${path}. ${err instanceof Error ? err.message : String(err)}`
|
|
2202
|
-
);
|
|
2614
|
+
function localRuntimePrepareErrorCode(err) {
|
|
2615
|
+
if (err && typeof err === "object" && "code" in err && err.code === "local_mcp_unsupported_node_version") {
|
|
2616
|
+
return "local_mcp_unsupported_node_version";
|
|
2203
2617
|
}
|
|
2618
|
+
return "local_mcp_runtime_install_failed";
|
|
2204
2619
|
}
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
hash: decision.hash,
|
|
2220
|
-
reason: decision.reason
|
|
2221
|
-
};
|
|
2222
|
-
} catch (err) {
|
|
2223
|
-
return {
|
|
2224
|
-
acknowledged: false,
|
|
2225
|
-
error: err instanceof Error ? err.message : String(err)
|
|
2226
|
-
};
|
|
2620
|
+
var execFileAsync3;
|
|
2621
|
+
var init_runtime_install = __esm({
|
|
2622
|
+
"src/runtime-install.ts"() {
|
|
2623
|
+
init_config_writers();
|
|
2624
|
+
init_server_names();
|
|
2625
|
+
init_local_mcp_consent();
|
|
2626
|
+
init_probes();
|
|
2627
|
+
init_local_mcp_runtime();
|
|
2628
|
+
init_signer_runtime();
|
|
2629
|
+
init_runtime_manifest();
|
|
2630
|
+
init_skill_install();
|
|
2631
|
+
init_runtime_registry();
|
|
2632
|
+
init_signer_consent();
|
|
2633
|
+
execFileAsync3 = promisify(execFile);
|
|
2227
2634
|
}
|
|
2635
|
+
});
|
|
2636
|
+
|
|
2637
|
+
// src/tombstone.ts
|
|
2638
|
+
var tombstone_exports = {};
|
|
2639
|
+
__export(tombstone_exports, {
|
|
2640
|
+
TOMBSTONE_FILENAME: () => TOMBSTONE_FILENAME,
|
|
2641
|
+
TOMBSTONE_MARKER: () => TOMBSTONE_MARKER,
|
|
2642
|
+
readAgentTombstone: () => readAgentTombstone,
|
|
2643
|
+
writeAgentTombstone: () => writeAgentTombstone
|
|
2644
|
+
});
|
|
2645
|
+
function tombstoneScript(info) {
|
|
2646
|
+
const lines = [
|
|
2647
|
+
`${TOMBSTONE_MARKER}: this Haven agent was retired.`,
|
|
2648
|
+
"",
|
|
2649
|
+
` agent: ${info.agent_id}`,
|
|
2650
|
+
` retired at: ${info.retired_at}`,
|
|
2651
|
+
` reason: ${info.reason}`,
|
|
2652
|
+
...info.replaced_by ? [` replaced by: ${info.replaced_by}`] : [],
|
|
2653
|
+
"",
|
|
2654
|
+
"This process is running with a wiring snapshot that predates the",
|
|
2655
|
+
"retirement \u2014 it loaded its MCP config at startup and has kept it since.",
|
|
2656
|
+
"Restart THIS host to pick up the current wiring. If several long-lived",
|
|
2657
|
+
"hosts are running (a gateway, a TUI worker, an editor), restart EVERY",
|
|
2658
|
+
"one of them: each holds the snapshot from its own start time, so after",
|
|
2659
|
+
"a chain of recreations each can be parked on a DIFFERENT old agent.",
|
|
2660
|
+
"",
|
|
2661
|
+
"Then verify with: npx @haven_ai/connect@alpha --doctor --runtime <runtime>"
|
|
2662
|
+
];
|
|
2663
|
+
return [
|
|
2664
|
+
"#!/usr/bin/env node",
|
|
2665
|
+
`// ${TOMBSTONE_MARKER} \u2014 written by @haven_ai/connect (#1681). Safe to delete`,
|
|
2666
|
+
"// once every long-lived MCP host on this machine has been restarted.",
|
|
2667
|
+
`process.stderr.write(${JSON.stringify(lines.join("\n") + "\n")})`,
|
|
2668
|
+
"process.exit(1)",
|
|
2669
|
+
""
|
|
2670
|
+
].join("\n");
|
|
2228
2671
|
}
|
|
2229
|
-
async function
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
const stored = await readLocalMcpAckFile(localMcpAckPath(identityPath));
|
|
2234
|
-
if (stored === hash) {
|
|
2235
|
-
return { acknowledged: true, hash, reason: "ack_file_match" };
|
|
2236
|
-
}
|
|
2237
|
-
return {
|
|
2238
|
-
acknowledged: false,
|
|
2239
|
-
hash,
|
|
2240
|
-
reason: stored ? "ack_file_mismatch" : "ack_file_missing"
|
|
2241
|
-
};
|
|
2242
|
-
} catch (err) {
|
|
2243
|
-
return {
|
|
2244
|
-
acknowledged: false,
|
|
2245
|
-
error: err instanceof Error ? err.message : String(err)
|
|
2246
|
-
};
|
|
2672
|
+
async function writeAgentTombstone(input) {
|
|
2673
|
+
const dirStat = await stat(input.directory).catch(() => null);
|
|
2674
|
+
if (!dirStat?.isDirectory()) {
|
|
2675
|
+
throw new Error(`Not a directory: ${input.directory} \u2014 nothing to tombstone.`);
|
|
2247
2676
|
}
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
}
|
|
2677
|
+
const info = {
|
|
2678
|
+
// reason / replaced_by are persisted to disk and re-emitted to the host's
|
|
2679
|
+
// MCP stderr log on EVERY stale probe, potentially for months — redact
|
|
2680
|
+
// like every other output path, at the write layer so any future caller
|
|
2681
|
+
// inherits it. (#1681 review, finding 1)
|
|
2682
|
+
agent_id: input.agentId,
|
|
2683
|
+
retired_at: input.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2684
|
+
reason: redactSecrets(input.reason),
|
|
2685
|
+
...input.replacedBy ? { replaced_by: redactSecrets(input.replacedBy) } : {}
|
|
2258
2686
|
};
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
delegateAddress: credentials.delegateAddress,
|
|
2267
|
-
chainId: credentials.chainId,
|
|
2268
|
-
allowanceSummary: credentials.allowanceSummary
|
|
2269
|
-
},
|
|
2270
|
-
registeredToolNames()
|
|
2271
|
-
);
|
|
2687
|
+
const binDir = join(input.directory, "bin");
|
|
2688
|
+
await mkdir(binDir, { recursive: true });
|
|
2689
|
+
const wrapperPath = join(binDir, "haven-signer.mjs");
|
|
2690
|
+
await writeFile(wrapperPath, tombstoneScript(info), "utf8");
|
|
2691
|
+
await chmod(wrapperPath, 493);
|
|
2692
|
+
await writeFile(join(input.directory, TOMBSTONE_FILENAME), JSON.stringify(info, null, 2) + "\n", "utf8");
|
|
2693
|
+
return info;
|
|
2272
2694
|
}
|
|
2273
|
-
async function
|
|
2695
|
+
async function readAgentTombstone(directory) {
|
|
2274
2696
|
try {
|
|
2275
|
-
const parsed = JSON.parse(await readFile(
|
|
2276
|
-
|
|
2697
|
+
const parsed = JSON.parse(await readFile(join(directory, TOMBSTONE_FILENAME), "utf8"));
|
|
2698
|
+
if (typeof parsed?.agent_id !== "string") return null;
|
|
2699
|
+
return parsed;
|
|
2277
2700
|
} catch {
|
|
2278
2701
|
return null;
|
|
2279
2702
|
}
|
|
2280
2703
|
}
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
init_probes();
|
|
2288
|
-
|
|
2289
|
-
// src/local-mcp-runtime.ts
|
|
2290
|
-
init_signer_runtime();
|
|
2291
|
-
init_runtime_manifest();
|
|
2292
|
-
var execFileAsync2 = promisify(execFile);
|
|
2293
|
-
var UnsupportedNodeVersionError = class extends Error {
|
|
2294
|
-
code = "local_mcp_unsupported_node_version";
|
|
2295
|
-
nodeVersion;
|
|
2296
|
-
minimumNodeVersion;
|
|
2297
|
-
constructor(nodeVersion, minimumNodeVersion, subject = "Haven setup") {
|
|
2298
|
-
super(unsupportedNodeVersionMessage({ subject, nodeVersion, minimumNodeVersion }));
|
|
2299
|
-
this.name = "UnsupportedNodeVersionError";
|
|
2300
|
-
this.nodeVersion = nodeVersion;
|
|
2301
|
-
this.minimumNodeVersion = minimumNodeVersion;
|
|
2302
|
-
}
|
|
2303
|
-
};
|
|
2304
|
-
async function prepareLocalMcpRuntime(input, deps = {}) {
|
|
2305
|
-
assertSupportedNodeVersion(input.nodeVersion);
|
|
2306
|
-
const homeDir = input.homeDir ?? homedir();
|
|
2307
|
-
const runtimeDirectory = resolve(homeDir, ".haven", "mcp-runtime", MCP_RUNTIME_MANIFEST.mcpVersion);
|
|
2308
|
-
const npmCacheDirectory = resolve(homeDir, ".haven", "npm-cache");
|
|
2309
|
-
const cliPath = join(runtimeDirectory, "node_modules", "@haven_ai", "mcp", "dist", "cli.js");
|
|
2310
|
-
const messages = [];
|
|
2311
|
-
await mkdir(runtimeDirectory, { recursive: true, mode: 448 });
|
|
2312
|
-
await chmod(runtimeDirectory, 448).catch(() => void 0);
|
|
2313
|
-
await mkdir(npmCacheDirectory, { recursive: true, mode: 448 });
|
|
2314
|
-
await chmod(npmCacheDirectory, 448).catch(() => void 0);
|
|
2315
|
-
if (await installedRuntimeMatches2(runtimeDirectory, cliPath)) {
|
|
2316
|
-
messages.push(`Using existing local Haven MCP runtime ${mcpPackageSpec()}.`);
|
|
2317
|
-
} else {
|
|
2318
|
-
await installRuntimePackages2(runtimeDirectory, npmCacheDirectory, deps);
|
|
2319
|
-
messages.push(`Installed local Haven MCP runtime ${mcpPackageSpec()}.`);
|
|
2704
|
+
var TOMBSTONE_FILENAME, TOMBSTONE_MARKER;
|
|
2705
|
+
var init_tombstone = __esm({
|
|
2706
|
+
"src/tombstone.ts"() {
|
|
2707
|
+
init_redact();
|
|
2708
|
+
TOMBSTONE_FILENAME = "TOMBSTONE.json";
|
|
2709
|
+
TOMBSTONE_MARKER = "HAVEN-TOMBSTONE";
|
|
2320
2710
|
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2711
|
+
});
|
|
2712
|
+
|
|
2713
|
+
// src/rekey.ts
|
|
2714
|
+
var rekey_exports = {};
|
|
2715
|
+
__export(rekey_exports, {
|
|
2716
|
+
finishRekey: () => finishRekey,
|
|
2717
|
+
startRekey: () => startRekey
|
|
2718
|
+
});
|
|
2719
|
+
async function startRekey(options, deps = {}) {
|
|
2720
|
+
const now = deps.now ?? (() => Date.now());
|
|
2721
|
+
const stored = await readStoredCredentials(
|
|
2722
|
+
options.serverName,
|
|
2723
|
+
options.agentId,
|
|
2724
|
+
options.credentialsDir
|
|
2725
|
+
);
|
|
2726
|
+
const api = (deps.createApi ?? ((url) => createConnectApiClient(url)))(stored.apiUrl);
|
|
2727
|
+
const identity = await probeIdentity(api, stored.apiKey, "current");
|
|
2728
|
+
assertRekeyable(identity, stored);
|
|
2729
|
+
const key = (deps.generateKey ?? generateDelegateKey)();
|
|
2730
|
+
const startedAt = new Date(now()).toISOString();
|
|
2731
|
+
const expiresAt = new Date(now() + REKEY_PENDING_TTL_MS).toISOString();
|
|
2732
|
+
await writeRekeyPending(stored.directory, {
|
|
2733
|
+
agent_id: stored.agentId,
|
|
2734
|
+
new_delegate_address: key.address,
|
|
2735
|
+
new_delegate_key: key.privateKey,
|
|
2736
|
+
started_at: startedAt,
|
|
2737
|
+
expires_at: expiresAt
|
|
2336
2738
|
});
|
|
2337
|
-
|
|
2739
|
+
const finishCommand = [
|
|
2740
|
+
"npx @haven_ai/connect@alpha --rekey-finish",
|
|
2741
|
+
options.serverName ? `--name ${options.serverName}` : void 0,
|
|
2742
|
+
"--api-key <the key the dashboard showed you>",
|
|
2743
|
+
options.runtime ? `--runtime ${options.runtime}` : "--runtime <your runtime>"
|
|
2744
|
+
].filter(Boolean).join(" ");
|
|
2338
2745
|
return {
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2746
|
+
started: true,
|
|
2747
|
+
agentId: stored.agentId,
|
|
2748
|
+
directory: stored.directory,
|
|
2749
|
+
newDelegateAddress: key.address,
|
|
2750
|
+
expiresAt,
|
|
2751
|
+
messages: [
|
|
2752
|
+
`New signing key generated on this machine for agent ${identity.name || stored.agentId}.`,
|
|
2753
|
+
"",
|
|
2754
|
+
` New signing address: ${key.address}`,
|
|
2755
|
+
"",
|
|
2756
|
+
"The private half stays here \u2014 Haven never receives it, and there is no way to move it",
|
|
2757
|
+
"between machines. That is what keeps the account non-custodial.",
|
|
2758
|
+
"",
|
|
2759
|
+
'Next, on the Haven agent page: choose "Replace signing key" and paste that address.',
|
|
2760
|
+
"When it finishes it shows a new API key ONCE. Come back here and run:",
|
|
2761
|
+
"",
|
|
2762
|
+
` ${finishCommand}`,
|
|
2763
|
+
"",
|
|
2764
|
+
`Nothing has changed yet \u2014 the agent keeps working on its old key until you finish.`,
|
|
2765
|
+
`This pending re-key expires ${expiresAt}.`
|
|
2766
|
+
]
|
|
2346
2767
|
};
|
|
2347
2768
|
}
|
|
2348
|
-
function
|
|
2349
|
-
|
|
2350
|
-
|
|
2769
|
+
async function finishRekey(options, deps = {}) {
|
|
2770
|
+
const now = deps.now ?? (() => Date.now());
|
|
2771
|
+
if (!options.newApiKey) {
|
|
2772
|
+
throw new Error("--rekey-finish needs --api-key <key> \u2014 the one the Haven agent page showed once.");
|
|
2351
2773
|
}
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2774
|
+
const stored = await readStoredCredentials(
|
|
2775
|
+
options.serverName,
|
|
2776
|
+
options.agentId,
|
|
2777
|
+
options.credentialsDir
|
|
2778
|
+
);
|
|
2779
|
+
const pending = await readRekeyPending(stored.directory, now());
|
|
2780
|
+
if (pending.agent_id !== stored.agentId) {
|
|
2781
|
+
throw new Error(
|
|
2782
|
+
`The pending re-key at ${stored.directory} belongs to agent ${pending.agent_id}, but that directory now holds ${stored.agentId}. Refusing to write a key into the wrong agent.`
|
|
2783
|
+
);
|
|
2784
|
+
}
|
|
2785
|
+
const api = (deps.createApi ?? ((url) => createConnectApiClient(url)))(stored.apiUrl);
|
|
2786
|
+
const identity = await probeIdentity(api, options.newApiKey, "new");
|
|
2787
|
+
if (identity.id !== stored.agentId) {
|
|
2788
|
+
throw new Error(
|
|
2789
|
+
`That API key belongs to agent ${identity.id}, not ${stored.agentId}. Nothing was changed.`
|
|
2790
|
+
);
|
|
2791
|
+
}
|
|
2792
|
+
const onChain = (identity.delegate_address ?? "").toLowerCase();
|
|
2793
|
+
const expected = pending.new_delegate_address.toLowerCase();
|
|
2794
|
+
if (onChain !== expected) {
|
|
2795
|
+
throw new Error(
|
|
2796
|
+
`Haven says this agent's signing address is ${identity.delegate_address ?? "unset"}, but this machine generated ${pending.new_delegate_address}. Nothing was changed. Either the re-key on the agent page used a different address, or it has not finished yet.`
|
|
2797
|
+
);
|
|
2798
|
+
}
|
|
2799
|
+
await rewriteCredentialFiles({
|
|
2800
|
+
baseDir: options.credentialsDir,
|
|
2801
|
+
agentId: stored.agentId,
|
|
2802
|
+
serverName: options.serverName,
|
|
2803
|
+
apiKey: options.newApiKey,
|
|
2804
|
+
delegateKey: pending.new_delegate_key,
|
|
2805
|
+
delegateAddress: pending.new_delegate_address,
|
|
2806
|
+
safeAddress: stored.safeAddress ?? identity.safe_address ?? void 0,
|
|
2807
|
+
chainId: stored.chainId ?? identity.chain_id ?? void 0,
|
|
2808
|
+
network: stored.network,
|
|
2809
|
+
agentBudget: stored.agentBudget,
|
|
2810
|
+
apiUrl: stored.apiUrl,
|
|
2811
|
+
hostedMcpUrl: stored.hostedMcpUrl,
|
|
2812
|
+
x402BindingSigner: stored.x402BindingSigner,
|
|
2813
|
+
warn: deps.log
|
|
2814
|
+
});
|
|
2815
|
+
await clearRekeyPending(stored.directory);
|
|
2816
|
+
const names = serverNamesFor(options.serverName);
|
|
2817
|
+
const messages = [
|
|
2818
|
+
`Agent ${identity.name || stored.agentId} is now on its new signing key.`,
|
|
2819
|
+
` Signing address: ${pending.new_delegate_address}`,
|
|
2820
|
+
` Credentials: ${stored.directory} (rewritten in place)`,
|
|
2821
|
+
` MCP servers: ${names.hosted} / ${names.signer} (unchanged names)`
|
|
2822
|
+
];
|
|
2823
|
+
let configRewritten = false;
|
|
2824
|
+
if (options.runtime) {
|
|
2825
|
+
const prepared = await (deps.prepareSigner ?? prepareSignerRuntime)(
|
|
2826
|
+
{
|
|
2827
|
+
credentialDirectory: stored.directory,
|
|
2828
|
+
signerPath: `${stored.directory}/signer.json`,
|
|
2829
|
+
homeDir: options.homeDir
|
|
2830
|
+
},
|
|
2831
|
+
{ runCommand: deps.runCommand }
|
|
2832
|
+
);
|
|
2833
|
+
const result = await (deps.writeConfig ?? writeHostedRuntimeConfig)(
|
|
2834
|
+
{ runCommand: deps.runCommand, homeDir: options.homeDir },
|
|
2835
|
+
{
|
|
2836
|
+
runtime: options.runtime,
|
|
2837
|
+
hostedMcpUrl: stored.hostedMcpUrl,
|
|
2838
|
+
apiKey: options.newApiKey,
|
|
2839
|
+
identityPath: `${stored.directory}/identity.json`,
|
|
2840
|
+
signerPath: `${stored.directory}/signer.json`,
|
|
2841
|
+
credentialDirectory: stored.directory,
|
|
2842
|
+
serverName: options.serverName
|
|
2843
|
+
},
|
|
2844
|
+
{ command: prepared.command, args: prepared.args }
|
|
2845
|
+
);
|
|
2846
|
+
configRewritten = result.hostedConfigured;
|
|
2847
|
+
messages.push(` Config: ${result.target}`);
|
|
2848
|
+
messages.push(...result.messages.map((line) => ` ${line}`));
|
|
2849
|
+
if (!configRewritten) {
|
|
2850
|
+
messages.push(
|
|
2851
|
+
"",
|
|
2852
|
+
"WARNING: the MCP config was NOT updated, so it still carries the OLD API key and every",
|
|
2853
|
+
`wired host will fail with 401. Fix the cause above and re-run with --runtime ${options.runtime},`,
|
|
2854
|
+
"or update the config by hand. The credential files on disk are already on the new key."
|
|
2855
|
+
);
|
|
2378
2856
|
}
|
|
2857
|
+
} else {
|
|
2858
|
+
messages.push(
|
|
2859
|
+
"",
|
|
2860
|
+
"NOTE: no --runtime was given, so the MCP config still carries the OLD API key and every",
|
|
2861
|
+
"wired host will fail with 401. Re-run with --runtime <name> to rewrite it."
|
|
2862
|
+
);
|
|
2863
|
+
}
|
|
2864
|
+
return {
|
|
2865
|
+
finished: true,
|
|
2866
|
+
agentId: stored.agentId,
|
|
2867
|
+
directory: stored.directory,
|
|
2868
|
+
newDelegateAddress: pending.new_delegate_address,
|
|
2869
|
+
serverNames: { hosted: names.hosted, signer: names.signer },
|
|
2870
|
+
configRewritten,
|
|
2871
|
+
messages
|
|
2379
2872
|
};
|
|
2873
|
+
}
|
|
2874
|
+
async function probeIdentity(api, apiKey, which) {
|
|
2380
2875
|
try {
|
|
2381
|
-
await
|
|
2382
|
-
} catch {
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2876
|
+
return await api.getAgentIdentity(apiKey);
|
|
2877
|
+
} catch (err) {
|
|
2878
|
+
const status = err?.status;
|
|
2879
|
+
if (status === 401 || status === 403) {
|
|
2880
|
+
throw new Error(
|
|
2881
|
+
which === "current" ? "This machine's Haven API key is no longer accepted. If a re-key already finished elsewhere, run --rekey-finish with the key that re-key produced instead of starting a new one." : "Haven rejected that API key. Check you pasted the whole key from the agent page \u2014 nothing was changed."
|
|
2882
|
+
);
|
|
2387
2883
|
}
|
|
2884
|
+
throw new Error(
|
|
2885
|
+
`Could not reach Haven to check this agent (${redactSecrets(
|
|
2886
|
+
err instanceof Error ? err.message : String(err)
|
|
2887
|
+
)}). Nothing was changed.`
|
|
2888
|
+
);
|
|
2388
2889
|
}
|
|
2389
2890
|
}
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
readPackageJson2(join(runtimeDirectory, "node_modules", "@haven_ai", "sdk", "package.json"))
|
|
2396
|
-
]);
|
|
2397
|
-
return mcpPackage.version === MCP_RUNTIME_MANIFEST.mcpVersion && sdkPackage.version === MCP_RUNTIME_MANIFEST.sdkVersion;
|
|
2398
|
-
} catch {
|
|
2399
|
-
return false;
|
|
2891
|
+
function assertRekeyable(identity, stored) {
|
|
2892
|
+
if (identity.id !== stored.agentId) {
|
|
2893
|
+
throw new Error(
|
|
2894
|
+
`The credentials at ${stored.directory} say agent ${stored.agentId}, but Haven says that key belongs to ${identity.id}. Refusing to re-key an agent this directory does not own.`
|
|
2895
|
+
);
|
|
2400
2896
|
}
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
"import { spawn } from 'node:child_process'",
|
|
2411
|
-
"",
|
|
2412
|
-
`const cliPath = ${JSON.stringify(input.cliPath)}`,
|
|
2413
|
-
`const identityPath = ${JSON.stringify(input.identityPath)}`,
|
|
2414
|
-
`const signerPath = ${JSON.stringify(input.signerPath)}`,
|
|
2415
|
-
"",
|
|
2416
|
-
"const child = spawn(process.execPath, [cliPath, '--identity', identityPath, '--signer', signerPath, ...process.argv.slice(2)], {",
|
|
2417
|
-
" stdio: 'inherit',",
|
|
2418
|
-
"})",
|
|
2419
|
-
"",
|
|
2420
|
-
"child.on('exit', (code, signal) => {",
|
|
2421
|
-
" if (signal) process.kill(process.pid, signal)",
|
|
2422
|
-
" else process.exit(code ?? 1)",
|
|
2423
|
-
"})",
|
|
2424
|
-
""
|
|
2425
|
-
].join("\n");
|
|
2426
|
-
await writeFile(input.wrapperPath, source, { mode: 448 });
|
|
2427
|
-
await chmod(input.wrapperPath, 448).catch(() => void 0);
|
|
2428
|
-
}
|
|
2429
|
-
async function writeRuntimeSidecar2(input) {
|
|
2430
|
-
const value = {
|
|
2431
|
-
...input.serverName ? { server_name: input.serverName } : {},
|
|
2432
|
-
mcp_package: MCP_RUNTIME_MANIFEST.mcpPackage,
|
|
2433
|
-
mcp_version: MCP_RUNTIME_MANIFEST.mcpVersion,
|
|
2434
|
-
sdk_package: MCP_RUNTIME_MANIFEST.sdkPackage,
|
|
2435
|
-
sdk_version: MCP_RUNTIME_MANIFEST.sdkVersion,
|
|
2436
|
-
minimum_node_version: MCP_RUNTIME_MANIFEST.minimumNodeVersion,
|
|
2437
|
-
wrapper_path: input.wrapperPath,
|
|
2438
|
-
runtime_directory: input.runtimeDirectory,
|
|
2439
|
-
npm_cache_directory: input.npmCacheDirectory,
|
|
2440
|
-
cli_path: input.cliPath
|
|
2441
|
-
};
|
|
2442
|
-
await writeFile(input.path, `${JSON.stringify(value, null, 2)}
|
|
2443
|
-
`, { mode: 384 });
|
|
2444
|
-
await chmod(input.path, 384).catch(() => void 0);
|
|
2445
|
-
}
|
|
2446
|
-
async function assertFileExists2(path, label) {
|
|
2447
|
-
try {
|
|
2448
|
-
await access(path);
|
|
2449
|
-
} catch {
|
|
2450
|
-
throw new Error(`Missing ${label}: ${path}`);
|
|
2897
|
+
if (identity.execution_rail === "legacy") {
|
|
2898
|
+
throw new Error(
|
|
2899
|
+
`Agent ${identity.name || identity.id} is on the legacy rail, which cannot be re-keyed \u2014 its authority is per-token Safe allowances, not a signed delegation there is anything to re-issue. Re-onboard the agent on the delegation rail instead.`
|
|
2900
|
+
);
|
|
2901
|
+
}
|
|
2902
|
+
if (identity.status === "revoked") {
|
|
2903
|
+
throw new Error(
|
|
2904
|
+
`Agent ${identity.name || identity.id} is revoked. Re-keying would hand a revoked agent fresh credentials \u2014 create a new agent instead.`
|
|
2905
|
+
);
|
|
2451
2906
|
}
|
|
2452
2907
|
}
|
|
2908
|
+
var init_rekey = __esm({
|
|
2909
|
+
"src/rekey.ts"() {
|
|
2910
|
+
init_api();
|
|
2911
|
+
init_runtime_install();
|
|
2912
|
+
init_signer_runtime();
|
|
2913
|
+
init_key();
|
|
2914
|
+
init_redact();
|
|
2915
|
+
init_server_names();
|
|
2916
|
+
init_storage();
|
|
2917
|
+
}
|
|
2918
|
+
});
|
|
2453
2919
|
|
|
2454
|
-
// src/
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
case "codex-cli":
|
|
2472
|
-
case "codex-desktop":
|
|
2473
|
-
return installCodexAgentsSection(deps);
|
|
2474
|
-
default:
|
|
2475
|
-
return void 0;
|
|
2920
|
+
// src/rekey-restart.ts
|
|
2921
|
+
var rekey_restart_exports = {};
|
|
2922
|
+
__export(rekey_restart_exports, {
|
|
2923
|
+
restartGuidance: () => restartGuidance
|
|
2924
|
+
});
|
|
2925
|
+
function restartGuidance(runtime) {
|
|
2926
|
+
const profile = runtime ? BY_RUNTIME[runtime] : void 0;
|
|
2927
|
+
const lines = ["The new key is only live in a process that started after now.", ""];
|
|
2928
|
+
if (profile) {
|
|
2929
|
+
lines.push(profile.how);
|
|
2930
|
+
for (const command of profile.commands) lines.push(` ${command}`);
|
|
2931
|
+
if (profile.commands.length > 0) lines.push("");
|
|
2932
|
+
} else {
|
|
2933
|
+
lines.push(
|
|
2934
|
+
runtime ? `No standard restart command is known for "${runtime}" \u2014 restart it the way you start it.` : "Pass --runtime <name> to get the restart command for a specific host."
|
|
2935
|
+
);
|
|
2936
|
+
lines.push("");
|
|
2476
2937
|
}
|
|
2938
|
+
lines.push(SWEEP);
|
|
2939
|
+
return { commands: profile?.commands ?? [], lines };
|
|
2477
2940
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2941
|
+
var SWEEP, BY_RUNTIME;
|
|
2942
|
+
var init_rekey_restart = __esm({
|
|
2943
|
+
"src/rekey-restart.ts"() {
|
|
2944
|
+
SWEEP = "Then restart EVERY other long-lived MCP host on this machine \u2014 gateways, TUI workers, editors. Each holds the wiring snapshot from its own start time, so after a re-key each one is still presenting the OLD API key and will fail with 401 until it restarts.";
|
|
2945
|
+
BY_RUNTIME = {
|
|
2946
|
+
"claude-code": {
|
|
2947
|
+
commands: ["claude --continue"],
|
|
2948
|
+
how: "Exit this Claude Code session and start a new one:"
|
|
2949
|
+
},
|
|
2950
|
+
"codex-cli": {
|
|
2951
|
+
commands: ["codex resume --last"],
|
|
2952
|
+
how: "Start a fresh Codex CLI session:"
|
|
2953
|
+
},
|
|
2954
|
+
"codex-desktop": {
|
|
2955
|
+
commands: [],
|
|
2956
|
+
how: "Quit Codex Desktop completely (not just the window) and reopen it."
|
|
2957
|
+
},
|
|
2958
|
+
"claude-desktop": {
|
|
2959
|
+
commands: [],
|
|
2960
|
+
how: "Quit Claude Desktop completely (not just the window) and reopen it."
|
|
2961
|
+
},
|
|
2962
|
+
hermes: {
|
|
2963
|
+
commands: ["systemctl --user restart hermes-gateway", "/restart"],
|
|
2964
|
+
how: "Restart the Hermes gateway, or run /restart inside a Hermes session. The first form is the one that matters if you run it as a user service:"
|
|
2965
|
+
},
|
|
2966
|
+
cursor: {
|
|
2967
|
+
commands: [],
|
|
2968
|
+
how: 'Cursor hot-reloads MCP config, so it will pick the new key up on its own. If a tool call still fails with 401, reload the window (Cmd/Ctrl+Shift+P \u2192 "Reload Window").'
|
|
2969
|
+
},
|
|
2970
|
+
vscode: {
|
|
2971
|
+
commands: [],
|
|
2972
|
+
how: 'VS Code hot-reloads MCP config. If a tool call still fails with 401, reload the window (Cmd/Ctrl+Shift+P \u2192 "Reload Window").'
|
|
2973
|
+
},
|
|
2974
|
+
"vscode-insiders": {
|
|
2975
|
+
commands: [],
|
|
2976
|
+
how: 'VS Code Insiders hot-reloads MCP config. If a tool call still fails with 401, reload the window (Cmd/Ctrl+Shift+P \u2192 "Reload Window").'
|
|
2977
|
+
}
|
|
2487
2978
|
};
|
|
2488
|
-
}
|
|
2979
|
+
}
|
|
2980
|
+
});
|
|
2981
|
+
|
|
2982
|
+
// src/doctor.ts
|
|
2983
|
+
var doctor_exports = {};
|
|
2984
|
+
__export(doctor_exports, {
|
|
2985
|
+
runDoctor: () => runDoctor,
|
|
2986
|
+
runRepair: () => runRepair
|
|
2987
|
+
});
|
|
2988
|
+
async function discoverCredentialDirectory(homeDir, explicit) {
|
|
2989
|
+
const root = explicit ? dirname(explicit) : join(homeDir, ".haven", "agents");
|
|
2990
|
+
let entries = [];
|
|
2991
|
+
try {
|
|
2992
|
+
entries = await readdir(root);
|
|
2993
|
+
} catch {
|
|
2994
|
+
return explicit ? { directory: explicit, others: [], parkedOnly: /* @__PURE__ */ new Set() } : { others: [], parkedOnly: /* @__PURE__ */ new Set() };
|
|
2995
|
+
}
|
|
2996
|
+
const candidates = [];
|
|
2997
|
+
const tombstonedOnly = [];
|
|
2998
|
+
const parkedOnly = [];
|
|
2999
|
+
for (const entry of entries) {
|
|
3000
|
+
const directory = join(root, entry);
|
|
3001
|
+
try {
|
|
3002
|
+
const s = await stat(join(directory, "identity.json"));
|
|
3003
|
+
candidates.push({ directory, mtimeMs: s.mtimeMs });
|
|
3004
|
+
} catch {
|
|
3005
|
+
try {
|
|
3006
|
+
await stat(join(directory, TOMBSTONE_FILENAME));
|
|
3007
|
+
tombstonedOnly.push(directory);
|
|
3008
|
+
} catch {
|
|
3009
|
+
try {
|
|
3010
|
+
await stat(join(directory, REKEY_PENDING_FILENAME));
|
|
3011
|
+
parkedOnly.push(directory);
|
|
3012
|
+
} catch {
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
const parkedOnlySet = new Set(parkedOnly);
|
|
3018
|
+
candidates.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
3019
|
+
if (explicit) {
|
|
2489
3020
|
return {
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
]
|
|
3021
|
+
directory: explicit,
|
|
3022
|
+
others: [...candidates.map((c) => c.directory), ...tombstonedOnly, ...parkedOnly].filter((d) => d !== explicit),
|
|
3023
|
+
parkedOnly: parkedOnlySet
|
|
2494
3024
|
};
|
|
2495
3025
|
}
|
|
3026
|
+
if (candidates.length === 0 && tombstonedOnly.length === 0 && parkedOnly.length === 0) {
|
|
3027
|
+
return { others: [], parkedOnly: parkedOnlySet };
|
|
3028
|
+
}
|
|
3029
|
+
return {
|
|
3030
|
+
directory: candidates[0]?.directory,
|
|
3031
|
+
others: [...candidates.slice(1).map((c) => c.directory), ...tombstonedOnly, ...parkedOnly],
|
|
3032
|
+
parkedOnly: parkedOnlySet
|
|
3033
|
+
};
|
|
2496
3034
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
const
|
|
2501
|
-
|
|
2502
|
-
const existing = await readFile(target, "utf8").catch(() => null);
|
|
2503
|
-
const next = upsertManagedSection(existing, codexManagedSection());
|
|
2504
|
-
if (next !== existing) {
|
|
2505
|
-
await writeFile(target, next, "utf8");
|
|
3035
|
+
function agentIsWired(configText, names, slug, identity, sidecar, isPrimary, bareOwnerExists) {
|
|
3036
|
+
if (configText === null) return isPrimary;
|
|
3037
|
+
if (slug) {
|
|
3038
|
+
for (const name of [names.hosted, names.codexHosted, names.signer, names.codexSigner]) {
|
|
3039
|
+
if (new RegExp(`(^|[."'\\s\\[])${name}(["'\\]:\\s]|$)`, "m").test(configText)) return true;
|
|
2506
3040
|
}
|
|
3041
|
+
return false;
|
|
3042
|
+
}
|
|
3043
|
+
if (sidecar?.wrapper_path && configText.includes(sidecar.wrapper_path)) return true;
|
|
3044
|
+
if (bareOwnerExists) return false;
|
|
3045
|
+
return isPrimary && Boolean(identity?.hosted_mcp_url && configText.includes(identity.hosted_mcp_url));
|
|
3046
|
+
}
|
|
3047
|
+
function rekeyPendingCheck(status, hostedDelegateAddress, runtime, slug) {
|
|
3048
|
+
const label = "Pending re-key";
|
|
3049
|
+
const nameFlag = slug ? ` --name ${slug}` : "";
|
|
3050
|
+
if (status.state === "unreadable") {
|
|
2507
3051
|
return {
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
3052
|
+
id: "rekey_pending",
|
|
3053
|
+
label,
|
|
3054
|
+
ok: false,
|
|
3055
|
+
detail: `A re-key was started here but ${status.path} does not parse, so neither the address it generated nor when it started can be read. The file still holds what was a private key.`,
|
|
3056
|
+
repair: `Delete ${status.path}, then start again: ${RERUN} --rekey${nameFlag}`
|
|
2513
3057
|
};
|
|
2514
|
-
}
|
|
3058
|
+
}
|
|
3059
|
+
const started = status.startedAt ?? "an unknown time";
|
|
3060
|
+
const address = status.newDelegateAddress ?? "unknown";
|
|
3061
|
+
const completedOnHaven = hostedDelegateAddress !== void 0 && status.newDelegateAddress !== void 0 && hostedDelegateAddress.toLowerCase() === status.newDelegateAddress.toLowerCase();
|
|
3062
|
+
if (completedOnHaven) {
|
|
2515
3063
|
return {
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
3064
|
+
id: "rekey_pending",
|
|
3065
|
+
label,
|
|
3066
|
+
ok: false,
|
|
3067
|
+
detail: `A re-key started ${started} has COMPLETED on Haven \u2014 the agent's signing address is already ${address}, the one this machine generated \u2014 but the local half was never finished, so the credential files here still hold the old key. Parked at ${status.path}.` + (status.state === "expired" ? " The local file is also past its 24h TTL, which --rekey-finish refuses, so the finish command below will not accept it any more." : ""),
|
|
3068
|
+
repair: status.state === "expired" ? `The parked key expired. Start again \u2014 ${RERUN} --rekey${nameFlag} \u2014 and re-run "Replace signing key" on the Haven agent page with the new address it prints.` : `Run: ${RERUN} --rekey-finish${nameFlag} --api-key <the key the agent page showed you> --runtime ${runtime}`
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
const wedgeNote = "Haven is NOT yet on this address, so the re-key did not complete. This machine cannot tell whether the on-chain revoke on the agent page already ran: if it did not, closing this costs nothing; if it did, the agent's old delegations are revoked, no new ones were issued, and only an owner re-grant restores its spend authority (#1868). Check the agent page before assuming the harmless case.";
|
|
3072
|
+
if (status.state === "expired") {
|
|
3073
|
+
return {
|
|
3074
|
+
id: "rekey_pending",
|
|
3075
|
+
label,
|
|
3076
|
+
ok: false,
|
|
3077
|
+
detail: `A re-key started ${started} EXPIRED ${status.expiresAt ?? ""} without being finished. Its address was ${address}; the private half it generated is still on disk at ${status.path}. ` + wedgeNote,
|
|
3078
|
+
repair: `Either delete ${status.path} to drop the parked key, or start over: ${RERUN} --rekey${nameFlag}. Connect never deletes it for you \u2014 an expired TTL is a refusal to USE the key, not a licence to destroy key material you may still be mid-flow on.`
|
|
2520
3079
|
};
|
|
2521
3080
|
}
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
${
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
3081
|
+
return {
|
|
3082
|
+
id: "rekey_pending",
|
|
3083
|
+
label,
|
|
3084
|
+
ok: true,
|
|
3085
|
+
detail: `A re-key started ${started} is still open (expires ${status.expiresAt ?? "unknown"}). Paste this address into "Replace signing key" on the Haven agent page: ${address}. Parked at ${status.path}. ` + wedgeNote
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
async function readIdentity(directory) {
|
|
3089
|
+
try {
|
|
3090
|
+
return JSON.parse(await readFile(join(directory, "identity.json"), "utf8"));
|
|
3091
|
+
} catch {
|
|
3092
|
+
return void 0;
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
async function checksForAgent(entry, input, deps) {
|
|
3096
|
+
const { directory, identity, sidecar } = entry;
|
|
3097
|
+
const checks = [];
|
|
3098
|
+
let signerCapabilities;
|
|
3099
|
+
let signerFile;
|
|
3100
|
+
try {
|
|
3101
|
+
const parsed = JSON.parse(await readFile(join(directory, "signer.json"), "utf8"));
|
|
3102
|
+
signerFile = typeof parsed === "object" && parsed !== null ? parsed : void 0;
|
|
3103
|
+
} catch {
|
|
3104
|
+
signerFile = void 0;
|
|
3105
|
+
}
|
|
3106
|
+
const credentialsOk = Boolean(identity?.api_key) && signerFile !== void 0;
|
|
3107
|
+
checks.push({
|
|
3108
|
+
id: "credentials",
|
|
3109
|
+
label: "Agent credentials",
|
|
3110
|
+
ok: credentialsOk,
|
|
3111
|
+
detail: credentialsOk ? `identity.json and signer.json parse (agent ${identity?.agent_id ?? "unknown"})` : "identity.json or signer.json is missing or unparseable.",
|
|
3112
|
+
...credentialsOk ? {} : { repair: `Re-run the full setup with a fresh token: ${RERUN} --setup <token>.` }
|
|
3113
|
+
});
|
|
3114
|
+
if (!sidecar) {
|
|
3115
|
+
checks.push({
|
|
3116
|
+
id: "signer_runtime",
|
|
3117
|
+
label: "Signer runtime (preinstalled wrapper)",
|
|
3118
|
+
ok: false,
|
|
3119
|
+
detail: "No signer-runtime.json sidecar \u2014 the pinned signer runtime was never prepared (or a pre-#1586 npx config).",
|
|
3120
|
+
repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}`
|
|
3121
|
+
});
|
|
3122
|
+
} else {
|
|
3123
|
+
const matches = await installedRuntimeMatches(sidecar.runtime_directory, sidecar.cli_path);
|
|
3124
|
+
const versionOk = sidecar.signer_version === MCP_RUNTIME_MANIFEST.signerVersion;
|
|
3125
|
+
const ok = matches && versionOk;
|
|
3126
|
+
checks.push({
|
|
3127
|
+
id: "signer_runtime",
|
|
3128
|
+
label: "Signer runtime (preinstalled wrapper)",
|
|
3129
|
+
ok,
|
|
3130
|
+
detail: ok ? `Installed ${sidecar.signer_package}@${sidecar.signer_version} at ${sidecar.runtime_directory}` : matches ? `Installed version ${sidecar.signer_version} does not match the connector's pinned ${MCP_RUNTIME_MANIFEST.signerVersion}.` : `Runtime directory is stale or empty (${sidecar.runtime_directory}) \u2014 the CLI or package versions are missing.`,
|
|
3131
|
+
...ok ? {} : { repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}` }
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
const hostedUrl = identity?.hosted_mcp_url ?? (identity?.api_url ? `${identity.api_url}/mcp` : void 0);
|
|
3135
|
+
if (identity?.api_key && hostedUrl) {
|
|
3136
|
+
const probe = await (deps.probeHosted ?? probeHostedMcpTools)(identity.api_key, hostedUrl, deps.fetch);
|
|
3137
|
+
checks.push({
|
|
3138
|
+
id: "hosted_mcp",
|
|
3139
|
+
label: "Hosted Haven MCP",
|
|
3140
|
+
ok: probe.status === "ok",
|
|
3141
|
+
detail: probe.status === "ok" ? `Reachable and authorized (${hostedUrl}).` : `Probe failed: ${probe.status} (${hostedUrl}).`,
|
|
3142
|
+
...probe.status === "ok" ? {} : {
|
|
3143
|
+
repair: probe.status === "unauthorized" ? `The stored API key was rejected \u2014 re-run the full setup with a fresh token: ${RERUN} --setup <token>.` : "Check network access to the hosted MCP URL, then re-run --doctor."
|
|
3144
|
+
}
|
|
3145
|
+
});
|
|
3146
|
+
} else {
|
|
3147
|
+
checks.push({
|
|
3148
|
+
id: "hosted_mcp",
|
|
3149
|
+
label: "Hosted Haven MCP",
|
|
3150
|
+
ok: false,
|
|
3151
|
+
detail: "No stored API key / hosted MCP URL to probe with.",
|
|
3152
|
+
repair: `Re-run the full setup: ${RERUN} --setup <token>.`
|
|
3153
|
+
});
|
|
2539
3154
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
3155
|
+
const localDelegate = typeof signerFile?.delegate_address === "string" ? signerFile.delegate_address : void 0;
|
|
3156
|
+
let hostedDelegateAddress;
|
|
3157
|
+
if (identity?.api_key && identity.api_url) {
|
|
3158
|
+
const probe = await (deps.probeHostedIdentity ?? probeHostedAgentIdentity)(
|
|
3159
|
+
identity.api_key,
|
|
3160
|
+
identity.api_url,
|
|
3161
|
+
deps.fetch
|
|
2543
3162
|
);
|
|
3163
|
+
if (probe.status === "ok") hostedDelegateAddress = probe.delegateAddress;
|
|
3164
|
+
if (probe.status !== "ok") {
|
|
3165
|
+
checks.push({
|
|
3166
|
+
id: "identity_match",
|
|
3167
|
+
label: "Hosted identity matches the local signing key",
|
|
3168
|
+
ok: false,
|
|
3169
|
+
detail: probe.status === "unauthorized" ? "The stored API key was rejected, so the agent it authenticates as cannot be compared with the local signing key." : `Could not read the hosted identity (${probe.status}) \u2014 the comparison did not happen, so it cannot be reported as a match.`,
|
|
3170
|
+
repair: probe.status === "unauthorized" ? `Re-run the full setup with a fresh token: ${RERUN} --setup <token>.` : `Restore network access to the Haven API, then re-run: ${RERUN} --doctor --runtime ${input.runtime}`
|
|
3171
|
+
});
|
|
3172
|
+
} else if (!localDelegate) {
|
|
3173
|
+
checks.push({
|
|
3174
|
+
id: "identity_match",
|
|
3175
|
+
label: "Hosted identity matches the local signing key",
|
|
3176
|
+
ok: false,
|
|
3177
|
+
detail: "signer.json holds no delegate_address to compare against the hosted identity.",
|
|
3178
|
+
repair: `Re-run the full setup with a fresh token: ${RERUN} --setup <token>.`
|
|
3179
|
+
});
|
|
3180
|
+
} else {
|
|
3181
|
+
const same = probe.delegateAddress?.toLowerCase() === localDelegate.toLowerCase();
|
|
3182
|
+
checks.push({
|
|
3183
|
+
id: "identity_match",
|
|
3184
|
+
label: "Hosted identity matches the local signing key",
|
|
3185
|
+
ok: same,
|
|
3186
|
+
detail: same ? `The stored API key authenticates as the agent whose signing key is in this directory (${shortAddress(localDelegate)}).` : `MISMATCH: the stored API key authenticates as agent ${probe.agentId ?? "unknown"} with delegate ${shortAddress(probe.delegateAddress ?? "unknown")}, but signer.json here holds ${shortAddress(localDelegate)}. This runtime would quote as one agent and sign as another.`,
|
|
3187
|
+
...same ? {} : {
|
|
3188
|
+
repair: `Re-run setup for this agent so its API key and signing key come from one run: ${RERUN} --setup <token>. Do not hand-edit either file.`
|
|
3189
|
+
}
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
2544
3192
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
const indexes = [];
|
|
2549
|
-
for (let from = 0; ; ) {
|
|
2550
|
-
const at = text.indexOf(marker, from);
|
|
2551
|
-
if (at === -1) return indexes;
|
|
2552
|
-
if (at === 0 || text[at - 1] === "\n") indexes.push(at);
|
|
2553
|
-
from = at + marker.length;
|
|
3193
|
+
const pending = await inspectRekeyPending(directory, deps.now?.() ?? Date.now());
|
|
3194
|
+
if (pending) {
|
|
3195
|
+
checks.push(rekeyPendingCheck(pending, hostedDelegateAddress, input.runtime, sidecar?.server_name));
|
|
2554
3196
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
"Custom runtime: Haven did not auto-configure it. Your credentials are on disk (chmod 600) \u2014 read them at runtime; never paste a key into the agent prompt, memory, or logs.",
|
|
2592
|
-
` identity (hosted MCP Bearer): ${input.identityPath}`,
|
|
2593
|
-
` signer (local signing key): ${input.signerPath}`,
|
|
2594
|
-
"After wallet approval, wire the runtime to Haven by reference:",
|
|
2595
|
-
` Hosted MCP + local signer: point your MCP client at ${input.hostedMcpUrl} with the api_key from identity.json, then run npx -y ${signerPackageSpec()} --credentials ${input.signerPath}`,
|
|
2596
|
-
` Fully local MCP (no hosted dependency): npx -y ${mcpPackageSpec()} --identity ${input.identityPath} --signer ${input.signerPath}`
|
|
2597
|
-
]
|
|
2598
|
-
};
|
|
3197
|
+
if (sidecar) {
|
|
3198
|
+
const consent = await getLocalSignerConsentStatus(join(directory, "signer.json"));
|
|
3199
|
+
if (!consent.acknowledged) {
|
|
3200
|
+
checks.push({
|
|
3201
|
+
id: "signer_process",
|
|
3202
|
+
label: "Signer stdio handshake",
|
|
3203
|
+
ok: false,
|
|
3204
|
+
detail: "The local-tools consent is not acknowledged, so the signer refuses to start (by design).",
|
|
3205
|
+
repair: `Run: ${RERUN} --ack-local-tools --setup <token> (or re-run your original setup command with --ack-local-tools).`
|
|
3206
|
+
});
|
|
3207
|
+
} else {
|
|
3208
|
+
const probe = await (deps.probeSignerTools ?? probeLocalMcpTools)(
|
|
3209
|
+
sidecar.wrapper_path,
|
|
3210
|
+
[],
|
|
3211
|
+
MCP_RUNTIME_MANIFEST.requiredSignerTools
|
|
3212
|
+
);
|
|
3213
|
+
const experimental = probe.capabilities?.experimental ?? probe.capabilities;
|
|
3214
|
+
const compat = experimental?.["haven/signer-compatibility"];
|
|
3215
|
+
signerCapabilities = compat ? { "haven/signer-compatibility": compat } : void 0;
|
|
3216
|
+
const compatDetail = compat ? ` Compat: x402 expected-context v${JSON.stringify(compat.x402_expected_context_versions ?? "?")}.` : "";
|
|
3217
|
+
checks.push({
|
|
3218
|
+
id: "signer_process",
|
|
3219
|
+
label: "Signer stdio handshake",
|
|
3220
|
+
ok: probe.status === "ok",
|
|
3221
|
+
detail: probe.status === "ok" ? `Signer started, listed ${probe.toolNames?.length ?? 0} tools${probe.serverInfo?.version ? ` (v${probe.serverInfo.version})` : ""}.${compatDetail}` : `Handshake failed: ${probe.status}.`,
|
|
3222
|
+
...probe.status === "ok" ? {} : { repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}` }
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
} else {
|
|
3226
|
+
checks.push({
|
|
3227
|
+
id: "signer_process",
|
|
3228
|
+
label: "Signer stdio handshake",
|
|
3229
|
+
ok: false,
|
|
3230
|
+
detail: "Skipped \u2014 no prepared signer runtime to probe.",
|
|
3231
|
+
repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}`
|
|
3232
|
+
});
|
|
2599
3233
|
}
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
3234
|
+
return { checks, ...signerCapabilities ? { signerCapabilities } : {} };
|
|
3235
|
+
}
|
|
3236
|
+
async function runDoctor(input, deps = {}) {
|
|
3237
|
+
const homeDir = deps.homeDir ?? homedir();
|
|
3238
|
+
const checks = [];
|
|
3239
|
+
let signerCapabilities;
|
|
3240
|
+
const { directory, others, parkedOnly } = await discoverCredentialDirectory(homeDir, input.credentialsDir);
|
|
3241
|
+
const configPath = runtimeConfigPathFor(input.runtime, homeDir);
|
|
3242
|
+
let configText = null;
|
|
3243
|
+
if (configPath !== null) {
|
|
2603
3244
|
try {
|
|
2604
|
-
|
|
2605
|
-
} catch
|
|
2606
|
-
|
|
3245
|
+
configText = await readFile(configPath, "utf8");
|
|
3246
|
+
} catch {
|
|
3247
|
+
configText = null;
|
|
2607
3248
|
}
|
|
2608
3249
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
localMcpConfigured: false,
|
|
2617
|
-
probeResult: errorCode2 === "local_mcp_unsupported_node_version" ? "local_stdio_mcp_unsupported_node_version" : "local_stdio_mcp_runtime_install_failed",
|
|
2618
|
-
restartRequired: true,
|
|
2619
|
-
nextUserAction: nextAction(runtime, profile.restartMode, errorCode2),
|
|
2620
|
-
errorCode: errorCode2,
|
|
2621
|
-
configTarget: profile.label,
|
|
2622
|
-
signerAcknowledged: signerConsent?.acknowledged,
|
|
2623
|
-
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2624
|
-
activationCommand: void 0,
|
|
2625
|
-
messages: [
|
|
2626
|
-
...consentMessages,
|
|
2627
|
-
`Could not prepare local Haven MCP runtime: ${localRuntimeError instanceof Error ? localRuntimeError.message : String(localRuntimeError)}`
|
|
2628
|
-
]
|
|
2629
|
-
};
|
|
2630
|
-
}
|
|
2631
|
-
let signerCommand;
|
|
2632
|
-
if (!localRuntime) {
|
|
2633
|
-
progress("Getting the signer ready\u2026");
|
|
2634
|
-
try {
|
|
2635
|
-
const signerRuntime = await prepareSignerForRuntime(input, deps);
|
|
2636
|
-
signerCommand = { command: signerRuntime.command, args: signerRuntime.args };
|
|
2637
|
-
consentMessages.push(...signerRuntime.messages);
|
|
2638
|
-
} catch (err) {
|
|
2639
|
-
return {
|
|
2640
|
-
runtime,
|
|
2641
|
-
runtimeMcpMode: "hosted_plus_signer",
|
|
2642
|
-
hostedMcpConfigured: false,
|
|
2643
|
-
localSignerConfigured: false,
|
|
2644
|
-
localMcpConfigured: false,
|
|
2645
|
-
probeResult: "signer_runtime_install_failed",
|
|
2646
|
-
restartRequired: false,
|
|
2647
|
-
nextUserAction: "The local Haven signer runtime could not be installed, so no configuration was written. Check your network (a cold install downloads the signer package set) and re-run: npx @haven_ai/connect@alpha",
|
|
2648
|
-
errorCode: "signer_runtime_install_failed",
|
|
2649
|
-
configTarget: profile.label,
|
|
2650
|
-
signerAcknowledged: signerConsent?.acknowledged,
|
|
2651
|
-
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2652
|
-
activationCommand: void 0,
|
|
2653
|
-
signerRuntimePrepared: false,
|
|
2654
|
-
messages: [
|
|
2655
|
-
...consentMessages,
|
|
2656
|
-
`Could not pre-install the local Haven signer: ${err instanceof Error ? err.message : String(err)}`,
|
|
2657
|
-
"No runtime configuration was written (fail-closed): a config pointing at an uninstalled signer looks wired but cannot start.",
|
|
2658
|
-
"Re-run `npx @haven_ai/connect@alpha` to retry the setup."
|
|
2659
|
-
]
|
|
2660
|
-
};
|
|
3250
|
+
const allDirectories = directory ? [directory, ...others] : others;
|
|
3251
|
+
let bareOwnerExists = false;
|
|
3252
|
+
for (const dir of allDirectories) {
|
|
3253
|
+
const sidecar = await readRuntimeSidecar(dir);
|
|
3254
|
+
if (!sidecar?.server_name && sidecar?.wrapper_path && configText?.includes(sidecar.wrapper_path)) {
|
|
3255
|
+
bareOwnerExists = true;
|
|
3256
|
+
break;
|
|
2661
3257
|
}
|
|
2662
3258
|
}
|
|
2663
|
-
const
|
|
2664
|
-
|
|
2665
|
-
const
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
runtime,
|
|
2685
|
-
runtimeMcpMode: configResult.runtimeMcpMode,
|
|
2686
|
-
hostedMcpConfigured: configResult.hostedConfigured,
|
|
2687
|
-
localSignerConfigured: earlySignerOk,
|
|
2688
|
-
localMcpConfigured: earlyLocalMcpOk,
|
|
2689
|
-
signerAcknowledged: signerConsent?.acknowledged,
|
|
2690
|
-
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2691
|
-
restartRequired: configResult.restartRequired || restartRequiredForRuntime(runtime, deps.env),
|
|
2692
|
-
nextUserAction: nextAction(runtime, profile.restartMode, configResult.errorCode),
|
|
2693
|
-
errorCode: configResult.errorCode
|
|
3259
|
+
const inventory = [];
|
|
3260
|
+
const capabilitiesByDirectory = /* @__PURE__ */ new Map();
|
|
3261
|
+
const primaryChecksById = /* @__PURE__ */ new Map();
|
|
3262
|
+
for (const dir of allDirectories) {
|
|
3263
|
+
const identity = await readIdentity(dir);
|
|
3264
|
+
const sidecar = await readRuntimeSidecar(dir);
|
|
3265
|
+
const tombstone = await readAgentTombstone(dir);
|
|
3266
|
+
const slug = sidecar?.server_name;
|
|
3267
|
+
const names = serverNamesFor(slug);
|
|
3268
|
+
const rekeyPending = await inspectRekeyPending(dir, deps.now?.() ?? Date.now());
|
|
3269
|
+
if (!identity?.api_key) {
|
|
3270
|
+
const agentId = tombstone?.agent_id ?? rekeyPending?.agentId;
|
|
3271
|
+
inventory.push({
|
|
3272
|
+
...slug ? { slug } : {},
|
|
3273
|
+
...agentId ? { agentId } : {},
|
|
3274
|
+
directory: dir,
|
|
3275
|
+
// A tombstone is a deliberate record and outranks the discovery tell:
|
|
3276
|
+
// a retired directory that also holds a parked key stays `retired`.
|
|
3277
|
+
classification: tombstone ? "retired" : parkedOnly.has(dir) ? "parked" : "orphaned",
|
|
3278
|
+
checks: rekeyPending ? [rekeyPendingCheck(rekeyPending, void 0, input.runtime, slug)] : [],
|
|
3279
|
+
...rekeyPending ? { rekeyPending } : {}
|
|
2694
3280
|
});
|
|
2695
|
-
|
|
3281
|
+
continue;
|
|
3282
|
+
}
|
|
3283
|
+
const wired = agentIsWired(configText, names, slug, identity, sidecar, dir === directory, bareOwnerExists);
|
|
3284
|
+
const entry = {
|
|
3285
|
+
...slug ? { slug } : {},
|
|
3286
|
+
...identity.agent_id ? { agentId: identity.agent_id } : {},
|
|
3287
|
+
directory: dir,
|
|
3288
|
+
classification: wired ? "wired" : "superseded",
|
|
3289
|
+
checks: [],
|
|
3290
|
+
...rekeyPending ? { rekeyPending } : {}
|
|
3291
|
+
};
|
|
3292
|
+
if (wired) {
|
|
3293
|
+
const result = await checksForAgent({ directory: dir, identity, sidecar }, input, deps);
|
|
3294
|
+
entry.checks = result.checks;
|
|
3295
|
+
capabilitiesByDirectory.set(dir, result.signerCapabilities);
|
|
3296
|
+
} else if (rekeyPending) {
|
|
3297
|
+
entry.checks = [rekeyPendingCheck(rekeyPending, void 0, input.runtime, slug)];
|
|
2696
3298
|
}
|
|
3299
|
+
inventory.push(entry);
|
|
2697
3300
|
}
|
|
2698
|
-
|
|
2699
|
-
const
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
const localMcpOk = configResult.runtimeMcpMode === "local_stdio" && configResult.localMcpConfigured && signerCredentialReady && Boolean(localMcpConsent?.acknowledged) && localMcpProbe?.status === "ok";
|
|
2713
|
-
const signerOk = configResult.runtimeMcpMode === "local_stdio" ? localMcpOk : configResult.signerConfigured && signerCredentialReady && Boolean(signerConsent?.acknowledged) && // #1587: no handshake, no green. A signer command that was registered
|
|
2714
|
-
// but not probed (manual topology) keeps the old semantics.
|
|
2715
|
-
(signerProbe === void 0 || signerProbe.status === "ok");
|
|
2716
|
-
const restartRequired = configResult.restartRequired || restartRequiredForRuntime(runtime, deps.env);
|
|
2717
|
-
const errorCode = configResult.errorCode ?? (configResult.runtimeMcpMode === "local_stdio" ? localMcpErrorCode(signerCredentialReady, localMcpConsent, localMcpProbe?.status) : hostedMcpErrorCode(configResult.hostedConfigured, hostedProbe.status) ?? signerConsentErrorCode(signerCredentialReady, signerConsent) ?? signerProbeErrorCode(signerProbe));
|
|
2718
|
-
const hostedProbeMessages = configResult.hostedConfigured && hostedProbe.status !== "ok" ? [`Hosted Haven MCP probe failed: ${hostedProbe.status}.`] : configResult.hostedConfigured ? ["Verified hosted Haven MCP tools with a read-only handshake."] : [];
|
|
2719
|
-
const signerProbeMessages = signerProbe ? signerProbe.status === "ok" ? ["Verified local Haven signer with a stdio handshake."] : [
|
|
2720
|
-
`Local Haven signer handshake failed: ${signerProbe.status}.`,
|
|
2721
|
-
"Re-run `npx @haven_ai/connect@alpha` to repair the signer setup."
|
|
2722
|
-
] : [];
|
|
2723
|
-
const localProbeMessages = localMcpProbe && localMcpProbe.status !== "ok" ? [`Local Haven MCP handshake failed: ${localMcpProbe.status}.`] : localMcpProbe?.status === "ok" ? ["Verified local Haven MCP tools with a stdio handshake."] : [];
|
|
2724
|
-
const skillInstall = !configResult.errorCode ? await installSkillForRuntime(runtime, { homeDir: deps.homeDir, env: deps.env }) : void 0;
|
|
2725
|
-
return {
|
|
2726
|
-
runtime,
|
|
2727
|
-
runtimeMcpMode: configResult.runtimeMcpMode,
|
|
2728
|
-
hostedMcpConfigured: hostedOk,
|
|
2729
|
-
localSignerConfigured: signerOk,
|
|
2730
|
-
localMcpConfigured: localMcpOk,
|
|
2731
|
-
probeResult: buildProbeResult(configResult.runtimeMcpMode, configResult.hostedConfigured, hostedProbe.status, signerOk, localMcpOk, localMcpProbe?.status),
|
|
2732
|
-
restartRequired,
|
|
2733
|
-
nextUserAction: nextAction(runtime, profile.restartMode, errorCode),
|
|
2734
|
-
errorCode,
|
|
2735
|
-
configTarget: configResult.target,
|
|
2736
|
-
signerAcknowledged: signerConsent?.acknowledged,
|
|
2737
|
-
localMcpAcknowledged: localMcpConsent?.acknowledged,
|
|
2738
|
-
activationCommand: configResult.activationCommand,
|
|
2739
|
-
skillInstalled: skillInstall?.installed,
|
|
2740
|
-
signerRuntimePrepared,
|
|
2741
|
-
messages: [...consentMessages, ...localRuntimeInstall?.messages ?? [], ...configResult.messages, ...hostedProbeMessages, ...signerProbeMessages, ...localProbeMessages, ...skillInstall?.messages ?? []]
|
|
2742
|
-
};
|
|
2743
|
-
}
|
|
2744
|
-
function runtimeInstallCapabilities(runtime, env = process.env) {
|
|
2745
|
-
const profile = runtimeProfile(runtime, env);
|
|
2746
|
-
return {
|
|
2747
|
-
canWriteRuntimeConfig: profile.canWriteRuntimeConfig,
|
|
2748
|
-
restartRequired: restartRequiredForRuntime(runtime, env)
|
|
2749
|
-
};
|
|
2750
|
-
}
|
|
2751
|
-
async function configureClaudeCode(deps, localMcpCommand, serverName) {
|
|
2752
|
-
const runCommand = deps.runCommand ?? defaultRunCommand;
|
|
2753
|
-
const serverJson = JSON.stringify({
|
|
2754
|
-
type: "stdio",
|
|
2755
|
-
command: localMcpCommand,
|
|
2756
|
-
args: [],
|
|
2757
|
-
env: {}
|
|
2758
|
-
});
|
|
2759
|
-
try {
|
|
2760
|
-
if (!localMcpCommand) throw new Error("local MCP wrapper command is required");
|
|
2761
|
-
const names = serverNamesFor(serverName);
|
|
2762
|
-
await runCommand("claude", ["mcp", "remove", names.hosted]).catch(() => void 0);
|
|
2763
|
-
await runCommand("claude", ["mcp", "remove", names.signer]).catch(() => void 0);
|
|
2764
|
-
await runCommand("claude", ["mcp", "add-json", names.hosted, serverJson, "--scope", "user"]).catch(async () => {
|
|
2765
|
-
await runCommand("claude", ["mcp", "add", names.hosted, "--scope", "user", "--", localMcpCommand]);
|
|
3301
|
+
const wiredDirectories = inventory.filter((entry) => entry.classification === "wired").map((entry) => entry.directory);
|
|
3302
|
+
const primaryDirectory = input.credentialsDir ? directory : wiredDirectories.includes(directory ?? "") ? directory : wiredDirectories[0] ?? directory;
|
|
3303
|
+
if (primaryDirectory) {
|
|
3304
|
+
const primaryEntry = inventory.find((entry) => entry.directory === primaryDirectory);
|
|
3305
|
+
signerCapabilities = capabilitiesByDirectory.get(primaryDirectory);
|
|
3306
|
+
for (const check of primaryEntry?.checks ?? []) primaryChecksById.set(check.id, check);
|
|
3307
|
+
}
|
|
3308
|
+
if (!primaryDirectory) {
|
|
3309
|
+
checks.push({
|
|
3310
|
+
id: "credentials",
|
|
3311
|
+
label: "Agent credentials",
|
|
3312
|
+
ok: false,
|
|
3313
|
+
detail: "No agent credential directory with an identity.json under ~/.haven/agents.",
|
|
3314
|
+
repair: `Run the full setup once: ${RERUN} --setup <token from the Haven dashboard>.`
|
|
2766
3315
|
});
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
hostedConfigured: false,
|
|
2784
|
-
signerConfigured: false,
|
|
2785
|
-
localMcpConfigured: false,
|
|
2786
|
-
runtimeMcpMode: "local_stdio",
|
|
2787
|
-
target: "Claude Code MCP config",
|
|
2788
|
-
changed: false,
|
|
2789
|
-
restartRequired: true,
|
|
2790
|
-
messages: [
|
|
2791
|
-
`Could not update Claude Code MCP config: ${err instanceof Error ? err.message : String(err)}`,
|
|
2792
|
-
"Install Claude Code or rerun the Haven setup command inside a Claude Code terminal."
|
|
2793
|
-
],
|
|
2794
|
-
errorCode: "claude_code_config_failed"
|
|
2795
|
-
};
|
|
3316
|
+
} else {
|
|
3317
|
+
const primaryIdentity = await readIdentity(primaryDirectory);
|
|
3318
|
+
const primarySidecar = await readRuntimeSidecar(primaryDirectory);
|
|
3319
|
+
if (!primaryChecksById.has("credentials")) {
|
|
3320
|
+
const result = await checksForAgent(
|
|
3321
|
+
{ directory: primaryDirectory, identity: primaryIdentity, sidecar: primarySidecar },
|
|
3322
|
+
input,
|
|
3323
|
+
deps
|
|
3324
|
+
);
|
|
3325
|
+
signerCapabilities = result.signerCapabilities;
|
|
3326
|
+
for (const check of result.checks) primaryChecksById.set(check.id, check);
|
|
3327
|
+
}
|
|
3328
|
+
for (const id of ["credentials", "signer_runtime"]) {
|
|
3329
|
+
const check = primaryChecksById.get(id);
|
|
3330
|
+
if (check) checks.push(check);
|
|
3331
|
+
}
|
|
2796
3332
|
}
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
})
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
await
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
const
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
messages: [
|
|
2827
|
-
"Updated hosted Haven MCP and local signer entries with Claude Code.",
|
|
2828
|
-
...verified ? ["Verified Claude Code MCP entry."] : []
|
|
2829
|
-
]
|
|
2830
|
-
};
|
|
2831
|
-
} catch (err) {
|
|
2832
|
-
return {
|
|
2833
|
-
hostedConfigured: false,
|
|
2834
|
-
signerConfigured: false,
|
|
2835
|
-
localMcpConfigured: false,
|
|
2836
|
-
runtimeMcpMode: "hosted_plus_signer",
|
|
2837
|
-
target: "Claude Code MCP config",
|
|
2838
|
-
changed: false,
|
|
2839
|
-
restartRequired: true,
|
|
2840
|
-
messages: [
|
|
2841
|
-
`Could not update Claude Code MCP config: ${err instanceof Error ? err.message : String(err)}`,
|
|
2842
|
-
"Install Claude Code or rerun the Haven setup command inside a Claude Code terminal."
|
|
2843
|
-
],
|
|
2844
|
-
errorCode: "claude_code_config_failed"
|
|
2845
|
-
};
|
|
3333
|
+
if (configPath === null) {
|
|
3334
|
+
checks.push({
|
|
3335
|
+
id: "runtime_config",
|
|
3336
|
+
label: "Runtime MCP config",
|
|
3337
|
+
ok: true,
|
|
3338
|
+
detail: `Runtime '${input.runtime}' has no file-based config the connector owns (CLI-managed) \u2014 skipping the file check.`
|
|
3339
|
+
});
|
|
3340
|
+
} else if (configText === null) {
|
|
3341
|
+
checks.push({
|
|
3342
|
+
id: "runtime_config",
|
|
3343
|
+
label: "Runtime MCP config",
|
|
3344
|
+
ok: false,
|
|
3345
|
+
detail: `No runtime config at ${configPath}.`,
|
|
3346
|
+
repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}`
|
|
3347
|
+
});
|
|
3348
|
+
} else {
|
|
3349
|
+
const primaryIdentity = await readIdentity(primaryDirectory ?? "");
|
|
3350
|
+
const primarySidecar = primaryDirectory ? await readRuntimeSidecar(primaryDirectory) : null;
|
|
3351
|
+
const hasHaven = primaryIdentity?.hosted_mcp_url ? configText.includes(primaryIdentity.hosted_mcp_url) : configText.includes("haven");
|
|
3352
|
+
const signerViaNpx = configText.includes("@haven_ai/signer");
|
|
3353
|
+
const wrapperReferenced = primarySidecar ? configText.includes(primarySidecar.wrapper_path) : false;
|
|
3354
|
+
const ok = hasHaven && !signerViaNpx && (primarySidecar ? wrapperReferenced : true);
|
|
3355
|
+
checks.push({
|
|
3356
|
+
id: "runtime_config",
|
|
3357
|
+
label: "Runtime MCP config",
|
|
3358
|
+
ok,
|
|
3359
|
+
detail: ok ? `Config at ${configPath} references the hosted server and the prepared signer wrapper.` : signerViaNpx ? `Config at ${configPath} still launches the signer via npx \u2014 the pre-#1586 shape that cannot start under a 120s startup timeout.` : `Config at ${configPath} is missing the Haven entries${primarySidecar && !wrapperReferenced ? " (or references a different signer wrapper)" : ""}.`,
|
|
3360
|
+
...ok ? {} : { repair: `Run: ${RERUN} --doctor --repair --runtime ${input.runtime}` }
|
|
3361
|
+
});
|
|
2846
3362
|
}
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2851
|
-
function buildProbeResult(mode, hostedConfigured, hostedStatus, signerReady, localMcpReady, localMcpProbeStatus) {
|
|
2852
|
-
if (mode === "local_stdio") {
|
|
2853
|
-
if (localMcpReady) return "local_stdio_mcp_ready";
|
|
2854
|
-
return localMcpProbeStatus ? `local_stdio_mcp_${localMcpProbeStatus}` : "local_stdio_mcp_unavailable";
|
|
3363
|
+
for (const id of ["hosted_mcp", "identity_match", "rekey_pending"]) {
|
|
3364
|
+
const check = primaryChecksById.get(id);
|
|
3365
|
+
if (check) checks.push(check);
|
|
2855
3366
|
}
|
|
2856
|
-
const
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
const
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
3367
|
+
const otherEntries = inventory.filter((entry) => entry.directory !== primaryDirectory);
|
|
3368
|
+
if (otherEntries.length > 0) {
|
|
3369
|
+
const live = [];
|
|
3370
|
+
const revoked = [];
|
|
3371
|
+
const unverifiable = [];
|
|
3372
|
+
const retired = [];
|
|
3373
|
+
for (const entry of otherEntries) {
|
|
3374
|
+
const identity = await readIdentity(entry.directory);
|
|
3375
|
+
const tombstone = await readAgentTombstone(entry.directory);
|
|
3376
|
+
const otherAgent = entry.agentId ?? basename(entry.directory);
|
|
3377
|
+
const otherUrl = identity?.hosted_mcp_url ?? (identity?.api_url ? `${identity.api_url}/mcp` : void 0);
|
|
3378
|
+
if (!identity?.api_key || !otherUrl) {
|
|
3379
|
+
if (tombstone) retired.push(`${otherAgent} (retired ${tombstone.retired_at})`);
|
|
3380
|
+
else unverifiable.push(`${otherAgent} (no stored key/URL to probe)`);
|
|
3381
|
+
continue;
|
|
3382
|
+
}
|
|
3383
|
+
const suffix = tombstone ? " [tombstoned \u2014 key material still present]" : "";
|
|
3384
|
+
const probe = await (deps.probeHosted ?? probeHostedMcpTools)(identity.api_key, otherUrl, deps.fetch);
|
|
3385
|
+
if (probe.status === "ok") live.push({ label: `${otherAgent}${suffix}`, entry });
|
|
3386
|
+
else if (probe.status === "unauthorized") revoked.push(`${otherAgent}${suffix}`);
|
|
3387
|
+
else unverifiable.push(`${otherAgent} (${probe.status})${suffix}`);
|
|
2867
3388
|
}
|
|
2868
|
-
|
|
3389
|
+
const parts = [];
|
|
3390
|
+
if (live.length > 0) parts.push(`STILL SPEND-CAPABLE: ${live.map((item) => item.label).join(", ")}`);
|
|
3391
|
+
if (revoked.length > 0) parts.push(`already revoked: ${revoked.join(", ")}`);
|
|
3392
|
+
if (retired.length > 0) parts.push(`tombstoned (keys removed): ${retired.join(", ")}`);
|
|
3393
|
+
if (unverifiable.length > 0) parts.push(`could not verify: ${unverifiable.join(", ")}`);
|
|
3394
|
+
const supersededLive = live.filter((item) => item.entry.classification !== "wired").map((item) => item.label);
|
|
3395
|
+
checks.push({
|
|
3396
|
+
id: "superseded_agents",
|
|
3397
|
+
label: "Superseded agent credentials",
|
|
3398
|
+
ok: supersededLive.length === 0,
|
|
3399
|
+
detail: supersededLive.length > 0 ? `${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.` : `${otherEntries.length} other credential dir(s) found \u2014 ${parts.join("; ")}.`,
|
|
3400
|
+
...supersededLive.length > 0 ? {
|
|
3401
|
+
repair: `Revoke ${supersededLive.join(", ")} on the Haven agent page, then remove the old director(y/ies) under ~/.haven/agents. Connect never revokes or deletes for you.`
|
|
3402
|
+
} : {}
|
|
3403
|
+
});
|
|
2869
3404
|
}
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
3405
|
+
const parkedElsewhere = inventory.filter((entry) => entry.directory !== primaryDirectory && entry.rekeyPending).map((entry) => ({ entry, pending: entry.rekeyPending }));
|
|
3406
|
+
if (parkedElsewhere.length > 0) {
|
|
3407
|
+
const abandoned = parkedElsewhere.filter((item) => item.pending.state !== "pending");
|
|
3408
|
+
const describe = (item) => `${item.entry.slug ?? item.entry.agentId ?? basename(item.entry.directory)} (${item.pending.state}, ${item.pending.path})`;
|
|
3409
|
+
checks.push({
|
|
3410
|
+
id: "rekey_pending_elsewhere",
|
|
3411
|
+
label: "Parked re-keys in other credential directories",
|
|
3412
|
+
ok: abandoned.length === 0,
|
|
3413
|
+
detail: abandoned.length > 0 ? `ABANDONED re-key key material outside the agent this report describes: ${abandoned.map(describe).join(", ")}. Each holds a private key that was generated for a re-key nobody finished.` : `${parkedElsewhere.length} other director(y/ies) hold an open pending re-key: ${parkedElsewhere.map(describe).join(", ")}.`,
|
|
3414
|
+
...abandoned.length > 0 ? {
|
|
3415
|
+
repair: "Check the Haven agent page for each before deleting: if its on-chain revoke already ran, the agent has no spend authority until you re-grant it (#1868), and that is not visible from this machine. Connect never deletes key material for you."
|
|
3416
|
+
} : {}
|
|
3417
|
+
});
|
|
2881
3418
|
}
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
if (!probe || probe.status === "ok") return void 0;
|
|
2891
|
-
return `local_signer_probe_${probe.status}`;
|
|
2892
|
-
}
|
|
2893
|
-
function hostedMcpErrorCode(hostedConfigured, hostedProbeStatus) {
|
|
2894
|
-
if (!hostedConfigured || hostedProbeStatus === "ok") return void 0;
|
|
2895
|
-
return `hosted_mcp_probe_${hostedProbeStatus}`;
|
|
2896
|
-
}
|
|
2897
|
-
function localMcpErrorCode(signerCredentialReady, localMcpConsent, localMcpProbeStatus) {
|
|
2898
|
-
if (!signerCredentialReady) return "local_signer_credential_unavailable";
|
|
2899
|
-
if (!localMcpConsent?.acknowledged) return "local_mcp_ack_required";
|
|
2900
|
-
if (localMcpProbeStatus && localMcpProbeStatus !== "ok") return `local_mcp_probe_${localMcpProbeStatus}`;
|
|
2901
|
-
return void 0;
|
|
2902
|
-
}
|
|
2903
|
-
function nextAction(runtime, restartMode, errorCode) {
|
|
2904
|
-
if (errorCode) return "return_to_haven_for_wallet_approval_then_finish_runtime_setup";
|
|
2905
|
-
if (restartMode === "hot-reload") return "return_to_haven_for_wallet_approval";
|
|
2906
|
-
if (runtime === "codex-cli" || runtime === "codex-desktop") return "return_to_haven_for_wallet_approval_then_restart_codex";
|
|
2907
|
-
if (runtime === "claude-code") return "return_to_haven_for_wallet_approval_then_restart_claude_code";
|
|
2908
|
-
if (restartMode === "restart-app") return "return_to_haven_for_wallet_approval_then_restart_app";
|
|
2909
|
-
if (restartMode === "restart-session") return "return_to_haven_for_wallet_approval_then_restart_agent_session";
|
|
2910
|
-
return "return_to_haven_for_wallet_approval_then_configure_runtime";
|
|
2911
|
-
}
|
|
2912
|
-
function supportsLocalMcp(runtime) {
|
|
2913
|
-
return runtime === "codex-cli" || runtime === "codex-desktop" || runtime === "claude-code";
|
|
2914
|
-
}
|
|
2915
|
-
async function prepareRuntimeForLocalMcp(input, deps) {
|
|
2916
|
-
const prepare = deps.prepareLocalMcpRuntime ?? ((runtimeInput) => prepareLocalMcpRuntime(runtimeInput, { runCommand: deps.runCommand, onProgress: deps.onProgress }));
|
|
2917
|
-
return prepare({
|
|
2918
|
-
credentialDirectory: input.credentialDirectory,
|
|
2919
|
-
identityPath: input.identityPath,
|
|
2920
|
-
signerPath: input.signerPath,
|
|
2921
|
-
homeDir: deps.homeDir,
|
|
2922
|
-
serverName: input.serverName
|
|
2923
|
-
});
|
|
2924
|
-
}
|
|
2925
|
-
async function prepareSignerForRuntime(input, deps) {
|
|
2926
|
-
const prepare = deps.prepareSignerRuntime ?? ((runtimeInput) => (
|
|
2927
|
-
// onProgress threaded through on purpose (#1586 review): without it the
|
|
2928
|
-
// install heartbeat was dead code in production and the console still
|
|
2929
|
-
// went silent for the whole cold install — the exact symptom the issue
|
|
2930
|
-
// set out to remove, at a longer timeout.
|
|
2931
|
-
prepareSignerRuntime(runtimeInput, { runCommand: deps.runCommand, onProgress: deps.onProgress })
|
|
2932
|
-
));
|
|
2933
|
-
return prepare({
|
|
2934
|
-
credentialDirectory: input.credentialDirectory,
|
|
2935
|
-
signerPath: input.signerPath,
|
|
2936
|
-
homeDir: deps.homeDir,
|
|
2937
|
-
serverName: input.serverName
|
|
3419
|
+
const signerProcess = primaryChecksById.get("signer_process");
|
|
3420
|
+
if (signerProcess) checks.push(signerProcess);
|
|
3421
|
+
const restart = restartRequiredForRuntime(input.runtime, deps.env);
|
|
3422
|
+
checks.push({
|
|
3423
|
+
id: "restart",
|
|
3424
|
+
label: "Runtime restart",
|
|
3425
|
+
ok: true,
|
|
3426
|
+
detail: restart ? "This runtime loads MCP config at startup \u2014 restart it after any repair before expecting the tools to appear." : "No restart requirement known for this runtime."
|
|
2938
3427
|
});
|
|
3428
|
+
const wiredOk = inventory.filter((entry) => entry.classification === "wired").every((entry) => entry.checks.every((check) => check.ok));
|
|
3429
|
+
return {
|
|
3430
|
+
version: 1,
|
|
3431
|
+
ok: checks.every((check) => check.ok) && wiredOk,
|
|
3432
|
+
runtime: input.runtime,
|
|
3433
|
+
credentialDirectory: primaryDirectory,
|
|
3434
|
+
checks,
|
|
3435
|
+
agents: inventory,
|
|
3436
|
+
...signerCapabilities ? { signerCapabilities } : {}
|
|
3437
|
+
};
|
|
2939
3438
|
}
|
|
2940
|
-
async function
|
|
2941
|
-
const
|
|
3439
|
+
async function runRepair(input, deps = {}) {
|
|
3440
|
+
const homeDir = deps.homeDir ?? homedir();
|
|
3441
|
+
const messages = [];
|
|
3442
|
+
const { directory, others } = await discoverCredentialDirectory(homeDir, input.credentialsDir);
|
|
3443
|
+
if (others.length > 0) {
|
|
3444
|
+
messages.push(`Note: ${others.length} other agent credential dir(s) exist \u2014 run --doctor for their status.`);
|
|
3445
|
+
}
|
|
3446
|
+
if (!directory) {
|
|
3447
|
+
return {
|
|
3448
|
+
ok: false,
|
|
3449
|
+
messages: [`No agent credentials found to repair \u2014 run the full setup: ${RERUN} --setup <token>.`]
|
|
3450
|
+
};
|
|
3451
|
+
}
|
|
3452
|
+
let identity;
|
|
2942
3453
|
try {
|
|
2943
|
-
|
|
3454
|
+
identity = JSON.parse(await readFile(join(directory, "identity.json"), "utf8"));
|
|
2944
3455
|
} catch {
|
|
2945
|
-
return {
|
|
3456
|
+
return { ok: false, messages: ["identity.json is unreadable \u2014 re-run the full setup with a fresh token."] };
|
|
2946
3457
|
}
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
if (err && typeof err === "object" && "code" in err && err.code === "local_mcp_unsupported_node_version") {
|
|
2950
|
-
return "local_mcp_unsupported_node_version";
|
|
3458
|
+
if (!identity.api_key || !(identity.hosted_mcp_url || identity.api_url)) {
|
|
3459
|
+
return { ok: false, messages: ["identity.json lacks the stored API key / hosted URL \u2014 re-run the full setup."] };
|
|
2951
3460
|
}
|
|
2952
|
-
|
|
3461
|
+
const configPath = runtimeConfigPathFor(input.runtime, homeDir);
|
|
3462
|
+
if (configPath) {
|
|
3463
|
+
try {
|
|
3464
|
+
const existing = await readFile(configPath, "utf8");
|
|
3465
|
+
if (existing.includes("bin/haven-mcp") || existing.includes(".haven/mcp-runtime")) {
|
|
3466
|
+
return {
|
|
3467
|
+
ok: false,
|
|
3468
|
+
messages: [
|
|
3469
|
+
`The config at ${configPath} is the LOCAL-stdio topology (--local). Repair currently rewrites only the hosted+signer shape and will not touch it.`,
|
|
3470
|
+
"Re-run your original setup command (with --local) to repair a local-stdio install."
|
|
3471
|
+
]
|
|
3472
|
+
};
|
|
3473
|
+
}
|
|
3474
|
+
} catch {
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
const existingSidecar = await readRuntimeSidecar(directory);
|
|
3478
|
+
const serverName = existingSidecar?.server_name;
|
|
3479
|
+
const signerPath = join(directory, "signer.json");
|
|
3480
|
+
const prepared = await prepareSignerRuntime(
|
|
3481
|
+
{ credentialDirectory: directory, signerPath, homeDir, serverName },
|
|
3482
|
+
{ runCommand: deps.runCommand }
|
|
3483
|
+
);
|
|
3484
|
+
messages.push(...prepared.messages);
|
|
3485
|
+
const names = serverNamesFor(serverName);
|
|
3486
|
+
messages.push(`Rewriting MCP entries ${names.hosted} / ${names.signer}${serverName ? ` (agent "${serverName}")` : " (unnamed pair)"} \u2014 no other pair is touched.`);
|
|
3487
|
+
const configResult = await writeRuntimeConfig({
|
|
3488
|
+
runtime: input.runtime,
|
|
3489
|
+
hostedMcpUrl: identity.hosted_mcp_url ?? `${identity.api_url}/mcp`,
|
|
3490
|
+
apiKey: identity.api_key,
|
|
3491
|
+
identityPath: join(directory, "identity.json"),
|
|
3492
|
+
signerPath,
|
|
3493
|
+
credentialDirectory: directory,
|
|
3494
|
+
signerCommand: { command: prepared.command, args: prepared.args },
|
|
3495
|
+
homeDir,
|
|
3496
|
+
mode: "hosted",
|
|
3497
|
+
serverName
|
|
3498
|
+
});
|
|
3499
|
+
messages.push(...configResult.messages);
|
|
3500
|
+
messages.push("Repair complete \u2014 restart the runtime, then verify with --doctor.");
|
|
3501
|
+
return { ok: true, messages };
|
|
2953
3502
|
}
|
|
3503
|
+
var RERUN;
|
|
3504
|
+
var init_doctor = __esm({
|
|
3505
|
+
"src/doctor.ts"() {
|
|
3506
|
+
init_runtime_manifest();
|
|
3507
|
+
init_probes();
|
|
3508
|
+
init_signer_runtime();
|
|
3509
|
+
init_config_writers();
|
|
3510
|
+
init_runtime_registry();
|
|
3511
|
+
init_signer_consent();
|
|
3512
|
+
init_tombstone();
|
|
3513
|
+
init_server_names();
|
|
3514
|
+
init_storage();
|
|
3515
|
+
init_redact();
|
|
3516
|
+
RERUN = "npx @haven_ai/connect@alpha";
|
|
3517
|
+
}
|
|
3518
|
+
});
|
|
2954
3519
|
|
|
2955
3520
|
// src/runtime.ts
|
|
3521
|
+
init_api();
|
|
3522
|
+
init_key();
|
|
3523
|
+
init_redact();
|
|
3524
|
+
init_server_names();
|
|
3525
|
+
init_storage();
|
|
3526
|
+
init_runtime_install();
|
|
2956
3527
|
init_runtime_registry();
|
|
2957
3528
|
init_connect_error();
|
|
2958
3529
|
|
|
@@ -3125,8 +3696,9 @@ function defaultPromptIo() {
|
|
|
3125
3696
|
}
|
|
3126
3697
|
|
|
3127
3698
|
// src/runtime.ts
|
|
3699
|
+
init_local_mcp_runtime();
|
|
3128
3700
|
init_runtime_manifest();
|
|
3129
|
-
var CONNECTOR_VERSION = "0.1.
|
|
3701
|
+
var CONNECTOR_VERSION = "0.1.30-alpha.0";
|
|
3130
3702
|
var CONNECT_OUTCOME_SCHEMA_VERSION = 1;
|
|
3131
3703
|
async function runConnect(options, deps = {}) {
|
|
3132
3704
|
assertSupportedNodeVersion(deps.nodeVersion, MCP_RUNTIME_MANIFEST.minimumNodeVersion);
|
|
@@ -3202,6 +3774,11 @@ async function runConnect(options, deps = {}) {
|
|
|
3202
3774
|
proofSignature,
|
|
3203
3775
|
apiKeyHash: hashAgentApiKey(localApiKey),
|
|
3204
3776
|
apiKeyPrefix: agentApiKeyPrefix(localApiKey),
|
|
3777
|
+
// #1878: report the pair we are ACTUALLY wiring, bare pair included, so
|
|
3778
|
+
// the dashboard can name it. Derived here rather than sent as the raw
|
|
3779
|
+
// slug — `serverNamesFor` is the one place the naming rule lives, and
|
|
3780
|
+
// the hosted name is what a user pastes into an MCP config.
|
|
3781
|
+
mcpServerName: serverNamesFor(options.serverName).hosted,
|
|
3205
3782
|
connectorContext: {
|
|
3206
3783
|
environment_label: options.environmentLabel ?? "Local workspace",
|
|
3207
3784
|
config_target: installCapabilities.canWriteRuntimeConfig ? "agent runtime MCP config" : "local credential files"
|
|
@@ -3605,6 +4182,8 @@ function parseArgs(argv, env = process.env) {
|
|
|
3605
4182
|
let json = false;
|
|
3606
4183
|
let doctor = false;
|
|
3607
4184
|
let repair = false;
|
|
4185
|
+
let rekeyPhase;
|
|
4186
|
+
let newApiKey;
|
|
3608
4187
|
let tombstoneDir;
|
|
3609
4188
|
let tombstoneReason;
|
|
3610
4189
|
let tombstoneReplacedBy;
|
|
@@ -3618,6 +4197,12 @@ function parseArgs(argv, env = process.env) {
|
|
|
3618
4197
|
doctor = true;
|
|
3619
4198
|
} else if (arg === "--repair") {
|
|
3620
4199
|
repair = true;
|
|
4200
|
+
} else if (arg === "--rekey") {
|
|
4201
|
+
rekeyPhase = "start";
|
|
4202
|
+
} else if (arg === "--rekey-finish") {
|
|
4203
|
+
rekeyPhase = "finish";
|
|
4204
|
+
} else if (arg === "--api-key") {
|
|
4205
|
+
newApiKey = requireValue(argv, ++i, arg);
|
|
3621
4206
|
} else if (arg === "--tombstone") {
|
|
3622
4207
|
tombstoneDir = requireValue(argv, ++i, arg);
|
|
3623
4208
|
} else if (arg === "--reason") {
|
|
@@ -3655,20 +4240,38 @@ function parseArgs(argv, env = process.env) {
|
|
|
3655
4240
|
}
|
|
3656
4241
|
}
|
|
3657
4242
|
const tombstone = tombstoneDir ? { directory: tombstoneDir, reason: tombstoneReason, replacedBy: tombstoneReplacedBy } : void 0;
|
|
4243
|
+
const rekey = rekeyPhase ? { phase: rekeyPhase, newApiKey } : void 0;
|
|
3658
4244
|
if (help) {
|
|
3659
|
-
return { options, help, json, doctor, repair, tombstone };
|
|
4245
|
+
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
4246
|
+
}
|
|
4247
|
+
if (rekey) {
|
|
4248
|
+
if (options.setupToken) {
|
|
4249
|
+
throw new Error("--rekey replaces an existing agent's key; it does not take --setup. Drop one of them.");
|
|
4250
|
+
}
|
|
4251
|
+
if (rekey.phase === "start" && newApiKey !== void 0) {
|
|
4252
|
+
throw new Error(
|
|
4253
|
+
"--api-key belongs to --rekey-finish. --rekey generates the new key here and prints the address to paste into Haven; the API key does not exist yet."
|
|
4254
|
+
);
|
|
4255
|
+
}
|
|
4256
|
+
if (rekey.phase === "finish" && !newApiKey) {
|
|
4257
|
+
throw new Error("--rekey-finish needs --api-key <key> \u2014 the one the Haven agent page showed once.");
|
|
4258
|
+
}
|
|
4259
|
+
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
4260
|
+
}
|
|
4261
|
+
if (newApiKey !== void 0) {
|
|
4262
|
+
throw new Error("--api-key requires --rekey-finish.");
|
|
3660
4263
|
}
|
|
3661
4264
|
if (!tombstoneDir && (tombstoneReason !== void 0 || tombstoneReplacedBy !== void 0)) {
|
|
3662
4265
|
throw new Error("--reason and --replaced-by require --tombstone <dir>.");
|
|
3663
4266
|
}
|
|
3664
4267
|
if (tombstone) {
|
|
3665
|
-
return { options, help, json, doctor, repair, tombstone };
|
|
4268
|
+
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
3666
4269
|
}
|
|
3667
4270
|
if (doctor || repair) {
|
|
3668
4271
|
if (!options.runtime) {
|
|
3669
4272
|
throw new Error("--doctor/--repair need --runtime <runtime> (which config to examine).");
|
|
3670
4273
|
}
|
|
3671
|
-
return { options, help, json, doctor, repair, tombstone };
|
|
4274
|
+
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
3672
4275
|
}
|
|
3673
4276
|
if (!options.setupToken) {
|
|
3674
4277
|
throw new Error("Missing --setup <hv_setup_...> setup token.");
|
|
@@ -3677,7 +4280,7 @@ function parseArgs(argv, env = process.env) {
|
|
|
3677
4280
|
throw new Error("Missing --api <Haven API URL>.");
|
|
3678
4281
|
}
|
|
3679
4282
|
options.apiBaseUrl = options.apiBaseUrl.replace(/\/+$/, "");
|
|
3680
|
-
return { options, help, json, doctor, repair, tombstone };
|
|
4283
|
+
return { options, help, json, doctor, repair, tombstone, rekey };
|
|
3681
4284
|
}
|
|
3682
4285
|
function helpText() {
|
|
3683
4286
|
return [
|
|
@@ -3714,6 +4317,14 @@ function helpText() {
|
|
|
3714
4317
|
" --repair Repair, then re-diagnose (implies --doctor): reinstall the pinned signer",
|
|
3715
4318
|
" runtime, rewrite the wrapper and runtime config from stored credentials.",
|
|
3716
4319
|
" Hosted topology only (refuses to touch a --local config). No keys, no token.",
|
|
4320
|
+
" --rekey Replace this agent's signing key (no token). Generates a fresh keypair HERE and",
|
|
4321
|
+
" prints its public address to paste into the Haven agent page. Nothing changes",
|
|
4322
|
+
" until you finish; the agent keeps working on its old key throughout.",
|
|
4323
|
+
" Add --name <slug> for a named agent. Refuses a legacy-rail or revoked agent.",
|
|
4324
|
+
" --rekey-finish Second half of --rekey: writes the new key and the API key the agent page",
|
|
4325
|
+
" showed once, in place at the same path, and rewrites only this agent's MCP",
|
|
4326
|
+
" config pair. Server names do not change, so wired hosts need only a restart.",
|
|
4327
|
+
" --api-key <key> The new API key, for --rekey-finish.",
|
|
3717
4328
|
" --tombstone <dir> Retire an agent credential directory in place (no token): replaces its signer",
|
|
3718
4329
|
" wrapper with a diagnostic that names the retirement in MCP stderr logs, and",
|
|
3719
4330
|
" writes TOMBSTONE.json. Touches NO key material and revokes nothing.",
|
|
@@ -3733,6 +4344,8 @@ function requireValue(argv, index, option) {
|
|
|
3733
4344
|
}
|
|
3734
4345
|
|
|
3735
4346
|
// src/index.ts
|
|
4347
|
+
init_api();
|
|
4348
|
+
init_key();
|
|
3736
4349
|
init_redact();
|
|
3737
4350
|
init_redact();
|
|
3738
4351
|
async function runCli(argv, io = {
|
|
@@ -3760,13 +4373,13 @@ async function runCli(argv, io = {
|
|
|
3760
4373
|
}
|
|
3761
4374
|
if (parsed.tombstone) {
|
|
3762
4375
|
const { writeAgentTombstone: writeAgentTombstone2 } = await Promise.resolve().then(() => (init_tombstone(), tombstone_exports));
|
|
3763
|
-
const { readFile:
|
|
4376
|
+
const { readFile: readFile12 } = await import('fs/promises');
|
|
3764
4377
|
const { join: join10 } = await import('path');
|
|
3765
4378
|
try {
|
|
3766
4379
|
let agentId = "unknown";
|
|
3767
4380
|
try {
|
|
3768
4381
|
const identity = JSON.parse(
|
|
3769
|
-
await
|
|
4382
|
+
await readFile12(join10(parsed.tombstone.directory, "identity.json"), "utf8")
|
|
3770
4383
|
);
|
|
3771
4384
|
agentId = identity.agent_id ?? "unknown";
|
|
3772
4385
|
} catch {
|
|
@@ -3793,6 +4406,64 @@ async function runCli(argv, io = {
|
|
|
3793
4406
|
return 0;
|
|
3794
4407
|
} catch (err) {
|
|
3795
4408
|
io.stderr(`${redactSecrets(err instanceof Error ? err.message : String(err))}
|
|
4409
|
+
`);
|
|
4410
|
+
return 1;
|
|
4411
|
+
}
|
|
4412
|
+
}
|
|
4413
|
+
if (parsed.rekey) {
|
|
4414
|
+
const { startRekey: startRekey2, finishRekey: finishRekey2 } = await Promise.resolve().then(() => (init_rekey(), rekey_exports));
|
|
4415
|
+
const { restartGuidance: restartGuidance2 } = await Promise.resolve().then(() => (init_rekey_restart(), rekey_restart_exports));
|
|
4416
|
+
const common = {
|
|
4417
|
+
serverName: parsed.options.serverName,
|
|
4418
|
+
credentialsDir: parsed.options.credentialsDir,
|
|
4419
|
+
runtime: parsed.options.runtime
|
|
4420
|
+
};
|
|
4421
|
+
try {
|
|
4422
|
+
if (parsed.rekey.phase === "start") {
|
|
4423
|
+
const result2 = await startRekey2(common);
|
|
4424
|
+
if (parsed.json) {
|
|
4425
|
+
io.stdout(
|
|
4426
|
+
`${redactSecrets(
|
|
4427
|
+
JSON.stringify({
|
|
4428
|
+
rekey: "started",
|
|
4429
|
+
agent_id: result2.agentId,
|
|
4430
|
+
new_delegate_address: result2.newDelegateAddress,
|
|
4431
|
+
expires_at: result2.expiresAt
|
|
4432
|
+
})
|
|
4433
|
+
)}
|
|
4434
|
+
`
|
|
4435
|
+
);
|
|
4436
|
+
} else {
|
|
4437
|
+
for (const line of result2.messages) io.stdout(redactSecrets(`${line}
|
|
4438
|
+
`));
|
|
4439
|
+
}
|
|
4440
|
+
return 0;
|
|
4441
|
+
}
|
|
4442
|
+
const result = await finishRekey2({ ...common, newApiKey: parsed.rekey.newApiKey });
|
|
4443
|
+
const restart = restartGuidance2(parsed.options.runtime);
|
|
4444
|
+
if (parsed.json) {
|
|
4445
|
+
io.stdout(
|
|
4446
|
+
`${redactSecrets(
|
|
4447
|
+
JSON.stringify({
|
|
4448
|
+
rekey: "finished",
|
|
4449
|
+
agent_id: result.agentId,
|
|
4450
|
+
new_delegate_address: result.newDelegateAddress,
|
|
4451
|
+
mcp_servers: result.serverNames,
|
|
4452
|
+
restart_commands: restart.commands
|
|
4453
|
+
})
|
|
4454
|
+
)}
|
|
4455
|
+
`
|
|
4456
|
+
);
|
|
4457
|
+
} else {
|
|
4458
|
+
for (const line of result.messages) io.stdout(redactSecrets(`${line}
|
|
4459
|
+
`));
|
|
4460
|
+
io.stdout("\n");
|
|
4461
|
+
for (const line of restart.lines) io.stdout(redactSecrets(`${line}
|
|
4462
|
+
`));
|
|
4463
|
+
}
|
|
4464
|
+
return 0;
|
|
4465
|
+
} catch (err) {
|
|
4466
|
+
io.stderr(`${redactSecrets(err instanceof Error ? err.message : String(err))}
|
|
3796
4467
|
`);
|
|
3797
4468
|
return 1;
|
|
3798
4469
|
}
|
|
@@ -3825,7 +4496,7 @@ async function runCli(argv, io = {
|
|
|
3825
4496
|
for (const agent of otherAgents) {
|
|
3826
4497
|
const name = agent.slug ? `${agent.slug} (${agent.agentId ?? "unknown"})` : agent.agentId ?? "unknown";
|
|
3827
4498
|
const failed = agent.checks.filter((check) => !check.ok);
|
|
3828
|
-
const verdict = agent.classification === "wired" ? failed.length === 0 ? "wired, all checks passed" : `wired, ${failed.length} check(s) FAILED` : agent.classification;
|
|
4499
|
+
const verdict = agent.classification === "wired" ? failed.length === 0 ? "wired, all checks passed" : `wired, ${failed.length} check(s) FAILED` : agent.classification === "parked" ? "parked re-key only \u2014 no identity.json in this directory, but key material is still there" : agent.classification;
|
|
3829
4500
|
io.stdout(redactSecrets(` ${failed.length > 0 ? "\u2717" : "\u2022"} ${name}: ${verdict}
|
|
3830
4501
|
`));
|
|
3831
4502
|
for (const check of failed) {
|
|
@@ -3891,9 +4562,11 @@ function isCliEntrypoint(argvPath = process.argv[1], moduleUrl = import.meta.url
|
|
|
3891
4562
|
if (isCliEntrypoint()) void main();
|
|
3892
4563
|
|
|
3893
4564
|
// src/index.ts
|
|
4565
|
+
init_runtime_install();
|
|
3894
4566
|
init_signer_runtime();
|
|
3895
4567
|
init_runtime_registry();
|
|
3896
4568
|
init_connect_error();
|
|
4569
|
+
init_storage();
|
|
3897
4570
|
init_runtime_manifest();
|
|
3898
4571
|
|
|
3899
4572
|
export { CONNECTOR_VERSION, CONNECT_OUTCOME_SCHEMA_VERSION, ConnectError, MCP_RUNTIME_MANIFEST, RUNTIME_FLAG_VALUES, completionOutcome, createConnectApiClient, defaultAgentDirectory, delegateKeyFromPrivateKey, failedConnectOutcome, generateDelegateKey, helpText, installRuntime, isConnectError, mcpPackageSpec, normalizeRuntime, parseArgs, prepareSignerRuntime, promptForInstalledClient, redactSecrets, resolveRuntimeByInstalledClientPrompt, resolveRuntimeSelection, runCli, runConnect, runtimeInstallCapabilities, runtimeProfile, scanInstalledClients, sdkPackageSpec, shortAddress, signerPackageSpec, writeCredentialFiles };
|