@haven_ai/cli 0.1.36-alpha.0 → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -425,7 +425,7 @@ ${failure.hint}` : failure.message);
425
425
  }
426
426
 
427
427
  // src/agent-guidance-text.ts
428
- var HAVEN_AGENT_RUNBOOK_MD = "# Haven for agents \u2014 set your user up to let you pay\n\nYou are an AI agent whose user has no Haven account yet, or has one but has not connected you.\n\n> Links below are paths on this same host: resolve them against the URL you fetched this file from.\n\n## What Haven is, in three sentences\n\nYour user gives you a **budget on their own account** \u2014 not their wallet, and not a key to their funds. The budget is a delegation they sign, enforced on-chain: a payment over it, to the wrong recipient, or past its expiry is refused at execution time, not by a dashboard promise. Haven constructs and relays the payments; you get an agent credential and a signing key made on your machine, and your user can revoke the budget without you and without Haven.\n\n## The sequence\n\nFour of the six steps are your user's \u2014 each needs a human signature or a human decision. The rest is yours. If they already have a funded account, start at step 3.\n\n1. **HUMAN \u2014 create the account.** Name, email, password, then a passkey (Face ID / Touch ID) or a wallet. Never offer to enter any of it: you must not have their password, and the passkey is bound to their device. With a terminal, `npx @haven_ai/cli@<channel> login --api <api-url>` afterwards gets you a scoped session for steps 3-4 (that flag or `HAVEN_API_URL`, on the first command \u2014 the session then remembers the backend; **the CLI's built-in default is Haven's hosted production backend**, so on any other deployment an omitted flag connects you somewhere real and wrong rather than failing) \u2014 they approve a code in the browser, you never hold their password. The `<channel>` in that command is the tag your deployment names \u2014 read it from `/.well-known/haven.json` (`packages.cli.channel`), never a tag you pick. Do not hold the process open while you wait: under `--json`, pass `--no-wait` to get the link object back at once, then poll it with `haven login --poll <device_code>` \u2014 one round per invocation, exit 3 while it is still pending, 0 once approved. It can set up agents and read the account; it cannot sign, approve a budget, move funds, or rotate any agent's keys.\n2. **HUMAN \u2014 fund it.** USDC only, no ETH: Haven sponsors the gas. `haven wallets funding` prints the address, the amount **and which chain** in one place; without a CLI session, the dashboard's funding card shows the address and amount and its Receive-funds screen names the chain. Read the chain off whichever you used and put it in your message \u2014 never assume one: a testnet deployment and production both call themselves Haven.\n3. **HUMAN \u2014 create the agent, set its budget**, and paste you the **setup prompt** it hands back. With a CLI session (step 1) you can do this step yourself: `haven agents connect --name <n> --budget <amount> --token USDC --period <minutes>` prints the same connector command and approval link; add `--run` to do step 4 too.\n4. **YOU \u2014 run the connector command** in that prompt (below). It makes your signing key locally, registering only the public address.\n5. **HUMAN \u2014 approve the budget** with their passkey, in the Haven tab they created the agent in: it advances to the approval step by itself once your run registers.\n6. **YOU \u2014 verify, then pay.**\n\n## Budget changes later (second token, raise, revoke)\n\nThe first budget rides the setup above. After the agent exists, a CLI session can construct the LATER changes \u2014 a second token, a bigger amount, a recipient pin, a stop \u2014 and hand your user a link; the human still signs, every time:\n\n```\nhaven budget grant <agentId> --amount <n> --token USDC --period <minutes> [--recipient <address>] [--wait]\nhaven budget revoke <agentId> <delegationHash> [--wait]\n```\n\nThe CLI never signs: it prints a dashboard link, your user opens it and signs with their passkey or wallet. `--wait` polls until the human's signature lands. The hash for `revoke` is in `haven agents show <agentId>`.\n\n## Hand-off scripts\n\nSend these as your own message, `<host>` replaced by the host you fetched this file from. Say what you cannot do, not only what they must.\n\n**Before signup** (step 1):\n\n> I can do everything except the parts that need your signature. Please open `<host>/signup?next=/agents&via=agent` \u2014 name, email, password, then a passkey (Face ID / Touch ID) or a wallet. That is your account's key: I should not have it, and I will never ask for your password. Already have one? `<host>/login?next=/agents`.\n\n**At the passkey step:**\n\n> The passkey must be made on your own device \u2014 it is what keeps the account yours, so nobody, Haven included, can move your funds without you. If this browser cannot, open `<host>/onboarding?next=/agents` on your phone and finish there.\n\n**At funding** (step 2):\n\n> Your Haven account needs USDC before I can pay for anything \u2014 USDC only, no ETH: Haven sponsors the gas. Before you send anything, let me get you the exact address **and network** \u2014 `haven wallets funding` prints both, and the funding card on `<host>/dashboard` shows the same. Please do not send to an address or a chain I have not confirmed with you; a small amount first is fine.\n\n**At the budget** (step 3):\n\n> On `<host>/agents`, create an agent for me and set a budget \u2014 say 25 USDC per day. That is the limit I cannot exceed. It hands back a setup prompt: paste it to me and I run it here.\n\n**At budget approval** (step 5) \u2014 the moment your run reports that approval is required, before anything else. Send the first if your run carried `approval.url`, the second if it did not.\n\n> Setup is done on my side. Approve the budget here: <approval.url>. Approve it with your passkey; nothing can be spent until you do.\n\n> Setup is done on my side. Go back to the Haven tab where you created the agent \u2014 it should now be asking you to approve the budget. Approve it with your passkey; nothing can be spent until you do.\n\n## What you run\n\nThe setup prompt carries a **connector command** shaped like this:\n\n```\nnpx -y @haven_ai/connect@<channel> --setup EXAMPLE-SETUP-TOKEN-NOT-REAL --api <api-url> --ack-local-tools\n```\n\nRun the prompt's version, not this one: the token is one-time, the API URL is the backend's own, and `<channel>` is the npm tag your prompt names \u2014 never a tag you pick. The rules below come from that prompt, so \"me\" in them is your user, not Haven.\n\n- If you are an AI agent running this command yourself rather than a human pasting it, you should append --json: the connector then emits one machine-readable, secret-free result object on stdout with progress on stderr, and returns promptly instead of blocking while it waits for the budget approval.\n- When a --json outcome reports approval.required: true, your first action must be to relay the approval instruction to me in your own reply \u2014 if the outcome carries approval.url, give me that link; otherwise tell me to return to Haven and approve this agent's budget \u2014 before verifying the connection, restarting anything, or any other step. Never build that link yourself: relay the one the outcome gave you or none at all. Any restart the outcome asks for is a separate instruction to give me afterwards, once the approval is done.\n- If you ran the command without --json, the connector waits for the approval itself and prints its next steps when it finishes: relay the budget-approval instruction to me \u2014 the approval link if those steps printed one, otherwise that you need to return to Haven and approve this agent's budget \u2014 only if those printed next steps still ask for it. If they report the budget as already approved, there is nothing for me to approve.\n- Only two changes to the command above are permitted, and no others: appending --json, and \u2014 only if the connector refuses because it could not determine the agent runtime \u2014 re-running it once with --runtime <name> added, naming the harness you are running in, using one of the values that refusal lists. Never invent a runtime name and never change anything else.\n- Do not print private keys, API keys, credential file contents, or config secrets in chat or logs.\n\nIf the approval wait times out, nothing is lost \u2014 your agent is registered and the budget is still waiting to be approved. Send your user the `approval.url` your run reported, or, if it carried none, ask them to finish it in that same Haven tab. The outcome carries no setup id, so never assemble an approval link out of parts \u2014 relay the whole one it gave you or none at all.\n\n## How to verify\n\nCall `haven_get_agent`, one of the Haven MCP tools the connector wires into your runtime in step 4. It returns identity plus `spend_authority_readiness`:\n\n- `ready` \u2014 a budget is live; you can pay.\n- `needs_approval` \u2014 the connector finished, nobody approved yet. Ask your user again, in their Haven tab; there is no queue to wait in.\n- `revoked` \u2014 the credential is not active; ask your user to create a new agent.\n\n`ready` covers hosted identity and the budget only, not your local signer. Check that with `npx -y @haven_ai/connect@<channel> --doctor`, the same tag your prompt named \u2014 a separate command, so the two-changes rule does not bind it.\n\n## If you cannot open a browser\n\nNothing here needs you to. Steps 1-3 are links: hand your user the full `<host>/\u2026` URL and ask them to say when it is done. Step 5 is a link only when your run reported one in `approval.url` \u2014 otherwise it is the tab they already have open, as above. Then poll `haven_get_agent` until it reads `ready`. Do not route around the sign-in wall \u2014 it makes the account theirs, not yours.\n\n## Vocabulary\n\n| Term | What it is |\n|---|---|\n| **setup prompt** | The text the dashboard hands your user to paste to you. Carries the command and its rules. |\n| **connector command** | The `npx -y @haven_ai/connect@\u2026` line you run. One-time token, one use. |\n| **agent credential** | Your API key (`sk_agent_\u2026`), written to `~/.haven`. It identifies you; alone it cannot move money. |\n| **delegate key** | Your signing key, made on this machine and never sent anywhere. |\n| **budget** | The on-chain delegation your user signed. It authorises the payment; Haven constructs and relays it. |\n\nNext: [your agent hit a 402](/402.md) \xB7 [everything agent-readable](/llms.txt)\n";
428
+ var HAVEN_AGENT_RUNBOOK_MD = "# Haven for agents \u2014 set your user up to let you pay\n\nYou are an AI agent whose user has no Haven account yet, or has one but has not connected you.\n\n> Links below are paths on this same host: resolve them against the URL you fetched this file from.\n\n## What Haven is, in three sentences\n\nYour user gives you a **budget on their own account** \u2014 not their wallet, and not a key to their funds. The budget is a delegation they sign, enforced on-chain: a payment over it, to the wrong recipient, or past its expiry is refused at execution time, not by a dashboard promise. Haven constructs and relays the payments; you get an agent credential and a signing key made on your machine, and your user can revoke the budget without you and without Haven.\n\n## The sequence\n\nFour of the six steps are your user's \u2014 each needs a human signature or a human decision. The rest is yours. If they already have a funded account, start at step 3.\n\n1. **HUMAN \u2014 create the account.** Name, email, password, then a passkey (Face ID / Touch ID) or a wallet. Never offer to enter any of it: you must not have their password, and the passkey is bound to their device. With a terminal, `npx @haven_ai/cli@<channel> login --api <api-url>` afterwards gets you a scoped session for steps 3-4 (that flag or `HAVEN_API_URL`, on the first command \u2014 the session then remembers the backend; **the CLI's built-in default is Haven's hosted production backend**, so on any other deployment an omitted flag connects you somewhere real and wrong rather than failing) \u2014 they approve a code in the browser, you never hold their password. The `<channel>` in that command is the tag your deployment names \u2014 read it from `/.well-known/haven.json` (`packages.cli.channel`), never a tag you pick. Do not hold the process open while you wait: under `--json`, pass `--no-wait` to get the link object back at once, then poll it with `haven login --poll <device_code>` \u2014 one round per invocation, exit 3 while it is still pending, 0 once approved. It can set up agents and read the account; it cannot sign, approve a budget, move funds, or rotate any agent's keys.\n2. **HUMAN \u2014 fund it.** USDC only, no ETH: Haven sponsors the gas. `/.well-known/haven.json` names `chains.default` as the deployment's expected chain, but after login `haven wallets funding` prints the address, the amount and which chain in one place; confirm that chain before you message your user. Without a CLI session, the dashboard's funding card shows the address and amount and its Receive-funds screen names the chain; never assume one: a testnet deployment and production both call themselves Haven. Before you write that message, read the manifest: `environment` says whether this deployment is `production`, and each `chains.supported` entry says whether that chain is a `testnet`. Real money is at stake only on a non-testnet chain of a `production` deployment \u2014 tell your user which case theirs is.\n3. **HUMAN \u2014 create the agent, set its budget**, and paste you the **setup prompt** it hands back. With a CLI session (step 1) you can do this step yourself: `haven agents connect --name <n> --budget <amount> --token USDC --period <minutes>` prints the same connector command and approval link; add `--run` to do step 4 too.\n4. **YOU \u2014 run the connector command** in that prompt (below). It makes your signing key locally, registering only the public address.\n5. **HUMAN \u2014 approve the budget** with their passkey, in the Haven tab they created the agent in: it advances to the approval step by itself once your run registers.\n6. **YOU \u2014 verify, then pay.**\n\n## Budget changes later (second token, raise, revoke)\n\nThe first budget rides the setup above. After the agent exists, a CLI session can construct the LATER changes \u2014 a second token, a bigger amount, a recipient pin, a stop \u2014 and hand your user a link; the human still signs, every time:\n\n```\nhaven budget grant <agentId> --amount <n> --token USDC --period <minutes> [--recipient <address>] [--wait]\nhaven budget revoke <agentId> <delegationHash> [--wait]\n```\n\nThe CLI never signs: it prints a dashboard link, your user opens it and signs with their passkey or wallet. `--wait` polls until the human's signature lands. The hash for `revoke` is in `haven agents show <agentId>`.\n\n## Hand-off scripts\n\nSend these as your own message, `<host>` replaced by the host you fetched this file from. Say what you cannot do, not only what they must.\n\n**Before signup** (step 1):\n\n> I can do everything except the parts that need your signature. Please open `<host>/signup?next=/agents&via=agent` \u2014 name, email, password, then a passkey (Face ID / Touch ID) or a wallet. That is your account's key: I should not have it, and I will never ask for your password. Already have one? `<host>/login?next=/agents`.\n\n**At the passkey step:**\n\n> The passkey must be made on your own device \u2014 it is what keeps the account yours, so nobody, Haven included, can move your funds without you. If this browser cannot, open `<host>/onboarding?next=/agents` on your phone and finish there.\n\n**At funding** (step 2):\n\n> Your Haven account needs USDC before I can pay for anything \u2014 USDC only, no ETH: Haven sponsors the gas. Before you send anything, let me get you the exact address **and network** \u2014 `haven wallets funding` prints both, and the funding card on `<host>/dashboard` shows the same. Please do not send to an address or a chain I have not confirmed with you; a small amount first is fine.\n\n**At the budget** (step 3):\n\n> On `<host>/agents`, create an agent for me and set a budget \u2014 say 25 USDC per day. That is the limit I cannot exceed. It hands back a setup prompt: paste it to me and I run it here.\n\n**At budget approval** (step 5) \u2014 the moment your run reports that approval is required, before anything else. Send the first if your run carried `approval.url`, the second if it did not.\n\n> Setup is done on my side. Approve the budget here: <approval.url>. Approve it with your passkey; nothing can be spent until you do.\n\n> Setup is done on my side. Go back to the Haven tab where you created the agent \u2014 it should now be asking you to approve the budget. Approve it with your passkey; nothing can be spent until you do.\n\n## What you run\n\nThe setup prompt carries a **connector command** shaped like this:\n\n```\nnpx -y @haven_ai/connect@<channel> --setup EXAMPLE-SETUP-TOKEN-NOT-REAL --api <api-url> --ack-local-tools\n```\n\nRun the prompt's version, not this one: the token is one-time, the API URL is the backend's own, and `<channel>` is the npm tag your prompt names \u2014 never a tag you pick. The rules below come from that prompt, so \"me\" in them is your user, not Haven.\n\n- If you are an AI agent running this command yourself rather than a human pasting it, you should append --json: the connector then emits one machine-readable, secret-free result object on stdout with progress on stderr, and returns promptly instead of blocking while it waits for the budget approval.\n- When a --json outcome reports approval.required: true, your first action must be to relay the approval instruction to me in your own reply \u2014 if the outcome carries approval.url, give me that link; otherwise tell me to return to Haven and approve this agent's budget \u2014 before verifying the connection, restarting anything, or any other step. Never build that link yourself: relay the one the outcome gave you or none at all. Any restart the outcome asks for is a separate instruction to give me afterwards, once the approval is done.\n- If you ran the command without --json, the connector waits for the approval itself and prints its next steps when it finishes: relay the budget-approval instruction to me \u2014 the approval link if those steps printed one, otherwise that you need to return to Haven and approve this agent's budget \u2014 only if those printed next steps still ask for it. If they report the budget as already approved, there is nothing for me to approve.\n- Only two changes to the command above are permitted, and no others: appending --json, and \u2014 only if the connector refuses because it could not determine the agent runtime \u2014 re-running it once with --runtime <name> added, naming the harness you are running in, using one of the values that refusal lists. Never invent a runtime name and never change anything else.\n- Do not print private keys, API keys, credential file contents, or config secrets in chat or logs.\n\nIf the approval wait times out, nothing is lost \u2014 your agent is registered and the budget is still waiting to be approved. Send your user the `approval.url` your run reported, or, if it carried none, ask them to finish it in that same Haven tab. The outcome carries no setup id, so never assemble an approval link out of parts \u2014 relay the whole one it gave you or none at all.\n\n## How to verify\n\nCall `haven_get_agent`, one of the Haven MCP tools the connector wires into your runtime in step 4. It returns identity plus `spend_authority_readiness`:\n\n- `ready` \u2014 a budget is live; you can pay.\n- `needs_approval` \u2014 the connector finished, nobody approved yet. Ask your user again, in their Haven tab; there is no queue to wait in.\n- `revoked` \u2014 the credential is not active; ask your user to create a new agent.\n\n`ready` covers hosted identity and the budget only, not your local signer. Check that with `npx -y @haven_ai/connect@<channel> --doctor`, the same tag your prompt named \u2014 a separate command, so the two-changes rule does not bind it.\n\n## If you cannot open a browser\n\nNothing here needs you to. Steps 1-3 are links: hand your user the full `<host>/\u2026` URL and ask them to say when it is done. Step 5 is a link only when your run reported one in `approval.url` \u2014 otherwise it is the tab they already have open, as above. Then poll `haven_get_agent` until it reads `ready`. Do not route around the sign-in wall \u2014 it makes the account theirs, not yours.\n\n## Vocabulary\n\n| Term | What it is |\n|---|---|\n| **setup prompt** | The text the dashboard hands your user to paste to you. Carries the command and its rules. |\n| **connector command** | The `npx -y @haven_ai/connect@\u2026` line you run. One-time token, one use. |\n| **agent credential** | Your API key (`sk_agent_\u2026`), written to `~/.haven`. It identifies you; alone it cannot move money. |\n| **delegate key** | Your signing key, made on this machine and never sent anywhere. |\n| **budget** | The on-chain delegation your user signed. It authorises the payment; Haven constructs and relays it. |\n\nNext: [your agent hit a 402](/402.md) \xB7 [everything agent-readable](/llms.txt)\n";
429
429
 
430
430
  // src/token.ts
431
431
  function sessionExpiry(token) {
@@ -600,7 +600,10 @@ async function runConnector(connectorCommand, spawner, onStderr) {
600
600
 
601
601
  // src/commands.ts
602
602
  var DEFAULT_API = "https://havenbackend-production-8a00.up.railway.app";
603
- var CLI_VERSION = "0.1.36-alpha.0";
603
+ var CLI_VERSION = "0.2.0-alpha.0";
604
+ function accountAddressOf(s) {
605
+ return s.account_address ?? s.safe_address ?? "";
606
+ }
604
607
  async function run(argv, deps = {}) {
605
608
  const out = deps.out ?? ((l) => process.stdout.write(`${l}
