@haven_ai/cli 0.10.0-alpha.0 → 0.12.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -14
- package/dist/cli.cjs +43 -21
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +43 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +43 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +43 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -88,6 +88,9 @@ function parseArgs(argv) {
|
|
|
88
88
|
} else if (arg === "--expires") {
|
|
89
89
|
const n = Number(value);
|
|
90
90
|
if (!Number.isInteger(n) || n <= 0) throw new Error("--expires must be a unix timestamp in seconds");
|
|
91
|
+
if (n > Math.floor(Date.now() / 1e3) + 365 * 86400) {
|
|
92
|
+
throw new Error("--expires must be at most 365 days from now");
|
|
93
|
+
}
|
|
91
94
|
flags.expires = n;
|
|
92
95
|
} else if (arg === "--format") {
|
|
93
96
|
if (value !== "csv" && value !== "sie") throw new Error('--format must be "csv" or "sie"');
|
|
@@ -172,9 +175,9 @@ function helpText() {
|
|
|
172
175
|
"Budgets (construct-and-hand-off \u2014 the CLI never signs, #2539):",
|
|
173
176
|
" budget grant <agentId> --amount <n> --token USDC --period <minutes>",
|
|
174
177
|
" [--recipient <address>] [--expires <unix-s>] [--wait]",
|
|
175
|
-
" Prints
|
|
178
|
+
" Prints an approval link; the human approves in the dashboard.",
|
|
176
179
|
" budget revoke <agentId> <delegationHash> [--wait]",
|
|
177
|
-
" Prints a revocation link; the human
|
|
180
|
+
" Prints a revocation link; the human approves in the dashboard.",
|
|
178
181
|
"",
|
|
179
182
|
"Options:",
|
|
180
183
|
" --json One JSON value on stdout, prose on stderr, on every",
|
|
@@ -469,7 +472,7 @@ ${failure.hint}` : failure.message);
|
|
|
469
472
|
}
|
|
470
473
|
|
|
471
474
|
// src/agent-guidance-text.ts
|
|
472
|
-
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, `<packages.cli.one_liner> 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. That command is the manifest's `packages.cli.one_liner` (`/.well-known/haven.json`) \u2014 run it as given: `packages.cli.channel` serves the full spec. 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 (see What you run). 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 in The sequence. 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 budget show <agentId> --hashes`.\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 three changes to the command above are permitted, and no others: appending --json; re-running it once with --runtime <name> added, only if the connector refuses because it could not determine the agent runtime, naming the harness you are running in and using one of the values that refusal lists; and re-running it once with the one flag I chose added, only after I have answered a wiring_collision relay \u2014 --name <the suggested_name or a name I gave> to add alongside, or --replace to replace \u2014 keeping any change already made. If that re-run is refused too, relay the refusal to me and stop. 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 have the authority to pay. It does not say the account holds funds \u2014 the `allowances[]` rows carry `funds_cover_remaining`, and `false` there is a heads-up to mention to your user, not a refusal.\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 command-modification rule does not bind it.\n\n## If you cannot open a browser\n\nNothing here needs you to. Steps 1-3 \u2014 account, funding, budget \u2014 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. 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## If something breaks\n\nIf a Haven result carries `client_update`, that client is out of date: run its `upgrade_command` exactly as given \u2014 a connector command may name your pair with `--name <slug>` \u2014 then any repair line it prints, then retry. `required: true` means payments are refused until you do. What changed: [/releases](/releases).\n\nSomething else wrong? `haven feedback submit \"<text>\"` sends it to Haven \u2014 it needs `haven login` first. Never put a credential in that text: no API key, no delegate key, no session token, no recovery phrase.\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";
|
|
475
|
+
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. The budget also ENDS on a date your user chooses \u2014 30, 90 (default), 180 or 365 days out \u2014 and that day is enforced on-chain too. When the budget ends, your authority to pay ends with it; ask your user to renew it (a new approval on the agent's page, or a new `budget grant`). 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 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, `<packages.cli.one_liner> 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. That command is the manifest's `packages.cli.one_liner` (`/.well-known/haven.json`) \u2014 run it as given: `packages.cli.channel` serves the full spec. 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 (see What you run). 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 in The sequence. 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 budget show <agentId> --hashes`.\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 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 three changes to the command above are permitted, and no others: appending --json; re-running it once with --runtime <name> added, only if the connector refuses because it could not determine the agent runtime, naming the harness you are running in and using one of the values that refusal lists; and re-running it once with the one flag I chose added, only after I have answered a wiring_collision relay \u2014 --name <the suggested_name or a name I gave> to add alongside, or --replace to replace \u2014 keeping any change already made. If that re-run is refused too, relay the refusal to me and stop. 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 have the authority to pay. It does not say the account holds funds \u2014 the `allowances[]` rows carry `funds_cover_remaining`, and `false` there is a heads-up to mention to your user, not a refusal.\n- `needs_approval` \u2014 no budget can pay. `allowances[]` empty with `budgetEndedAt` set: your budget ENDED on that date; waiting will not help \u2014 ask your user to set a new one in their Haven tab. `allowances[]` empty with `budgetEndedAt` null: nobody approved one yet; ask your user again \u2014 there is no queue. Rows, all spent: it refills at `budgetRefillsAt`; tell your user, then wait or ask them to raise it (`null`: it ends first; ask them to renew it).\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 command-modification rule does not bind it.\n\n## If you cannot open a browser\n\nNothing here needs you to. Steps 1-3 \u2014 account, funding, budget \u2014 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. 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## If something breaks\n\nIf a Haven result carries `client_update`, that client is out of date: run its `upgrade_command` exactly as given \u2014 a connector command may name your pair with `--name <slug>` \u2014 then any repair line it prints, then retry. `required: true` means payments are refused until you do. What changed: [/releases](/releases).\n\nSomething else wrong? `haven feedback submit \"<text>\"` sends it to Haven \u2014 it needs `haven login` first. Never put a credential in that text: no API key, no delegate key, no session token, no recovery phrase.\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";
|
|
473
476
|
|
|
474
477
|
// src/token.ts
|
|
475
478
|
function sessionExpiry(token) {
|
|
@@ -3150,7 +3153,7 @@ async function checkTextForSecrets(text, deps) {
|
|
|
3150
3153
|
|
|
3151
3154
|
// src/commands.ts
|
|
3152
3155
|
var DEFAULT_API = "https://havenbackend-production-8a00.up.railway.app";
|
|
3153
|
-
var CLI_VERSION = "0.
|
|
3156
|
+
var CLI_VERSION = "0.12.0-alpha.0";
|
|
3154
3157
|
var CLI_CLIENT_IDENTITY = `@haven_ai/cli/${CLI_VERSION}`;
|
|
3155
3158
|
function accountAddressOf(s) {
|
|
3156
3159
|
return s.account_address ?? "";
|
|
@@ -3609,6 +3612,11 @@ function budgetSummary(allowances) {
|
|
|
3609
3612
|
if (!allowances || allowances.length === 0) return "\u2014";
|
|
3610
3613
|
return allowances.map((a) => `${a.allowance_amount} ${a.token_symbol}`).join(", ");
|
|
3611
3614
|
}
|
|
3615
|
+
var STILL_ENABLED_STATUSES = /* @__PURE__ */ new Set([
|
|
3616
|
+
"pending",
|
|
3617
|
+
"active",
|
|
3618
|
+
"replaced"
|
|
3619
|
+
]);
|
|
3612
3620
|
var BUDGET_WAIT_TIMEOUT_S = 15 * 60;
|
|
3613
3621
|
var BUDGET_WAIT_INTERVAL_MS = 5e3;
|
|
3614
3622
|
async function cmdBudgetGrant(args, d) {
|
|
@@ -3646,13 +3654,27 @@ async function cmdBudgetGrant(args, d) {
|
|
|
3646
3654
|
}
|
|
3647
3655
|
const amount = parseTokenAmount(args.flags.amount, token.decimals, token.symbol);
|
|
3648
3656
|
if (!amount.ok) throw new UsageError(amount.message);
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3657
|
+
let built;
|
|
3658
|
+
try {
|
|
3659
|
+
built = await api.post(`/agents/${id}/delegations/build`, {
|
|
3660
|
+
token_address: token.address,
|
|
3661
|
+
recipient_address: args.flags.recipient ?? null,
|
|
3662
|
+
budget_atomic: amount.atomic,
|
|
3663
|
+
period_seconds: args.flags.period * 60,
|
|
3664
|
+
...args.flags.expires !== void 0 ? { expires_at: args.flags.expires } : {}
|
|
3665
|
+
});
|
|
3666
|
+
} catch (err) {
|
|
3667
|
+
const body = err instanceof CliApiError ? err.body : void 0;
|
|
3668
|
+
if (body?.error_code === "BUDGET_SLOT_OCCUPIED") {
|
|
3669
|
+
throw new HavenCliError(
|
|
3670
|
+
err instanceof Error ? err.message : "This agent already has a live budget for this token and recipient.",
|
|
3671
|
+
EXIT.refused,
|
|
3672
|
+
"Edit that budget on the agent's page in the Haven dashboard instead: editing replaces it and stops the old one on-chain. Open task and sub-budgets carved from the old budget end when it is stopped.",
|
|
3673
|
+
{ error_code: "BUDGET_SLOT_OCCUPIED", existing_delegation_hash: body.existing_delegation_hash ?? null }
|
|
3674
|
+
);
|
|
3675
|
+
}
|
|
3676
|
+
throw err;
|
|
3677
|
+
}
|
|
3656
3678
|
const emitGrant = (status) => emit(
|
|
3657
3679
|
d,
|
|
3658
3680
|
args.flags.json,
|
|
@@ -3660,10 +3682,10 @@ async function cmdBudgetGrant(args, d) {
|
|
|
3660
3682
|
() => [
|
|
3661
3683
|
`Budget of ${args.flags.amount} ${token.symbol} per ${args.flags.period} minutes built for agent ${id}.`,
|
|
3662
3684
|
args.flags.recipient ? `Recipient pin: ${args.flags.recipient}` : null,
|
|
3663
|
-
"Open this link and
|
|
3685
|
+
"Open this link and approve \u2014 the budget goes live the moment you do:",
|
|
3664
3686
|
built.signing_url,
|
|
3665
3687
|
`Delegation: ${built.delegation_hash} (version ${built.version})`,
|
|
3666
|
-
status === "active" ? "
|
|
3688
|
+
status === "active" ? "Approved and active." : "Waiting for your approval. Run the same command with --wait to poll until it is active."
|
|
3667
3689
|
].filter((line) => line !== null).join("\n")
|
|
3668
3690
|
);
|
|
3669
3691
|
emitGrant();
|
|
@@ -3673,19 +3695,19 @@ async function cmdBudgetGrant(args, d) {
|
|
|
3673
3695
|
await d.sleep(BUDGET_WAIT_INTERVAL_MS);
|
|
3674
3696
|
const { delegations } = await api.get(`/agents/${id}/delegations`);
|
|
3675
3697
|
const mine = delegations.find((row) => row.delegation_hash === built.delegation_hash);
|
|
3676
|
-
if (mine
|
|
3698
|
+
if (mine && (mine.is_live ?? mine.status === "active")) {
|
|
3677
3699
|
emitGrant("active");
|
|
3678
3700
|
return EXIT.ok;
|
|
3679
3701
|
}
|
|
3680
3702
|
if (mine?.status === "revoked" || mine?.status === "replaced") {
|
|
3681
3703
|
throw new HavenCliError(
|
|
3682
|
-
`Delegation ${built.delegation_hash} is now ${mine.status} without being
|
|
3704
|
+
`Delegation ${built.delegation_hash} is now ${mine.status} without being approved.`,
|
|
3683
3705
|
EXIT.refused
|
|
3684
3706
|
);
|
|
3685
3707
|
}
|
|
3686
3708
|
}
|
|
3687
3709
|
throw new HavenCliError(
|
|
3688
|
-
`Timed out waiting for delegation ${built.delegation_hash} to go active (${BUDGET_WAIT_TIMEOUT_S / 60} minutes). The
|
|
3710
|
+
`Timed out waiting for delegation ${built.delegation_hash} to go active (${BUDGET_WAIT_TIMEOUT_S / 60} minutes). The approval link stays valid until it expires \u2014 approve it, or rerun with --wait.`,
|
|
3689
3711
|
EXIT.failed
|
|
3690
3712
|
);
|
|
3691
3713
|
}
|
|
@@ -3717,11 +3739,11 @@ async function cmdBudgetRevoke(args, d) {
|
|
|
3717
3739
|
args.flags.json,
|
|
3718
3740
|
{ agent_id: id, delegation_hash: hash, status, ...prepared },
|
|
3719
3741
|
() => [
|
|
3720
|
-
"Revocation prepared \u2014 one
|
|
3721
|
-
"Open this link and
|
|
3742
|
+
"Revocation prepared \u2014 one approval, sponsored (no gas).",
|
|
3743
|
+
"Open this link and approve to stop this budget:",
|
|
3722
3744
|
revokeUrl,
|
|
3723
3745
|
`Delegation: ${hash}`,
|
|
3724
|
-
status === "revoked" ? "Revoked." : "The budget keeps working until you
|
|
3746
|
+
status === "revoked" ? "Revoked." : "The budget keeps working until you approve. Run the same command with --wait to poll until it is revoked."
|
|
3725
3747
|
].filter((line) => line !== null).join("\n")
|
|
3726
3748
|
);
|
|
3727
3749
|
emitRevoke("pending_revoke");
|
|
@@ -3737,7 +3759,7 @@ async function cmdBudgetRevoke(args, d) {
|
|
|
3737
3759
|
}
|
|
3738
3760
|
}
|
|
3739
3761
|
throw new HavenCliError(
|
|
3740
|
-
`Timed out waiting for delegation ${hash} to be revoked (${BUDGET_WAIT_TIMEOUT_S / 60} minutes). The link stays valid \u2014
|
|
3762
|
+
`Timed out waiting for delegation ${hash} to be revoked (${BUDGET_WAIT_TIMEOUT_S / 60} minutes). The link stays valid \u2014 approve it, or rerun with --wait.`,
|
|
3741
3763
|
EXIT.failed
|
|
3742
3764
|
);
|
|
3743
3765
|
}
|
|
@@ -3777,7 +3799,7 @@ async function cmdAgentRevoke(args, d) {
|
|
|
3777
3799
|
const agent = await api.get(`/agents/${id}`);
|
|
3778
3800
|
if ((agent.live_delegation_count ?? 0) > 0) {
|
|
3779
3801
|
const { delegations } = await api.get(`/agents/${id}/delegations`);
|
|
3780
|
-
live = delegations.filter((r) =>
|
|
3802
|
+
live = delegations.filter((r) => STILL_ENABLED_STATUSES.has(r.status));
|
|
3781
3803
|
}
|
|
3782
3804
|
} catch (err) {
|
|
3783
3805
|
d.o.note(`Couldn't check budgets for agent ${id}, so the revocation was not attempted.`);
|