@haven_ai/cli 0.0.0-dev.202609060949.092c4e4 → 0.0.0-dev.202609061037.7cf43bb

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/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/args.ts","../src/api.ts","../src/session.ts","../src/format.ts","../src/csv.ts","../src/errors.ts","../src/output.ts","../src/agent-guidance-text.ts","../src/token.ts","../src/amount.ts","../src/connect-runner.ts","../src/commands.ts","../src/prompt.ts","../src/cli.ts"],"names":["resolve","homedir","join","readFile","mkdir","writeFile","chmod","rm","spawn","run","emitKeypressEvents"],"mappings":";;;;;;;;;;AA2CA,IAAM,WAAA,uBAAkB,GAAA,CAAI;AAAA,EAC1B,OAAA;AAAA,EAAS,SAAA;AAAA,EAAW,QAAA;AAAA,EAAU,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW,UAAA;AAAA,EAAY,aAAA;AAAA,EAChE,UAAA;AAAA,EAAY,QAAA;AAAA,EAAU,MAAA;AAAA,EAAQ,WAAA;AAAA,EAC9B,QAAA;AAAA,EAAU,UAAA;AAAA,EAAY,SAAA;AAAA,EAAW,UAAA;AAAA,EAAY;AAC/C,CAAC,CAAA;AAMM,SAAS,UAAU,IAAA,EAA4B;AACpD,EAAA,MAAM,cAAwB,EAAC;AAC/B,EAAA,MAAM,KAAA,GAA6B;AAAA,IACjC,IAAA,EAAM,KAAA;AAAA,IAAO,IAAA,EAAM,KAAA;AAAA,IAAO,OAAA,EAAS,KAAA;AAAA,IAAO,GAAA,EAAK,KAAA;AAAA,IAAO,MAAA,EAAQ,KAAA;AAAA,IAAO,GAAA,EAAK,KAAA;AAAA,IAAO,IAAA,EAAM;AAAA,GACzF;AAEA,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,IAAA,CAAK,MAAA,EAAQ,KAAK,CAAA,EAAG;AACvC,IAAA,MAAM,GAAA,GAAM,KAAK,C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C;AACA,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA","file":"cli.cjs","sourcesContent":["export interface ParsedArgs {\n command?: string\n sub?: string\n positionals: string[]\n flags: {\n json: boolean\n help: boolean\n /** #2526: print the code and exit instead of polling for approval. */\n noWait: boolean\n /** #2527: run the printed connector command as a child process. */\n run: boolean\n /** #2527: poll `agents connect --status` until it settles. */\n wait: boolean\n version: boolean\n yes: boolean\n api?: string\n email?: string\n safe?: string\n agent?: string\n limit?: number\n offset?: number\n direction?: 'in' | 'out'\n format?: string\n from?: string\n to?: string\n company?: string\n /** #2527 */\n name?: string\n budget?: string\n token?: string\n period?: number\n status?: string\n /**\n * #2527: deliberately absent — `--recipient`. The issue sketched one, and\n * neither `POST /agents` nor `POST /agent-connection-setups` has a field to\n * put it in: a recipient pin lives in the delegation's caveat enforcers and\n * is set when the human approves the budget. A flag accepted here would\n * either be silently dropped or invent a wire field, and a budget control\n * that looks applied and is not is worse than one you cannot ask for.\n */\n }\n}\n\nconst VALUE_FLAGS = new Set([\n '--api', '--email', '--safe', '--agent', '--limit', '--offset', '--direction',\n '--format', '--from', '--to', '--company',\n '--name', '--budget', '--token', '--period', '--status',\n])\n\n/**\n * `haven <command> [sub] [positionals] [--flags]`. Deliberately small — no\n * dependency, no clever aliasing. Unknown flags throw so typos fail loudly.\n */\nexport function parseArgs(argv: string[]): ParsedArgs {\n const positionals: string[] = []\n const flags: ParsedArgs['flags'] = {\n json: false, help: false, version: false, yes: false, noWait: false, run: false, wait: false,\n }\n\n for (let i = 0; i < argv.length; i += 1) {\n const arg = argv[i]\n if (arg === '--json') flags.json = true\n else if (arg === '--help' || arg === '-h') flags.help = true\n else if (arg === '--version' || arg === '-v') flags.version = true\n else if (arg === '--yes' || arg === '-y') flags.yes = true\n else if (arg === '--no-wait') flags.noWait = true\n else if (arg === '--run') flags.run = true\n else if (arg === '--wait') flags.wait = true\n else if (VALUE_FLAGS.has(arg)) {\n const value = argv[++i]\n if (value === undefined || value.startsWith('--')) {\n throw new Error(`Missing value for ${arg}`)\n }\n if (arg === '--api') flags.api = value\n else if (arg === '--name') flags.name = value\n else if (arg === '--budget') flags.budget = value\n else if (arg === '--token') flags.token = value\n else if (arg === '--status') flags.status = value\n else if (arg === '--period') {\n const n = Number(value)\n if (!Number.isInteger(n) || n < 0) throw new Error('--period must be a whole number of minutes')\n flags.period = n\n }\n else if (arg === '--email') flags.email = value\n else if (arg === '--safe') flags.safe = value\n else if (arg === '--agent') flags.agent = value\n else if (arg === '--limit') {\n const n = Number(value)\n if (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer')\n flags.limit = n\n } else if (arg === '--offset') {\n const n = Number(value)\n if (!Number.isInteger(n) || n < 0) throw new Error('--offset must be a non-negative integer')\n flags.offset = n\n } else if (arg === '--direction') {\n if (value !== 'in' && value !== 'out') throw new Error('--direction must be \"in\" or \"out\"')\n flags.direction = value\n } else if (arg === '--format') {\n if (value !== 'csv' && value !== 'sie') throw new Error('--format must be \"csv\" or \"sie\"')\n flags.format = value\n } else if (arg === '--from') flags.from = value\n else if (arg === '--to') flags.to = value\n else if (arg === '--company') flags.company = value\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`)\n } else {\n positionals.push(arg)\n }\n }\n\n const [command, sub, ...rest] = positionals\n return { command, sub, positionals: rest, flags }\n}\n\nexport function helpText(): string {\n return [\n 'haven — terminal-native companion to the Haven dashboard',\n '',\n 'Usage: haven <command> [subcommand] [options]',\n '',\n 'Auth:',\n ' login Sign in. Opens a browser device-code approval by default —',\n ' it prints a code and a link, and never asks for a password',\n ' login --email <e> Password path instead (prompt, or HAVEN_PASSWORD)',\n ' logout Clear the saved session',\n ' whoami Show the signed-in user, session expiry and API URL',\n '',\n 'For agents:',\n ' guide Print the agent onboarding runbook (same text as /for-agents.md)',\n ' agents connect --name <n> --budget <amount> --token USDC --period <minutes>',\n ' Create a connection setup; prints the connector command and',\n ' the approval link for your human. --run executes it here.',\n ' agents connect --status <setupId> [--wait] Read one setup\\'s status',\n '',\n 'Read:',\n ' wallets list List your Haven wallets',\n ' wallets balances [--safe <id|address>] Token balances for a wallet',\n ' wallets funding [--safe <id|address>] [--wait] The paste-ready funding',\n ' instruction: what to send, where, on which chain.',\n ' --wait polls until the account counts as funded.',\n ' agents list List your agents',\n ' agents show <id> Show one agent + its budget',\n ' budget show <agentId> Show an agent\\'s configured budget',\n ' activity list [--safe <id|address>] [--agent <id>] [--direction in|out] [--limit <n>] [--offset <n>]',\n ' activity export [filters] Emit CSV to stdout (--format csv, default)',\n ' activity export --format sie [--from <ISO>] [--to <ISO>] [--company <name>]',\n ' Bookkeeping-ready SIE 4I (Fortnox/Visma/Bokio)',\n ' catalog list List payable services',\n ' contacts list List your address book',\n '',\n 'Manage (backend-only — no on-chain signing):',\n ' agents pause <id> Stop the agent spending; keeps its budget',\n ' agents resume <id> Let it spend again',\n ' agents revoke <id> --yes Permanently revoke an agent',\n ' agents rotate-key <id> Issue a new API key (shown once)',\n ' agents rename <id> <name>',\n ' wallets rename <id> <name>',\n ' contacts add <name> <address> Save an address under a name',\n ' contacts remove <id> Forget one',\n '',\n 'Options:',\n ' --json One JSON value on stdout, prose on stderr, on every',\n ' command including refusals: { ok: false, error: { code, message, hint? } }',\n ' --yes, -y Skip the confirmation prompt for destructive actions',\n ' --api <url> Backend URL. Default: HAVEN_API_URL, else Haven\\'s hosted',\n ' production backend — NOT localhost. On any other',\n ' deployment an omitted flag connects to production.',\n ' --help, --version',\n '',\n 'Exit codes: 0 ok · 1 failed · 2 usage · 3 not authenticated · 4 refused · 5 network',\n '',\n 'On-chain actions (deploy, budgets, approvers, send) are signed in the',\n 'dashboard — this CLI reads and manages; it never holds your keys.',\n ].join('\\n')\n}\n","export class CliApiError extends Error {\n status: number\n /**\n * The parsed response body, when there was one (#2526).\n *\n * The message is built FROM `body.error` for humans, and the device flow\n * needs the same value as DATA: `authorization_pending` and `slow_down` are\n * control signals in a poll loop, and branching on them by matching the\n * message string would make the loop depend on prose that is free to change.\n */\n body?: unknown\n constructor(message: string, status: number, body?: unknown) {\n super(message)\n this.name = 'CliApiError'\n this.status = status\n this.body = body\n }\n}\n\nexport interface CliApi {\n get<T>(path: string): Promise<T>\n post<T>(path: string, body?: unknown): Promise<T>\n put<T>(path: string, body?: unknown): Promise<T>\n del<T>(path: string): Promise<T>\n /** GET a non-JSON body (e.g. an export file) as raw text. */\n getText(path: string): Promise<string>\n}\n\nexport interface CreateCliApiOptions {\n baseUrl: string\n token?: string\n fetchImpl?: typeof fetch\n}\n\n/**\n * Minimal JSON client for the Haven backend. Sends the user JWT as a Bearer\n * token when present, and surfaces backend `{ error }` messages as\n * `CliApiError` so commands can print something human.\n */\nexport function createCliApi({ baseUrl, token, fetchImpl = fetch }: CreateCliApiOptions): CliApi {\n const root = baseUrl.replace(/\\/+$/, '')\n\n async function request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const headers: Record<string, string> = { Accept: 'application/json' }\n if (token) headers.Authorization = `Bearer ${token}`\n if (body !== undefined) headers['Content-Type'] = 'application/json'\n\n let res: Response\n try {\n res = await fetchImpl(`${root}${path}`, {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n })\n } catch (err) {\n throw new CliApiError(\n `Could not reach Haven at ${root}: ${err instanceof Error ? err.message : String(err)}`,\n 0,\n )\n }\n\n if (res.status === 401) {\n throw new CliApiError('Not authenticated. Run `haven login` first.', 401)\n }\n\n const text = await res.text()\n const payload = text ? safeParse(text) : undefined\n\n if (!res.ok) {\n const message =\n (payload && typeof payload === 'object' && 'error' in payload && typeof payload.error === 'string'\n ? payload.error\n : null) ?? `Request failed (HTTP ${res.status}).`\n throw new CliApiError(message, res.status, payload)\n }\n\n return payload as T\n }\n\n async function requestText(path: string): Promise<string> {\n const headers: Record<string, string> = { Accept: 'text/plain' }\n if (token) headers.Authorization = `Bearer ${token}`\n\n let res: Response\n try {\n res = await fetchImpl(`${root}${path}`, { method: 'GET', headers })\n } catch (err) {\n throw new CliApiError(\n `Could not reach Haven at ${root}: ${err instanceof Error ? err.message : String(err)}`,\n 0,\n )\n }\n\n if (res.status === 401) {\n throw new CliApiError('Not authenticated. Run `haven login` first.', 401)\n }\n\n const text = await res.text()\n if (!res.ok) {\n const payload = text ? safeParse(text) : undefined\n const message =\n (payload && typeof payload === 'object' && 'error' in payload && typeof payload.error === 'string'\n ? payload.error\n : null) ?? `Request failed (HTTP ${res.status}).`\n throw new CliApiError(message, res.status)\n }\n return text\n }\n\n return {\n get: <T>(path: string) => request<T>('GET', path),\n post: <T>(path: string, body?: unknown) => request<T>('POST', path, body),\n put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),\n del: <T>(path: string) => request<T>('DELETE', path),\n getText: (path: string) => requestText(path),\n }\n}\n\nfunction safeParse(text: string): unknown {\n try {\n return JSON.parse(text)\n } catch {\n return undefined\n }\n}\n","import { mkdir, readFile, rm, writeFile, chmod } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { join, resolve } from 'node:path'\n\n/**\n * The signed-in user session. The token is a *user* JWT (same credential the\n * dashboard holds) — treat it like a secret: stored owner-only, never logged,\n * never sent anywhere but the Haven API. `apiBaseUrl` is pinned at login so\n * later commands talk to the same backend.\n */\nexport interface Session {\n token: string\n apiBaseUrl: string\n user: { id: string; email: string; name: string | null }\n}\n\nexport interface SessionStore {\n load(): Promise<Session | null>\n save(session: Session): Promise<void>\n clear(): Promise<void>\n path: string\n}\n\nfunction sessionDir(homeDir: string): string {\n return resolve(homeDir, '.haven')\n}\n\nexport function sessionPath(homeDir: string = homedir()): string {\n return join(sessionDir(homeDir), 'session.json')\n}\n\n/** File-backed session store, owner-only perms (0600 file in a 0700 dir). */\nexport function createSessionStore(homeDir: string = homedir()): SessionStore {\n const path = sessionPath(homeDir)\n return {\n path,\n async load() {\n try {\n const raw = await readFile(path, 'utf8')\n const parsed = JSON.parse(raw) as Partial<Session>\n if (!parsed.token || !parsed.apiBaseUrl || !parsed.user) return null\n return parsed as Session\n } catch {\n return null\n }\n },\n async save(session) {\n await mkdir(sessionDir(homeDir), { recursive: true, mode: 0o700 })\n await writeFile(path, `${JSON.stringify(session, null, 2)}\\n`, { mode: 0o600 })\n await chmod(path, 0o600).catch(() => undefined)\n },\n async clear() {\n await rm(path, { force: true })\n },\n }\n}\n","/** Tiny fixed-width table for human output. Scriptable callers use `--json`. */\nexport function table(headers: string[], rows: string[][]): string {\n const widths = headers.map((h, i) =>\n Math.max(h.length, ...rows.map((r) => (r[i] ?? '').length)),\n )\n const line = (cells: string[]) =>\n cells.map((c, i) => (c ?? '').padEnd(widths[i])).join(' ').trimEnd()\n return [line(headers), line(widths.map((w) => '-'.repeat(w))), ...rows.map(line)].join('\\n')\n}\n\nexport function truncateAddress(address: string): string {\n if (!address || address.length <= 12) return address\n return `${address.slice(0, 6)}…${address.slice(-4)}`\n}\n\nconst CHAIN_NAMES: Record<number, string> = { 100: 'Gnosis', 8453: 'Base' }\n\nexport function chainName(chainId: number): string {\n return CHAIN_NAMES[chainId] ?? `chain ${chainId}`\n}\n","/**\n * CSV serialization for `haven activity export`. Mirrors the dashboard export\n * (#411): RFC 4180 quoting, CRLF line endings, and a spreadsheet\n * formula-injection guard. Kept self-contained so the CLI has no @haven_ai/*\n * runtime dependency.\n */\n\n/** Quote per RFC 4180 and neutralise leading =,+,-,@ (Excel formula injection). */\nfunction csvField(value: string): string {\n let v = value\n if (/^[=+\\-@\\t\\r]/.test(v)) v = `'${v}`\n return `\"${v.replace(/\"/g, '\"\"')}\"`\n}\n\nexport function toCsv(headers: string[], rows: string[][]): string {\n const lines = [headers.join(','), ...rows.map((r) => r.map(csvField).join(','))]\n return lines.join('\\r\\n')\n}\n","import { CliApiError } from './api.js'\n\n/**\n * Exit codes (#2525). Documented in README.md § For agents and scripts, and\n * asserted in `json-contract.test.ts` (every code, over the whole command list)\n * and `commands.test.ts` (the individual commands that produce them) — an agent\n * branches on these, so they are a contract rather than an implementation\n * detail.\n */\nexport const EXIT = {\n ok: 0,\n /** Something failed and none of the specific codes below describe it. */\n failed: 1,\n /** The command line was wrong: unknown command, missing argument, bad flag. */\n usage: 2,\n /** No stored session, or the backend rejected the one we have. Log in again. */\n notAuthenticated: 3,\n /** Authenticated, and the backend refused anyway (403, 410, other 4xx). */\n refused: 4,\n /** The backend could not be reached at all. */\n network: 5,\n} as const\n\nexport type ExitCode = (typeof EXIT)[keyof typeof EXIT]\n\n/** Machine-readable `error.code` values, one per exit code above 0. */\nexport type FailureCode = 'failed' | 'usage' | 'not_authenticated' | 'refused' | 'network'\n\n/** A wrong command line. Carries `usage` so callers do not guess the exit code. */\nexport class UsageError extends Error {\n readonly hint?: string\n constructor(message: string, hint?: string) {\n super(message)\n this.name = 'UsageError'\n this.hint = hint\n }\n}\n\n/**\n * A failure that already knows its exit code (#2526).\n *\n * The device flow's outcomes are not exceptions in the usual sense — a denied\n * approval and an expired code are ordinary, expected answers — but they must\n * still exit non-zero with the RIGHT code, because that is the contract an\n * agent reads. Carrying the code on the error keeps the decision at the place\n * that knows the outcome rather than in a string match downstream.\n */\nexport class HavenCliError extends Error {\n readonly exit: ExitCode\n readonly hint?: string\n constructor(message: string, exit: ExitCode, hint?: string) {\n super(message)\n this.name = 'HavenCliError'\n this.exit = exit\n this.hint = hint\n }\n}\n\nexport interface Failure {\n code: FailureCode\n exit: ExitCode\n message: string\n hint?: string\n}\n\n/**\n * One place that decides what an error means, so the JSON body and the exit\n * code cannot disagree — they are read off the same object.\n *\n * **On 401 → `not_authenticated`, not `refused`.** The issue lists 401\n * alongside 403/410 under \"refused by the backend\", and separately lists\n * \"not logged in / session expired\" — the two overlap, and a 401 is exactly\n * the second one. An agent seeing `not_authenticated` knows to re-run\n * `haven login`; `refused` tells it the opposite (the session is fine, the\n * action is not allowed). Splitting them on the wire is the whole point of\n * having two codes, so 401 resolves to the one it can act on.\n */\nexport function toFailure(err: unknown): Failure {\n if (err instanceof UsageError) {\n return { code: 'usage', exit: EXIT.usage, message: err.message, hint: err.hint }\n }\n if (err instanceof HavenCliError) {\n // The error already decided; this only translates the number to its slug,\n // so the JSON body and the exit code still come off one object.\n const code: FailureCode =\n err.exit === EXIT.notAuthenticated\n ? 'not_authenticated'\n : err.exit === EXIT.refused\n ? 'refused'\n : err.exit === EXIT.network\n ? 'network'\n : 'failed'\n return { code, exit: err.exit, message: err.message, hint: err.hint }\n }\n if (err instanceof CliApiError) {\n if (err.status === 0) {\n return {\n code: 'network',\n exit: EXIT.network,\n message: err.message,\n hint: 'Check the network and `--api`, then retry.',\n }\n }\n if (err.status === 401) {\n return {\n code: 'not_authenticated',\n exit: EXIT.notAuthenticated,\n message: err.message,\n hint: 'Run `haven login` (or set HAVEN_EMAIL and HAVEN_PASSWORD).',\n }\n }\n if (err.status >= 400 && err.status < 500) {\n // 403 and 410 are the named cases; every other 4xx is the same shape of\n // answer — the backend understood and said no — so it gets the same code\n // rather than falling through to the generic one.\n return { code: 'refused', exit: EXIT.refused, message: err.message }\n }\n return { code: 'failed', exit: EXIT.failed, message: err.message }\n }\n return { code: 'failed', exit: EXIT.failed, message: err instanceof Error ? err.message : String(err) }\n}\n","import type { Failure } from './errors.js'\n\n/**\n * The `--json` contract (#2525).\n *\n * Under `--json`, **stdout carries exactly one JSON value and nothing else** —\n * every line of human prose goes to stderr instead. That is what lets an agent\n * pipe stdout straight into a parser without stripping progress chatter, and\n * it is why `note()` exists: the same call site prints a sentence for a human\n * and stays silent (on stdout) for a machine.\n *\n * Success keeps the payload shape each command already emitted — including the\n * bare arrays that `agents list` and friends return — so this change adds a\n * failure contract without breaking a script that already parses a success.\n * Failures are always the object `{ ok: false, error: { code, message, hint? } }`.\n */\nexport interface Output {\n readonly json: boolean\n /** The command's success payload. At most one per run, on stdout. */\n data(payload: unknown, human: () => string): void\n /** Raw text (an export file). Printed as-is; wrapped under `--json`. */\n text(content: string, meta: Record<string, unknown>): void\n /** Human prose. Stdout in prose mode; stderr under `--json`. */\n note(line: string): void\n /** The one failure object. Always stdout under `--json`, stderr otherwise. */\n failure(failure: Failure): void\n}\n\nexport function createOutput(\n json: boolean,\n out: (line: string) => void,\n err: (line: string) => void,\n): Output {\n return {\n json,\n data(payload, human) {\n out(json ? JSON.stringify(payload, null, 2) : human())\n },\n text(content, meta) {\n // A CSV/SIE body is the payload in prose mode. Under --json it becomes a\n // field of the single object, so the contract (\"one JSON value on\n // stdout\") holds for exports too and the content stays recoverable.\n out(json ? JSON.stringify({ ok: true, ...meta, content }, null, 2) : content)\n },\n note(line) {\n if (json) err(line)\n else out(line)\n },\n failure(failure) {\n const body = {\n ok: false as const,\n error: {\n code: failure.code,\n message: failure.message,\n ...(failure.hint ? { hint: failure.hint } : {}),\n },\n }\n if (json) out(JSON.stringify(body, null, 2))\n else err(failure.hint ? `${failure.message}\\n${failure.hint}` : failure.message)\n },\n }\n}\n","/**\n * The agent onboarding runbook — GENERATED, do not edit by hand.\n *\n * Canonical source: `packages/sdk/src/agent-guidance.ts` (#2523), served to\n * agents at `/for-agents.md`. This is a decoupled copy so `@haven_ai/cli`\n * keeps zero runtime dependencies: importing it from the SDK would put ethers,\n * viem and x402 on the `npx @haven_ai/cli` path for one Markdown string.\n * Same arrangement, and the same reason, as\n * `packages/frontend/src/lib/agent-skill-bundle.ts`.\n *\n * Regenerate: node packages/cli/scripts/sync-agent-guidance.mjs\n * The parity test in `agent-guidance-text.test.ts` fails if you forget.\n */\n\nexport const HAVEN_AGENT_RUNBOOK_MD = \"# Haven for agents — 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** — 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 — 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 — 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 login` afterwards gets you a scoped session for steps 3-4 — they approve a code in the browser, you never hold their password. 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 — fund it.** USDC on Base, to the address the dashboard shows. With a CLI session, `haven wallets funding` prints the address and the amount to send.\\n3. **HUMAN — 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 — run the connector command** in that prompt (below). It makes your signing key locally, registering only the public address.\\n5. **HUMAN — 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 — verify, then pay.**\\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` — 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 — 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 on Base before I can pay for anything — USDC only, no ETH: Haven sponsors the gas. The dashboard shows the address to send it to; a small amount first is fine. If I have a terminal session, `haven wallets funding` prints the address, the amount and an explorer link — say the word and I will paste them here.\\n\\n**At the budget** (step 3):\\n\\n> On `<host>/agents`, create an agent for me and set a budget — 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) — 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 — 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 — 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 — if the outcome carries approval.url, give me that link; otherwise tell me to return to Haven and approve this agent's budget — 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 — the approval link if those steps printed one, otherwise that you need to return to Haven and approve this agent's budget — 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 — only if the connector refuses because it could not determine the agent runtime — 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 — 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 — 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` — a budget is live; you can pay.\\n- `needs_approval` — the connector finished, nobody approved yet. Ask your user again, in their Haven tab; there is no queue to wait in.\\n- `revoked` — 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 — 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>/…` URL and ask them to say when it is done. Step 5 is a link only when your run reported one in `approval.url` — 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 — 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@…` line you run. One-time token, one use. |\\n| **agent credential** | Your API key (`sk_agent_…`), 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) · [everything agent-readable](/llms.txt)\\n\"\n","/**\n * Read the expiry out of the stored session JWT (#2525).\n *\n * `whoami --json` and `login --json` report when the session dies, and the\n * only place that fact exists is the token's own `exp` claim — the backend\n * signs it with `expiresIn: '7d'` (`routes/auth.ts`) and `/auth/me` does not\n * return it. So the payload segment is base64url-decoded and read.\n *\n * This deliberately does NOT verify the signature, and must never be used to\n * decide anything but what to print: the CLI has no key to verify with, and a\n * forged `exp` would only mislead the user about a token the backend will\n * reject on its own terms. It never logs, echoes or returns the token itself.\n */\nexport function sessionExpiry(token: string): string | null {\n const segment = token.split('.')[1]\n if (!segment) return null\n try {\n const json = Buffer.from(segment.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8')\n const claims = JSON.parse(json) as { exp?: unknown }\n if (typeof claims.exp !== 'number' || !Number.isFinite(claims.exp)) return null\n return new Date(claims.exp * 1000).toISOString()\n } catch {\n // A token we cannot read is not an error worth failing a command over —\n // the expiry is informational, and every other field still resolves.\n return null\n }\n}\n","/**\n * Human token amounts → atomic units, without a dependency (#2527).\n *\n * ## Why this exists rather than `parseUnits`\n *\n * The dashboard modal converts with viem's `parseUnits` before it POSTs\n * (`useAgentConnectionSetup.ts`), and this CLI has to produce the same string\n * for the same input. It cannot call the same function: `@haven_ai/cli` ships\n * with **zero runtime dependencies** — asserted by a test, because `npx\n * @haven_ai/cli` is the path an agent uses and viem's tree is ~94 MB — so this\n * is the arithmetic done in strings over Node builtins.\n *\n * ## The two shapes, and why this direction is the dangerous one\n *\n * `allowance_amount` is ATOMIC on the way in and HUMAN-DECIMAL on the way back\n * (#2295). One name, two shapes. Nothing here sniffs which it is holding: the\n * caller says, and this function only ever converts human → atomic. A number\n * that is wrong by 10^6 is a budget that is wrong by a factor of a million.\n *\n * ## Excess precision is REFUSED, never rounded\n *\n * `parseUnits` ROUNDS the excess rather than dropping it, which is worse than\n * it sounds: measured against viem, `parseUnits('1.9999999', 6)` is `2000000n`\n * — **two whole tokens** — and `parseUnits('0.0000005', 6)` is `1n`, a budget\n * conjured out of a value below the token's precision. An earlier version of\n * this comment said it truncates to `1999999n`; that was wrong, and the truth\n * is the stronger argument for refusing (haven-reviewer, #2527).\n *\n * For a field a person typed and is about to authorise, quietly changing the\n * number is worse than declining it, so this mirrors the modal's own\n * `validateMoneyInput`, which refuses before it ever reaches `parseUnits`. The\n * rule is the same on both surfaces on purpose: a budget the dashboard would\n * not accept must not become acceptable by being typed into a terminal.\n */\n\nexport interface AmountResult {\n ok: true\n /** The normalised human string, e.g. `.5` → `0.5`. */\n human: string\n /** Atomic units as a decimal string — what the wire wants. */\n atomic: string\n}\n\nexport interface AmountRefusal {\n ok: false\n message: string\n}\n\nfunction decimalLabel(decimals: number): string {\n return decimals === 1 ? '1 decimal place' : `${decimals} decimal places`\n}\n\n/**\n * Convert a human amount to atomic units for a token with `decimals`.\n *\n * Refuses rather than guesses: anything that is not a plain non-negative\n * decimal, anything that is zero, and anything carrying more fraction digits\n * than the token can represent.\n */\nexport function parseTokenAmount(\n input: string,\n decimals: number,\n tokenSymbol?: string,\n): AmountResult | AmountRefusal {\n if (!Number.isInteger(decimals) || decimals < 0 || decimals > 36) {\n return { ok: false, message: `Unusable token decimals: ${String(decimals)}` }\n }\n\n // `.5` → `0.5`, matching the modal's `normalizeMoneyInput` so the two\n // surfaces accept the same set of strings.\n const trimmed = String(input ?? '').trim()\n const human = trimmed.startsWith('.') ? `0${trimmed}` : trimmed\n const label = tokenSymbol ? ` ${tokenSymbol}` : ''\n\n if (human === '') return { ok: false, message: 'Enter an amount greater than 0' }\n // No sign, no exponent, no separators. `1e6` and `1_000` are the shapes most\n // likely to be meant well and read wrong, so they are refused by omission.\n if (!/^\\d+(?:\\.\\d+)?$/.test(human)) {\n return { ok: false, message: `Enter a valid${label} amount — digits, with an optional decimal point` }\n }\n\n const [whole, fraction = ''] = human.split('.')\n if (fraction.length > decimals) {\n return {\n ok: false,\n message: `${tokenSymbol ?? 'This token'} supports up to ${decimalLabel(decimals)}`,\n }\n }\n\n // Right-pad the fraction to the token's precision and concatenate: the whole\n // conversion, with no float anywhere near it. BigInt then strips leading\n // zeros, so `0.5` at 6 decimals is `500000` rather than `0500000`.\n const atomic = BigInt(`${whole}${fraction.padEnd(decimals, '0')}`)\n if (atomic === 0n) return { ok: false, message: 'Enter an amount greater than 0' }\n\n return { ok: true, human, atomic: atomic.toString() }\n}\n","import { spawn } from 'node:child_process'\n\n/**\n * Running the connector as a child process, for `haven agents connect --run`\n * (#2527).\n *\n * ## The command is not ours to edit\n *\n * The backend builds `connector_command` and the setup prompt states the rule\n * an agent must follow: the command may be changed in exactly two ways, and\n * appending `--json` is one of them. So this splits the printed command and\n * appends `--json` — nothing else. It does not add `--replace`, it does not add\n * `--name`, it does not rewrite `--api`, and it never composes a command of its\n * own. `haven agents connect` has no flags for those on purpose: a wiring\n * collision is a decision for the human, and a CLI that could resolve one would\n * be making that decision on their behalf (boundary note on #2527 from #2551).\n *\n * ## Why the exit code is not the verdict\n *\n * The connector exits **1** on a refusal while still writing a complete outcome\n * object to stdout (`cli.test.ts`, the `wiring_collision` case). Treating a\n * non-zero exit as \"it did not run\" would throw away exactly the structured\n * refusal the human needs. So the outcome is parsed from stdout whatever the\n * exit code was, and the exit code only decides what to do when there is no\n * parseable outcome at all.\n *\n * ## Refusals are recognised structurally, never by name\n *\n * A refusal is \"the outcome carries an `error`\". The relay text comes from\n * `error.next_action`. Nothing here enumerates `runtime_undetermined` or\n * `wiring_collision`, so a refusal added to the connector tomorrow reaches the\n * user through this path without a CLI change — which is the whole point of\n * the connector having a typed vocabulary in the first place.\n */\n\n/** The connector's `--json` outcome. Only the fields this CLI reads. */\nexport interface ConnectorOutcome {\n schema_version?: number\n outcome?: 'complete' | 'action_required' | 'failed' | string\n next_action?: string\n approval?: { required?: boolean; expires_at?: string | null; url?: string }\n error?: {\n code?: string\n next_action?: string\n message?: string\n allowed_runtimes?: readonly string[]\n installed_clients?: readonly string[]\n suggested_runtime?: string\n superseded_agent_ids?: readonly string[]\n suggested_name?: string\n }\n [key: string]: unknown\n}\n\nexport interface ConnectorRun {\n /** The parsed outcome, when the connector produced one. */\n outcome: ConnectorOutcome | null\n exitCode: number\n /** Everything the connector wrote to stderr, already streamed to ours. */\n stderr: string\n /** stdout that was not the outcome object — kept so a failure can say why. */\n stdoutNoise: string\n}\n\nexport interface Spawner {\n (command: string, args: string[], onStderr: (chunk: string) => void): Promise<{\n stdout: string\n stderr: string\n exitCode: number\n }>\n}\n\n/**\n * Split a printed connector command into argv.\n *\n * The backend shell-quotes the setup token and the API url with single quotes\n * (`buildConnectorCommand`), so this understands single quotes and nothing\n * else. It is deliberately not a shell: no globbing, no variable expansion, no\n * `&&`. A command carrying anything this cannot represent is refused rather\n * than approximated, because the alternative is executing a rewritten version\n * of a command whose whole contract is that it is not rewritten.\n */\nexport function splitConnectorCommand(command: string): string[] {\n const argv: string[] = []\n let current = ''\n let quoted = false\n let started = false\n\n for (let i = 0; i < command.length; i += 1) {\n const ch = command[i]\n if (quoted) {\n if (ch === \"'\") quoted = false\n else current += ch\n continue\n }\n if (ch === \"'\") {\n quoted = true\n started = true\n continue\n }\n if (ch === ' ' || ch === '\\t') {\n if (started) argv.push(current)\n current = ''\n started = false\n continue\n }\n // The ONE backslash form this understands: POSIX `'\\''`, which is how the\n // backend's `shellQuote` escapes a single quote inside a quoted value\n // (`'a'\\''b'` means `a'b`). Supported because the builder can emit it, and\n // a command the builder can produce but `--run` cannot execute is a broken\n // contract rather than a safe refusal. Every OTHER backslash is still\n // refused — this is a parser for one known quoting function, not a shell.\n if (ch === '\\\\') {\n if (command[i + 1] === \"'\") {\n current += \"'\"\n started = true\n i += 1\n continue\n }\n throw new Error('Refusing to run a connector command with a backslash escape')\n }\n if (ch === '\"' || ch === '`' || ch === '$' || ch === '|' || ch === '&' || ch === ';' ||\n ch === '>' || ch === '<' || ch === '(' || ch === ')' || ch === '\\n') {\n throw new Error(`Refusing to run a connector command containing ${JSON.stringify(ch)}`)\n }\n current += ch\n started = true\n }\n if (quoted) throw new Error('Refusing to run a connector command with an unterminated quote')\n if (started) argv.push(current)\n if (argv.length === 0) throw new Error('The backend returned an empty connector command')\n return argv\n}\n\n/** The real spawner. Injected in tests so no child process runs there. */\nexport const nodeSpawner: Spawner = (command, args, onStderr) =>\n new Promise((resolve, reject) => {\n // `shell: false` is the point: argv goes to the process as-is, so nothing\n // in a token or url can be read as shell syntax.\n const child = spawn(command, args, { shell: false, stdio: ['ignore', 'pipe', 'pipe'] })\n let stdout = ''\n let stderr = ''\n child.stdout.setEncoding('utf8')\n child.stderr.setEncoding('utf8')\n child.stdout.on('data', (chunk: string) => {\n stdout += chunk\n })\n child.stderr.on('data', (chunk: string) => {\n stderr += chunk\n // Streamed rather than buffered to the end: a connector run can take\n // minutes, and its stderr is the only progress a human sees.\n onStderr(chunk)\n })\n child.on('error', reject)\n child.on('close', (code) => resolve({ stdout, stderr, exitCode: code ?? 1 }))\n })\n\n/**\n * Find the connector's outcome object in its stdout.\n *\n * The contract is one JSON object on stdout under `--json`. This assumes none\n * of the things that contract does not actually say: not that the object is\n * the whole stream (a package manager on the `npx` path writes its own lines),\n * not that it is on one line (a pretty-printed object), and not that it is\n * alone on its line (`npm notice {...}`). Each of those assumptions turned a\n * real refusal into \"no outcome\" in an earlier version. The LAST balanced\n * object wins.\n */\nexport function parseOutcome(stdout: string): { outcome: ConnectorOutcome | null; noise: string } {\n const noise: string[] = []\n let outcome: ConnectorOutcome | null = null\n\n // A scanner over the WHOLE stream, not over lines. Two assumptions died\n // here, both of them unstated until a reviewer looked: that the object is on\n // one line (a pretty-printed refusal was swallowed), and that the object is\n // ALONE on its line (`npm notice {...}` or a trailing word dropped it the\n // same way). Both regressed a real refusal to \"the connector produced no\n // outcome\", losing the exit code and the `next_action` a caller branches on.\n // Anything outside a balanced object is noise; the LAST balanced object\n // wins, so a stray object from a package manager cannot displace the\n // outcome.\n let depth = 0\n let start = -1\n let inString = false\n let escaped = false\n let plain = ''\n\n for (let i = 0; i < stdout.length; i += 1) {\n const ch = stdout[i]\n\n if (depth === 0) {\n if (ch === '{') {\n depth = 1\n start = i\n inString = false\n escaped = false\n } else {\n plain += ch\n }\n continue\n }\n\n if (inString) {\n if (escaped) escaped = false\n else if (ch === '\\\\') escaped = true\n else if (ch === '\"') inString = false\n continue\n }\n if (ch === '\"') inString = true\n else if (ch === '{') depth += 1\n else if (ch === '}') {\n depth -= 1\n if (depth === 0) {\n const candidate = stdout.slice(start, i + 1)\n try {\n // No `Array.isArray` check here, deliberately. A candidate always\n // starts at `{`, so `JSON.parse` can only return an object — the\n // anchor IS the guarantee. An earlier version carried the array\n // check as well and a mutation removing it passed the whole suite,\n // because it was unreachable: a guard nothing can violate reads like\n // protection while proving nothing, which is the shape this file has\n // already been wrong about once.\n outcome = JSON.parse(candidate) as ConnectorOutcome\n } catch {\n plain += candidate\n }\n start = -1\n }\n }\n }\n\n // An object that never closed is not an outcome; keep it readable rather\n // than dropping it, so a truncated stream still says something.\n if (depth > 0 && start >= 0) plain += stdout.slice(start)\n\n for (const line of plain.split('\\n')) {\n const text = line.trim()\n if (text) noise.push(text)\n }\n return { outcome, noise: noise.join('\\n') }\n}\n\n/** Is this outcome a refusal the human has to act on? */\nexport function isRefusal(outcome: ConnectorOutcome | null): boolean {\n return Boolean(outcome?.error)\n}\n\n/**\n * The one line that goes first (#2483's one-gate rule).\n *\n * An approval that is waiting outranks everything else on screen, and a\n * refusal outranks a completed run. The text is built from what the connector\n * said rather than from a table of codes here.\n */\nexport function relayLine(outcome: ConnectorOutcome | null): string | null {\n if (!outcome) return null\n if (outcome.error) {\n const message = outcome.error.message?.trim()\n const next = outcome.error.next_action ?? outcome.next_action\n // The message is the connector's own prose and is what a human reads; the\n // next action is what an agent branches on. Both, in that order.\n return message\n ? `${message}${next ? ` (next: ${next})` : ''}`\n : `The connector refused${next ? `: ${next}` : '.'}`\n }\n if (outcome.approval?.required) {\n return outcome.approval.url\n ? `Approve the budget to finish: ${outcome.approval.url}`\n : 'Approve the budget in your Haven tab to finish.'\n }\n return null\n}\n\n/**\n * Run the connector command, appending `--json` and nothing else.\n */\nexport async function runConnector(\n connectorCommand: string,\n spawner: Spawner,\n onStderr: (chunk: string) => void,\n): Promise<ConnectorRun> {\n const argv = splitConnectorCommand(connectorCommand)\n // Appended, never inserted: the rule is \"exactly `--json` appended\", and a\n // flag placed anywhere else is a different command line.\n const args = [...argv.slice(1), '--json']\n const { stdout, stderr, exitCode } = await spawner(argv[0], args, onStderr)\n const { outcome, noise } = parseOutcome(stdout)\n return { outcome, exitCode, stderr, stdoutNoise: noise }\n}\n","import { parseArgs, helpText, type ParsedArgs } from './args.js'\nimport { createCliApi, CliApiError, type CliApi } from './api.js'\nimport { createSessionStore, type Session, type SessionStore } from './session.js'\nimport { chainName, table, truncateAddress } from './format.js'\nimport { toCsv } from './csv.js'\nimport { EXIT, HavenCliError, UsageError, toFailure, type ExitCode } from './errors.js'\nimport { createOutput, type Output } from './output.js'\nimport { HAVEN_AGENT_RUNBOOK_MD } from './agent-guidance-text.js'\nimport { sessionExpiry } from './token.js'\nimport { parseTokenAmount } from './amount.js'\nimport {\n isRefusal,\n nodeSpawner,\n relayLine,\n runConnector,\n type ConnectorOutcome,\n type Spawner,\n} from './connect-runner.js'\n\n// Hosted Haven backend. Override with `--api <url>` or HAVEN_API_URL (e.g. a\n// local backend at http://localhost:3001, or your own domain once self-hosted).\nexport const DEFAULT_API = 'https://havenbackend-production-8a00.up.railway.app'\n// Self-reported CLI version. Owned by scripts/release-bump.mjs, which rewrites\n// the string literal below on every release — keep it a bare quoted literal.\nexport const CLI_VERSION = '0.0.0-dev.202609060949.092c4e4'\n\nexport interface RunDeps {\n sessionStore?: SessionStore\n /** Build an API client; injected so tests can stub the backend. */\n makeApi?: (baseUrl: string, token?: string) => CliApi\n promptPassword?: () => Promise<string>\n /** #2526: injected so the device poll loop is testable without real time. */\n sleep?: (ms: number) => Promise<void>\n /** #2527: injected so `--run` is testable without spawning a real process. */\n spawner?: Spawner\n out?: (line: string) => void\n err?: (line: string) => void\n env?: NodeJS.ProcessEnv\n}\n\ninterface ResolvedDeps {\n sessionStore: SessionStore\n makeApi: (baseUrl: string, token?: string) => CliApi\n promptPassword: () => Promise<string>\n sleep: (ms: number) => Promise<void>\n spawner: Spawner\n out: (line: string) => void\n err: (line: string) => void\n env: NodeJS.ProcessEnv\n /** Set once `--json` is known; every command writes through it. */\n o: Output\n}\n\n/**\n * Every command this CLI dispatches, as data (#2525).\n *\n * The table-driven contract test in `json-contract.test.ts` iterates THIS list\n * and asserts each command's `--json` refusal is one JSON object on stdout, so\n * a command added to `dispatch` without adding it here is not covered. Its\n * ceiling, stated plainly: the test proves the listed commands honour the\n * contract, not that the list is complete. A drift test below pins the list\n * against `dispatch`'s own switch to close that gap by execution.\n */\nexport const COMMANDS = [\n 'login', 'logout', 'whoami', 'guide',\n 'wallets list', 'wallets balances', 'wallets rename', 'wallets funding',\n 'agents list', 'agents show', 'agents pause', 'agents resume', 'agents revoke',\n 'agents rotate-key', 'agents rename', 'agents connect',\n 'budget show',\n 'activity list', 'activity export',\n 'catalog list',\n 'contacts list', 'contacts add', 'contacts remove',\n] as const\n\n// ── Backend response shapes (subset the CLI needs) ──────────────────\ninterface Safe { id: string; safe_address: string; chain_id: number; name: string; is_default: boolean }\ninterface Allowance { token_symbol: string; allowance_amount: string; reset_period_min: number }\ninterface Agent { id: string; name: string; status: string; allowances?: Allowance[] }\ninterface Balance { symbol: string; formatted: string; balance: string }\ninterface Txn {\n hash: string; direction: 'in' | 'out'; valueFormatted: string; asset: string\n source?: string; timestamp: number; safeName?: string\n from?: string; to?: string; isError?: boolean\n tokenSymbol?: string; tokenAddress?: string; chainId?: number; safeAddress?: string\n agentName?: string; paymentFlowStatus?: string | null; activityType?: string\n}\ninterface CatalogEntry { name: string; category: string; rail: string; price_display?: string | null; status: string }\ninterface Contact { id: string; name: string; address: string }\ninterface BalanceToken { symbol: string; address: string | null; decimals: number }\ninterface CreateSetupResponse {\n setup_id: string\n status: string\n approval_url: string\n expires_at: string\n connector_command: string\n connector_package: string\n setup_prompt: string\n}\ninterface SetupStatus {\n setup_id: string\n status: string\n agent_id: string | null\n approval_url: string\n expires_at: string\n}\n\n/** `GET /user/safes/:safeId/funding` — the wire shape the route documents. */\ninterface FundingResponse {\n account_address: string\n chain: { id: number; name: string; explorer_url: string }\n tokens: {\n symbol: string\n address: string\n decimals: number\n balance_human: string\n minimum_useful_human: string | null\n }[]\n native: { symbol: string; balance_human: string; needed: boolean }\n funded: boolean\n faucet_url?: string\n}\n\n/** Entry point. Returns a process exit code; never throws for expected errors. */\nexport async function run(argv: string[], deps: RunDeps = {}): Promise<number> {\n const out = deps.out ?? ((l: string) => process.stdout.write(`${l}\\n`))\n const err = deps.err ?? ((l: string) => process.stderr.write(`${l}\\n`))\n\n // `--json` has to be known before anything can be emitted, including a parse\n // failure's own message. Scanning argv for the flag is deliberate: parseArgs\n // throws on a bad line, and a refusal that ignored --json because the parse\n // failed would break the contract exactly when a caller most needs it.\n const json = argv.includes('--json')\n const o = createOutput(json, out, err)\n\n const d: ResolvedDeps = {\n sessionStore: deps.sessionStore ?? createSessionStore(),\n makeApi: deps.makeApi ?? ((baseUrl, token) => createCliApi({ baseUrl, token })),\n promptPassword: deps.promptPassword ?? (() => Promise.reject(new Error('No password input available'))),\n sleep: deps.sleep ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))),\n spawner: deps.spawner ?? nodeSpawner,\n out,\n err,\n env: deps.env ?? process.env,\n o,\n }\n\n let args: ParsedArgs\n try {\n args = parseArgs(argv)\n } catch (e) {\n return fail(d, new UsageError(e instanceof Error ? e.message : String(e), 'Run `haven --help`.'))\n }\n\n if (args.flags.version) {\n o.data({ version: CLI_VERSION }, () => CLI_VERSION)\n return EXIT.ok\n }\n if (args.flags.help || !args.command) {\n o.data({ help: helpText() }, () => helpText())\n return EXIT.ok\n }\n\n try {\n return await dispatch(args, d)\n } catch (e) {\n return fail(d, e)\n }\n}\n\n/** The single exit: one failure object, one exit code, read off one decision. */\nfunction fail(d: ResolvedDeps, err: unknown): ExitCode {\n const failure = toFailure(err)\n d.o.failure(failure)\n return failure.exit\n}\n\nasync function dispatch(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const key = args.sub ? `${args.command} ${args.sub}` : args.command\n switch (key) {\n case 'guide': return cmdGuide(args, d)\n case 'login': return cmdLogin(args, d)\n case 'logout': return cmdLogout(args, d)\n case 'whoami': return cmdWhoami(args, d)\n case 'wallets list': return cmdWalletsList(args, d)\n case 'wallets balances': return cmdWalletsBalances(args, d)\n case 'wallets funding': return cmdWalletsFunding(args, d)\n case 'agents list': return cmdAgentsList(args, d)\n case 'agents show': return cmdAgentsShow(args, d)\n case 'agents connect': return cmdAgentsConnect(args, d)\n case 'agents pause': return cmdAgentLifecycle(args, d, 'pause')\n case 'agents resume': return cmdAgentLifecycle(args, d, 'resume')\n case 'agents revoke': return cmdAgentRevoke(args, d)\n case 'agents rotate-key': return cmdAgentRotateKey(args, d)\n case 'agents rename': return cmdAgentRename(args, d)\n case 'budget show': return cmdBudgetShow(args, d)\n case 'wallets rename': return cmdWalletRename(args, d)\n case 'activity list': return cmdActivityList(args, d)\n case 'activity export': return cmdActivityExport(args, d)\n case 'catalog list': return cmdCatalogList(args, d)\n case 'contacts list': return cmdContactsList(args, d)\n case 'contacts add': return cmdContactsAdd(args, d)\n case 'contacts remove': return cmdContactsRemove(args, d)\n default:\n throw new UsageError(`Unknown command: ${key}.`, 'Run `haven --help` for the command list.')\n }\n}\n\nfunction baseUrlFor(args: ParsedArgs, d: ResolvedDeps, session: Session | null): string {\n return args.flags.api ?? session?.apiBaseUrl ?? d.env.HAVEN_API_URL ?? DEFAULT_API\n}\n\nasync function authed(args: ParsedArgs, d: ResolvedDeps): Promise<{ session: Session; api: CliApi }> {\n const session = await d.sessionStore.load()\n // Status 401 so a missing local session and a rejected one produce the same\n // code and the same advice — from the caller's side they are one situation.\n if (!session) throw new CliApiError('Not authenticated.', 401)\n return { session, api: d.makeApi(baseUrlFor(args, d, session), session.token) }\n}\n\nfunction emit(d: ResolvedDeps, _json: boolean, data: unknown, human: () => string): void {\n d.o.data(data, human)\n}\n\n// ── Guide ───────────────────────────────────────────────────────────\n\n/**\n * Print the agent onboarding runbook — the same text served at\n * `/for-agents.md` (#2523). Offline by construction: the string is compiled in,\n * so an agent with no session and no network still gets the instructions that\n * tell it what to do about exactly that.\n */\nasync function cmdGuide(_args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n d.o.data({ ok: true, format: 'markdown', content: HAVEN_AGENT_RUNBOOK_MD }, () => HAVEN_AGENT_RUNBOOK_MD)\n return EXIT.ok\n}\n\n// ── Auth ────────────────────────────────────────────────────────────\n\ninterface DeviceStart {\n device_code: string\n user_code: string\n verification_url: string\n expires_in: number\n interval: number\n}\n\n/**\n * Browser-approved login (#2526), the DEFAULT for `haven login`.\n *\n * The reason this is the default and the password path is not: an agent drives\n * this CLI, and an agent must never hold its user's password. The cold-test\n * agent correctly refused to type one. This asks the human instead — the agent\n * pastes a link, and every signature stays with the person.\n *\n * Under `--json` the first object is emitted BEFORE polling starts, so an agent\n * can hand its user the link immediately rather than after the flow completes.\n */\nasync function deviceLogin(args: ParsedArgs, d: ResolvedDeps, baseUrl: string): Promise<number> {\n const api = d.makeApi(baseUrl)\n const label = d.env.HAVEN_CLIENT_LABEL ?? `Haven CLI on ${d.env.HOSTNAME ?? 'this machine'}`\n const start = await api.post<DeviceStart>('/auth/device/start', { client_label: label })\n\n const deadline = Date.now() + start.expires_in * 1000\n // Emitted first, not last: the whole point is that the agent can pass the\n // link on while the poll runs.\n d.o.data(\n {\n ok: true,\n verification_url: start.verification_url,\n user_code: start.user_code,\n expires_at: new Date(deadline).toISOString(),\n },\n () =>\n `Open ${start.verification_url}\\nand approve the code ${start.user_code}.\\n` +\n `It expires in ${Math.round(start.expires_in / 60)} minutes.`,\n )\n\n if (args.flags.noWait) return EXIT.ok\n\n // The server names the interval; the client does not invent one. `slow_down`\n // widens it, which is the only backoff signal this flow has.\n let interval = start.interval * 1000\n for (;;) {\n if (Date.now() >= deadline) {\n throw new HavenCliError('The code expired before it was approved.', EXIT.notAuthenticated)\n }\n await d.sleep(interval)\n let res: { token: string; user: Session['user'] } | null = null\n try {\n res = await api.post<{ token: string; user: Session['user'] }>('/auth/device/token', {\n device_code: start.device_code,\n })\n } catch (err) {\n const code = deviceErrorCode(err)\n if (code === 'authorization_pending') continue\n if (code === 'slow_down') {\n interval += 5000\n continue\n }\n if (code === 'access_denied') {\n throw new HavenCliError('The request was denied.', EXIT.refused)\n }\n if (code === 'expired_token') {\n throw new HavenCliError('The code expired before it was approved.', EXIT.notAuthenticated)\n }\n throw err\n }\n await d.sessionStore.save({ token: res.token, apiBaseUrl: baseUrl, user: res.user })\n emit(\n d,\n args.flags.json,\n { ok: true, email: res.user.email, expires_at: sessionExpiry(res.token), user: res.user, apiBaseUrl: baseUrl },\n () => `Signed in as ${res!.user.email}.`,\n )\n return EXIT.ok\n }\n}\n\n/** The RFC 8628 error slug in a 400 body, or null. */\nfunction deviceErrorCode(err: unknown): string | null {\n const body = (err as { body?: { error?: unknown } } | undefined)?.body\n return typeof body?.error === 'string' ? body.error : null\n}\n\nasync function cmdLogin(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const email = args.flags.email ?? d.env.HAVEN_EMAIL\n // #2526: the browser flow is the DEFAULT. `--email` (or HAVEN_EMAIL) keeps\n // the password path for a human who wants it — it is not removed, it is no\n // longer what an agent gets by asking for `login`.\n if (!email) {\n return deviceLogin(args, d, baseUrlFor(args, d, null))\n }\n const password = d.env.HAVEN_PASSWORD ?? (await d.promptPassword())\n if (!password) {\n throw new UsageError('A password is required.', 'Set HAVEN_PASSWORD for a non-interactive run.')\n }\n const baseUrl = baseUrlFor(args, d, null)\n const api = d.makeApi(baseUrl)\n const res = await api.post<{ token: string; user: Session['user'] }>('/auth/login', { email, password })\n await d.sessionStore.save({ token: res.token, apiBaseUrl: baseUrl, user: res.user })\n // The issue specifies { ok, email, expires_at }; `user` and `apiBaseUrl` stay\n // because they were already the shape and dropping them would break a script\n // that reads them for no gain. Neither the password nor the token is echoed —\n // `expires_at` is derived from the token, never the token itself.\n emit(\n d,\n args.flags.json,\n { ok: true, email: res.user.email, expires_at: sessionExpiry(res.token), user: res.user, apiBaseUrl: baseUrl },\n () => `Signed in as ${res.user.email}.`,\n )\n return EXIT.ok\n}\n\nasync function cmdLogout(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n await d.sessionStore.clear()\n emit(d, args.flags.json, { ok: true, signed_out: true }, () => 'Signed out.')\n return EXIT.ok\n}\n\nasync function cmdWhoami(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { session, api } = await authed(args, d)\n const user = await api.get<Session['user']>('/auth/me')\n // The four fields #2525 asks for — id, email, session expiry, api url — laid\n // over the profile the route already returned, so nothing a caller reads\n // today disappears. `expires_at` is null when the token carries no readable\n // `exp`, which is a fact worth reporting rather than an error.\n emit(\n d,\n args.flags.json,\n { ...user, id: user.id, email: user.email, expires_at: sessionExpiry(session.token), api_url: session.apiBaseUrl },\n () => `${user.email}${user.name ? ` (${user.name})` : ''}`,\n )\n return EXIT.ok\n}\n\n// ── Wallets ─────────────────────────────────────────────────────────\n\nasync function cmdWalletsList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n emit(d, args.flags.json, safes, () =>\n safes.length === 0\n ? 'No Haven wallets yet.'\n : table(\n ['NAME', 'NETWORK', 'ADDRESS', 'DEFAULT'],\n safes.map((s) => [s.name, chainName(s.chain_id), truncateAddress(s.safe_address), s.is_default ? '✓' : '']),\n ),\n )\n return EXIT.ok\n}\n\nasync function cmdWalletsBalances(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n const safe = pickSafe(safes, args.flags.safe)\n if (!safe) {\n if (args.flags.safe) throw new UsageError(`No wallet matches \"${args.flags.safe}\".`)\n throw new CliApiError('No Haven wallet found.', 404)\n }\n const { balances } = await api.get<{ balances: Balance[] }>(\n `/balances/${safe.safe_address}?chain_id=${safe.chain_id}`,\n )\n emit(d, args.flags.json, { safe: safe.name, chainId: safe.chain_id, balances }, () =>\n [\n `${safe.name} · ${chainName(safe.chain_id)} · ${truncateAddress(safe.safe_address)}`,\n balances.length === 0\n ? ' (no balances)'\n : table(['TOKEN', 'BALANCE'], balances.map((b) => [b.symbol, b.formatted])),\n ].join('\\n'),\n )\n return EXIT.ok\n}\n\nfunction pickSafe(safes: Safe[], ref?: string): Safe | undefined {\n if (!ref) return safes.find((s) => s.is_default) ?? safes[0]\n const lower = ref.toLowerCase()\n return safes.find((s) => s.id === ref || s.safe_address.toLowerCase() === lower)\n}\n\n// ── Wallet funding (#2534) ──────────────────────────────────────────\n\n/**\n * The paste-ready funding instruction, read from the backend.\n *\n * The endpoint is the source; this command renders it. Every number in the\n * prose — the minimum to send, the address, the explorer link — comes out of\n * the response, so the CLI, the dashboard's funding card and the backend's\n * own docs cannot drift apart: `@haven_ai/core` owns the constants, the\n * route composes them, and nothing here repeats one. Prose mode prints the\n * sentence an agent hands to its human; `--json` prints the response object\n * itself, so a machine that wants to relay fields rather than a sentence has\n * the same facts in the same place.\n *\n * `--wait` polls until `funded` flips — how a turn actually waits out a human\n * moving money — with elapsed time visible so nobody stares at a silent\n * terminal. It exits 0 once funded and 1 on timeout (elapsed time in the\n * message); it never sends anything, never touches a faucet — this is\n * read-only facts for the human to act on, whatever the flag.\n */\nasync function cmdWalletsFunding(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n const safe = pickSafe(safes, args.flags.safe)\n if (!safe) {\n if (args.flags.safe) throw new UsageError(`No wallet matches \"${args.flags.safe}\".`)\n throw new CliApiError('No Haven wallet found.', 404)\n }\n // The endpoint is keyed by safe ID and resolves ownership itself — the\n // address/chain in the response are the route's answer, not ours to compose.\n const funding = await api.get<FundingResponse>(`/user/safes/${safe.id}/funding`)\n\n if (!args.flags.wait) {\n emitFunding(d, funding)\n return EXIT.ok\n }\n\n // ── `--wait`: poll until the human's transfer lands ────────────────\n const started = Date.now()\n // The poll interval, injectable so tests can run the loop without real time.\n const pollMs = Number(d.env.HAVEN_FUNDING_POLL_MS ?? '5000')\n // A default cap, not a guess about the user's patience: two hours covers a\n // bank-transfer detour, and `HAVEN_FUNDING_WAIT_MS` shortens it for tests.\n const waitMs = Number(d.env.HAVEN_FUNDING_WAIT_MS ?? String(2 * 60 * 60 * 1000))\n if (!Number.isFinite(pollMs) || pollMs <= 0 || !Number.isFinite(waitMs) || waitMs <= 0) {\n throw new UsageError('HAVEN_FUNDING_POLL_MS / HAVEN_FUNDING_WAIT_MS must be positive numbers of milliseconds')\n }\n let current = funding\n for (;;) {\n // The cap is checked BEFORE each poll, so a zero-length wait exits without\n // ever calling the endpoint twice.\n const spent = Date.now() - started\n if (spent >= waitMs) {\n throw new HavenCliError(\n `Still not funded after ${elapsedLabel(spent)} — the transfer may not have landed yet. Check the explorer link, then re-run.`,\n EXIT.failed,\n )\n }\n await d.sleep(pollMs)\n current = await api.get<FundingResponse>(`/user/safes/${safe.id}/funding`)\n if (current.funded) break\n d.o.note(`Still waiting after ${elapsedLabel(Date.now() - started)} — funded: no.`)\n }\n d.o.note(`Account shows funded after ${elapsedLabel(Date.now() - started)}.`)\n emitFunding(d, current)\n return EXIT.ok\n}\n\n/** One renderer, both modes: prose carries the paste-ready sentence. */\nfunction emitFunding(d: ResolvedDeps, funding: FundingResponse): void {\n emit(d, d.o.json, funding, () => {\n const token = funding.tokens.find((t) => t.minimum_useful_human !== null)\n const asset = token\n ? `at least ${token.minimum_useful_human} ${token.symbol}`\n : funding.native.needed\n ? funding.native.symbol\n : 'USDC'\n const gas = funding.native.needed\n ? ` plus ${funding.native.symbol} for gas`\n : ' — no gas token needed; Haven sponsors it'\n const faucet = funding.faucet_url !== undefined ? ` faucet: ${funding.faucet_url},` : ''\n return [\n `Send ${asset} on ${funding.chain.name} to ${funding.account_address}${gas}.`,\n `Explorer: ${funding.chain.explorer_url}.${faucet ? faucet.slice(0, -1) : ''}`,\n funding.funded ? 'The account already counts as funded.' : 'Nothing has arrived yet.',\n ].join('\\n')\n })\n}\n\n/** `83s` → `1m23s` → `1h02m` — the poll line and the timeout message share it. */\nfunction elapsedLabel(ms: number): string {\n const total = Math.floor(ms / 1000)\n const h = Math.floor(total / 3600)\n const m = Math.floor((total % 3600) / 60)\n const s = total % 60\n if (h > 0) return `${h}h${String(m).padStart(2, '0')}m`\n if (m > 0) return `${m}m${String(s).padStart(2, '0')}s`\n return `${s}s`\n}\n\n// ── Agents & budget ─────────────────────────────────────────────────\n\nasync function cmdAgentsList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { agents } = await api.get<{ agents: Agent[] }>('/agents')\n emit(d, args.flags.json, agents, () =>\n agents.length === 0\n ? 'No agents yet.'\n : table(\n ['ID', 'NAME', 'STATUS', 'BUDGETS'],\n agents.map((a) => [a.id, a.name, a.status, budgetSummary(a.allowances)]),\n ),\n )\n return EXIT.ok\n}\n\nasync function cmdAgentsShow(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven agents show <id>')\n const { api } = await authed(args, d)\n const agent = await api.get<Agent>(`/agents/${id}`)\n emit(d, args.flags.json, agent, () =>\n [\n `${agent.name} [${agent.status}]`,\n `id: ${agent.id}`,\n `budget: ${budgetSummary(agent.allowances)}`,\n ].join('\\n'),\n )\n return EXIT.ok\n}\n\nasync function cmdBudgetShow(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven budget show <agentId>')\n const { api } = await authed(args, d)\n const agent = await api.get<Agent>(`/agents/${id}`)\n const allowances = agent.allowances ?? []\n emit(d, args.flags.json, allowances, () =>\n allowances.length === 0\n ? `${agent.name} has no configured budget.`\n : table(\n ['TOKEN', 'AMOUNT', 'RESETS'],\n allowances.map((a) => [a.token_symbol, a.allowance_amount, resetLabel(a.reset_period_min)]),\n ),\n )\n return EXIT.ok\n}\n\nfunction budgetSummary(allowances?: Allowance[]): string {\n if (!allowances || allowances.length === 0) return '—'\n return allowances.map((a) => `${a.allowance_amount} ${a.token_symbol}`).join(', ')\n}\n\nfunction resetLabel(mins: number): string {\n if (mins === 0) return 'one-time'\n if (mins === 1440) return 'daily'\n if (mins === 10080) return 'weekly'\n if (mins === 43200) return 'monthly'\n return `every ${mins}m`\n}\n\nasync function cmdAgentLifecycle(args: ParsedArgs, d: ResolvedDeps, action: 'pause' | 'resume'): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError(`Usage: haven agents ${action} <id>`)\n const { api } = await authed(args, d)\n await api.post(`/agents/${id}/${action}`)\n const status = action === 'pause' ? 'paused' : 'resumed'\n emit(d, args.flags.json, { ok: true, agent_id: id, status }, () => `Agent ${id} ${status}.`)\n return EXIT.ok\n}\n\nasync function cmdAgentRevoke(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven agents revoke <id> --yes')\n // Revoke is terminal (status can't go back to active). Require explicit --yes\n // so it can't happen by accident in a script.\n if (!args.flags.yes) {\n throw new UsageError(\n `This permanently revokes agent ${id}.`,\n 'Re-run with --yes to confirm. Revoke is terminal — the agent cannot go back to active.',\n )\n }\n const { api } = await authed(args, d)\n await api.post(`/agents/${id}/revoke`)\n emit(\n d,\n args.flags.json,\n { ok: true, agent_id: id, status: 'revoked' },\n () => `Agent ${id} revoked. To also remove its on-chain allowance, use the dashboard.`,\n )\n return EXIT.ok\n}\n\nasync function cmdAgentRotateKey(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven agents rotate-key <id>')\n const { api } = await authed(args, d)\n const res = await api.post<{ api_key: string; api_key_prefix: string }>(`/agents/${id}/rotate-key`)\n // The key is the payload, so it belongs on stdout in both modes. The\n // SENTENCE about it is prose and moves to stderr under --json, which is what\n // keeps stdout a single parseable object with a secret in exactly one field.\n d.o.note('New API key (shown once — store it now; the old key stops working):')\n emit(d, args.flags.json, res, () => res.api_key)\n return EXIT.ok\n}\n\nasync function cmdAgentRename(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const [id, ...nameParts] = args.positionals\n const name = nameParts.join(' ').trim()\n if (!id || !name) throw new UsageError('Usage: haven agents rename <id> <name>')\n const { api } = await authed(args, d)\n await api.put(`/agents/${id}`, { name })\n emit(d, args.flags.json, { ok: true, agent_id: id, name }, () => `Agent ${id} renamed to \"${name}\".`)\n return EXIT.ok\n}\n\nasync function cmdWalletRename(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const [id, ...nameParts] = args.positionals\n const name = nameParts.join(' ').trim()\n if (!id || !name) throw new UsageError('Usage: haven wallets rename <id> <name>')\n const { api } = await authed(args, d)\n await api.put(`/user/safes/${id}`, { name })\n emit(d, args.flags.json, { ok: true, safe_id: id, name }, () => `Wallet ${id} renamed to \"${name}\".`)\n return EXIT.ok\n}\n\n// ── Activity ────────────────────────────────────────────────────────\n\n/**\n * Resolve `--safe` (id or address) to a Safe id for the `/transactions` filter,\n * mirroring `wallets balances`. Throws if `--safe` was given but matches no\n * wallet, so a typo'd filter fails loudly instead of silently returning all rows.\n */\nasync function resolveSafeId(args: ParsedArgs, api: CliApi): Promise<string | undefined> {\n if (!args.flags.safe) return undefined\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n const safe = pickSafe(safes, args.flags.safe)\n if (!safe) throw new UsageError(`No wallet matches \"${args.flags.safe}\".`)\n return safe.id\n}\n\nasync function cmdActivityList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const safeId = await resolveSafeId(args, api)\n const params = new URLSearchParams({\n offset: String(args.flags.offset ?? 0),\n limit: String(args.flags.limit ?? 25),\n })\n if (safeId) params.set('safeId', safeId)\n if (args.flags.agent) params.set('agentId', args.flags.agent)\n const { transactions } = await api.get<{ transactions: Txn[] }>(`/transactions?${params.toString()}`)\n const visible = args.flags.direction\n ? transactions.filter((t) => t.direction === args.flags.direction)\n : transactions\n emit(d, args.flags.json, visible, () =>\n visible.length === 0\n ? 'No activity.'\n : table(\n ['DATE', 'DIR', 'AMOUNT', 'TYPE', 'ACCOUNT'],\n visible.map((t) => [\n new Date(t.timestamp * 1000).toISOString().slice(0, 10),\n t.direction === 'in' ? 'in' : 'out',\n `${t.direction === 'in' ? '+' : '-'}${t.valueFormatted} ${t.asset}`,\n t.source ?? 'transfer',\n t.safeName ?? '',\n ]),\n ),\n )\n return EXIT.ok\n}\n\nasync function cmdActivityExport(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n if (args.flags.format === 'sie') return exportSie(args, d)\n const { api } = await authed(args, d)\n const safeId = await resolveSafeId(args, api)\n const params = new URLSearchParams({\n offset: String(args.flags.offset ?? 0),\n limit: String(args.flags.limit ?? 1000),\n })\n if (safeId) params.set('safeId', safeId)\n if (args.flags.agent) params.set('agentId', args.flags.agent)\n const { transactions } = await api.get<{ transactions: Txn[] }>(`/transactions?${params.toString()}`)\n const visible = args.flags.direction\n ? transactions.filter((t) => t.direction === args.flags.direction)\n : transactions\n\n // Same columns as the dashboard export (#411), minus counterparty_name\n // (no contacts join in the CLI yet).\n const headers = [\n 'date', 'type', 'status', 'direction', 'amount', 'token_symbol', 'token_address',\n 'counterparty_address', 'safe_address', 'agent_name', 'tx_hash', 'chain_id',\n ]\n const rows = visible.map((t) => [\n new Date(t.timestamp * 1000).toISOString(),\n exportType(t),\n exportStatus(t),\n t.direction,\n t.valueFormatted,\n t.tokenSymbol ?? t.asset ?? '',\n t.tokenAddress ?? '',\n (t.direction === 'in' ? t.from : t.to) ?? '',\n t.safeAddress ?? '',\n t.agentName ?? '',\n t.hash,\n t.chainId != null ? String(t.chainId) : '',\n ])\n d.o.text(toCsv(headers, rows), { format: 'csv', rows: rows.length })\n return EXIT.ok\n}\n\nfunction exportType(t: Txn): string {\n if (t.activityType === 'delegate_sweep') return 'allowance funding'\n if (t.source === 'x402') return 'x402'\n if (t.source === 'mpp_demo') return 'mpp'\n return t.direction === 'in' ? 'receive' : 'send'\n}\n\nfunction exportStatus(t: Txn): string {\n if (t.isError) return 'failed'\n if (t.paymentFlowStatus === 'confirming_merchant') return 'pending'\n return 'executed'\n}\n\n/** SIE 4I export: the backend builds the verifikat file (book-time SEK + BAS). */\nasync function exportSie(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const params = new URLSearchParams({ format: 'sie' })\n if (args.flags.from) params.set('from', args.flags.from)\n if (args.flags.to) params.set('to', args.flags.to)\n if (args.flags.company) params.set('company', args.flags.company)\n const content = await api.getText(`/accounting/export?${params.toString()}`)\n d.o.text(content, { format: 'sie' })\n return EXIT.ok\n}\n\n// ── Catalog ─────────────────────────────────────────────────────────\n\nasync function cmdCatalogList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { entries } = await api.get<{ entries: CatalogEntry[] }>('/catalog')\n emit(d, args.flags.json, entries, () =>\n entries.length === 0\n ? 'Catalog is empty.'\n : table(\n ['NAME', 'CATEGORY', 'RAIL', 'PRICE', 'STATUS'],\n entries.map((e) => [e.name, e.category, e.rail, e.price_display ?? '—', e.status]),\n ),\n )\n return EXIT.ok\n}\n\n\n// ── Connect (#2527) ─────────────────────────────────────────────────\n\n/**\n * Resolve the wallet this setup belongs to, and the token's decimals.\n *\n * The decimals are READ from the backend rather than kept in a table here.\n * `GET /balances/:safeAddress` lists every token the chain is configured for —\n * zero balance included — with its address and decimals, which is the same\n * registry the dashboard modal reads. A local table would be a second source\n * of truth for a number that decides a budget's magnitude, and it would drift\n * silently the first time a chain gained a token.\n */\nasync function resolveWalletAndToken(\n args: ParsedArgs,\n api: CliApi,\n symbol: string,\n): Promise<{ safeId: string; token: BalanceToken }> {\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n if (safes.length === 0) {\n throw new HavenCliError('No wallet on this account yet — finish onboarding first.', EXIT.refused)\n }\n const safe = args.flags.safe\n ? safes.find((s) => s.id === args.flags.safe || s.safe_address === args.flags.safe)\n : (safes.find((s) => s.is_default) ?? safes[0])\n if (!safe) throw new UsageError(`No wallet matches --safe ${args.flags.safe}`)\n\n // `chain_id` is REQUIRED here, not decorative. The same account address is\n // provisioned on every supported chain, so a wallet address usually owns more\n // than one ownership row — and `GET /balances/:address` answers\n // `400 chain_id required` rather than guessing when it finds more than one\n // (`routes/balances.ts`). `wallets balances` has always passed it; this call\n // omitted it and would have failed for exactly the ordinary multi-chain\n // account (haven-reviewer, #2527).\n const { balances } = await api.get<{ balances: BalanceToken[] }>(\n `/balances/${safe.safe_address}?chain_id=${safe.chain_id}`,\n )\n const wanted = symbol.trim().toUpperCase()\n const token = balances.find((b) => b.symbol.toUpperCase() === wanted)\n if (!token) {\n const known = balances.map((b) => b.symbol).join(', ')\n throw new UsageError(`Unknown token ${symbol} on this wallet's chain. Available: ${known || 'none'}`)\n }\n return { safeId: safe.id, token }\n}\n\n/** Poll a setup until it leaves the states that are still in flight. */\nconst SETTLED = new Set(['active', 'expired', 'cancelled', 'failed'])\n\nasync function pollSetup(\n api: CliApi,\n setupId: string,\n d: ResolvedDeps,\n wait: boolean,\n): Promise<SetupStatus> {\n let status = await api.get<SetupStatus>(`/agent-connection-setups/${setupId}`)\n if (!wait) return status\n // Bounded by the setup's own expiry rather than a local guess, so the loop\n // cannot outlive the thing it is watching.\n const deadline = new Date(status.expires_at).getTime()\n while (!SETTLED.has(status.status) && Date.now() < deadline) {\n await d.sleep(5000)\n status = await api.get<SetupStatus>(`/agent-connection-setups/${setupId}`)\n }\n return status\n}\n\n/**\n * `haven agents connect` — the connect flow without the dashboard modal.\n *\n * Three shapes: create a setup, `--status <id>` to read one, and `--run` to\n * additionally execute the connector command the backend printed.\n *\n * The command is PRINTED, never composed. `connector_command` comes back from\n * `POST /agent-connection-setups` and is emitted verbatim, which is what makes\n * it byte-identical to the dashboard's for the same setup — they are the same\n * string from the same builder, not two constructions that have to be kept in\n * agreement.\n */\nasync function cmdAgentsConnect(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n\n if (args.flags.status) {\n const status = await pollSetup(api, args.flags.status, d, args.flags.wait)\n emit(d, args.flags.json, status, () =>\n [\n `setup ${status.setup_id}: ${status.status}`,\n status.agent_id ? `agent: ${status.agent_id}` : null,\n SETTLED.has(status.status) ? null : `approve: ${status.approval_url}`,\n ]\n .filter(Boolean)\n .join('\\n'),\n )\n return EXIT.ok\n }\n\n const name = args.flags.name?.trim()\n if (!name) throw new UsageError('Usage: haven agents connect --name <name> --budget <amount> --token USDC --period <minutes>')\n if (!args.flags.budget || !args.flags.token || args.flags.period === undefined) {\n throw new UsageError('--budget, --token and --period are required (period is whole minutes; 0 means one-time)')\n }\n\n const { safeId, token } = await resolveWalletAndToken(args, api, args.flags.token)\n const amount = parseTokenAmount(args.flags.budget, token.decimals, token.symbol)\n if (!amount.ok) throw new UsageError(amount.message)\n\n const setup = await api.post<CreateSetupResponse>('/agent-connection-setups', {\n name,\n safe_id: safeId,\n allowances: [\n {\n token_address: token.address ?? '0x0000000000000000000000000000000000000000',\n token_symbol: token.symbol,\n // ATOMIC on the way in, human on the way back (#2295). Converted here\n // exactly once, from the decimals the backend just told us.\n allowance_amount: amount.atomic,\n reset_period_min: args.flags.period,\n },\n ],\n // How this setup was made, for connect attribution (#2302). The route\n // already accepts any slug, so nothing backend-side had to change.\n source: 'cli',\n // #2522: the hand-off marker, set only when an agent is driving this CLI\n // and says so. Never inferred — a guess here mislabels a human's own run.\n ...(d.env.HAVEN_AGENT_DRIVEN === '1' ? { via: 'agent' } : {}),\n })\n\n if (!args.flags.run) {\n emit(d, args.flags.json, setup, () =>\n [\n 'Run this where the agent runs:',\n '',\n setup.connector_command,\n '',\n `Then approve the budget: ${setup.approval_url}`,\n `Setup ${setup.setup_id} expires ${setup.expires_at}.`,\n ].join('\\n'),\n )\n return EXIT.ok\n }\n\n // `--run`: execute the printed command with `--json` appended and nothing\n // else changed. The connector's stderr is streamed as it arrives — a run can\n // take minutes and that is the only progress anyone sees.\n const run = await runConnector(setup.connector_command, d.spawner, (chunk) => d.err(chunk.trimEnd()))\n const relay = relayLine(run.outcome)\n const merged = {\n setup_id: setup.setup_id,\n approval_url: setup.approval_url,\n connector_command: setup.connector_command,\n connector_exit_code: run.exitCode,\n outcome: run.outcome,\n relay,\n }\n\n if (isRefusal(run.outcome)) {\n // Exit 4 with the refusal carried whole. Recognised by the presence of\n // `error`, never by matching a code — a refusal the connector adds later\n // reaches the user through this same path with no CLI change.\n emitConnectResult(d, args.flags.json, merged, relay)\n return EXIT.refused\n }\n if (!run.outcome) {\n throw new HavenCliError(\n `The connector produced no outcome (exit ${run.exitCode}).${run.stdoutNoise ? ` Output: ${run.stdoutNoise}` : ''}`,\n run.exitCode === 0 ? EXIT.failed : EXIT.failed,\n )\n }\n emitConnectResult(d, args.flags.json, merged, relay)\n return EXIT.ok\n}\n\n/**\n * Print a `--run` result with the relay line FIRST under prose (#2483's\n * one-gate rule): whatever the human has to act on outranks the record of what\n * happened, because a link buried under an outcome dump is a link nobody sees.\n */\nfunction emitConnectResult(\n d: ResolvedDeps,\n json: boolean,\n merged: { relay: string | null; outcome: ConnectorOutcome | null; setup_id: string },\n relay: string | null,\n): void {\n emit(d, json, merged, () =>\n [relay, relay ? '' : null, `setup ${merged.setup_id}: ${merged.outcome?.outcome ?? 'unknown'}`]\n .filter((line) => line !== null)\n .join('\\n'),\n )\n}\n\n// ── Contacts ────────────────────────────────────────────────────────\n\nasync function cmdContactsList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { contacts } = await api.get<{ contacts: Contact[] }>('/contacts')\n emit(d, args.flags.json, contacts, () =>\n contacts.length === 0\n ? 'No contacts yet.'\n : table(['ID', 'NAME', 'ADDRESS'], contacts.map((c) => [c.id, c.name, truncateAddress(c.address)])),\n )\n return EXIT.ok\n}\n\nasync function cmdContactsAdd(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const [address, ...nameParts] = [...args.positionals].reverse()\n // positionals are <name...> <address>; address is last, name is the rest.\n const name = nameParts.reverse().join(' ').trim()\n if (!name || !address) throw new UsageError('Usage: haven contacts add <name> <address>')\n const { api } = await authed(args, d)\n const contact = await api.post<Contact>('/contacts', { name, address })\n emit(d, args.flags.json, contact, () => `Added contact \"${contact.name}\" (${truncateAddress(contact.address)}).`)\n return EXIT.ok\n}\n\nasync function cmdContactsRemove(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven contacts remove <id>')\n const { api } = await authed(args, d)\n await api.del(`/contacts/${id}`)\n emit(d, args.flags.json, { ok: true, contact_id: id, removed: true }, () => `Contact ${id} removed.`)\n return EXIT.ok\n}\n","import { emitKeypressEvents } from 'node:readline'\n\n/** The three streams the prompt touches, injectable so a test can watch them. */\nexport interface PromptStreams {\n stdin: NodeJS.ReadStream\n stdout: NodeJS.WriteStream\n stderr: NodeJS.WriteStream\n}\n\n/**\n * Read a password from the TTY without echoing it. Falls back to a plain line\n * read when stdin isn't a TTY (so piping `HAVEN_PASSWORD` or a heredoc still\n * works, though the env var is the documented non-interactive path).\n *\n * Exported and stream-injected for one reason: which stream the prompt writes\n * to is part of the `--json` contract, and asserting it needs a seam. It is\n * `stderr` — see the comment at the write.\n */\nexport function promptPasswordWith(streams: PromptStreams): Promise<string> {\n return new Promise((resolve, reject) => {\n const { stdin, stderr } = streams\n if (!stdin.isTTY) {\n let data = ''\n stdin.setEncoding('utf8')\n stdin.on('data', (chunk) => (data += chunk))\n stdin.on('end', () => resolve(data.trim()))\n stdin.on('error', reject)\n return\n }\n // stderr, never stdout (#2525 review): under `--json` stdout carries one\n // JSON value and nothing else, and a prompt written there would land ahead\n // of it. A prompt is prose addressed to a human at a terminal, so stderr is\n // where it belongs in both modes — the TTY still shows it.\n stderr.write('Password: ')\n emitKeypressEvents(stdin)\n stdin.setRawMode(true)\n let value = ''\n const onKey = (char: string, key: { name?: string; ctrl?: boolean }) => {\n if (key.name === 'return' || key.name === 'enter') {\n cleanup()\n stderr.write('\\n')\n resolve(value)\n } else if (key.ctrl && key.name === 'c') {\n cleanup()\n stderr.write('\\n')\n reject(new Error('Cancelled'))\n } else if (key.name === 'backspace') {\n value = value.slice(0, -1)\n } else if (char && !key.ctrl) {\n value += char\n }\n }\n function cleanup() {\n stdin.setRawMode(false)\n stdin.pause()\n stdin.off('keypress', onKey)\n }\n stdin.resume()\n stdin.on('keypress', onKey)\n })\n}\n","#!/usr/bin/env node\n\nimport { run } from './commands.js'\nimport { promptPasswordWith } from './prompt.js'\n\n/**\n * The bin entry, and deliberately nothing else.\n *\n * It used to also define `promptPasswordWith`, which meant importing this file\n * to test that function EXECUTED the CLI — `run(process.argv.slice(2))` against\n * vitest's own argv, ending in `process.exit(1)`. The suite still reported 102\n * passing tests with one unhandled error beside them, which is exactly the\n * shape of failure a `grep` for \"Tests\" hides (#2525 review round 3, caught by\n * CI). An entry point that self-executes must not also be an import target, so\n * the prompt lives in `prompt.ts` and this file only wires and runs.\n */\nfunction promptPassword(): Promise<string> {\n return promptPasswordWith({ stdin: process.stdin, stdout: process.stdout, stderr: process.stderr })\n}\n\nrun(process.argv.slice(2), { promptPassword })\n .then((code) => process.exit(code))\n .catch((err) => {\n // The last resort: anything that escaped run()'s own handling. It should be\n // unreachable — run() catches around both parseArgs and dispatch — but if\n // it is ever reached under `--json`, a bare sentence on stderr with exit 1\n // would be the one refusal a machine caller cannot parse. So it emits the\n // same failure shape as everything else (#2525 review, finding 2).\n const message = err instanceof Error ? err.message : String(err)\n if (process.argv.includes('--json')) {\n process.stdout.write(`${JSON.stringify({ ok: false, error: { code: 'failed', message } }, null, 2)}\\n`)\n } else {\n process.stderr.write(`${message}\\n`)\n }\n process.exit(1)\n })\n"]}
1
+ {"version":3,"sources":["../src/args.ts","../src/api.ts","../src/session.ts","../src/format.ts","../src/csv.ts","../src/errors.ts","../src/output.ts","../src/agent-guidance-text.ts","../src/token.ts","../src/amount.ts","../src/connect-runner.ts","../src/commands.ts","../src/prompt.ts","../src/cli.ts"],"names":["resolve","homedir","join","readFile","mkdir","writeFile","chmod","rm","spawn","run","emitKeypressEvents"],"mappings":";;;;;;;;;;AA2CA,IAAM,WAAA,uBAAkB,GAAA,CAAI;AAAA,EAC1B,OAAA;AAAA,EAAS,SAAA;AAAA,EAAW,QAAA;AAAA,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A;AACpG;AAEA,GAAA,CAAI,QAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,EAAE,gBAAgB,CAAA,CAC1C,KAAK,CAAC,IAAA,KAAS,QAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,CACjC,KAAA,CAAM,CAAC,GAAA,KAAQ;AAMd,EAAA,MAAM,UAAU,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,OAAA,GAAU,OAAO,GAAG,CAAA;AAC/D,EAAA,IAAI,OAAA,CAAQ,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA,EAAG;AACnC,IAAA,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,EAAE,EAAA,EAAI,KAAA,EAAO,KAAA,EAAO,EAAE,MAAM,QAAA,EAAU,OAAA,IAAU,EAAG,IAAA,EAAM,CAAC,CAAC;AAAA,CAAI,CAAA;AAAA,EACxG,CAAA,MAAO;AACL,IAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,OAAO;AAAA,CAAI,CAAA;AAAA,EACrC;AACA,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA","file":"cli.cjs","sourcesContent":["export interface ParsedArgs {\n command?: string\n sub?: string\n positionals: string[]\n flags: {\n json: boolean\n help: boolean\n /** #2526: print the code and exit instead of polling for approval. */\n noWait: boolean\n /** #2527: run the printed connector command as a child process. */\n run: boolean\n /** #2527: poll `agents connect --status` until it settles. */\n wait: boolean\n version: boolean\n yes: boolean\n api?: string\n email?: string\n safe?: string\n agent?: string\n limit?: number\n offset?: number\n direction?: 'in' | 'out'\n format?: string\n from?: string\n to?: string\n company?: string\n /** #2527 */\n name?: string\n budget?: string\n token?: string\n period?: number\n status?: string\n /**\n * #2527: deliberately absent — `--recipient`. The issue sketched one, and\n * neither `POST /agents` nor `POST /agent-connection-setups` has a field to\n * put it in: a recipient pin lives in the delegation's caveat enforcers and\n * is set when the human approves the budget. A flag accepted here would\n * either be silently dropped or invent a wire field, and a budget control\n * that looks applied and is not is worse than one you cannot ask for.\n */\n }\n}\n\nconst VALUE_FLAGS = new Set([\n '--api', '--email', '--safe', '--agent', '--limit', '--offset', '--direction',\n '--format', '--from', '--to', '--company',\n '--name', '--budget', '--token', '--period', '--status',\n])\n\n/**\n * `haven <command> [sub] [positionals] [--flags]`. Deliberately small — no\n * dependency, no clever aliasing. Unknown flags throw so typos fail loudly.\n */\nexport function parseArgs(argv: string[]): ParsedArgs {\n const positionals: string[] = []\n const flags: ParsedArgs['flags'] = {\n json: false, help: false, version: false, yes: false, noWait: false, run: false, wait: false,\n }\n\n for (let i = 0; i < argv.length; i += 1) {\n const arg = argv[i]\n if (arg === '--json') flags.json = true\n else if (arg === '--help' || arg === '-h') flags.help = true\n else if (arg === '--version' || arg === '-v') flags.version = true\n else if (arg === '--yes' || arg === '-y') flags.yes = true\n else if (arg === '--no-wait') flags.noWait = true\n else if (arg === '--run') flags.run = true\n else if (arg === '--wait') flags.wait = true\n else if (VALUE_FLAGS.has(arg)) {\n const value = argv[++i]\n if (value === undefined || value.startsWith('--')) {\n throw new Error(`Missing value for ${arg}`)\n }\n if (arg === '--api') flags.api = value\n else if (arg === '--name') flags.name = value\n else if (arg === '--budget') flags.budget = value\n else if (arg === '--token') flags.token = value\n else if (arg === '--status') flags.status = value\n else if (arg === '--period') {\n const n = Number(value)\n if (!Number.isInteger(n) || n < 0) throw new Error('--period must be a whole number of minutes')\n flags.period = n\n }\n else if (arg === '--email') flags.email = value\n else if (arg === '--safe') flags.safe = value\n else if (arg === '--agent') flags.agent = value\n else if (arg === '--limit') {\n const n = Number(value)\n if (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer')\n flags.limit = n\n } else if (arg === '--offset') {\n const n = Number(value)\n if (!Number.isInteger(n) || n < 0) throw new Error('--offset must be a non-negative integer')\n flags.offset = n\n } else if (arg === '--direction') {\n if (value !== 'in' && value !== 'out') throw new Error('--direction must be \"in\" or \"out\"')\n flags.direction = value\n } else if (arg === '--format') {\n if (value !== 'csv' && value !== 'sie') throw new Error('--format must be \"csv\" or \"sie\"')\n flags.format = value\n } else if (arg === '--from') flags.from = value\n else if (arg === '--to') flags.to = value\n else if (arg === '--company') flags.company = value\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`)\n } else {\n positionals.push(arg)\n }\n }\n\n const [command, sub, ...rest] = positionals\n return { command, sub, positionals: rest, flags }\n}\n\nexport function helpText(): string {\n return [\n 'haven — terminal-native companion to the Haven dashboard',\n '',\n 'Usage: haven <command> [subcommand] [options]',\n '',\n 'Auth:',\n ' login Sign in. Opens a browser device-code approval by default —',\n ' it prints a code and a link, and never asks for a password',\n ' login --email <e> Password path instead (prompt, or HAVEN_PASSWORD)',\n ' logout Clear the saved session',\n ' whoami Show the signed-in user, session expiry and API URL',\n '',\n 'For agents:',\n ' guide Print the agent onboarding runbook (same text as /for-agents.md)',\n ' agents connect --name <n> --budget <amount> --token USDC --period <minutes>',\n ' Create a connection setup; prints the connector command and',\n ' the approval link for your human. --run executes it here.',\n ' agents connect --status <setupId> [--wait] Read one setup\\'s status',\n '',\n 'Read:',\n ' wallets list List your Haven wallets',\n ' wallets balances [--safe <id|address>] Token balances for a wallet',\n ' wallets funding [--safe <id|address>] [--wait] The paste-ready funding',\n ' instruction: what to send, where, on which chain.',\n ' --wait polls until the account counts as funded.',\n ' agents list List your agents',\n ' agents show <id> Show one agent + its budget',\n ' budget show <agentId> Show an agent\\'s configured budget',\n ' activity list [--safe <id|address>] [--agent <id>] [--direction in|out] [--limit <n>] [--offset <n>]',\n ' activity export [filters] Emit CSV to stdout (--format csv, default)',\n ' activity export --format sie [--from <ISO>] [--to <ISO>] [--company <name>]',\n ' Bookkeeping-ready SIE 4I (Fortnox/Visma/Bokio)',\n ' catalog list List payable services',\n ' contacts list List your address book',\n '',\n 'Manage (backend-only — no on-chain signing):',\n ' agents pause <id> Stop the agent spending; keeps its budget',\n ' agents resume <id> Let it spend again',\n ' agents revoke <id> --yes Permanently revoke an agent',\n ' agents rotate-key <id> Issue a new API key (shown once)',\n ' agents rename <id> <name>',\n ' wallets rename <id> <name>',\n ' contacts add <name> <address> Save an address under a name',\n ' contacts remove <id> Forget one',\n '',\n 'Options:',\n ' --json One JSON value on stdout, prose on stderr, on every',\n ' command including refusals: { ok: false, error: { code, message, hint? } }',\n ' --yes, -y Skip the confirmation prompt for destructive actions',\n ' --api <url> Backend URL. Default: HAVEN_API_URL, else Haven\\'s hosted',\n ' production backend — NOT localhost. On any other',\n ' deployment an omitted flag connects to production.',\n ' --help, --version',\n '',\n 'Exit codes: 0 ok · 1 failed · 2 usage · 3 not authenticated · 4 refused · 5 network',\n '',\n 'On-chain actions (deploy, budgets, approvers, send) are signed in the',\n 'dashboard — this CLI reads and manages; it never holds your keys.',\n ].join('\\n')\n}\n","export class CliApiError extends Error {\n status: number\n /**\n * The parsed response body, when there was one (#2526).\n *\n * The message is built FROM `body.error` for humans, and the device flow\n * needs the same value as DATA: `authorization_pending` and `slow_down` are\n * control signals in a poll loop, and branching on them by matching the\n * message string would make the loop depend on prose that is free to change.\n */\n body?: unknown\n constructor(message: string, status: number, body?: unknown) {\n super(message)\n this.name = 'CliApiError'\n this.status = status\n this.body = body\n }\n}\n\nexport interface CliApi {\n get<T>(path: string): Promise<T>\n post<T>(path: string, body?: unknown): Promise<T>\n put<T>(path: string, body?: unknown): Promise<T>\n del<T>(path: string): Promise<T>\n /** GET a non-JSON body (e.g. an export file) as raw text. */\n getText(path: string): Promise<string>\n}\n\nexport interface CreateCliApiOptions {\n baseUrl: string\n token?: string\n fetchImpl?: typeof fetch\n}\n\n/**\n * Minimal JSON client for the Haven backend. Sends the user JWT as a Bearer\n * token when present, and surfaces backend `{ error }` messages as\n * `CliApiError` so commands can print something human.\n */\nexport function createCliApi({ baseUrl, token, fetchImpl = fetch }: CreateCliApiOptions): CliApi {\n const root = baseUrl.replace(/\\/+$/, '')\n\n async function request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const headers: Record<string, string> = { Accept: 'application/json' }\n if (token) headers.Authorization = `Bearer ${token}`\n if (body !== undefined) headers['Content-Type'] = 'application/json'\n\n let res: Response\n try {\n res = await fetchImpl(`${root}${path}`, {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n })\n } catch (err) {\n throw new CliApiError(\n `Could not reach Haven at ${root}: ${err instanceof Error ? err.message : String(err)}`,\n 0,\n )\n }\n\n if (res.status === 401) {\n throw new CliApiError('Not authenticated. Run `haven login` first.', 401)\n }\n\n const text = await res.text()\n const payload = text ? safeParse(text) : undefined\n\n if (!res.ok) {\n const message =\n (payload && typeof payload === 'object' && 'error' in payload && typeof payload.error === 'string'\n ? payload.error\n : null) ?? `Request failed (HTTP ${res.status}).`\n throw new CliApiError(message, res.status, payload)\n }\n\n return payload as T\n }\n\n async function requestText(path: string): Promise<string> {\n const headers: Record<string, string> = { Accept: 'text/plain' }\n if (token) headers.Authorization = `Bearer ${token}`\n\n let res: Response\n try {\n res = await fetchImpl(`${root}${path}`, { method: 'GET', headers })\n } catch (err) {\n throw new CliApiError(\n `Could not reach Haven at ${root}: ${err instanceof Error ? err.message : String(err)}`,\n 0,\n )\n }\n\n if (res.status === 401) {\n throw new CliApiError('Not authenticated. Run `haven login` first.', 401)\n }\n\n const text = await res.text()\n if (!res.ok) {\n const payload = text ? safeParse(text) : undefined\n const message =\n (payload && typeof payload === 'object' && 'error' in payload && typeof payload.error === 'string'\n ? payload.error\n : null) ?? `Request failed (HTTP ${res.status}).`\n throw new CliApiError(message, res.status)\n }\n return text\n }\n\n return {\n get: <T>(path: string) => request<T>('GET', path),\n post: <T>(path: string, body?: unknown) => request<T>('POST', path, body),\n put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),\n del: <T>(path: string) => request<T>('DELETE', path),\n getText: (path: string) => requestText(path),\n }\n}\n\nfunction safeParse(text: string): unknown {\n try {\n return JSON.parse(text)\n } catch {\n return undefined\n }\n}\n","import { mkdir, readFile, rm, writeFile, chmod } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { join, resolve } from 'node:path'\n\n/**\n * The signed-in user session. The token is a *user* JWT (same credential the\n * dashboard holds) — treat it like a secret: stored owner-only, never logged,\n * never sent anywhere but the Haven API. `apiBaseUrl` is pinned at login so\n * later commands talk to the same backend.\n */\nexport interface Session {\n token: string\n apiBaseUrl: string\n user: { id: string; email: string; name: string | null }\n}\n\nexport interface SessionStore {\n load(): Promise<Session | null>\n save(session: Session): Promise<void>\n clear(): Promise<void>\n path: string\n}\n\nfunction sessionDir(homeDir: string): string {\n return resolve(homeDir, '.haven')\n}\n\nexport function sessionPath(homeDir: string = homedir()): string {\n return join(sessionDir(homeDir), 'session.json')\n}\n\n/** File-backed session store, owner-only perms (0600 file in a 0700 dir). */\nexport function createSessionStore(homeDir: string = homedir()): SessionStore {\n const path = sessionPath(homeDir)\n return {\n path,\n async load() {\n try {\n const raw = await readFile(path, 'utf8')\n const parsed = JSON.parse(raw) as Partial<Session>\n if (!parsed.token || !parsed.apiBaseUrl || !parsed.user) return null\n return parsed as Session\n } catch {\n return null\n }\n },\n async save(session) {\n await mkdir(sessionDir(homeDir), { recursive: true, mode: 0o700 })\n await writeFile(path, `${JSON.stringify(session, null, 2)}\\n`, { mode: 0o600 })\n await chmod(path, 0o600).catch(() => undefined)\n },\n async clear() {\n await rm(path, { force: true })\n },\n }\n}\n","/** Tiny fixed-width table for human output. Scriptable callers use `--json`. */\nexport function table(headers: string[], rows: string[][]): string {\n const widths = headers.map((h, i) =>\n Math.max(h.length, ...rows.map((r) => (r[i] ?? '').length)),\n )\n const line = (cells: string[]) =>\n cells.map((c, i) => (c ?? '').padEnd(widths[i])).join(' ').trimEnd()\n return [line(headers), line(widths.map((w) => '-'.repeat(w))), ...rows.map(line)].join('\\n')\n}\n\nexport function truncateAddress(address: string): string {\n if (!address || address.length <= 12) return address\n return `${address.slice(0, 6)}…${address.slice(-4)}`\n}\n\nconst CHAIN_NAMES: Record<number, string> = { 100: 'Gnosis', 8453: 'Base' }\n\nexport function chainName(chainId: number): string {\n return CHAIN_NAMES[chainId] ?? `chain ${chainId}`\n}\n","/**\n * CSV serialization for `haven activity export`. Mirrors the dashboard export\n * (#411): RFC 4180 quoting, CRLF line endings, and a spreadsheet\n * formula-injection guard. Kept self-contained so the CLI has no @haven_ai/*\n * runtime dependency.\n */\n\n/** Quote per RFC 4180 and neutralise leading =,+,-,@ (Excel formula injection). */\nfunction csvField(value: string): string {\n let v = value\n if (/^[=+\\-@\\t\\r]/.test(v)) v = `'${v}`\n return `\"${v.replace(/\"/g, '\"\"')}\"`\n}\n\nexport function toCsv(headers: string[], rows: string[][]): string {\n const lines = [headers.join(','), ...rows.map((r) => r.map(csvField).join(','))]\n return lines.join('\\r\\n')\n}\n","import { CliApiError } from './api.js'\n\n/**\n * Exit codes (#2525). Documented in README.md § For agents and scripts, and\n * asserted in `json-contract.test.ts` (every code, over the whole command list)\n * and `commands.test.ts` (the individual commands that produce them) — an agent\n * branches on these, so they are a contract rather than an implementation\n * detail.\n */\nexport const EXIT = {\n ok: 0,\n /** Something failed and none of the specific codes below describe it. */\n failed: 1,\n /** The command line was wrong: unknown command, missing argument, bad flag. */\n usage: 2,\n /** No stored session, or the backend rejected the one we have. Log in again. */\n notAuthenticated: 3,\n /** Authenticated, and the backend refused anyway (403, 410, other 4xx). */\n refused: 4,\n /** The backend could not be reached at all. */\n network: 5,\n} as const\n\nexport type ExitCode = (typeof EXIT)[keyof typeof EXIT]\n\n/** Machine-readable `error.code` values, one per exit code above 0. */\nexport type FailureCode = 'failed' | 'usage' | 'not_authenticated' | 'refused' | 'network'\n\n/** A wrong command line. Carries `usage` so callers do not guess the exit code. */\nexport class UsageError extends Error {\n readonly hint?: string\n constructor(message: string, hint?: string) {\n super(message)\n this.name = 'UsageError'\n this.hint = hint\n }\n}\n\n/**\n * A failure that already knows its exit code (#2526).\n *\n * The device flow's outcomes are not exceptions in the usual sense — a denied\n * approval and an expired code are ordinary, expected answers — but they must\n * still exit non-zero with the RIGHT code, because that is the contract an\n * agent reads. Carrying the code on the error keeps the decision at the place\n * that knows the outcome rather than in a string match downstream.\n */\nexport class HavenCliError extends Error {\n readonly exit: ExitCode\n readonly hint?: string\n constructor(message: string, exit: ExitCode, hint?: string) {\n super(message)\n this.name = 'HavenCliError'\n this.exit = exit\n this.hint = hint\n }\n}\n\nexport interface Failure {\n code: FailureCode\n exit: ExitCode\n message: string\n hint?: string\n}\n\n/**\n * One place that decides what an error means, so the JSON body and the exit\n * code cannot disagree — they are read off the same object.\n *\n * **On 401 → `not_authenticated`, not `refused`.** The issue lists 401\n * alongside 403/410 under \"refused by the backend\", and separately lists\n * \"not logged in / session expired\" — the two overlap, and a 401 is exactly\n * the second one. An agent seeing `not_authenticated` knows to re-run\n * `haven login`; `refused` tells it the opposite (the session is fine, the\n * action is not allowed). Splitting them on the wire is the whole point of\n * having two codes, so 401 resolves to the one it can act on.\n */\nexport function toFailure(err: unknown): Failure {\n if (err instanceof UsageError) {\n return { code: 'usage', exit: EXIT.usage, message: err.message, hint: err.hint }\n }\n if (err instanceof HavenCliError) {\n // The error already decided; this only translates the number to its slug,\n // so the JSON body and the exit code still come off one object.\n const code: FailureCode =\n err.exit === EXIT.notAuthenticated\n ? 'not_authenticated'\n : err.exit === EXIT.refused\n ? 'refused'\n : err.exit === EXIT.network\n ? 'network'\n : 'failed'\n return { code, exit: err.exit, message: err.message, hint: err.hint }\n }\n if (err instanceof CliApiError) {\n if (err.status === 0) {\n return {\n code: 'network',\n exit: EXIT.network,\n message: err.message,\n hint: 'Check the network and `--api`, then retry.',\n }\n }\n if (err.status === 401) {\n return {\n code: 'not_authenticated',\n exit: EXIT.notAuthenticated,\n message: err.message,\n hint: 'Run `haven login` (or set HAVEN_EMAIL and HAVEN_PASSWORD).',\n }\n }\n if (err.status >= 400 && err.status < 500) {\n // 403 and 410 are the named cases; every other 4xx is the same shape of\n // answer — the backend understood and said no — so it gets the same code\n // rather than falling through to the generic one.\n return { code: 'refused', exit: EXIT.refused, message: err.message }\n }\n return { code: 'failed', exit: EXIT.failed, message: err.message }\n }\n return { code: 'failed', exit: EXIT.failed, message: err instanceof Error ? err.message : String(err) }\n}\n","import type { Failure } from './errors.js'\n\n/**\n * The `--json` contract (#2525).\n *\n * Under `--json`, **stdout carries exactly one JSON value and nothing else** —\n * every line of human prose goes to stderr instead. That is what lets an agent\n * pipe stdout straight into a parser without stripping progress chatter, and\n * it is why `note()` exists: the same call site prints a sentence for a human\n * and stays silent (on stdout) for a machine.\n *\n * Success keeps the payload shape each command already emitted — including the\n * bare arrays that `agents list` and friends return — so this change adds a\n * failure contract without breaking a script that already parses a success.\n * Failures are always the object `{ ok: false, error: { code, message, hint? } }`.\n */\nexport interface Output {\n readonly json: boolean\n /** The command's success payload. At most one per run, on stdout. */\n data(payload: unknown, human: () => string): void\n /** Raw text (an export file). Printed as-is; wrapped under `--json`. */\n text(content: string, meta: Record<string, unknown>): void\n /** Human prose. Stdout in prose mode; stderr under `--json`. */\n note(line: string): void\n /** The one failure object. Always stdout under `--json`, stderr otherwise. */\n failure(failure: Failure): void\n}\n\nexport function createOutput(\n json: boolean,\n out: (line: string) => void,\n err: (line: string) => void,\n): Output {\n return {\n json,\n data(payload, human) {\n out(json ? JSON.stringify(payload, null, 2) : human())\n },\n text(content, meta) {\n // A CSV/SIE body is the payload in prose mode. Under --json it becomes a\n // field of the single object, so the contract (\"one JSON value on\n // stdout\") holds for exports too and the content stays recoverable.\n out(json ? JSON.stringify({ ok: true, ...meta, content }, null, 2) : content)\n },\n note(line) {\n if (json) err(line)\n else out(line)\n },\n failure(failure) {\n const body = {\n ok: false as const,\n error: {\n code: failure.code,\n message: failure.message,\n ...(failure.hint ? { hint: failure.hint } : {}),\n },\n }\n if (json) out(JSON.stringify(body, null, 2))\n else err(failure.hint ? `${failure.message}\\n${failure.hint}` : failure.message)\n },\n }\n}\n","/**\n * The agent onboarding runbook — GENERATED, do not edit by hand.\n *\n * Canonical source: `packages/sdk/src/agent-guidance.ts` (#2523), served to\n * agents at `/for-agents.md`. This is a decoupled copy so `@haven_ai/cli`\n * keeps zero runtime dependencies: importing it from the SDK would put ethers,\n * viem and x402 on the `npx @haven_ai/cli` path for one Markdown string.\n * Same arrangement, and the same reason, as\n * `packages/frontend/src/lib/agent-skill-bundle.ts`.\n *\n * Regenerate: node packages/cli/scripts/sync-agent-guidance.mjs\n * The parity test in `agent-guidance-text.test.ts` fails if you forget.\n */\n\nexport const HAVEN_AGENT_RUNBOOK_MD = \"# Haven for agents — 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** — 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 — 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 — 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 login --api <api-url>` afterwards gets you a scoped session for steps 3-4 (that flag or `HAVEN_API_URL`, on the first command — 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) — they approve a code in the browser, you never hold their password. 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 — 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 — never assume one: a testnet deployment and production both call themselves Haven.\\n3. **HUMAN — 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 — run the connector command** in that prompt (below). It makes your signing key locally, registering only the public address.\\n5. **HUMAN — 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 — verify, then pay.**\\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` — 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 — 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 — USDC only, no ETH: Haven sponsors the gas. Before you send anything, let me get you the exact address **and network** — `haven wallets funding` prints both, and the 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 — 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) — 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 — 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 — 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 — if the outcome carries approval.url, give me that link; otherwise tell me to return to Haven and approve this agent's budget — 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 — the approval link if those steps printed one, otherwise that you need to return to Haven and approve this agent's budget — 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 — only if the connector refuses because it could not determine the agent runtime — 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 — 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 — 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` — a budget is live; you can pay.\\n- `needs_approval` — the connector finished, nobody approved yet. Ask your user again, in their Haven tab; there is no queue to wait in.\\n- `revoked` — 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 — 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>/…` URL and ask them to say when it is done. Step 5 is a link only when your run reported one in `approval.url` — 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 — 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@…` line you run. One-time token, one use. |\\n| **agent credential** | Your API key (`sk_agent_…`), 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) · [everything agent-readable](/llms.txt)\\n\"\n","/**\n * Read the expiry out of the stored session JWT (#2525).\n *\n * `whoami --json` and `login --json` report when the session dies, and the\n * only place that fact exists is the token's own `exp` claim — the backend\n * signs it with `expiresIn: '7d'` (`routes/auth.ts`) and `/auth/me` does not\n * return it. So the payload segment is base64url-decoded and read.\n *\n * This deliberately does NOT verify the signature, and must never be used to\n * decide anything but what to print: the CLI has no key to verify with, and a\n * forged `exp` would only mislead the user about a token the backend will\n * reject on its own terms. It never logs, echoes or returns the token itself.\n */\nexport function sessionExpiry(token: string): string | null {\n const segment = token.split('.')[1]\n if (!segment) return null\n try {\n const json = Buffer.from(segment.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8')\n const claims = JSON.parse(json) as { exp?: unknown }\n if (typeof claims.exp !== 'number' || !Number.isFinite(claims.exp)) return null\n return new Date(claims.exp * 1000).toISOString()\n } catch {\n // A token we cannot read is not an error worth failing a command over —\n // the expiry is informational, and every other field still resolves.\n return null\n }\n}\n","/**\n * Human token amounts → atomic units, without a dependency (#2527).\n *\n * ## Why this exists rather than `parseUnits`\n *\n * The dashboard modal converts with viem's `parseUnits` before it POSTs\n * (`useAgentConnectionSetup.ts`), and this CLI has to produce the same string\n * for the same input. It cannot call the same function: `@haven_ai/cli` ships\n * with **zero runtime dependencies** — asserted by a test, because `npx\n * @haven_ai/cli` is the path an agent uses and viem's tree is ~94 MB — so this\n * is the arithmetic done in strings over Node builtins.\n *\n * ## The two shapes, and why this direction is the dangerous one\n *\n * `allowance_amount` is ATOMIC on the way in and HUMAN-DECIMAL on the way back\n * (#2295). One name, two shapes. Nothing here sniffs which it is holding: the\n * caller says, and this function only ever converts human → atomic. A number\n * that is wrong by 10^6 is a budget that is wrong by a factor of a million.\n *\n * ## Excess precision is REFUSED, never rounded\n *\n * `parseUnits` ROUNDS the excess rather than dropping it, which is worse than\n * it sounds: measured against viem, `parseUnits('1.9999999', 6)` is `2000000n`\n * — **two whole tokens** — and `parseUnits('0.0000005', 6)` is `1n`, a budget\n * conjured out of a value below the token's precision. An earlier version of\n * this comment said it truncates to `1999999n`; that was wrong, and the truth\n * is the stronger argument for refusing (haven-reviewer, #2527).\n *\n * For a field a person typed and is about to authorise, quietly changing the\n * number is worse than declining it, so this mirrors the modal's own\n * `validateMoneyInput`, which refuses before it ever reaches `parseUnits`. The\n * rule is the same on both surfaces on purpose: a budget the dashboard would\n * not accept must not become acceptable by being typed into a terminal.\n */\n\nexport interface AmountResult {\n ok: true\n /** The normalised human string, e.g. `.5` → `0.5`. */\n human: string\n /** Atomic units as a decimal string — what the wire wants. */\n atomic: string\n}\n\nexport interface AmountRefusal {\n ok: false\n message: string\n}\n\nfunction decimalLabel(decimals: number): string {\n return decimals === 1 ? '1 decimal place' : `${decimals} decimal places`\n}\n\n/**\n * Convert a human amount to atomic units for a token with `decimals`.\n *\n * Refuses rather than guesses: anything that is not a plain non-negative\n * decimal, anything that is zero, and anything carrying more fraction digits\n * than the token can represent.\n */\nexport function parseTokenAmount(\n input: string,\n decimals: number,\n tokenSymbol?: string,\n): AmountResult | AmountRefusal {\n if (!Number.isInteger(decimals) || decimals < 0 || decimals > 36) {\n return { ok: false, message: `Unusable token decimals: ${String(decimals)}` }\n }\n\n // `.5` → `0.5`, matching the modal's `normalizeMoneyInput` so the two\n // surfaces accept the same set of strings.\n const trimmed = String(input ?? '').trim()\n const human = trimmed.startsWith('.') ? `0${trimmed}` : trimmed\n const label = tokenSymbol ? ` ${tokenSymbol}` : ''\n\n if (human === '') return { ok: false, message: 'Enter an amount greater than 0' }\n // No sign, no exponent, no separators. `1e6` and `1_000` are the shapes most\n // likely to be meant well and read wrong, so they are refused by omission.\n if (!/^\\d+(?:\\.\\d+)?$/.test(human)) {\n return { ok: false, message: `Enter a valid${label} amount — digits, with an optional decimal point` }\n }\n\n const [whole, fraction = ''] = human.split('.')\n if (fraction.length > decimals) {\n return {\n ok: false,\n message: `${tokenSymbol ?? 'This token'} supports up to ${decimalLabel(decimals)}`,\n }\n }\n\n // Right-pad the fraction to the token's precision and concatenate: the whole\n // conversion, with no float anywhere near it. BigInt then strips leading\n // zeros, so `0.5` at 6 decimals is `500000` rather than `0500000`.\n const atomic = BigInt(`${whole}${fraction.padEnd(decimals, '0')}`)\n if (atomic === 0n) return { ok: false, message: 'Enter an amount greater than 0' }\n\n return { ok: true, human, atomic: atomic.toString() }\n}\n","import { spawn } from 'node:child_process'\n\n/**\n * Running the connector as a child process, for `haven agents connect --run`\n * (#2527).\n *\n * ## The command is not ours to edit\n *\n * The backend builds `connector_command` and the setup prompt states the rule\n * an agent must follow: the command may be changed in exactly two ways, and\n * appending `--json` is one of them. So this splits the printed command and\n * appends `--json` — nothing else. It does not add `--replace`, it does not add\n * `--name`, it does not rewrite `--api`, and it never composes a command of its\n * own. `haven agents connect` has no flags for those on purpose: a wiring\n * collision is a decision for the human, and a CLI that could resolve one would\n * be making that decision on their behalf (boundary note on #2527 from #2551).\n *\n * ## Why the exit code is not the verdict\n *\n * The connector exits **1** on a refusal while still writing a complete outcome\n * object to stdout (`cli.test.ts`, the `wiring_collision` case). Treating a\n * non-zero exit as \"it did not run\" would throw away exactly the structured\n * refusal the human needs. So the outcome is parsed from stdout whatever the\n * exit code was, and the exit code only decides what to do when there is no\n * parseable outcome at all.\n *\n * ## Refusals are recognised structurally, never by name\n *\n * A refusal is \"the outcome carries an `error`\". The relay text comes from\n * `error.next_action`. Nothing here enumerates `runtime_undetermined` or\n * `wiring_collision`, so a refusal added to the connector tomorrow reaches the\n * user through this path without a CLI change — which is the whole point of\n * the connector having a typed vocabulary in the first place.\n */\n\n/** The connector's `--json` outcome. Only the fields this CLI reads. */\nexport interface ConnectorOutcome {\n schema_version?: number\n outcome?: 'complete' | 'action_required' | 'failed' | string\n next_action?: string\n approval?: { required?: boolean; expires_at?: string | null; url?: string }\n error?: {\n code?: string\n next_action?: string\n message?: string\n allowed_runtimes?: readonly string[]\n installed_clients?: readonly string[]\n suggested_runtime?: string\n superseded_agent_ids?: readonly string[]\n suggested_name?: string\n }\n [key: string]: unknown\n}\n\nexport interface ConnectorRun {\n /** The parsed outcome, when the connector produced one. */\n outcome: ConnectorOutcome | null\n exitCode: number\n /** Everything the connector wrote to stderr, already streamed to ours. */\n stderr: string\n /** stdout that was not the outcome object — kept so a failure can say why. */\n stdoutNoise: string\n}\n\nexport interface Spawner {\n (command: string, args: string[], onStderr: (chunk: string) => void): Promise<{\n stdout: string\n stderr: string\n exitCode: number\n }>\n}\n\n/**\n * Split a printed connector command into argv.\n *\n * The backend shell-quotes the setup token and the API url with single quotes\n * (`buildConnectorCommand`), so this understands single quotes and nothing\n * else. It is deliberately not a shell: no globbing, no variable expansion, no\n * `&&`. A command carrying anything this cannot represent is refused rather\n * than approximated, because the alternative is executing a rewritten version\n * of a command whose whole contract is that it is not rewritten.\n */\nexport function splitConnectorCommand(command: string): string[] {\n const argv: string[] = []\n let current = ''\n let quoted = false\n let started = false\n\n for (let i = 0; i < command.length; i += 1) {\n const ch = command[i]\n if (quoted) {\n if (ch === \"'\") quoted = false\n else current += ch\n continue\n }\n if (ch === \"'\") {\n quoted = true\n started = true\n continue\n }\n if (ch === ' ' || ch === '\\t') {\n if (started) argv.push(current)\n current = ''\n started = false\n continue\n }\n // The ONE backslash form this understands: POSIX `'\\''`, which is how the\n // backend's `shellQuote` escapes a single quote inside a quoted value\n // (`'a'\\''b'` means `a'b`). Supported because the builder can emit it, and\n // a command the builder can produce but `--run` cannot execute is a broken\n // contract rather than a safe refusal. Every OTHER backslash is still\n // refused — this is a parser for one known quoting function, not a shell.\n if (ch === '\\\\') {\n if (command[i + 1] === \"'\") {\n current += \"'\"\n started = true\n i += 1\n continue\n }\n throw new Error('Refusing to run a connector command with a backslash escape')\n }\n if (ch === '\"' || ch === '`' || ch === '$' || ch === '|' || ch === '&' || ch === ';' ||\n ch === '>' || ch === '<' || ch === '(' || ch === ')' || ch === '\\n') {\n throw new Error(`Refusing to run a connector command containing ${JSON.stringify(ch)}`)\n }\n current += ch\n started = true\n }\n if (quoted) throw new Error('Refusing to run a connector command with an unterminated quote')\n if (started) argv.push(current)\n if (argv.length === 0) throw new Error('The backend returned an empty connector command')\n return argv\n}\n\n/** The real spawner. Injected in tests so no child process runs there. */\nexport const nodeSpawner: Spawner = (command, args, onStderr) =>\n new Promise((resolve, reject) => {\n // `shell: false` is the point: argv goes to the process as-is, so nothing\n // in a token or url can be read as shell syntax.\n const child = spawn(command, args, { shell: false, stdio: ['ignore', 'pipe', 'pipe'] })\n let stdout = ''\n let stderr = ''\n child.stdout.setEncoding('utf8')\n child.stderr.setEncoding('utf8')\n child.stdout.on('data', (chunk: string) => {\n stdout += chunk\n })\n child.stderr.on('data', (chunk: string) => {\n stderr += chunk\n // Streamed rather than buffered to the end: a connector run can take\n // minutes, and its stderr is the only progress a human sees.\n onStderr(chunk)\n })\n child.on('error', reject)\n child.on('close', (code) => resolve({ stdout, stderr, exitCode: code ?? 1 }))\n })\n\n/**\n * Find the connector's outcome object in its stdout.\n *\n * The contract is one JSON object on stdout under `--json`. This assumes none\n * of the things that contract does not actually say: not that the object is\n * the whole stream (a package manager on the `npx` path writes its own lines),\n * not that it is on one line (a pretty-printed object), and not that it is\n * alone on its line (`npm notice {...}`). Each of those assumptions turned a\n * real refusal into \"no outcome\" in an earlier version. The LAST balanced\n * object wins.\n */\nexport function parseOutcome(stdout: string): { outcome: ConnectorOutcome | null; noise: string } {\n const noise: string[] = []\n let outcome: ConnectorOutcome | null = null\n\n // A scanner over the WHOLE stream, not over lines. Two assumptions died\n // here, both of them unstated until a reviewer looked: that the object is on\n // one line (a pretty-printed refusal was swallowed), and that the object is\n // ALONE on its line (`npm notice {...}` or a trailing word dropped it the\n // same way). Both regressed a real refusal to \"the connector produced no\n // outcome\", losing the exit code and the `next_action` a caller branches on.\n // Anything outside a balanced object is noise; the LAST balanced object\n // wins, so a stray object from a package manager cannot displace the\n // outcome.\n let depth = 0\n let start = -1\n let inString = false\n let escaped = false\n let plain = ''\n\n for (let i = 0; i < stdout.length; i += 1) {\n const ch = stdout[i]\n\n if (depth === 0) {\n if (ch === '{') {\n depth = 1\n start = i\n inString = false\n escaped = false\n } else {\n plain += ch\n }\n continue\n }\n\n if (inString) {\n if (escaped) escaped = false\n else if (ch === '\\\\') escaped = true\n else if (ch === '\"') inString = false\n continue\n }\n if (ch === '\"') inString = true\n else if (ch === '{') depth += 1\n else if (ch === '}') {\n depth -= 1\n if (depth === 0) {\n const candidate = stdout.slice(start, i + 1)\n try {\n // No `Array.isArray` check here, deliberately. A candidate always\n // starts at `{`, so `JSON.parse` can only return an object — the\n // anchor IS the guarantee. An earlier version carried the array\n // check as well and a mutation removing it passed the whole suite,\n // because it was unreachable: a guard nothing can violate reads like\n // protection while proving nothing, which is the shape this file has\n // already been wrong about once.\n outcome = JSON.parse(candidate) as ConnectorOutcome\n } catch {\n plain += candidate\n }\n start = -1\n }\n }\n }\n\n // An object that never closed is not an outcome; keep it readable rather\n // than dropping it, so a truncated stream still says something.\n if (depth > 0 && start >= 0) plain += stdout.slice(start)\n\n for (const line of plain.split('\\n')) {\n const text = line.trim()\n if (text) noise.push(text)\n }\n return { outcome, noise: noise.join('\\n') }\n}\n\n/** Is this outcome a refusal the human has to act on? */\nexport function isRefusal(outcome: ConnectorOutcome | null): boolean {\n return Boolean(outcome?.error)\n}\n\n/**\n * The one line that goes first (#2483's one-gate rule).\n *\n * An approval that is waiting outranks everything else on screen, and a\n * refusal outranks a completed run. The text is built from what the connector\n * said rather than from a table of codes here.\n */\nexport function relayLine(outcome: ConnectorOutcome | null): string | null {\n if (!outcome) return null\n if (outcome.error) {\n const message = outcome.error.message?.trim()\n const next = outcome.error.next_action ?? outcome.next_action\n // The message is the connector's own prose and is what a human reads; the\n // next action is what an agent branches on. Both, in that order.\n return message\n ? `${message}${next ? ` (next: ${next})` : ''}`\n : `The connector refused${next ? `: ${next}` : '.'}`\n }\n if (outcome.approval?.required) {\n return outcome.approval.url\n ? `Approve the budget to finish: ${outcome.approval.url}`\n : 'Approve the budget in your Haven tab to finish.'\n }\n return null\n}\n\n/**\n * Run the connector command, appending `--json` and nothing else.\n */\nexport async function runConnector(\n connectorCommand: string,\n spawner: Spawner,\n onStderr: (chunk: string) => void,\n): Promise<ConnectorRun> {\n const argv = splitConnectorCommand(connectorCommand)\n // Appended, never inserted: the rule is \"exactly `--json` appended\", and a\n // flag placed anywhere else is a different command line.\n const args = [...argv.slice(1), '--json']\n const { stdout, stderr, exitCode } = await spawner(argv[0], args, onStderr)\n const { outcome, noise } = parseOutcome(stdout)\n return { outcome, exitCode, stderr, stdoutNoise: noise }\n}\n","import { parseArgs, helpText, type ParsedArgs } from './args.js'\nimport { createCliApi, CliApiError, type CliApi } from './api.js'\nimport { createSessionStore, type Session, type SessionStore } from './session.js'\nimport { chainName, table, truncateAddress } from './format.js'\nimport { toCsv } from './csv.js'\nimport { EXIT, HavenCliError, UsageError, toFailure, type ExitCode } from './errors.js'\nimport { createOutput, type Output } from './output.js'\nimport { HAVEN_AGENT_RUNBOOK_MD } from './agent-guidance-text.js'\nimport { sessionExpiry } from './token.js'\nimport { parseTokenAmount } from './amount.js'\nimport {\n isRefusal,\n nodeSpawner,\n relayLine,\n runConnector,\n type ConnectorOutcome,\n type Spawner,\n} from './connect-runner.js'\n\n// Hosted Haven backend. Override with `--api <url>` or HAVEN_API_URL (e.g. a\n// local backend at http://localhost:3001, or your own domain once self-hosted).\nexport const DEFAULT_API = 'https://havenbackend-production-8a00.up.railway.app'\n// Self-reported CLI version. Owned by scripts/release-bump.mjs, which rewrites\n// the string literal below on every release — keep it a bare quoted literal.\nexport const CLI_VERSION = '0.0.0-dev.202609061037.7cf43bb'\n\nexport interface RunDeps {\n sessionStore?: SessionStore\n /** Build an API client; injected so tests can stub the backend. */\n makeApi?: (baseUrl: string, token?: string) => CliApi\n promptPassword?: () => Promise<string>\n /** #2526: injected so the device poll loop is testable without real time. */\n sleep?: (ms: number) => Promise<void>\n /** #2527: injected so `--run` is testable without spawning a real process. */\n spawner?: Spawner\n out?: (line: string) => void\n err?: (line: string) => void\n env?: NodeJS.ProcessEnv\n}\n\ninterface ResolvedDeps {\n sessionStore: SessionStore\n makeApi: (baseUrl: string, token?: string) => CliApi\n promptPassword: () => Promise<string>\n sleep: (ms: number) => Promise<void>\n spawner: Spawner\n out: (line: string) => void\n err: (line: string) => void\n env: NodeJS.ProcessEnv\n /** Set once `--json` is known; every command writes through it. */\n o: Output\n}\n\n/**\n * Every command this CLI dispatches, as data (#2525).\n *\n * The table-driven contract test in `json-contract.test.ts` iterates THIS list\n * and asserts each command's `--json` refusal is one JSON object on stdout, so\n * a command added to `dispatch` without adding it here is not covered. Its\n * ceiling, stated plainly: the test proves the listed commands honour the\n * contract, not that the list is complete. A drift test below pins the list\n * against `dispatch`'s own switch to close that gap by execution.\n */\nexport const COMMANDS = [\n 'login', 'logout', 'whoami', 'guide',\n 'wallets list', 'wallets balances', 'wallets rename', 'wallets funding',\n 'agents list', 'agents show', 'agents pause', 'agents resume', 'agents revoke',\n 'agents rotate-key', 'agents rename', 'agents connect',\n 'budget show',\n 'activity list', 'activity export',\n 'catalog list',\n 'contacts list', 'contacts add', 'contacts remove',\n] as const\n\n// ── Backend response shapes (subset the CLI needs) ──────────────────\ninterface Safe { id: string; safe_address: string; chain_id: number; name: string; is_default: boolean }\ninterface Allowance { token_symbol: string; allowance_amount: string; reset_period_min: number }\ninterface Agent { id: string; name: string; status: string; allowances?: Allowance[] }\ninterface Balance { symbol: string; formatted: string; balance: string }\ninterface Txn {\n hash: string; direction: 'in' | 'out'; valueFormatted: string; asset: string\n source?: string; timestamp: number; safeName?: string\n from?: string; to?: string; isError?: boolean\n tokenSymbol?: string; tokenAddress?: string; chainId?: number; safeAddress?: string\n agentName?: string; paymentFlowStatus?: string | null; activityType?: string\n}\ninterface CatalogEntry { name: string; category: string; rail: string; price_display?: string | null; status: string }\ninterface Contact { id: string; name: string; address: string }\ninterface BalanceToken { symbol: string; address: string | null; decimals: number }\ninterface CreateSetupResponse {\n setup_id: string\n status: string\n approval_url: string\n expires_at: string\n connector_command: string\n connector_package: string\n setup_prompt: string\n}\ninterface SetupStatus {\n setup_id: string\n status: string\n agent_id: string | null\n approval_url: string\n expires_at: string\n}\n\n/** `GET /user/safes/:safeId/funding` — the wire shape the route documents. */\ninterface FundingResponse {\n account_address: string\n chain: { id: number; name: string; explorer_url: string }\n tokens: {\n symbol: string\n address: string\n decimals: number\n balance_human: string\n minimum_useful_human: string | null\n }[]\n native: { symbol: string; balance_human: string; needed: boolean }\n funded: boolean\n faucet_url?: string\n}\n\n/** Entry point. Returns a process exit code; never throws for expected errors. */\nexport async function run(argv: string[], deps: RunDeps = {}): Promise<number> {\n const out = deps.out ?? ((l: string) => process.stdout.write(`${l}\\n`))\n const err = deps.err ?? ((l: string) => process.stderr.write(`${l}\\n`))\n\n // `--json` has to be known before anything can be emitted, including a parse\n // failure's own message. Scanning argv for the flag is deliberate: parseArgs\n // throws on a bad line, and a refusal that ignored --json because the parse\n // failed would break the contract exactly when a caller most needs it.\n const json = argv.includes('--json')\n const o = createOutput(json, out, err)\n\n const d: ResolvedDeps = {\n sessionStore: deps.sessionStore ?? createSessionStore(),\n makeApi: deps.makeApi ?? ((baseUrl, token) => createCliApi({ baseUrl, token })),\n promptPassword: deps.promptPassword ?? (() => Promise.reject(new Error('No password input available'))),\n sleep: deps.sleep ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))),\n spawner: deps.spawner ?? nodeSpawner,\n out,\n err,\n env: deps.env ?? process.env,\n o,\n }\n\n let args: ParsedArgs\n try {\n args = parseArgs(argv)\n } catch (e) {\n return fail(d, new UsageError(e instanceof Error ? e.message : String(e), 'Run `haven --help`.'))\n }\n\n if (args.flags.version) {\n o.data({ version: CLI_VERSION }, () => CLI_VERSION)\n return EXIT.ok\n }\n if (args.flags.help || !args.command) {\n o.data({ help: helpText() }, () => helpText())\n return EXIT.ok\n }\n\n try {\n return await dispatch(args, d)\n } catch (e) {\n return fail(d, e)\n }\n}\n\n/** The single exit: one failure object, one exit code, read off one decision. */\nfunction fail(d: ResolvedDeps, err: unknown): ExitCode {\n const failure = toFailure(err)\n d.o.failure(failure)\n return failure.exit\n}\n\nasync function dispatch(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const key = args.sub ? `${args.command} ${args.sub}` : args.command\n switch (key) {\n case 'guide': return cmdGuide(args, d)\n case 'login': return cmdLogin(args, d)\n case 'logout': return cmdLogout(args, d)\n case 'whoami': return cmdWhoami(args, d)\n case 'wallets list': return cmdWalletsList(args, d)\n case 'wallets balances': return cmdWalletsBalances(args, d)\n case 'wallets funding': return cmdWalletsFunding(args, d)\n case 'agents list': return cmdAgentsList(args, d)\n case 'agents show': return cmdAgentsShow(args, d)\n case 'agents connect': return cmdAgentsConnect(args, d)\n case 'agents pause': return cmdAgentLifecycle(args, d, 'pause')\n case 'agents resume': return cmdAgentLifecycle(args, d, 'resume')\n case 'agents revoke': return cmdAgentRevoke(args, d)\n case 'agents rotate-key': return cmdAgentRotateKey(args, d)\n case 'agents rename': return cmdAgentRename(args, d)\n case 'budget show': return cmdBudgetShow(args, d)\n case 'wallets rename': return cmdWalletRename(args, d)\n case 'activity list': return cmdActivityList(args, d)\n case 'activity export': return cmdActivityExport(args, d)\n case 'catalog list': return cmdCatalogList(args, d)\n case 'contacts list': return cmdContactsList(args, d)\n case 'contacts add': return cmdContactsAdd(args, d)\n case 'contacts remove': return cmdContactsRemove(args, d)\n default:\n throw new UsageError(`Unknown command: ${key}.`, 'Run `haven --help` for the command list.')\n }\n}\n\nfunction baseUrlFor(args: ParsedArgs, d: ResolvedDeps, session: Session | null): string {\n return args.flags.api ?? session?.apiBaseUrl ?? d.env.HAVEN_API_URL ?? DEFAULT_API\n}\n\nasync function authed(args: ParsedArgs, d: ResolvedDeps): Promise<{ session: Session; api: CliApi }> {\n const session = await d.sessionStore.load()\n // Status 401 so a missing local session and a rejected one produce the same\n // code and the same advice — from the caller's side they are one situation.\n if (!session) throw new CliApiError('Not authenticated.', 401)\n return { session, api: d.makeApi(baseUrlFor(args, d, session), session.token) }\n}\n\nfunction emit(d: ResolvedDeps, _json: boolean, data: unknown, human: () => string): void {\n d.o.data(data, human)\n}\n\n// ── Guide ───────────────────────────────────────────────────────────\n\n/**\n * Print the agent onboarding runbook — the same text served at\n * `/for-agents.md` (#2523). Offline by construction: the string is compiled in,\n * so an agent with no session and no network still gets the instructions that\n * tell it what to do about exactly that.\n */\nasync function cmdGuide(_args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n d.o.data({ ok: true, format: 'markdown', content: HAVEN_AGENT_RUNBOOK_MD }, () => HAVEN_AGENT_RUNBOOK_MD)\n return EXIT.ok\n}\n\n// ── Auth ────────────────────────────────────────────────────────────\n\ninterface DeviceStart {\n device_code: string\n user_code: string\n verification_url: string\n expires_in: number\n interval: number\n}\n\n/**\n * Browser-approved login (#2526), the DEFAULT for `haven login`.\n *\n * The reason this is the default and the password path is not: an agent drives\n * this CLI, and an agent must never hold its user's password. The cold-test\n * agent correctly refused to type one. This asks the human instead — the agent\n * pastes a link, and every signature stays with the person.\n *\n * Under `--json` the first object is emitted BEFORE polling starts, so an agent\n * can hand its user the link immediately rather than after the flow completes.\n */\nasync function deviceLogin(args: ParsedArgs, d: ResolvedDeps, baseUrl: string): Promise<number> {\n const api = d.makeApi(baseUrl)\n const label = d.env.HAVEN_CLIENT_LABEL ?? `Haven CLI on ${d.env.HOSTNAME ?? 'this machine'}`\n const start = await api.post<DeviceStart>('/auth/device/start', { client_label: label })\n\n const deadline = Date.now() + start.expires_in * 1000\n // Emitted first, not last: the whole point is that the agent can pass the\n // link on while the poll runs.\n d.o.data(\n {\n ok: true,\n verification_url: start.verification_url,\n user_code: start.user_code,\n expires_at: new Date(deadline).toISOString(),\n },\n () =>\n `Open ${start.verification_url}\\nand approve the code ${start.user_code}.\\n` +\n `It expires in ${Math.round(start.expires_in / 60)} minutes.`,\n )\n\n if (args.flags.noWait) return EXIT.ok\n\n // The server names the interval; the client does not invent one. `slow_down`\n // widens it, which is the only backoff signal this flow has.\n let interval = start.interval * 1000\n for (;;) {\n if (Date.now() >= deadline) {\n throw new HavenCliError('The code expired before it was approved.', EXIT.notAuthenticated)\n }\n await d.sleep(interval)\n let res: { token: string; user: Session['user'] } | null = null\n try {\n res = await api.post<{ token: string; user: Session['user'] }>('/auth/device/token', {\n device_code: start.device_code,\n })\n } catch (err) {\n const code = deviceErrorCode(err)\n if (code === 'authorization_pending') continue\n if (code === 'slow_down') {\n interval += 5000\n continue\n }\n if (code === 'access_denied') {\n throw new HavenCliError('The request was denied.', EXIT.refused)\n }\n if (code === 'expired_token') {\n throw new HavenCliError('The code expired before it was approved.', EXIT.notAuthenticated)\n }\n throw err\n }\n await d.sessionStore.save({ token: res.token, apiBaseUrl: baseUrl, user: res.user })\n emit(\n d,\n args.flags.json,\n { ok: true, email: res.user.email, expires_at: sessionExpiry(res.token), user: res.user, apiBaseUrl: baseUrl },\n () => `Signed in as ${res!.user.email}.`,\n )\n return EXIT.ok\n }\n}\n\n/** The RFC 8628 error slug in a 400 body, or null. */\nfunction deviceErrorCode(err: unknown): string | null {\n const body = (err as { body?: { error?: unknown } } | undefined)?.body\n return typeof body?.error === 'string' ? body.error : null\n}\n\nasync function cmdLogin(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const email = args.flags.email ?? d.env.HAVEN_EMAIL\n // #2526: the browser flow is the DEFAULT. `--email` (or HAVEN_EMAIL) keeps\n // the password path for a human who wants it — it is not removed, it is no\n // longer what an agent gets by asking for `login`.\n if (!email) {\n return deviceLogin(args, d, baseUrlFor(args, d, null))\n }\n const password = d.env.HAVEN_PASSWORD ?? (await d.promptPassword())\n if (!password) {\n throw new UsageError('A password is required.', 'Set HAVEN_PASSWORD for a non-interactive run.')\n }\n const baseUrl = baseUrlFor(args, d, null)\n const api = d.makeApi(baseUrl)\n const res = await api.post<{ token: string; user: Session['user'] }>('/auth/login', { email, password })\n await d.sessionStore.save({ token: res.token, apiBaseUrl: baseUrl, user: res.user })\n // The issue specifies { ok, email, expires_at }; `user` and `apiBaseUrl` stay\n // because they were already the shape and dropping them would break a script\n // that reads them for no gain. Neither the password nor the token is echoed —\n // `expires_at` is derived from the token, never the token itself.\n emit(\n d,\n args.flags.json,\n { ok: true, email: res.user.email, expires_at: sessionExpiry(res.token), user: res.user, apiBaseUrl: baseUrl },\n () => `Signed in as ${res.user.email}.`,\n )\n return EXIT.ok\n}\n\nasync function cmdLogout(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n await d.sessionStore.clear()\n emit(d, args.flags.json, { ok: true, signed_out: true }, () => 'Signed out.')\n return EXIT.ok\n}\n\nasync function cmdWhoami(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { session, api } = await authed(args, d)\n const user = await api.get<Session['user']>('/auth/me')\n // The four fields #2525 asks for — id, email, session expiry, api url — laid\n // over the profile the route already returned, so nothing a caller reads\n // today disappears. `expires_at` is null when the token carries no readable\n // `exp`, which is a fact worth reporting rather than an error.\n emit(\n d,\n args.flags.json,\n { ...user, id: user.id, email: user.email, expires_at: sessionExpiry(session.token), api_url: session.apiBaseUrl },\n () => `${user.email}${user.name ? ` (${user.name})` : ''}`,\n )\n return EXIT.ok\n}\n\n// ── Wallets ─────────────────────────────────────────────────────────\n\nasync function cmdWalletsList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n emit(d, args.flags.json, safes, () =>\n safes.length === 0\n ? 'No Haven wallets yet.'\n : table(\n ['NAME', 'NETWORK', 'ADDRESS', 'DEFAULT'],\n safes.map((s) => [s.name, chainName(s.chain_id), truncateAddress(s.safe_address), s.is_default ? '✓' : '']),\n ),\n )\n return EXIT.ok\n}\n\nasync function cmdWalletsBalances(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n const safe = pickSafe(safes, args.flags.safe)\n if (!safe) {\n if (args.flags.safe) throw new UsageError(`No wallet matches \"${args.flags.safe}\".`)\n throw new CliApiError('No Haven wallet found.', 404)\n }\n const { balances } = await api.get<{ balances: Balance[] }>(\n `/balances/${safe.safe_address}?chain_id=${safe.chain_id}`,\n )\n emit(d, args.flags.json, { safe: safe.name, chainId: safe.chain_id, balances }, () =>\n [\n `${safe.name} · ${chainName(safe.chain_id)} · ${truncateAddress(safe.safe_address)}`,\n balances.length === 0\n ? ' (no balances)'\n : table(['TOKEN', 'BALANCE'], balances.map((b) => [b.symbol, b.formatted])),\n ].join('\\n'),\n )\n return EXIT.ok\n}\n\nfunction pickSafe(safes: Safe[], ref?: string): Safe | undefined {\n if (!ref) return safes.find((s) => s.is_default) ?? safes[0]\n const lower = ref.toLowerCase()\n return safes.find((s) => s.id === ref || s.safe_address.toLowerCase() === lower)\n}\n\n// ── Wallet funding (#2534) ──────────────────────────────────────────\n\n/**\n * The paste-ready funding instruction, read from the backend.\n *\n * The endpoint is the source; this command renders it. Every number in the\n * prose — the minimum to send, the address, the explorer link — comes out of\n * the response, so the CLI, the dashboard's funding card and the backend's\n * own docs cannot drift apart: `@haven_ai/core` owns the constants, the\n * route composes them, and nothing here repeats one. Prose mode prints the\n * sentence an agent hands to its human; `--json` prints the response object\n * itself, so a machine that wants to relay fields rather than a sentence has\n * the same facts in the same place.\n *\n * `--wait` polls until `funded` flips — how a turn actually waits out a human\n * moving money — with elapsed time visible so nobody stares at a silent\n * terminal. It exits 0 once funded and 1 on timeout (elapsed time in the\n * message); it never sends anything, never touches a faucet — this is\n * read-only facts for the human to act on, whatever the flag.\n */\nasync function cmdWalletsFunding(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n const safe = pickSafe(safes, args.flags.safe)\n if (!safe) {\n if (args.flags.safe) throw new UsageError(`No wallet matches \"${args.flags.safe}\".`)\n throw new CliApiError('No Haven wallet found.', 404)\n }\n // The endpoint is keyed by safe ID and resolves ownership itself — the\n // address/chain in the response are the route's answer, not ours to compose.\n const funding = await api.get<FundingResponse>(`/user/safes/${safe.id}/funding`)\n\n if (!args.flags.wait) {\n emitFunding(d, funding)\n return EXIT.ok\n }\n\n // ── `--wait`: poll until the human's transfer lands ────────────────\n const started = Date.now()\n // The poll interval, injectable so tests can run the loop without real time.\n const pollMs = Number(d.env.HAVEN_FUNDING_POLL_MS ?? '5000')\n // A default cap, not a guess about the user's patience: two hours covers a\n // bank-transfer detour, and `HAVEN_FUNDING_WAIT_MS` shortens it for tests.\n const waitMs = Number(d.env.HAVEN_FUNDING_WAIT_MS ?? String(2 * 60 * 60 * 1000))\n if (!Number.isFinite(pollMs) || pollMs <= 0 || !Number.isFinite(waitMs) || waitMs <= 0) {\n throw new UsageError('HAVEN_FUNDING_POLL_MS / HAVEN_FUNDING_WAIT_MS must be positive numbers of milliseconds')\n }\n let current = funding\n for (;;) {\n // The cap is checked BEFORE each poll, so a zero-length wait exits without\n // ever calling the endpoint twice.\n const spent = Date.now() - started\n if (spent >= waitMs) {\n throw new HavenCliError(\n `Still not funded after ${elapsedLabel(spent)} — the transfer may not have landed yet. Check the explorer link, then re-run.`,\n EXIT.failed,\n )\n }\n await d.sleep(pollMs)\n current = await api.get<FundingResponse>(`/user/safes/${safe.id}/funding`)\n if (current.funded) break\n d.o.note(`Still waiting after ${elapsedLabel(Date.now() - started)} — funded: no.`)\n }\n d.o.note(`Account shows funded after ${elapsedLabel(Date.now() - started)}.`)\n emitFunding(d, current)\n return EXIT.ok\n}\n\n/** One renderer, both modes: prose carries the paste-ready sentence. */\nfunction emitFunding(d: ResolvedDeps, funding: FundingResponse): void {\n emit(d, d.o.json, funding, () => {\n const token = funding.tokens.find((t) => t.minimum_useful_human !== null)\n const asset = token\n ? `at least ${token.minimum_useful_human} ${token.symbol}`\n : funding.native.needed\n ? funding.native.symbol\n : 'USDC'\n const gas = funding.native.needed\n ? ` plus ${funding.native.symbol} for gas`\n : ' — no gas token needed; Haven sponsors it'\n const faucet = funding.faucet_url !== undefined ? ` faucet: ${funding.faucet_url},` : ''\n return [\n `Send ${asset} on ${funding.chain.name} to ${funding.account_address}${gas}.`,\n `Explorer: ${funding.chain.explorer_url}.${faucet ? faucet.slice(0, -1) : ''}`,\n funding.funded ? 'The account already counts as funded.' : 'Nothing has arrived yet.',\n ].join('\\n')\n })\n}\n\n/** `83s` → `1m23s` → `1h02m` — the poll line and the timeout message share it. */\nfunction elapsedLabel(ms: number): string {\n const total = Math.floor(ms / 1000)\n const h = Math.floor(total / 3600)\n const m = Math.floor((total % 3600) / 60)\n const s = total % 60\n if (h > 0) return `${h}h${String(m).padStart(2, '0')}m`\n if (m > 0) return `${m}m${String(s).padStart(2, '0')}s`\n return `${s}s`\n}\n\n// ── Agents & budget ─────────────────────────────────────────────────\n\nasync function cmdAgentsList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { agents } = await api.get<{ agents: Agent[] }>('/agents')\n emit(d, args.flags.json, agents, () =>\n agents.length === 0\n ? 'No agents yet.'\n : table(\n ['ID', 'NAME', 'STATUS', 'BUDGETS'],\n agents.map((a) => [a.id, a.name, a.status, budgetSummary(a.allowances)]),\n ),\n )\n return EXIT.ok\n}\n\nasync function cmdAgentsShow(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven agents show <id>')\n const { api } = await authed(args, d)\n const agent = await api.get<Agent>(`/agents/${id}`)\n emit(d, args.flags.json, agent, () =>\n [\n `${agent.name} [${agent.status}]`,\n `id: ${agent.id}`,\n `budget: ${budgetSummary(agent.allowances)}`,\n ].join('\\n'),\n )\n return EXIT.ok\n}\n\nasync function cmdBudgetShow(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven budget show <agentId>')\n const { api } = await authed(args, d)\n const agent = await api.get<Agent>(`/agents/${id}`)\n const allowances = agent.allowances ?? []\n emit(d, args.flags.json, allowances, () =>\n allowances.length === 0\n ? `${agent.name} has no configured budget.`\n : table(\n ['TOKEN', 'AMOUNT', 'RESETS'],\n allowances.map((a) => [a.token_symbol, a.allowance_amount, resetLabel(a.reset_period_min)]),\n ),\n )\n return EXIT.ok\n}\n\nfunction budgetSummary(allowances?: Allowance[]): string {\n if (!allowances || allowances.length === 0) return '—'\n return allowances.map((a) => `${a.allowance_amount} ${a.token_symbol}`).join(', ')\n}\n\nfunction resetLabel(mins: number): string {\n if (mins === 0) return 'one-time'\n if (mins === 1440) return 'daily'\n if (mins === 10080) return 'weekly'\n if (mins === 43200) return 'monthly'\n return `every ${mins}m`\n}\n\nasync function cmdAgentLifecycle(args: ParsedArgs, d: ResolvedDeps, action: 'pause' | 'resume'): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError(`Usage: haven agents ${action} <id>`)\n const { api } = await authed(args, d)\n await api.post(`/agents/${id}/${action}`)\n const status = action === 'pause' ? 'paused' : 'resumed'\n emit(d, args.flags.json, { ok: true, agent_id: id, status }, () => `Agent ${id} ${status}.`)\n return EXIT.ok\n}\n\nasync function cmdAgentRevoke(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven agents revoke <id> --yes')\n // Revoke is terminal (status can't go back to active). Require explicit --yes\n // so it can't happen by accident in a script.\n if (!args.flags.yes) {\n throw new UsageError(\n `This permanently revokes agent ${id}.`,\n 'Re-run with --yes to confirm. Revoke is terminal — the agent cannot go back to active.',\n )\n }\n const { api } = await authed(args, d)\n await api.post(`/agents/${id}/revoke`)\n emit(\n d,\n args.flags.json,\n { ok: true, agent_id: id, status: 'revoked' },\n () => `Agent ${id} revoked. To also remove its on-chain allowance, use the dashboard.`,\n )\n return EXIT.ok\n}\n\nasync function cmdAgentRotateKey(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven agents rotate-key <id>')\n const { api } = await authed(args, d)\n const res = await api.post<{ api_key: string; api_key_prefix: string }>(`/agents/${id}/rotate-key`)\n // The key is the payload, so it belongs on stdout in both modes. The\n // SENTENCE about it is prose and moves to stderr under --json, which is what\n // keeps stdout a single parseable object with a secret in exactly one field.\n d.o.note('New API key (shown once — store it now; the old key stops working):')\n emit(d, args.flags.json, res, () => res.api_key)\n return EXIT.ok\n}\n\nasync function cmdAgentRename(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const [id, ...nameParts] = args.positionals\n const name = nameParts.join(' ').trim()\n if (!id || !name) throw new UsageError('Usage: haven agents rename <id> <name>')\n const { api } = await authed(args, d)\n await api.put(`/agents/${id}`, { name })\n emit(d, args.flags.json, { ok: true, agent_id: id, name }, () => `Agent ${id} renamed to \"${name}\".`)\n return EXIT.ok\n}\n\nasync function cmdWalletRename(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const [id, ...nameParts] = args.positionals\n const name = nameParts.join(' ').trim()\n if (!id || !name) throw new UsageError('Usage: haven wallets rename <id> <name>')\n const { api } = await authed(args, d)\n await api.put(`/user/safes/${id}`, { name })\n emit(d, args.flags.json, { ok: true, safe_id: id, name }, () => `Wallet ${id} renamed to \"${name}\".`)\n return EXIT.ok\n}\n\n// ── Activity ────────────────────────────────────────────────────────\n\n/**\n * Resolve `--safe` (id or address) to a Safe id for the `/transactions` filter,\n * mirroring `wallets balances`. Throws if `--safe` was given but matches no\n * wallet, so a typo'd filter fails loudly instead of silently returning all rows.\n */\nasync function resolveSafeId(args: ParsedArgs, api: CliApi): Promise<string | undefined> {\n if (!args.flags.safe) return undefined\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n const safe = pickSafe(safes, args.flags.safe)\n if (!safe) throw new UsageError(`No wallet matches \"${args.flags.safe}\".`)\n return safe.id\n}\n\nasync function cmdActivityList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const safeId = await resolveSafeId(args, api)\n const params = new URLSearchParams({\n offset: String(args.flags.offset ?? 0),\n limit: String(args.flags.limit ?? 25),\n })\n if (safeId) params.set('safeId', safeId)\n if (args.flags.agent) params.set('agentId', args.flags.agent)\n const { transactions } = await api.get<{ transactions: Txn[] }>(`/transactions?${params.toString()}`)\n const visible = args.flags.direction\n ? transactions.filter((t) => t.direction === args.flags.direction)\n : transactions\n emit(d, args.flags.json, visible, () =>\n visible.length === 0\n ? 'No activity.'\n : table(\n ['DATE', 'DIR', 'AMOUNT', 'TYPE', 'ACCOUNT'],\n visible.map((t) => [\n new Date(t.timestamp * 1000).toISOString().slice(0, 10),\n t.direction === 'in' ? 'in' : 'out',\n `${t.direction === 'in' ? '+' : '-'}${t.valueFormatted} ${t.asset}`,\n t.source ?? 'transfer',\n t.safeName ?? '',\n ]),\n ),\n )\n return EXIT.ok\n}\n\nasync function cmdActivityExport(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n if (args.flags.format === 'sie') return exportSie(args, d)\n const { api } = await authed(args, d)\n const safeId = await resolveSafeId(args, api)\n const params = new URLSearchParams({\n offset: String(args.flags.offset ?? 0),\n limit: String(args.flags.limit ?? 1000),\n })\n if (safeId) params.set('safeId', safeId)\n if (args.flags.agent) params.set('agentId', args.flags.agent)\n const { transactions } = await api.get<{ transactions: Txn[] }>(`/transactions?${params.toString()}`)\n const visible = args.flags.direction\n ? transactions.filter((t) => t.direction === args.flags.direction)\n : transactions\n\n // Same columns as the dashboard export (#411), minus counterparty_name\n // (no contacts join in the CLI yet).\n const headers = [\n 'date', 'type', 'status', 'direction', 'amount', 'token_symbol', 'token_address',\n 'counterparty_address', 'safe_address', 'agent_name', 'tx_hash', 'chain_id',\n ]\n const rows = visible.map((t) => [\n new Date(t.timestamp * 1000).toISOString(),\n exportType(t),\n exportStatus(t),\n t.direction,\n t.valueFormatted,\n t.tokenSymbol ?? t.asset ?? '',\n t.tokenAddress ?? '',\n (t.direction === 'in' ? t.from : t.to) ?? '',\n t.safeAddress ?? '',\n t.agentName ?? '',\n t.hash,\n t.chainId != null ? String(t.chainId) : '',\n ])\n d.o.text(toCsv(headers, rows), { format: 'csv', rows: rows.length })\n return EXIT.ok\n}\n\nfunction exportType(t: Txn): string {\n if (t.activityType === 'delegate_sweep') return 'allowance funding'\n if (t.source === 'x402') return 'x402'\n if (t.source === 'mpp_demo') return 'mpp'\n return t.direction === 'in' ? 'receive' : 'send'\n}\n\nfunction exportStatus(t: Txn): string {\n if (t.isError) return 'failed'\n if (t.paymentFlowStatus === 'confirming_merchant') return 'pending'\n return 'executed'\n}\n\n/** SIE 4I export: the backend builds the verifikat file (book-time SEK + BAS). */\nasync function exportSie(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const params = new URLSearchParams({ format: 'sie' })\n if (args.flags.from) params.set('from', args.flags.from)\n if (args.flags.to) params.set('to', args.flags.to)\n if (args.flags.company) params.set('company', args.flags.company)\n const content = await api.getText(`/accounting/export?${params.toString()}`)\n d.o.text(content, { format: 'sie' })\n return EXIT.ok\n}\n\n// ── Catalog ─────────────────────────────────────────────────────────\n\nasync function cmdCatalogList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { entries } = await api.get<{ entries: CatalogEntry[] }>('/catalog')\n emit(d, args.flags.json, entries, () =>\n entries.length === 0\n ? 'Catalog is empty.'\n : table(\n ['NAME', 'CATEGORY', 'RAIL', 'PRICE', 'STATUS'],\n entries.map((e) => [e.name, e.category, e.rail, e.price_display ?? '—', e.status]),\n ),\n )\n return EXIT.ok\n}\n\n\n// ── Connect (#2527) ─────────────────────────────────────────────────\n\n/**\n * Resolve the wallet this setup belongs to, and the token's decimals.\n *\n * The decimals are READ from the backend rather than kept in a table here.\n * `GET /balances/:safeAddress` lists every token the chain is configured for —\n * zero balance included — with its address and decimals, which is the same\n * registry the dashboard modal reads. A local table would be a second source\n * of truth for a number that decides a budget's magnitude, and it would drift\n * silently the first time a chain gained a token.\n */\nasync function resolveWalletAndToken(\n args: ParsedArgs,\n api: CliApi,\n symbol: string,\n): Promise<{ safeId: string; token: BalanceToken }> {\n const { safes } = await api.get<{ safes: Safe[] }>('/user/safes')\n if (safes.length === 0) {\n throw new HavenCliError('No wallet on this account yet — finish onboarding first.', EXIT.refused)\n }\n const safe = args.flags.safe\n ? safes.find((s) => s.id === args.flags.safe || s.safe_address === args.flags.safe)\n : (safes.find((s) => s.is_default) ?? safes[0])\n if (!safe) throw new UsageError(`No wallet matches --safe ${args.flags.safe}`)\n\n // `chain_id` is REQUIRED here, not decorative. The same account address is\n // provisioned on every supported chain, so a wallet address usually owns more\n // than one ownership row — and `GET /balances/:address` answers\n // `400 chain_id required` rather than guessing when it finds more than one\n // (`routes/balances.ts`). `wallets balances` has always passed it; this call\n // omitted it and would have failed for exactly the ordinary multi-chain\n // account (haven-reviewer, #2527).\n const { balances } = await api.get<{ balances: BalanceToken[] }>(\n `/balances/${safe.safe_address}?chain_id=${safe.chain_id}`,\n )\n const wanted = symbol.trim().toUpperCase()\n const token = balances.find((b) => b.symbol.toUpperCase() === wanted)\n if (!token) {\n const known = balances.map((b) => b.symbol).join(', ')\n throw new UsageError(`Unknown token ${symbol} on this wallet's chain. Available: ${known || 'none'}`)\n }\n return { safeId: safe.id, token }\n}\n\n/** Poll a setup until it leaves the states that are still in flight. */\nconst SETTLED = new Set(['active', 'expired', 'cancelled', 'failed'])\n\nasync function pollSetup(\n api: CliApi,\n setupId: string,\n d: ResolvedDeps,\n wait: boolean,\n): Promise<SetupStatus> {\n let status = await api.get<SetupStatus>(`/agent-connection-setups/${setupId}`)\n if (!wait) return status\n // Bounded by the setup's own expiry rather than a local guess, so the loop\n // cannot outlive the thing it is watching.\n const deadline = new Date(status.expires_at).getTime()\n while (!SETTLED.has(status.status) && Date.now() < deadline) {\n await d.sleep(5000)\n status = await api.get<SetupStatus>(`/agent-connection-setups/${setupId}`)\n }\n return status\n}\n\n/**\n * `haven agents connect` — the connect flow without the dashboard modal.\n *\n * Three shapes: create a setup, `--status <id>` to read one, and `--run` to\n * additionally execute the connector command the backend printed.\n *\n * The command is PRINTED, never composed. `connector_command` comes back from\n * `POST /agent-connection-setups` and is emitted verbatim, which is what makes\n * it byte-identical to the dashboard's for the same setup — they are the same\n * string from the same builder, not two constructions that have to be kept in\n * agreement.\n */\nasync function cmdAgentsConnect(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n\n if (args.flags.status) {\n const status = await pollSetup(api, args.flags.status, d, args.flags.wait)\n emit(d, args.flags.json, status, () =>\n [\n `setup ${status.setup_id}: ${status.status}`,\n status.agent_id ? `agent: ${status.agent_id}` : null,\n SETTLED.has(status.status) ? null : `approve: ${status.approval_url}`,\n ]\n .filter(Boolean)\n .join('\\n'),\n )\n return EXIT.ok\n }\n\n const name = args.flags.name?.trim()\n if (!name) throw new UsageError('Usage: haven agents connect --name <name> --budget <amount> --token USDC --period <minutes>')\n if (!args.flags.budget || !args.flags.token || args.flags.period === undefined) {\n throw new UsageError('--budget, --token and --period are required (period is whole minutes; 0 means one-time)')\n }\n\n const { safeId, token } = await resolveWalletAndToken(args, api, args.flags.token)\n const amount = parseTokenAmount(args.flags.budget, token.decimals, token.symbol)\n if (!amount.ok) throw new UsageError(amount.message)\n\n const setup = await api.post<CreateSetupResponse>('/agent-connection-setups', {\n name,\n safe_id: safeId,\n allowances: [\n {\n token_address: token.address ?? '0x0000000000000000000000000000000000000000',\n token_symbol: token.symbol,\n // ATOMIC on the way in, human on the way back (#2295). Converted here\n // exactly once, from the decimals the backend just told us.\n allowance_amount: amount.atomic,\n reset_period_min: args.flags.period,\n },\n ],\n // How this setup was made, for connect attribution (#2302). The route\n // already accepts any slug, so nothing backend-side had to change.\n source: 'cli',\n // #2522: the hand-off marker, set only when an agent is driving this CLI\n // and says so. Never inferred — a guess here mislabels a human's own run.\n ...(d.env.HAVEN_AGENT_DRIVEN === '1' ? { via: 'agent' } : {}),\n })\n\n if (!args.flags.run) {\n emit(d, args.flags.json, setup, () =>\n [\n 'Run this where the agent runs:',\n '',\n setup.connector_command,\n '',\n `Then approve the budget: ${setup.approval_url}`,\n `Setup ${setup.setup_id} expires ${setup.expires_at}.`,\n ].join('\\n'),\n )\n return EXIT.ok\n }\n\n // `--run`: execute the printed command with `--json` appended and nothing\n // else changed. The connector's stderr is streamed as it arrives — a run can\n // take minutes and that is the only progress anyone sees.\n const run = await runConnector(setup.connector_command, d.spawner, (chunk) => d.err(chunk.trimEnd()))\n const relay = relayLine(run.outcome)\n const merged = {\n setup_id: setup.setup_id,\n approval_url: setup.approval_url,\n connector_command: setup.connector_command,\n connector_exit_code: run.exitCode,\n outcome: run.outcome,\n relay,\n }\n\n if (isRefusal(run.outcome)) {\n // Exit 4 with the refusal carried whole. Recognised by the presence of\n // `error`, never by matching a code — a refusal the connector adds later\n // reaches the user through this same path with no CLI change.\n emitConnectResult(d, args.flags.json, merged, relay)\n return EXIT.refused\n }\n if (!run.outcome) {\n throw new HavenCliError(\n `The connector produced no outcome (exit ${run.exitCode}).${run.stdoutNoise ? ` Output: ${run.stdoutNoise}` : ''}`,\n run.exitCode === 0 ? EXIT.failed : EXIT.failed,\n )\n }\n emitConnectResult(d, args.flags.json, merged, relay)\n return EXIT.ok\n}\n\n/**\n * Print a `--run` result with the relay line FIRST under prose (#2483's\n * one-gate rule): whatever the human has to act on outranks the record of what\n * happened, because a link buried under an outcome dump is a link nobody sees.\n */\nfunction emitConnectResult(\n d: ResolvedDeps,\n json: boolean,\n merged: { relay: string | null; outcome: ConnectorOutcome | null; setup_id: string },\n relay: string | null,\n): void {\n emit(d, json, merged, () =>\n [relay, relay ? '' : null, `setup ${merged.setup_id}: ${merged.outcome?.outcome ?? 'unknown'}`]\n .filter((line) => line !== null)\n .join('\\n'),\n )\n}\n\n// ── Contacts ────────────────────────────────────────────────────────\n\nasync function cmdContactsList(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const { api } = await authed(args, d)\n const { contacts } = await api.get<{ contacts: Contact[] }>('/contacts')\n emit(d, args.flags.json, contacts, () =>\n contacts.length === 0\n ? 'No contacts yet.'\n : table(['ID', 'NAME', 'ADDRESS'], contacts.map((c) => [c.id, c.name, truncateAddress(c.address)])),\n )\n return EXIT.ok\n}\n\nasync function cmdContactsAdd(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const [address, ...nameParts] = [...args.positionals].reverse()\n // positionals are <name...> <address>; address is last, name is the rest.\n const name = nameParts.reverse().join(' ').trim()\n if (!name || !address) throw new UsageError('Usage: haven contacts add <name> <address>')\n const { api } = await authed(args, d)\n const contact = await api.post<Contact>('/contacts', { name, address })\n emit(d, args.flags.json, contact, () => `Added contact \"${contact.name}\" (${truncateAddress(contact.address)}).`)\n return EXIT.ok\n}\n\nasync function cmdContactsRemove(args: ParsedArgs, d: ResolvedDeps): Promise<number> {\n const id = args.positionals[0]\n if (!id) throw new UsageError('Usage: haven contacts remove <id>')\n const { api } = await authed(args, d)\n await api.del(`/contacts/${id}`)\n emit(d, args.flags.json, { ok: true, contact_id: id, removed: true }, () => `Contact ${id} removed.`)\n return EXIT.ok\n}\n","import { emitKeypressEvents } from 'node:readline'\n\n/** The three streams the prompt touches, injectable so a test can watch them. */\nexport interface PromptStreams {\n stdin: NodeJS.ReadStream\n stdout: NodeJS.WriteStream\n stderr: NodeJS.WriteStream\n}\n\n/**\n * Read a password from the TTY without echoing it. Falls back to a plain line\n * read when stdin isn't a TTY (so piping `HAVEN_PASSWORD` or a heredoc still\n * works, though the env var is the documented non-interactive path).\n *\n * Exported and stream-injected for one reason: which stream the prompt writes\n * to is part of the `--json` contract, and asserting it needs a seam. It is\n * `stderr` — see the comment at the write.\n */\nexport function promptPasswordWith(streams: PromptStreams): Promise<string> {\n return new Promise((resolve, reject) => {\n const { stdin, stderr } = streams\n if (!stdin.isTTY) {\n let data = ''\n stdin.setEncoding('utf8')\n stdin.on('data', (chunk) => (data += chunk))\n stdin.on('end', () => resolve(data.trim()))\n stdin.on('error', reject)\n return\n }\n // stderr, never stdout (#2525 review): under `--json` stdout carries one\n // JSON value and nothing else, and a prompt written there would land ahead\n // of it. A prompt is prose addressed to a human at a terminal, so stderr is\n // where it belongs in both modes — the TTY still shows it.\n stderr.write('Password: ')\n emitKeypressEvents(stdin)\n stdin.setRawMode(true)\n let value = ''\n const onKey = (char: string, key: { name?: string; ctrl?: boolean }) => {\n if (key.name === 'return' || key.name === 'enter') {\n cleanup()\n stderr.write('\\n')\n resolve(value)\n } else if (key.ctrl && key.name === 'c') {\n cleanup()\n stderr.write('\\n')\n reject(new Error('Cancelled'))\n } else if (key.name === 'backspace') {\n value = value.slice(0, -1)\n } else if (char && !key.ctrl) {\n value += char\n }\n }\n function cleanup() {\n stdin.setRawMode(false)\n stdin.pause()\n stdin.off('keypress', onKey)\n }\n stdin.resume()\n stdin.on('keypress', onKey)\n })\n}\n","#!/usr/bin/env node\n\nimport { run } from './commands.js'\nimport { promptPasswordWith } from './prompt.js'\n\n/**\n * The bin entry, and deliberately nothing else.\n *\n * It used to also define `promptPasswordWith`, which meant importing this file\n * to test that function EXECUTED the CLI — `run(process.argv.slice(2))` against\n * vitest's own argv, ending in `process.exit(1)`. The suite still reported 102\n * passing tests with one unhandled error beside them, which is exactly the\n * shape of failure a `grep` for \"Tests\" hides (#2525 review round 3, caught by\n * CI). An entry point that self-executes must not also be an import target, so\n * the prompt lives in `prompt.ts` and this file only wires and runs.\n */\nfunction promptPassword(): Promise<string> {\n return promptPasswordWith({ stdin: process.stdin, stdout: process.stdout, stderr: process.stderr })\n}\n\nrun(process.argv.slice(2), { promptPassword })\n .then((code) => process.exit(code))\n .catch((err) => {\n // The last resort: anything that escaped run()'s own handling. It should be\n // unreachable — run() catches around both parseArgs and dispatch — but if\n // it is ever reached under `--json`, a bare sentence on stderr with exit 1\n // would be the one refusal a machine caller cannot parse. So it emits the\n // same failure shape as everything else (#2525 review, finding 2).\n const message = err instanceof Error ? err.message : String(err)\n if (process.argv.includes('--json')) {\n process.stdout.write(`${JSON.stringify({ ok: false, error: { code: 'failed', message } }, null, 2)}\\n`)\n } else {\n process.stderr.write(`${message}\\n`)\n }\n process.exit(1)\n })\n"]}