606
609
  `));
@@ -727,6 +730,7 @@ async function deviceLogin(args, d, baseUrl) {
727
730
  verification_url: start.verification_url,
728
731
  user_code: start.user_code,
729
732
  device_code: start.device_code,
733
+ interval: start.interval,
730
734
  expires_at: new Date(deadline).toISOString()
731
735
  },
732
736
  () => `Open ${start.verification_url}
@@ -870,35 +874,35 @@ async function cmdWhoami(args, d) {
870
874
  }
871
875
  async function cmdWalletsList(args, d) {
872
876
  const { api } = await authed(args, d);
873
- const { safes } = await api.get("/user/safes");
877
+ const { safes } = await api.get("/user/accounts");
874
878
  emit(
875
879
  d,
876
880
  args.flags.json,
877
881
  safes,
878
882
  () => safes.length === 0 ? "No Haven wallets yet." : table(
879
883
  ["NAME", "NETWORK", "ADDRESS", "DEFAULT"],
880
- safes.map((s) => [s.name, chainName(s.chain_id), truncateAddress(s.safe_address), s.is_default ? "\u2713" : ""])
884
+ safes.map((s) => [s.name, chainName(s.chain_id), truncateAddress(accountAddressOf(s)), s.is_default ? "\u2713" : ""])
881
885
  )
882
886
  );
883
887
  return EXIT.ok;
884
888
  }
