@haven_ai/connect 0.1.5-alpha → 0.1.10-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/dist/index.cjs CHANGED
@@ -8,6 +8,7 @@ var path = require('path');
8
8
  var child_process = require('child_process');
9
9
  var util = require('util');
10
10
  var mcp = require('@haven_ai/mcp');
11
+ var sdk = require('@haven_ai/sdk');
11
12
  var signer = require('@haven_ai/signer');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -59,6 +60,7 @@ function createConnectApiClient(baseUrl, fetchImpl = fetch) {
59
60
  signer_acknowledged: input.signerAcknowledged,
60
61
  local_mcp_acknowledged: input.localMcpAcknowledged,
61
62
  activation_command_available: input.activationCommandAvailable,
63
+ skill_installed: input.skillInstalled,
62
64
  probe_result: input.probeResult,
63
65
  restart_required: input.restartRequired,
64
66
  next_user_action: input.nextUserAction,
@@ -211,9 +213,9 @@ var MCP_RUNTIME_MANIFEST = {
211
213
  mcpPackage: "@haven_ai/mcp",
212
214
  mcpVersion: mcp.MCP_VERSION,
213
215
  sdkPackage: "@haven_ai/sdk",
214
- sdkVersion: "0.1.8",
216
+ sdkVersion: "0.1.10-alpha.0",
215
217
  signerPackage: "@haven_ai/signer",
216
- signerVersion: "0.1.2-alpha",
218
+ signerVersion: "0.1.10-alpha.0",
217
219
  minimumNodeVersion: "20.0.0",
218
220
  supportedClients: ["codex-cli", "codex-desktop", "claude-code"],
219
221
  requiredTools: mcp.registeredToolNames()
@@ -418,6 +420,26 @@ function mergeCodexToml(existingToml, localMcpCommand) {
418
420
  validateCodexToml(block, "Generated Codex Haven config");
419
421
  const merged = `${next ? `${next}
420
422
 
423
+ ` : ""}${block}
424
+ `;
425
+ return merged;
426
+ }
427
+ function mergeCodexTomlHosted(existingToml, hostedMcpUrl, apiKey, signerPath) {
428
+ let next = removeTomlTableTree(removeTomlTableTree(existingToml, "mcp_servers.haven"), "mcp_servers.haven_signer");
429
+ next = next.trimEnd();
430
+ const block = [
431
+ "[mcp_servers.haven]",
432
+ `url = ${tomlString(hostedMcpUrl)}`,
433
+ `http_headers = { "Authorization" = ${tomlString(`Bearer ${apiKey}`)} }`,
434
+ "",
435
+ "[mcp_servers.haven_signer]",
436
+ 'command = "npx"',
437
+ `args = ["-y", ${tomlString(signerPackageSpec())}, "--credentials", ${tomlString(signerPath)}]`,
438
+ "startup_timeout_sec = 120"
439
+ ].join("\n");
440
+ validateCodexToml(block, "Generated Codex Haven config");
441
+ const merged = `${next ? `${next}
442
+
421
443
  ` : ""}${block}
422
444
  `;
423
445
  return merged;
@@ -458,27 +480,46 @@ async function writeJsonRuntimeConfig(input, target, serverRoot) {
458
480
  }
459
481
  async function writeCodexConfig(input) {
460
482
  const target = codexConfigPath(input.homeDir);
483
+ const local = input.mode === "local";
484
+ const restartMessage = runtimeRequiresHardRestart(input.runtime) ? "After Haven approval, restart Codex Desktop so it can load Haven tools." : "After Haven approval, Haven tools should appear in your next Codex message. If they don't, restart Codex to load them.";
461
485
  try {
462
486
  const existing = await readOptional(target);
463
- if (!input.localMcpCommand) {
464
- throw new Error("local MCP wrapper command is required");
487
+ if (local) {
488
+ if (!input.localMcpCommand) {
489
+ throw new Error("local MCP wrapper command is required");
490
+ }
491
+ const merged2 = mergeCodexToml(existing ?? "", input.localMcpCommand);
492
+ await writeOwnerOnlyText(target, merged2);
493
+ return {
494
+ hostedConfigured: false,
495
+ signerConfigured: true,
496
+ localMcpConfigured: true,
497
+ runtimeMcpMode: "local_stdio",
498
+ target: configTargetLabel(input.runtime),
499
+ changed: existing !== merged2,
500
+ restartRequired: true,
501
+ messages: [
502
+ `Updated local Haven MCP entry in ${configTargetLabel(input.runtime)}.`,
503
+ // Codex Desktop loads MCP servers at app launch; Codex CLI typically
504
+ // picks them up in the next session. Branch the copy so desktop users
505
+ // get the unambiguous instruction.
506
+ restartMessage
507
+ ]
508
+ };
465
509
  }
466
- const merged = mergeCodexToml(existing ?? "", input.localMcpCommand);
510
+ const merged = mergeCodexTomlHosted(existing ?? "", input.hostedMcpUrl, input.apiKey, input.signerPath);
467
511
  await writeOwnerOnlyText(target, merged);
468
512
  return {
469
- hostedConfigured: false,
513
+ hostedConfigured: true,
470
514
  signerConfigured: true,
471
- localMcpConfigured: true,
472
- runtimeMcpMode: "local_stdio",
515
+ localMcpConfigured: false,
516
+ runtimeMcpMode: "hosted_plus_signer",
473
517
  target: configTargetLabel(input.runtime),
474
518
  changed: existing !== merged,
475
519
  restartRequired: true,
476
520
  messages: [
477
- `Updated local Haven MCP entry in ${configTargetLabel(input.runtime)}.`,
478
- // Codex Desktop loads MCP servers at app launch; Codex CLI typically
479
- // picks them up in the next session. Branch the copy so desktop users
480
- // get the unambiguous instruction.
481
- runtimeRequiresHardRestart(input.runtime) ? "After Haven approval, restart Codex Desktop so it can load Haven tools." : "After Haven approval, Haven tools should appear in your next Codex message. If they don't, restart Codex to load them."
521
+ `Updated Haven MCP entries in ${configTargetLabel(input.runtime)}.`,
522
+ restartMessage
482
523
  ]
483
524
  };
484
525
  } catch (err) {
@@ -487,7 +528,7 @@ async function writeCodexConfig(input) {
487
528
  hostedConfigured: false,
488
529
  signerConfigured: false,
489
530
  localMcpConfigured: false,
490
- runtimeMcpMode: "local_stdio",
531
+ runtimeMcpMode: local ? "local_stdio" : "hosted_plus_signer",
491
532
  target: configTargetLabel(input.runtime),
492
533
  changed: false,
493
534
  restartRequired: true,
@@ -867,7 +908,7 @@ async function probeLocalSignerCredential(signerPath) {
867
908
  }
868
909
  }
869
910
  async function probeLocalMcpTools(command, args, requiredTools, timeoutMs = 1e4) {
870
- return new Promise((resolve6) => {
911
+ return new Promise((resolve7) => {
871
912
  const child = child_process.spawn(command, args, { stdio: ["pipe", "pipe", "ignore"] });
872
913
  let stdout = "";
873
914
  let settled = false;
@@ -877,7 +918,7 @@ async function probeLocalMcpTools(command, args, requiredTools, timeoutMs = 1e4)
877
918
  settled = true;
878
919
  clearTimeout(timeout);
879
920
  child.kill();
880
- resolve6(result);
921
+ resolve7(result);
881
922
  };
882
923
  const timeout = setTimeout(() => finish({ status: "timeout" }), timeoutMs);
883
924
  child.on("error", () => finish({ status: "process_error" }));
@@ -1190,7 +1231,7 @@ var execFileAsync2 = util.promisify(child_process.execFile);
1190
1231
  async function installRuntime(input, deps = {}) {
1191
1232
  const runtime = normalizeRuntime(input.runtime, deps.env);
1192
1233
  const profile = runtimeProfile(runtime, deps.env);
1193
- const localRuntime = usesLocalMcp(runtime);
1234
+ const localRuntime = input.localMcp === true && supportsLocalMcp(runtime);
1194
1235
  const consentMessages = [];
1195
1236
  const localMcpConsent = localRuntime ? await resolveLocalMcpConsent(input, consentMessages) : void 0;
1196
1237
  const signerConsent = localRuntime ? void 0 : await resolveSignerConsent(input, consentMessages);
@@ -1247,7 +1288,7 @@ async function installRuntime(input, deps = {}) {
1247
1288
  ]
1248
1289
  };
1249
1290
  }
1250
- const configResult = runtime === "claude-code" ? await configureClaudeCode(deps, localRuntimeInstall?.command ?? "") : await writeRuntimeConfig({
1291
+ const configResult = runtime === "claude-code" ? localRuntime ? await configureClaudeCode(deps, localRuntimeInstall?.command ?? "") : await configureClaudeCodeHosted(deps, input) : await writeRuntimeConfig({
1251
1292
  runtime,
1252
1293
  hostedMcpUrl: input.hostedMcpUrl,
1253
1294
  apiKey: input.apiKey,
@@ -1255,7 +1296,8 @@ async function installRuntime(input, deps = {}) {
1255
1296
  signerPath: input.signerPath,
1256
1297
  credentialDirectory: input.credentialDirectory,
1257
1298
  localMcpCommand: localRuntimeInstall?.command,
1258
- homeDir: deps.homeDir
1299
+ homeDir: deps.homeDir,
1300
+ mode: localRuntime ? "local" : "hosted"
1259
1301
  });
1260
1302
  const localProbePromise = configResult.runtimeMcpMode === "local_stdio" && localRuntimeInstall ? runLocalMcpProbe(localRuntimeInstall, deps) : Promise.resolve(void 0);
1261
1303
  const [hostedProbe, signerCredentialReady, localMcpProbe] = await Promise.all([
@@ -1269,6 +1311,7 @@ async function installRuntime(input, deps = {}) {
1269
1311
  const restartRequired = configResult.restartRequired || restartRequiredForRuntime(runtime, deps.env);
1270
1312
  const errorCode = configResult.errorCode ?? (configResult.runtimeMcpMode === "local_stdio" ? localMcpErrorCode(signerCredentialReady, localMcpConsent, localMcpProbe?.status) : signerConsentErrorCode(signerCredentialReady, signerConsent));
1271
1313
  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."] : [];
1314
+ const skillInstall = runtime === "claude-code" && !configResult.errorCode ? await installClaudeSkill(deps.homeDir) : void 0;
1272
1315
  return {
1273
1316
  runtime,
1274
1317
  runtimeMcpMode: configResult.runtimeMcpMode,
@@ -1283,7 +1326,8 @@ async function installRuntime(input, deps = {}) {
1283
1326
  signerAcknowledged: signerConsent?.acknowledged,
1284
1327
  localMcpAcknowledged: localMcpConsent?.acknowledged,
1285
1328
  activationCommand: configResult.activationCommand,
1286
- messages: [...consentMessages, ...localRuntimeInstall?.messages ?? [], ...configResult.messages, ...localProbeMessages]
1329
+ skillInstalled: skillInstall?.installed,
1330
+ messages: [...consentMessages, ...localRuntimeInstall?.messages ?? [], ...configResult.messages, ...localProbeMessages, ...skillInstall?.messages ?? []]
1287
1331
  };
1288
1332
  }
1289
1333
  function runtimeInstallCapabilities(runtime, env = process.env) {
@@ -1339,9 +1383,75 @@ async function configureClaudeCode(deps, localMcpCommand) {
1339
1383
  };
1340
1384
  }
1341
1385
  }
1386
+ async function configureClaudeCodeHosted(deps, input) {
1387
+ const runCommand = deps.runCommand ?? defaultRunCommand;
1388
+ const hostedJson = JSON.stringify({
1389
+ type: "http",
1390
+ url: input.hostedMcpUrl,
1391
+ headers: { Authorization: `Bearer ${input.apiKey}` }
1392
+ });
1393
+ const signerJson = JSON.stringify({
1394
+ type: "stdio",
1395
+ command: "npx",
1396
+ args: ["-y", signerPackageSpec(), "--credentials", input.signerPath],
1397
+ env: {}
1398
+ });
1399
+ try {
1400
+ await runCommand("claude", ["mcp", "remove", "haven"]).catch(() => void 0);
1401
+ await runCommand("claude", ["mcp", "remove", "haven-signer"]).catch(() => void 0);
1402
+ await runCommand("claude", ["mcp", "add-json", "haven", hostedJson, "--scope", "user"]);
1403
+ await runCommand("claude", ["mcp", "add-json", "haven-signer", signerJson, "--scope", "user"]);
1404
+ const verified = await runCommand("claude", ["mcp", "get", "haven"]).then(() => true).catch(() => false);
1405
+ return {
1406
+ hostedConfigured: true,
1407
+ signerConfigured: true,
1408
+ localMcpConfigured: false,
1409
+ runtimeMcpMode: "hosted_plus_signer",
1410
+ target: "Claude Code MCP config",
1411
+ changed: true,
1412
+ restartRequired: true,
1413
+ messages: [
1414
+ "Updated hosted Haven MCP and local signer entries with Claude Code.",
1415
+ ...verified ? ["Verified Claude Code MCP entry."] : [],
1416
+ "After Haven approval, Haven tools should appear in your next Claude Code message. If they don't, restart the session to load them."
1417
+ ]
1418
+ };
1419
+ } catch (err) {
1420
+ return {
1421
+ hostedConfigured: false,
1422
+ signerConfigured: false,
1423
+ localMcpConfigured: false,
1424
+ runtimeMcpMode: "hosted_plus_signer",
1425
+ target: "Claude Code MCP config",
1426
+ changed: false,
1427
+ restartRequired: true,
1428
+ messages: [
1429
+ `Could not update Claude Code MCP config: ${err instanceof Error ? err.message : String(err)}`,
1430
+ "Install Claude Code or rerun the Haven setup command inside a Claude Code terminal."
1431
+ ],
1432
+ errorCode: "claude_code_config_failed"
1433
+ };
1434
+ }
1435
+ }
1342
1436
  async function defaultRunCommand(command, args) {
1343
1437
  await execFileAsync2(command, args, { timeout: 1e4 });
1344
1438
  }
1439
+ async function installClaudeSkill(homeDir) {
1440
+ try {
1441
+ const skillDir = path.resolve(homeDir ?? os.homedir(), ".claude", "skills", sdk.SKILL_FOLDER_NAME);
1442
+ await promises.mkdir(skillDir, { recursive: true });
1443
+ await promises.writeFile(path.join(skillDir, "SKILL.md"), sdk.HAVEN_SKILL_MD, "utf8");
1444
+ return {
1445
+ installed: true,
1446
+ messages: ["Installed the generic Haven payment skill (~/.claude/skills/haven-pay). It contains no secrets."]
1447
+ };
1448
+ } catch (err) {
1449
+ return {
1450
+ installed: false,
1451
+ messages: [`Could not install the Haven payment skill: ${err instanceof Error ? err.message : String(err)}. Download it from the Haven dashboard instead.`]
1452
+ };
1453
+ }
1454
+ }
1345
1455
  function buildProbeResult(mode, hostedConfigured, hostedStatus, signerReady, localMcpReady, localMcpProbeStatus) {
1346
1456
  if (mode === "local_stdio") {
1347
1457
  if (localMcpReady) return "local_stdio_mcp_ready";
@@ -1395,7 +1505,7 @@ function nextAction(runtime, restartMode, errorCode) {
1395
1505
  if (restartMode === "restart-session") return "return_to_haven_for_wallet_approval_then_restart_agent_session";
1396
1506
  return "return_to_haven_for_wallet_approval_then_configure_runtime";
1397
1507
  }
1398
- function usesLocalMcp(runtime) {
1508
+ function supportsLocalMcp(runtime) {
1399
1509
  return runtime === "codex-cli" || runtime === "codex-desktop" || runtime === "claude-code";
1400
1510
  }
1401
1511
  async function prepareRuntimeForLocalMcp(input, deps) {
@@ -1435,6 +1545,14 @@ async function runConnect(options, deps = {}) {
1435
1545
  const generateKey = deps.generateKey ?? generateDelegateKey;
1436
1546
  const generateLocalApiKey = deps.generateApiKey ?? generateAgentApiKey;
1437
1547
  const installCapabilities = runtimeInstallCapabilities(options.runtime);
1548
+ if (options.localMcp) {
1549
+ const resolvedRuntime = normalizeRuntime(options.runtime);
1550
+ if (!supportsLocalMcp(resolvedRuntime)) {
1551
+ throw new Error(
1552
+ `--local (fully-local Haven MCP) is only available for Claude Code and Codex. The detected runtime is ${runtimeProfile(resolvedRuntime).label}. Re-run without --local to use the default hosted MCP + local signer setup.`
1553
+ );
1554
+ }
1555
+ }
1438
1556
  const setup = await api.resolveSetup({
1439
1557
  setupToken: options.setupToken,
1440
1558
  connectorVersion,
@@ -1493,7 +1611,8 @@ async function runConnect(options, deps = {}) {
1493
1611
  credentialDirectory: credentialPaths.directory,
1494
1612
  environmentLabel: options.environmentLabel ?? "Local workspace",
1495
1613
  ackSigner: options.ackSigner,
1496
- ackLocalTools: options.ackLocalTools
1614
+ ackLocalTools: options.ackLocalTools,
1615
+ localMcp: options.localMcp
1497
1616
  });
1498
1617
  printRuntimeInstall(runtimeInstall, log);
1499
1618
  try {
@@ -1508,6 +1627,7 @@ async function runConnect(options, deps = {}) {
1508
1627
  signerAcknowledged: runtimeInstall.signerAcknowledged,
1509
1628
  localMcpAcknowledged: runtimeInstall.localMcpAcknowledged,
1510
1629
  activationCommandAvailable: Boolean(runtimeInstall.activationCommand),
1630
+ skillInstalled: runtimeInstall.skillInstalled,
1511
1631
  probeResult: runtimeInstall.probeResult,
1512
1632
  restartRequired: runtimeInstall.restartRequired,
1513
1633
  nextUserAction: runtimeInstall.nextUserAction,
@@ -1589,6 +1709,8 @@ function parseArgs(argv, env = process.env) {
1589
1709
  } else if (arg === "--ack-signer") {
1590
1710
  options.ackSigner = true;
1591
1711
  options.ackLocalTools = true;
1712
+ } else if (arg === "--local" || arg === "--local-mcp") {
1713
+ options.localMcp = true;
1592
1714
  } else if (arg === "--version") {
1593
1715
  process.stdout.write(`${CONNECTOR_VERSION}
1594
1716
  `);
@@ -1627,6 +1749,8 @@ function helpText() {
1627
1749
  " --environment-label <text> Non-sensitive label shown in Haven setup review.",
1628
1750
  " --ack-local-tools Write the one-time local Haven tools acknowledgement during setup.",
1629
1751
  " --ack-signer Backward-compatible alias for --ack-local-tools.",
1752
+ " --local Advanced: install the fully-local Haven MCP (no hosted dependency).",
1753
+ " Only available for Claude Code and Codex. Default is hosted MCP + local signer.",
1630
1754
  " --help Show this help.",
1631
1755
  "",
1632
1756
  "The connector never prints the private key and never sends it to Haven."
@@ -1641,19 +1765,23 @@ function requireValue(argv, index, option) {
1641
1765
  }
1642
1766
 
1643
1767
  exports.CONNECTOR_VERSION = CONNECTOR_VERSION;
1768
+ exports.MCP_RUNTIME_MANIFEST = MCP_RUNTIME_MANIFEST;
1644
1769
  exports.createConnectApiClient = createConnectApiClient;
1645
1770
  exports.defaultAgentDirectory = defaultAgentDirectory;
1646
1771
  exports.delegateKeyFromPrivateKey = delegateKeyFromPrivateKey;
1647
1772
  exports.generateDelegateKey = generateDelegateKey;
1648
1773
  exports.helpText = helpText;
1649
1774
  exports.installRuntime = installRuntime;
1775
+ exports.mcpPackageSpec = mcpPackageSpec;
1650
1776
  exports.normalizeRuntime = normalizeRuntime;
1651
1777
  exports.parseArgs = parseArgs;
1652
1778
  exports.redactSecrets = redactSecrets;
1653
1779
  exports.runConnect = runConnect;
1654
1780
  exports.runtimeInstallCapabilities = runtimeInstallCapabilities;
1655
1781
  exports.runtimeProfile = runtimeProfile;
1782
+ exports.sdkPackageSpec = sdkPackageSpec;
1656
1783
  exports.shortAddress = shortAddress;
1784
+ exports.signerPackageSpec = signerPackageSpec;
1657
1785
  exports.writeCredentialFiles = writeCredentialFiles;
1658
1786
  //# sourceMappingURL=index.cjs.map
1659
1787
  //# sourceMappingURL=index.cjs.map