885
889
  async function cmdWalletsBalances(args, d) {
886
890
  const { api } = await authed(args, d);
887
- const { safes } = await api.get("/user/safes");
891
+ const { safes } = await api.get("/user/accounts");
888
892
  const safe = pickSafe(safes, args.flags.safe);
889
893
  if (!safe) {
890
894
  if (args.flags.safe) throw new UsageError(`No wallet matches "${args.flags.safe}".`);
891
895
  throw new CliApiError("No Haven wallet found.", 404);
892
896
  }
893
897
  const { balances } = await api.get(
894
- `/balances/${safe.safe_address}?chain_id=${safe.chain_id}`
898
+ `/balances/${accountAddressOf(safe)}?chain_id=${safe.chain_id}`
895
899
  );
896
900
  emit(
897
901
  d,
898
902
  args.flags.json,
899
- { safe: safe.name, chainId: safe.chain_id, balances },
903
+ { account: safe.name, safe: safe.name, chainId: safe.chain_id, balances },
900
904
  () => [
901
- `${safe.name} \xB7 ${chainName(safe.chain_id)} \xB7 ${truncateAddress(safe.safe_address)}`,
905
+ `${safe.name} \xB7 ${chainName(safe.chain_id)} \xB7 ${truncateAddress(accountAddressOf(safe))}`,
902
906
  balances.length === 0 ? " (no balances)" : table(["TOKEN", "BALANCE"], balances.map((b) => [b.symbol, b.formatted]))
903
907
  ].join("\n")
904
908
  );
@@ -907,17 +911,17 @@ async function cmdWalletsBalances(args, d) {
907
911
  function pickSafe(safes, ref) {
908
912
  if (!ref) return safes.find((s) => s.is_default) ?? safes[0];
909
913
  const lower = ref.toLowerCase();
910
- return safes.find((s) => s.id === ref || s.safe_address.toLowerCase() === lower);
914
+ return safes.find((s) => s.id === ref || accountAddressOf(s).toLowerCase() === lower);
911
915
  }
912
916
  async function cmdWalletsFunding(args, d) {
913
917
  const { api } = await authed(args, d);
914
- const { safes } = await api.get("/user/safes");
918
+ const { safes } = await api.get("/user/accounts");
915
919
  const safe = pickSafe(safes, args.flags.safe);
916
920
  if (!safe) {
917
921
  if (args.flags.safe) throw new UsageError(`No wallet matches "${args.flags.safe}".`);
918
922
  throw new CliApiError("No Haven wallet found.", 404);
919
923
  }
920
- const funding = await api.get(`/user/safes/${safe.id}/funding`);
924
+ const funding = await api.get(`/user/accounts/${safe.id}/funding`);
921
925
  if (!args.flags.wait) {
922
926
  emitFunding(d, funding);
923
927
  return EXIT.ok;
@@ -938,7 +942,7 @@ async function cmdWalletsFunding(args, d) {
938
942
  );
939
943
  }
940
944
  await d.sleep(pollMs);
941
- current = await api.get(`/user/safes/${safe.id}/funding`);
945
+ current = await api.get(`/user/accounts/${safe.id}/funding`);
942
946
  if (current.funded) break;
943
947
  d.o.note(`Still waiting after ${elapsedLabel(Date.now() - started)} \u2014 funded: no.`);
944
948
  }
@@ -1055,11 +1059,13 @@ async function cmdBudgetGrant(args, d) {
1055
1059
  EXIT.refused
1056
1060
  );
1057
1061
  }
1058
- if (!agent.safe_address || !agent.safe_chain_id) {
1062
+ const accountAddress = agent.account_address ?? agent.safe_address;
1063
+ const accountChainId = agent.account_chain_id ?? agent.safe_chain_id;
1064
+ if (!accountAddress || !accountChainId) {
1059
1065
  throw new HavenCliError(`Agent ${id} has no wallet assigned yet \u2014 connect it first.`, EXIT.refused);
1060
1066
  }
1061
1067
  const { balances } = await api.get(
1062
- `/balances/${agent.safe_address}?chain_id=${agent.safe_chain_id}`
1068
+ `/balances/${accountAddress}?chain_id=${accountChainId}`
1063
1069
  );
1064
1070
  const wanted = args.flags.token.trim().toUpperCase();
1065
1071
  const token = balances.find((b) => b.symbol.toUpperCase() === wanted);
@@ -1228,13 +1234,13 @@ async function cmdWalletRename(args, d) {
1228
1234
  const name = nameParts.join(" ").trim();
1229
1235
  if (!id || !name) throw new UsageError("Usage: haven wallets rename <id> <name>");
1230
1236
  const { api } = await authed(args, d);
1231
- await api.put(`/user/safes/${id}`, { name });
1232
- emit(d, args.flags.json, { ok: true, safe_id: id, name }, () => `Wallet ${id} renamed to "${name}".`);
1237
+ await api.put(`/user/accounts/${id}`, { name });
1238
+ emit(d, args.flags.json, { ok: true, account_id: id, safe_id: id, name }, () => `Wallet ${id} renamed to "${name}".`);
1233
1239
  return EXIT.ok;
1234
1240
  }
1235
1241
  async function resolveSafeId(args, api) {
1236
1242
  if (!args.flags.safe) return void 0;
1237
- const { safes } = await api.get("/user/safes");
1243
+ const { safes } = await api.get("/user/accounts");
1238
1244
  const safe = pickSafe(safes, args.flags.safe);
1239
1245
  if (!safe) throw new UsageError(`No wallet matches "${args.flags.safe}".`);
1240
1246
  return safe.id;
@@ -1246,7 +1252,10 @@ async function cmdActivityList(args, d) {
1246
1252
  offset: String(args.flags.offset ?? 0),
1247
1253
  limit: String(args.flags.limit ?? 25)
1248
1254
  });
1249
- if (safeId) params.set("safeId", safeId);
1255
+ if (safeId) {
1256
+ params.set("accountId", safeId);
1257
+ params.set("safeId", safeId);
1258
+ }
1250
1259
  if (args.flags.agent) params.set("agentId", args.flags.agent);
1251
1260
  const { transactions } = await api.get(`/transactions?${params.toString()}`);
1252
1261
  const visible = args.flags.direction ? transactions.filter((t) => t.direction === args.flags.direction) : transactions;
@@ -1275,7 +1284,10 @@ async function cmdActivityExport(args, d) {
1275
1284
  offset: String(args.flags.offset ?? 0),
1276
1285
  limit: String(args.flags.limit ?? 1e3)
1277
1286
  });
1278
- if (safeId) params.set("safeId", safeId);
1287
+ if (safeId) {
1288
+ params.set("accountId", safeId);
1289
+ params.set("safeId", safeId);
1290
+ }
1279
1291
  if (args.flags.agent) params.set("agentId", args.flags.agent);
1280
1292
  const { transactions } = await api.get(`/transactions?${params.toString()}`);
1281
1293
  const visible = args.flags.direction ? transactions.filter((t) => t.direction === args.flags.direction) : transactions;
@@ -1291,7 +1303,8 @@ async function cmdActivityExport(args, d) {
1291
1303
  "safe_address",
1292
1304
  "agent_name",
1293
1305
  "tx_hash",
1294
- "chain_id"
1306
+ "chain_id",
1307
+ "account_address"
1295
1308
  ];
1296
1309
  const rows = visible.map((t) => [
1297
1310
  new Date(t.timestamp * 1e3).toISOString(),
@@ -1302,16 +1315,17 @@ async function cmdActivityExport(args, d) {
1302
1315
  t.tokenSymbol ?? t.asset ?? "",
1303
1316
  t.tokenAddress ?? "",
1304
1317
  (t.direction === "in" ? t.from : t.to) ?? "",
1305
- t.safeAddress ?? "",
1318
+ t.accountAddress ?? t.safeAddress ?? "",
1306
1319
  t.agentName ?? "",
1307
1320
  t.hash,
1308
- t.chainId != null ? String(t.chainId) : ""
1321
+ t.chainId != null ? String(t.chainId) : "",
1322
+ t.accountAddress ?? t.safeAddress ?? ""
1309
1323
  ]);
1310
1324
  d.o.text(toCsv(headers, rows), { format: "csv", rows: rows.length });
1311
1325
  return EXIT.ok;
1312
1326
  }
1313
1327
  function exportType(t) {
1314
- if (t.activityType === "delegate_sweep") return "allowance funding";
1328
+ if (t.activityType === "delegate_sweep") return "sweep";
1315
1329
  if (t.source === "x402") return "x402";
1316
1330
  if (t.source === "mpp_demo") return "mpp";
1317
1331
  return t.direction === "in" ? "receive" : "send";
@@ -1346,14 +1360,14 @@ async function cmdCatalogList(args, d) {
1346
1360
  return EXIT.ok;
1347
1361
  }
1348
1362
  async function resolveWalletAndToken(args, api, symbol) {
1349
- const { safes } = await api.get("/user/safes");
1363
+ const { safes } = await api.get("/user/accounts");
1350
1364
  if (safes.length === 0) {
1351
1365
  throw new HavenCliError("No wallet on this account yet \u2014 finish onboarding first.", EXIT.refused);
1352
1366
  }
1353
- const safe = args.flags.safe ? safes.find((s) => s.id === args.flags.safe || s.safe_address === args.flags.safe) : safes.find((s) => s.is_default) ?? safes[0];
1367
+ const safe = args.flags.safe ? safes.find((s) => s.id === args.flags.safe || accountAddressOf(s) === args.flags.safe) : safes.find((s) => s.is_default) ?? safes[0];
1354
1368
  if (!safe) throw new UsageError(`No wallet matches --safe ${args.flags.safe}`);
1355
1369
  const { balances } = await api.get(
1356
- `/balances/${safe.safe_address}?chain_id=${safe.chain_id}`
1370
+ `/balances/${accountAddressOf(safe)}?chain_id=${safe.chain_id}`
1357
1371
  );
1358
1372
  const wanted = symbol.trim().toUpperCase();
1359
1373
  const token = balances.find((b) => b.symbol.toUpperCase() === wanted);
@@ -1400,6 +1414,10 @@ async function cmdAgentsConnect(args, d) {
1400
1414
  if (!amount.ok) throw new UsageError(amount.message);
1401
1415
  const setup = await api.post("/agent-connection-setups", {
1402
1416
  name,
1417
+ // #2908: both id keys for the window — `account_id` is the #2907 twin
1418
+ // (landing in P0's second round), `safe_id` is what a server without it
1419
+ // reads; the request works against either.
1420
+ account_id: safeId,
1403
1421
  safe_id: safeId,
1404
1422
  allowances: [
1405
1423
  {