@conto_finance/create-conto-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js ADDED
@@ -0,0 +1,1228 @@
1
+ import {
2
+ browserAuth,
3
+ createApiClient,
4
+ fetchChains,
5
+ getChain,
6
+ runInit
7
+ } from "./chunk-M7X7S5QC.js";
8
+ import {
9
+ isJsonMode,
10
+ printAmount,
11
+ printError,
12
+ printHeader,
13
+ printInfo,
14
+ printJson,
15
+ printKeyValue,
16
+ printPending,
17
+ printSuccess,
18
+ printTable,
19
+ setJsonMode,
20
+ truncateAddress
21
+ } from "./chunk-6TRDZ4JG.js";
22
+ import {
23
+ loadConfig,
24
+ loadGlobalConfig,
25
+ saveGlobalConfig
26
+ } from "./chunk-X7AY7G2E.js";
27
+ import "./chunk-QGM4M3NI.js";
28
+
29
+ // src/cli.ts
30
+ import { Command } from "commander";
31
+
32
+ // src/commands/status.ts
33
+ async function statusCommand() {
34
+ const config = loadConfig();
35
+ if (!config.apiKey) {
36
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
37
+ process.exit(1);
38
+ }
39
+ const api = createApiClient({
40
+ baseUrl: config.baseUrl,
41
+ apiKey: config.apiKey
42
+ });
43
+ try {
44
+ const [info, walletsData] = await Promise.all([api.getAgentInfo(), api.getWallets()]);
45
+ if (isJsonMode()) {
46
+ printJson({ agent: info, wallets: walletsData.wallets });
47
+ return;
48
+ }
49
+ printHeader("Agent");
50
+ printKeyValue("Name", info.agent.name);
51
+ printKeyValue("Type", info.agent.agentType);
52
+ printKeyValue("Status", info.agent.status);
53
+ printKeyValue("Wallets", String(info.walletCount));
54
+ if (walletsData.wallets.length > 0) {
55
+ printHeader("Wallets");
56
+ for (const w of walletsData.wallets) {
57
+ console.log(` ${w.name}`);
58
+ printKeyValue(" Address", truncateAddress(w.address));
59
+ printKeyValue(" Balance", printAmount(w.balance, w.currency || config.currency || "USD"));
60
+ printKeyValue(" Chain", `${w.chainType} (${w.chainId})`);
61
+ printKeyValue(" Status", w.status);
62
+ if (w.limits?.daily) {
63
+ const pct = w.limits.daily > 0 ? Math.round(w.spent.today / w.limits.daily * 100) : 0;
64
+ const bar2 = progressBar(pct);
65
+ printKeyValue(
66
+ " Daily",
67
+ `${bar2} ${printAmount(w.spent.today, "USD")} / ${printAmount(w.limits.daily, "USD")} (${pct}%)`
68
+ );
69
+ }
70
+ }
71
+ }
72
+ console.log("");
73
+ } catch (err) {
74
+ const message = err instanceof Error ? err.message : "Failed to fetch status";
75
+ if (isJsonMode()) {
76
+ printJson({ error: message });
77
+ } else {
78
+ printError(message);
79
+ }
80
+ process.exit(1);
81
+ }
82
+ }
83
+ function progressBar(pct, width = 20) {
84
+ const filled = Math.round(pct / 100 * width);
85
+ const empty = width - filled;
86
+ const color = pct > 90 ? "\x1B[31m" : pct > 70 ? "\x1B[33m" : "\x1B[32m";
87
+ return `${color}[${"\u2588".repeat(filled)}${"\u2591".repeat(empty)}]\x1B[0m`;
88
+ }
89
+
90
+ // src/commands/balance.ts
91
+ async function balanceCommand() {
92
+ const config = loadConfig();
93
+ if (!config.apiKey) {
94
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
95
+ process.exit(1);
96
+ }
97
+ const api = createApiClient({
98
+ baseUrl: config.baseUrl,
99
+ apiKey: config.apiKey
100
+ });
101
+ try {
102
+ const { wallets } = await api.getWallets();
103
+ if (isJsonMode()) {
104
+ printJson(wallets);
105
+ return;
106
+ }
107
+ if (wallets.length === 0) {
108
+ printError("No wallets linked to this agent.");
109
+ return;
110
+ }
111
+ printHeader("Wallet Balances");
112
+ printTable(
113
+ ["Name", "Address", "Balance", "Chain", "Status"],
114
+ wallets.map((w) => [
115
+ w.name,
116
+ truncateAddress(w.address),
117
+ printAmount(w.balance, w.currency || "USD"),
118
+ `${w.chainId}`,
119
+ w.status
120
+ ])
121
+ );
122
+ } catch (err) {
123
+ const message = err instanceof Error ? err.message : "Failed to fetch balances";
124
+ if (isJsonMode()) {
125
+ printJson({ error: message });
126
+ } else {
127
+ printError(message);
128
+ }
129
+ process.exit(1);
130
+ }
131
+ }
132
+
133
+ // src/commands/pay.ts
134
+ import chalk from "chalk";
135
+ async function payCommand(address, amountStr, options) {
136
+ const config = loadConfig();
137
+ if (!config.apiKey) {
138
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
139
+ process.exit(1);
140
+ }
141
+ const amount = Number(amountStr);
142
+ if (isNaN(amount) || amount <= 0) {
143
+ printError("Amount must be a positive number.");
144
+ process.exit(1);
145
+ }
146
+ const api = createApiClient({
147
+ baseUrl: config.baseUrl,
148
+ apiKey: config.apiKey
149
+ });
150
+ try {
151
+ if (!isJsonMode()) {
152
+ printHeader(options.dryRun ? "Policy Check (dry run)" : "Payment Request");
153
+ printKeyValue("To", address);
154
+ printKeyValue("Amount", printAmount(amount, config.currency || "USD"));
155
+ if (options.purpose) printKeyValue("Purpose", options.purpose);
156
+ console.log("");
157
+ }
158
+ const request = await api.requestPayment({
159
+ amount,
160
+ recipientAddress: address,
161
+ purpose: options.purpose,
162
+ category: options.category,
163
+ walletId: options.wallet
164
+ });
165
+ if (isJsonMode() && options.dryRun) {
166
+ printJson(request);
167
+ return;
168
+ }
169
+ if (request.status === "DENIED") {
170
+ if (isJsonMode()) {
171
+ printJson(request);
172
+ return;
173
+ }
174
+ printError("Payment denied by policy");
175
+ if (request.violations) {
176
+ for (const v of request.violations) {
177
+ console.log(chalk.red(` ${v.message}`));
178
+ }
179
+ }
180
+ if (request.reasons.length > 0) {
181
+ console.log(chalk.dim(`
182
+ Reasons: ${request.reasons.join(", ")}`));
183
+ }
184
+ process.exit(1);
185
+ }
186
+ if (request.status === "REQUIRES_APPROVAL") {
187
+ if (isJsonMode()) {
188
+ printJson(request);
189
+ return;
190
+ }
191
+ printPending("Payment requires manual approval");
192
+ printKeyValue("Request ID", request.requestId);
193
+ console.log(chalk.dim(" Approve in the Conto dashboard to execute."));
194
+ return;
195
+ }
196
+ if (options.dryRun) {
197
+ if (isJsonMode()) {
198
+ printJson(request);
199
+ return;
200
+ }
201
+ printSuccess("Payment would be APPROVED");
202
+ printKeyValue("Wallet", request.wallet?.address || "\u2014");
203
+ printKeyValue(
204
+ "Balance",
205
+ printAmount(request.wallet?.availableBalance || 0, config.currency || "USD")
206
+ );
207
+ printKeyValue("Request ID", request.requestId);
208
+ return;
209
+ }
210
+ const result = await api.executePayment(request.requestId);
211
+ if (isJsonMode()) {
212
+ printJson(result);
213
+ return;
214
+ }
215
+ printSuccess("Payment sent!");
216
+ printKeyValue("TX Hash", result.txHash);
217
+ printKeyValue("Amount", printAmount(result.amount, result.currency));
218
+ printKeyValue("Recipient", result.recipient);
219
+ printKeyValue("Status", result.status);
220
+ printKeyValue("Explorer", result.explorerUrl);
221
+ console.log("");
222
+ } catch (err) {
223
+ const message = err instanceof Error ? err.message : "Payment failed";
224
+ if (isJsonMode()) {
225
+ printJson({ error: message });
226
+ } else {
227
+ printError(message);
228
+ }
229
+ process.exit(1);
230
+ }
231
+ }
232
+
233
+ // src/commands/transactions.ts
234
+ async function transactionsCommand(id, options) {
235
+ const config = loadConfig();
236
+ if (!config.apiKey) {
237
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
238
+ process.exit(1);
239
+ }
240
+ const api = createApiClient({
241
+ baseUrl: config.baseUrl,
242
+ apiKey: config.apiKey
243
+ });
244
+ try {
245
+ if (id) {
246
+ const tx = await api.getTransaction(id);
247
+ if (isJsonMode()) {
248
+ printJson(tx);
249
+ return;
250
+ }
251
+ printHeader("Transaction Details");
252
+ printKeyValue("ID", tx.id);
253
+ printKeyValue("TX Hash", tx.txHash);
254
+ printKeyValue("Status", tx.status);
255
+ printKeyValue("Amount", printAmount(tx.amount, tx.currency));
256
+ printKeyValue("Recipient", tx.recipientAddress);
257
+ if (tx.recipientName) printKeyValue("Recipient Name", tx.recipientName);
258
+ if (tx.purpose) printKeyValue("Purpose", tx.purpose);
259
+ if (tx.category) printKeyValue("Category", tx.category);
260
+ printKeyValue("Explorer", tx.explorerUrl);
261
+ printKeyValue("Created", new Date(tx.createdAt).toLocaleString());
262
+ if (tx.confirmedAt) printKeyValue("Confirmed", new Date(tx.confirmedAt).toLocaleString());
263
+ if (tx.alerts && tx.alerts.length > 0) {
264
+ printHeader("Alerts");
265
+ for (const a of tx.alerts) {
266
+ console.log(` [${a.type}] ${a.message}`);
267
+ }
268
+ }
269
+ } else {
270
+ const { transactions, total } = await api.getTransactions({
271
+ limit: options?.limit ? Number(options.limit) : 10,
272
+ status: options?.status
273
+ });
274
+ if (isJsonMode()) {
275
+ printJson({ transactions, total });
276
+ return;
277
+ }
278
+ if (transactions.length === 0) {
279
+ printError("No transactions found.");
280
+ return;
281
+ }
282
+ printHeader(`Transactions (${transactions.length} of ${total})`);
283
+ printTable(
284
+ ["Date", "Amount", "Recipient", "Purpose", "Status", "TX Hash"],
285
+ transactions.map((tx) => [
286
+ new Date(tx.createdAt).toLocaleDateString(),
287
+ printAmount(tx.amount, tx.currency),
288
+ tx.recipientName || truncateAddress(tx.recipientAddress),
289
+ tx.purpose || "\u2014",
290
+ tx.status,
291
+ tx.txHash ? truncateAddress(tx.txHash, 8) : "\u2014"
292
+ ])
293
+ );
294
+ }
295
+ console.log("");
296
+ } catch (err) {
297
+ const message = err instanceof Error ? err.message : "Failed to fetch transactions";
298
+ if (isJsonMode()) {
299
+ printJson({ error: message });
300
+ } else {
301
+ printError(message);
302
+ }
303
+ process.exit(1);
304
+ }
305
+ }
306
+
307
+ // src/commands/wallets.ts
308
+ import chalk2 from "chalk";
309
+ async function walletsCommand(subcommand) {
310
+ const config = loadConfig();
311
+ if (!config.apiKey) {
312
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
313
+ process.exit(1);
314
+ }
315
+ const api = createApiClient({
316
+ baseUrl: config.baseUrl,
317
+ apiKey: config.apiKey
318
+ });
319
+ try {
320
+ await fetchChains(config.baseUrl);
321
+ const { wallets } = await api.getWallets();
322
+ if (subcommand === "list") {
323
+ if (isJsonMode()) {
324
+ printJson(wallets);
325
+ return;
326
+ }
327
+ if (wallets.length === 0) {
328
+ printError("No wallets linked to this agent.");
329
+ return;
330
+ }
331
+ printHeader("Wallets");
332
+ printTable(
333
+ ["Name", "Address", "Balance", "Chain ID", "Status"],
334
+ wallets.map((w) => [
335
+ w.name,
336
+ truncateAddress(w.address),
337
+ printAmount(w.balance, w.currency || "USD"),
338
+ w.chainId,
339
+ w.status
340
+ ])
341
+ );
342
+ console.log("");
343
+ return;
344
+ }
345
+ if (wallets.length === 0) {
346
+ printError("No wallets to fund.");
347
+ return;
348
+ }
349
+ for (const w of wallets) {
350
+ const chainEntry = getChain(w.chainId);
351
+ if (isJsonMode()) {
352
+ printJson({
353
+ wallet: w,
354
+ fundingInstructions: getFundingInstructions(
355
+ chainEntry?.currency || w.currency || "USD",
356
+ chainEntry
357
+ )
358
+ });
359
+ continue;
360
+ }
361
+ printHeader(`${w.name}`);
362
+ printKeyValue("Address", w.address);
363
+ printKeyValue(
364
+ "Network",
365
+ chainEntry ? `${chainEntry.name} (chain ID ${chainEntry.chainId})` : w.chainId
366
+ );
367
+ printKeyValue("Currency", w.currency || "USD");
368
+ printKeyValue("Balance", printAmount(w.balance, w.currency || "USD"));
369
+ console.log("");
370
+ if (chainEntry?.faucetAvailable && config.testnet) {
371
+ console.log(
372
+ chalk2.cyan(
373
+ ' This is a testnet wallet. Use "conto fund --faucet" to get free test tokens.'
374
+ )
375
+ );
376
+ console.log("");
377
+ } else {
378
+ console.log(` To fund your agent wallet, send ${chalk2.bold(w.currency || "USD")} to:
379
+ `);
380
+ console.log(chalk2.bold(` ${w.address}`));
381
+ console.log("");
382
+ const instructions = getFundingInstructions(w.currency || "USD", chainEntry);
383
+ console.log(` How to get ${w.currency || "USD"}:`);
384
+ for (const instruction of instructions) {
385
+ console.log(` ${chalk2.dim("\u2022")} ${instruction}`);
386
+ }
387
+ console.log("");
388
+ if (chainEntry) {
389
+ printKeyValue("Explorer", `${chainEntry.explorerUrl}/address/${w.address}`);
390
+ }
391
+ }
392
+ }
393
+ console.log("");
394
+ } catch (err) {
395
+ const message = err instanceof Error ? err.message : "Failed to fetch wallets";
396
+ if (isJsonMode()) {
397
+ printJson({ error: message });
398
+ } else {
399
+ printError(message);
400
+ }
401
+ process.exit(1);
402
+ }
403
+ }
404
+ function getFundingInstructions(currency, chain) {
405
+ if (currency === "pathUSD") {
406
+ return [
407
+ "Swap USDC \u2192 pathUSD on Tempo DEX",
408
+ "Bridge USDC from Base/Ethereum via Tempo bridge",
409
+ "Transfer from another Tempo wallet"
410
+ ];
411
+ }
412
+ if (currency === "USDC" && chain?.chainId === "8453") {
413
+ return [
414
+ "Bridge USDC from Ethereum via Base bridge",
415
+ "Buy USDC on a centralized exchange and withdraw to Base",
416
+ "Swap ETH \u2192 USDC on Base DEXs (Uniswap, Aerodrome)"
417
+ ];
418
+ }
419
+ if (currency === "USDC" && chain?.chainType === "SOLANA") {
420
+ return [
421
+ "Buy USDC on a centralized exchange and withdraw to Solana",
422
+ "Swap SOL \u2192 USDC on Jupiter or Raydium",
423
+ "Bridge USDC from Ethereum/Base via Wormhole"
424
+ ];
425
+ }
426
+ return [`Transfer ${currency} from another wallet`, `Buy ${currency} on an exchange`];
427
+ }
428
+
429
+ // src/commands/policies.ts
430
+ import chalk3 from "chalk";
431
+ import * as p from "@clack/prompts";
432
+ var POLICY_TYPES = [
433
+ {
434
+ value: "SPEND_LIMIT",
435
+ label: "Spend Limit",
436
+ hint: "Cap per-transaction, daily, weekly, or monthly totals"
437
+ },
438
+ {
439
+ value: "APPROVAL_THRESHOLD",
440
+ label: "Approval Threshold",
441
+ hint: "Require human approval above a dollar amount"
442
+ },
443
+ {
444
+ value: "COUNTERPARTY",
445
+ label: "Counterparty",
446
+ hint: "Allow or block specific wallet addresses"
447
+ },
448
+ { value: "CATEGORY", label: "Category", hint: "Restrict which spend categories are permitted" },
449
+ {
450
+ value: "GEOGRAPHIC",
451
+ label: "Geographic",
452
+ hint: "Block transactions involving sanctioned countries"
453
+ },
454
+ {
455
+ value: "BUDGET_ALLOCATION",
456
+ label: "Budget Allocation",
457
+ hint: "Set a total budget cap for a time period"
458
+ },
459
+ { value: "EXPIRATION", label: "Expiration", hint: "Policy only active within a date range" },
460
+ { value: "MERCHANT", label: "Merchant", hint: "Allow or block specific merchants by address" },
461
+ {
462
+ value: "TIME_WINDOW",
463
+ label: "Time Window",
464
+ hint: "Restrict transactions to specific hours or days"
465
+ },
466
+ {
467
+ value: "VELOCITY",
468
+ label: "Velocity",
469
+ hint: "Rate limit: max number of transactions per time period"
470
+ },
471
+ {
472
+ value: "WHITELIST",
473
+ label: "Whitelist",
474
+ hint: "Only pre-approved addresses can receive payments"
475
+ },
476
+ {
477
+ value: "COMPOSITE",
478
+ label: "Composite",
479
+ hint: "Combine multiple policy conditions with AND/OR logic"
480
+ },
481
+ {
482
+ value: "CONTRACT_ALLOWLIST",
483
+ label: "Contract Allowlist",
484
+ hint: "Restrict to approved smart contract addresses"
485
+ },
486
+ {
487
+ value: "BLACKOUT_PERIOD",
488
+ label: "Blackout Period",
489
+ hint: "Block all transactions during specific time windows"
490
+ }
491
+ ];
492
+ var RULE_TYPES = {
493
+ SPEND_LIMIT: [
494
+ { value: "MAX_AMOUNT", label: "Max Amount", hint: "Maximum per-transaction amount" },
495
+ { value: "DAILY_LIMIT", label: "Daily Limit", hint: "Maximum total spend per day" },
496
+ { value: "WEEKLY_LIMIT", label: "Weekly Limit", hint: "Maximum total spend per week" },
497
+ { value: "MONTHLY_LIMIT", label: "Monthly Limit", hint: "Maximum total spend per month" },
498
+ { value: "BUDGET_CAP", label: "Budget Cap", hint: "Absolute spend ceiling" }
499
+ ],
500
+ APPROVAL_THRESHOLD: [
501
+ {
502
+ value: "REQUIRE_APPROVAL_ABOVE",
503
+ label: "Require Approval Above",
504
+ hint: "Payments above this amount need human approval"
505
+ }
506
+ ],
507
+ COUNTERPARTY: [
508
+ {
509
+ value: "ALLOWED_COUNTERPARTIES",
510
+ label: "Allowed Counterparties",
511
+ hint: "Whitelist of permitted wallet addresses"
512
+ },
513
+ {
514
+ value: "BLOCKED_COUNTERPARTIES",
515
+ label: "Blocked Counterparties",
516
+ hint: "Blacklist of blocked wallet addresses"
517
+ },
518
+ {
519
+ value: "COUNTERPARTY_STATUS",
520
+ label: "Counterparty Status",
521
+ hint: "Check trust status (TRUSTED, BLOCKED, etc.)"
522
+ },
523
+ { value: "TRUST_SCORE", label: "Trust Score", hint: "Minimum trust score required (0-100)" }
524
+ ],
525
+ CATEGORY: [
526
+ {
527
+ value: "ALLOWED_CATEGORIES",
528
+ label: "Allowed Categories",
529
+ hint: "Only these spend categories permitted"
530
+ },
531
+ {
532
+ value: "BLOCKED_CATEGORIES",
533
+ label: "Blocked Categories",
534
+ hint: "These spend categories are denied"
535
+ }
536
+ ],
537
+ GEOGRAPHIC: [
538
+ {
539
+ value: "GEOGRAPHIC_RESTRICTION",
540
+ label: "Geographic Restriction",
541
+ hint: "Block sanctioned countries (OFAC list)"
542
+ }
543
+ ],
544
+ BUDGET_ALLOCATION: [
545
+ {
546
+ value: "BUDGET_CAP",
547
+ label: "Budget Cap",
548
+ hint: "Total budget for a period (e.g. quarterly)"
549
+ }
550
+ ],
551
+ EXPIRATION: [
552
+ { value: "DATE_RANGE", label: "Date Range", hint: "Policy active between start and end dates" }
553
+ ],
554
+ MERCHANT: [
555
+ {
556
+ value: "ALLOWED_COUNTERPARTIES",
557
+ label: "Allowed Merchants",
558
+ hint: "Whitelist of permitted merchant addresses"
559
+ },
560
+ {
561
+ value: "BLOCKED_COUNTERPARTIES",
562
+ label: "Blocked Merchants",
563
+ hint: "Blacklist of blocked merchant addresses"
564
+ }
565
+ ],
566
+ TIME_WINDOW: [
567
+ { value: "TIME_WINDOW", label: "Time Window", hint: "Allowed hours (e.g. 9am-5pm)" },
568
+ { value: "DAY_OF_WEEK", label: "Day of Week", hint: "Allowed days (e.g. Mon-Fri)" }
569
+ ],
570
+ VELOCITY: [
571
+ {
572
+ value: "VELOCITY_LIMIT",
573
+ label: "Velocity Limit",
574
+ hint: "Max transactions per time window (e.g. 5 per hour)"
575
+ }
576
+ ],
577
+ WHITELIST: [
578
+ {
579
+ value: "ALLOWED_COUNTERPARTIES",
580
+ label: "Allowed Addresses",
581
+ hint: "Only these addresses can receive payments"
582
+ }
583
+ ],
584
+ COMPOSITE: [
585
+ {
586
+ value: "REQUIRE_APPROVAL_ABOVE",
587
+ label: "Require Approval Above",
588
+ hint: "Combine with other conditions"
589
+ },
590
+ { value: "MAX_AMOUNT", label: "Max Amount", hint: "Combine with other conditions" },
591
+ {
592
+ value: "ALLOWED_COUNTERPARTIES",
593
+ label: "Allowed Counterparties",
594
+ hint: "Combine with other conditions"
595
+ }
596
+ ],
597
+ CONTRACT_ALLOWLIST: [
598
+ {
599
+ value: "CONTRACT_ALLOWLIST",
600
+ label: "Contract Allowlist",
601
+ hint: "Approved smart contract addresses"
602
+ },
603
+ {
604
+ value: "ALLOWED_CONTRACTS",
605
+ label: "Allowed Contracts",
606
+ hint: "Specific contracts this agent can interact with"
607
+ },
608
+ { value: "PROTOCOL_ALLOWLIST", label: "Protocol Allowlist", hint: "Approved DeFi protocols" }
609
+ ],
610
+ BLACKOUT_PERIOD: [
611
+ {
612
+ value: "BLACKOUT_PERIOD",
613
+ label: "Blackout Period",
614
+ hint: "Block transactions during this window"
615
+ },
616
+ {
617
+ value: "MAINTENANCE_WINDOW",
618
+ label: "Maintenance Window",
619
+ hint: "Scheduled downtime \u2014 no payments"
620
+ },
621
+ { value: "BLOCKED_TIME_WINDOW", label: "Blocked Time Window", hint: "Recurring blocked hours" }
622
+ ]
623
+ };
624
+ var OPERATORS = [
625
+ { value: "LESS_THAN", label: "< (less than)", hint: "Value must be strictly less" },
626
+ { value: "LTE", label: "<= (at most)", hint: "Value must be at most this amount" },
627
+ { value: "GREATER_THAN", label: "> (greater than)", hint: "Value must exceed this amount" },
628
+ { value: "GTE", label: ">= (at least)", hint: "Value must be at least this amount" },
629
+ { value: "EQUALS", label: "= (equals)", hint: "Must match exactly" },
630
+ { value: "NOT_EQUALS", label: "!= (not equals)", hint: "Must not match" },
631
+ { value: "IN_LIST", label: "in list", hint: "Value must be in the provided list" },
632
+ { value: "NOT_IN_LIST", label: "not in list", hint: "Value must not be in the provided list" },
633
+ { value: "IN", label: "in (alias)", hint: "Same as in list" },
634
+ { value: "NOT_IN", label: "not in (alias)", hint: "Same as not in list" },
635
+ { value: "BETWEEN", label: "between", hint: "Value must be within a range" },
636
+ { value: "NOT_BETWEEN", label: "not between", hint: "Value must be outside a range" },
637
+ { value: "DENY", label: "deny (block)", hint: "Unconditionally block" }
638
+ ];
639
+ var ACTIONS = [
640
+ { value: "ALLOW", label: "Allow", hint: "Payment proceeds if rule passes" },
641
+ { value: "DENY", label: "Deny", hint: "Payment is blocked if rule fails" },
642
+ {
643
+ value: "REQUIRE_APPROVAL",
644
+ label: "Require Approval",
645
+ hint: "Payment needs human approval if rule triggers"
646
+ }
647
+ ];
648
+ async function policiesCommand(subcommand = "list", idOrAmount, extra) {
649
+ const config = loadConfig();
650
+ if (!config.apiKey) {
651
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
652
+ process.exit(1);
653
+ }
654
+ const api = createApiClient({
655
+ baseUrl: config.baseUrl,
656
+ apiKey: config.apiKey,
657
+ orgApiKey: config.orgApiKey
658
+ });
659
+ try {
660
+ switch (subcommand) {
661
+ case "list":
662
+ return await listAgentPolicies(api);
663
+ case "all":
664
+ return await listAllPolicies(api);
665
+ case "create":
666
+ return await createPolicy(api, config.agentId);
667
+ case "update":
668
+ if (!idOrAmount) {
669
+ printError("Usage: conto policies update <policy-id>");
670
+ process.exit(1);
671
+ }
672
+ return await updatePolicy(api, idOrAmount);
673
+ case "delete":
674
+ if (!idOrAmount) {
675
+ printError("Usage: conto policies delete <policy-id>");
676
+ process.exit(1);
677
+ }
678
+ return await deletePolicy(api, idOrAmount);
679
+ case "assign":
680
+ if (!idOrAmount) {
681
+ printError("Usage: conto policies assign <policy-id>");
682
+ process.exit(1);
683
+ }
684
+ return await assignPolicy(api, config.agentId, idOrAmount);
685
+ case "unassign":
686
+ if (!idOrAmount) {
687
+ printError("Usage: conto policies unassign <policy-id>");
688
+ process.exit(1);
689
+ }
690
+ return await unassignPolicy(api, config.agentId, idOrAmount);
691
+ case "add-rule":
692
+ if (!idOrAmount) {
693
+ printError("Usage: conto policies add-rule <policy-id>");
694
+ process.exit(1);
695
+ }
696
+ return await addRule(api, idOrAmount);
697
+ case "remove-rule":
698
+ if (!idOrAmount || !extra) {
699
+ printError("Usage: conto policies remove-rule <policy-id> <rule-id>");
700
+ process.exit(1);
701
+ }
702
+ return await removeRule(api, idOrAmount, extra);
703
+ default:
704
+ printError(`Unknown subcommand: ${subcommand}`);
705
+ printInfo(
706
+ "Available: list, all, create, update <id>, delete <id>, assign <id>, unassign <id>, add-rule <id>, remove-rule <policyId> <ruleId>"
707
+ );
708
+ process.exit(1);
709
+ }
710
+ } catch (err) {
711
+ const message = err instanceof Error ? err.message : "Failed to manage policies";
712
+ if (isJsonMode()) {
713
+ printJson({ error: message });
714
+ } else {
715
+ printError(message);
716
+ }
717
+ process.exit(1);
718
+ }
719
+ }
720
+ async function listAgentPolicies(api) {
721
+ const { policies } = await api.getPolicies();
722
+ if (isJsonMode()) {
723
+ printJson(policies);
724
+ return;
725
+ }
726
+ if (policies.length === 0) {
727
+ printInfo("No policies assigned to this agent.");
728
+ return;
729
+ }
730
+ printHeader("Agent Policies");
731
+ for (const policy of policies) {
732
+ const scope = policy.assignedVia === "agent" ? chalk3.cyan("[agent]") : chalk3.dim("[org-wide]");
733
+ console.log(
734
+ `
735
+ ${chalk3.bold(policy.name)} ${scope} ${chalk3.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
736
+ );
737
+ console.log(` ${chalk3.dim("ID:")} ${policy.id}`);
738
+ console.log(
739
+ ` ${chalk3.dim("Active:")} ${policy.isActive ? chalk3.green("Yes") : chalk3.red("No")}`
740
+ );
741
+ if (policy.rules.length > 0) {
742
+ console.log(` ${chalk3.dim("Rules:")}`);
743
+ for (const rule of policy.rules) {
744
+ const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
745
+ console.log(
746
+ ` ${chalk3.dim("\u2022")} ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
747
+ );
748
+ }
749
+ }
750
+ }
751
+ console.log("");
752
+ }
753
+ async function listAllPolicies(api) {
754
+ const { policies } = await api.listOrgPolicies();
755
+ if (isJsonMode()) {
756
+ printJson(policies);
757
+ return;
758
+ }
759
+ if (policies.length === 0) {
760
+ printInfo("No policies in this organization.");
761
+ return;
762
+ }
763
+ printHeader(`All Organization Policies (${policies.length})`);
764
+ for (const policy of policies) {
765
+ const agentCount = policy._count?.agentPolicies ?? "?";
766
+ console.log(
767
+ `
768
+ ${chalk3.bold(policy.name)} ${chalk3.dim(`(${policy.policyType}, priority: ${policy.priority}, ${agentCount} agents)`)}`
769
+ );
770
+ console.log(` ${chalk3.dim("ID:")} ${policy.id}`);
771
+ console.log(
772
+ ` ${chalk3.dim("Active:")} ${policy.isActive ? chalk3.green("Yes") : chalk3.red("No")}`
773
+ );
774
+ if (policy.rules.length > 0) {
775
+ console.log(` ${chalk3.dim("Rules:")}`);
776
+ for (const rule of policy.rules) {
777
+ const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
778
+ console.log(
779
+ ` ${chalk3.dim("\u2022")} [${rule.id.slice(-6)}] ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
780
+ );
781
+ }
782
+ }
783
+ }
784
+ console.log("");
785
+ }
786
+ async function createPolicy(api, agentId) {
787
+ const name = await p.text({
788
+ message: "Policy name",
789
+ placeholder: "Daily Spend Limit"
790
+ });
791
+ if (p.isCancel(name)) process.exit(0);
792
+ const policyType = await p.select({
793
+ message: "Policy type",
794
+ options: POLICY_TYPES
795
+ });
796
+ if (p.isCancel(policyType)) process.exit(0);
797
+ const priority = await p.text({
798
+ message: "Priority (lower = evaluated first)",
799
+ initialValue: "50"
800
+ });
801
+ if (p.isCancel(priority)) process.exit(0);
802
+ const addFirstRule = await p.confirm({ message: "Add a rule now?" });
803
+ if (p.isCancel(addFirstRule)) process.exit(0);
804
+ const rules = [];
805
+ if (addFirstRule) {
806
+ const rule = await promptForRule(policyType);
807
+ if (rule) rules.push(rule);
808
+ }
809
+ const assignToAgent = agentId ? await p.confirm({ message: "Assign to current agent?" }) : false;
810
+ if (p.isCancel(assignToAgent)) process.exit(0);
811
+ const result = await api.createPolicy({
812
+ name,
813
+ policyType,
814
+ priority: Number(priority),
815
+ isActive: true,
816
+ rules,
817
+ agentIds: assignToAgent && agentId ? [agentId] : void 0
818
+ });
819
+ if (isJsonMode()) {
820
+ printJson(result);
821
+ } else {
822
+ printSuccess(`Policy "${result.name}" created (ID: ${result.id})`);
823
+ if (assignToAgent) printSuccess("Assigned to current agent");
824
+ }
825
+ }
826
+ async function updatePolicy(api, policyId) {
827
+ const name = await p.text({
828
+ message: "New name (leave empty to skip)",
829
+ initialValue: ""
830
+ });
831
+ if (p.isCancel(name)) process.exit(0);
832
+ const priority = await p.text({
833
+ message: "New priority (leave empty to skip)",
834
+ initialValue: ""
835
+ });
836
+ if (p.isCancel(priority)) process.exit(0);
837
+ const isActive = await p.select({
838
+ message: "Active?",
839
+ options: [
840
+ { value: "skip", label: "No change" },
841
+ { value: "true", label: "Yes" },
842
+ { value: "false", label: "No" }
843
+ ]
844
+ });
845
+ if (p.isCancel(isActive)) process.exit(0);
846
+ const params = {};
847
+ if (name) params.name = name;
848
+ if (priority) params.priority = Number(priority);
849
+ if (isActive !== "skip") params.isActive = isActive === "true";
850
+ if (Object.keys(params).length === 0) {
851
+ printInfo("No changes to make.");
852
+ return;
853
+ }
854
+ const result = await api.updatePolicy(policyId, params);
855
+ if (isJsonMode()) {
856
+ printJson(result);
857
+ } else {
858
+ printSuccess(`Policy "${result.name}" updated`);
859
+ }
860
+ }
861
+ async function deletePolicy(api, policyId) {
862
+ const confirm2 = await p.confirm({
863
+ message: `Delete policy ${policyId}? This cannot be undone.`
864
+ });
865
+ if (p.isCancel(confirm2) || !confirm2) {
866
+ printInfo("Cancelled.");
867
+ return;
868
+ }
869
+ await api.deletePolicy(policyId);
870
+ printSuccess(`Policy ${policyId} deleted`);
871
+ }
872
+ async function assignPolicy(api, agentId, policyId) {
873
+ await api.assignPolicyToAgent(agentId, policyId);
874
+ if (isJsonMode()) {
875
+ printJson({ success: true, agentId, policyId });
876
+ } else {
877
+ printSuccess(`Policy ${policyId} assigned to agent`);
878
+ }
879
+ }
880
+ async function unassignPolicy(api, agentId, policyId) {
881
+ await api.unassignPolicyFromAgent(agentId, policyId);
882
+ if (isJsonMode()) {
883
+ printJson({ success: true, agentId, policyId });
884
+ } else {
885
+ printSuccess(`Policy ${policyId} unassigned from agent`);
886
+ }
887
+ }
888
+ async function addRule(api, policyId) {
889
+ const rule = await promptForRule();
890
+ if (!rule) return;
891
+ const result = await api.addPolicyRule(policyId, rule);
892
+ if (isJsonMode()) {
893
+ printJson(result);
894
+ } else {
895
+ printSuccess(`Rule "${rule.ruleType}" added to policy`);
896
+ }
897
+ }
898
+ async function removeRule(api, policyId, ruleId) {
899
+ await api.deletePolicyRule(policyId, ruleId);
900
+ if (isJsonMode()) {
901
+ printJson({ success: true, policyId, ruleId });
902
+ } else {
903
+ printSuccess(`Rule ${ruleId} removed from policy`);
904
+ }
905
+ }
906
+ async function promptForRule(policyType) {
907
+ const availableRules = policyType ? RULE_TYPES[policyType] || [] : Object.values(RULE_TYPES).flat();
908
+ const seen = /* @__PURE__ */ new Set();
909
+ const uniqueRules = availableRules.filter((r) => {
910
+ if (seen.has(r.value)) return false;
911
+ seen.add(r.value);
912
+ return true;
913
+ });
914
+ const ruleType = await p.select({
915
+ message: "Rule type",
916
+ options: uniqueRules
917
+ });
918
+ if (p.isCancel(ruleType)) return null;
919
+ const operator = await p.select({
920
+ message: "Operator",
921
+ options: OPERATORS
922
+ });
923
+ if (p.isCancel(operator)) return null;
924
+ const ruleStr = ruleType.toString();
925
+ let placeholder = "500";
926
+ let valueHint = "Enter a number for limits, or JSON for lists";
927
+ if (ruleStr.includes("LIMIT") || ruleStr.includes("AMOUNT") || ruleStr.includes("CAP") || ruleStr === "REQUIRE_APPROVAL_ABOVE") {
928
+ placeholder = "500";
929
+ valueHint = "Dollar amount (e.g. 500)";
930
+ } else if (ruleStr.includes("COUNTERPART") || ruleStr.includes("CATEGOR")) {
931
+ placeholder = '["0xabc...","0xdef..."]';
932
+ valueHint = "JSON array of addresses or category names";
933
+ } else if (ruleStr === "TRUST_SCORE") {
934
+ placeholder = "50";
935
+ valueHint = "Trust score 0-100";
936
+ } else if (ruleStr === "COUNTRY" || ruleStr === "GEOGRAPHIC_RESTRICTION") {
937
+ placeholder = '["US","GB","DE"]';
938
+ valueHint = "JSON array of country codes";
939
+ } else if (ruleStr === "DATE_RANGE") {
940
+ placeholder = '{"start":"2025-01-01","end":"2025-12-31"}';
941
+ valueHint = "JSON with start and end dates (ISO format)";
942
+ }
943
+ const value = await p.text({
944
+ message: `Value \u2014 ${valueHint}`,
945
+ placeholder
946
+ });
947
+ if (p.isCancel(value)) return null;
948
+ const action = await p.select({
949
+ message: "Action when rule triggers",
950
+ options: ACTIONS
951
+ });
952
+ if (p.isCancel(action)) return null;
953
+ return {
954
+ ruleType,
955
+ operator,
956
+ value,
957
+ action
958
+ };
959
+ }
960
+ function formatRuleValue(ruleType, value) {
961
+ if (ruleType.includes("LIMIT") || ruleType.includes("AMOUNT") || ruleType.includes("CAP")) {
962
+ const num = Number(value);
963
+ if (!isNaN(num)) return `$${num.toFixed(2)}`;
964
+ }
965
+ try {
966
+ const parsed = JSON.parse(value);
967
+ if (typeof parsed === "object") return JSON.stringify(parsed);
968
+ } catch {
969
+ }
970
+ return value;
971
+ }
972
+
973
+ // src/commands/limits.ts
974
+ import chalk4 from "chalk";
975
+ async function limitsCommand() {
976
+ const config = loadConfig();
977
+ if (!config.apiKey) {
978
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
979
+ process.exit(1);
980
+ }
981
+ const api = createApiClient({
982
+ baseUrl: config.baseUrl,
983
+ apiKey: config.apiKey
984
+ });
985
+ try {
986
+ const { limits } = await api.getSpendingLimits();
987
+ if (isJsonMode()) {
988
+ printJson(limits);
989
+ return;
990
+ }
991
+ if (limits.length === 0) {
992
+ printError("No spending limits configured.");
993
+ return;
994
+ }
995
+ printHeader("Spending Limits");
996
+ for (const l of limits) {
997
+ console.log(`
998
+ ${chalk4.bold(l.walletName)}`);
999
+ const dailyPct = l.daily.limit > 0 ? Math.round(l.daily.spent / l.daily.limit * 100) : 0;
1000
+ console.log(
1001
+ ` ${chalk4.dim("Daily:")} ${bar(dailyPct)} ${printAmount(l.daily.spent, "USD")} / ${printAmount(l.daily.limit, "USD")} ${chalk4.dim(`(${printAmount(l.daily.remaining, "USD")} remaining)`)}`
1002
+ );
1003
+ if (l.weekly) {
1004
+ const weeklyPct = l.weekly.limit > 0 ? Math.round(l.weekly.spent / l.weekly.limit * 100) : 0;
1005
+ console.log(
1006
+ ` ${chalk4.dim("Weekly:")} ${bar(weeklyPct)} ${printAmount(l.weekly.spent, "USD")} / ${printAmount(l.weekly.limit, "USD")} ${chalk4.dim(`(${printAmount(l.weekly.remaining, "USD")} remaining)`)}`
1007
+ );
1008
+ }
1009
+ if (l.monthly) {
1010
+ const monthlyPct = l.monthly.limit > 0 ? Math.round(l.monthly.spent / l.monthly.limit * 100) : 0;
1011
+ console.log(
1012
+ ` ${chalk4.dim("Monthly:")} ${bar(monthlyPct)} ${printAmount(l.monthly.spent, "USD")} / ${printAmount(l.monthly.limit, "USD")} ${chalk4.dim(`(${printAmount(l.monthly.remaining, "USD")} remaining)`)}`
1013
+ );
1014
+ }
1015
+ printKeyValue(" Per-TX max", printAmount(l.perTransaction, "USD"));
1016
+ }
1017
+ console.log("");
1018
+ } catch (err) {
1019
+ const message = err instanceof Error ? err.message : "Failed to fetch spending limits";
1020
+ if (isJsonMode()) {
1021
+ printJson({ error: message });
1022
+ } else {
1023
+ printError(message);
1024
+ }
1025
+ process.exit(1);
1026
+ }
1027
+ }
1028
+ function bar(pct, width = 15) {
1029
+ const filled = Math.round(pct / 100 * width);
1030
+ const empty = width - filled;
1031
+ const color = pct > 90 ? "\x1B[31m" : pct > 70 ? "\x1B[33m" : "\x1B[32m";
1032
+ return `${color}[${"\u2588".repeat(filled)}${"\u2591".repeat(empty)}]\x1B[0m`;
1033
+ }
1034
+
1035
+ // src/commands/alerts.ts
1036
+ import chalk5 from "chalk";
1037
+ async function alertsCommand(options = {}) {
1038
+ const config = loadConfig();
1039
+ if (!config.apiKey) {
1040
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
1041
+ process.exit(1);
1042
+ }
1043
+ const api = createApiClient({
1044
+ baseUrl: config.baseUrl,
1045
+ apiKey: config.apiKey
1046
+ });
1047
+ try {
1048
+ const { alerts } = await api.getAlerts({
1049
+ status: options.unread ? "UNREAD" : void 0
1050
+ });
1051
+ if (isJsonMode()) {
1052
+ printJson(alerts);
1053
+ return;
1054
+ }
1055
+ if (alerts.length === 0) {
1056
+ console.log("\n No alerts." + (options.unread ? " (showing unread only)" : ""));
1057
+ return;
1058
+ }
1059
+ printHeader(`Alerts (${alerts.length})`);
1060
+ printTable(
1061
+ ["Date", "Severity", "Type", "Message", "Status"],
1062
+ alerts.map((a) => [
1063
+ new Date(a.createdAt).toLocaleDateString(),
1064
+ severityColor(a.severity),
1065
+ a.type,
1066
+ a.message.length > 50 ? a.message.slice(0, 50) + "..." : a.message,
1067
+ a.status
1068
+ ])
1069
+ );
1070
+ console.log("");
1071
+ } catch (err) {
1072
+ const message = err instanceof Error ? err.message : "Failed to fetch alerts";
1073
+ if (isJsonMode()) {
1074
+ printJson({ error: message });
1075
+ } else {
1076
+ printError(message);
1077
+ }
1078
+ process.exit(1);
1079
+ }
1080
+ }
1081
+ function severityColor(severity) {
1082
+ switch (severity.toUpperCase()) {
1083
+ case "CRITICAL":
1084
+ return chalk5.red.bold(severity);
1085
+ case "HIGH":
1086
+ return chalk5.red(severity);
1087
+ case "MEDIUM":
1088
+ return chalk5.yellow(severity);
1089
+ case "LOW":
1090
+ return chalk5.dim(severity);
1091
+ default:
1092
+ return severity;
1093
+ }
1094
+ }
1095
+
1096
+ // src/commands/config.ts
1097
+ import chalk6 from "chalk";
1098
+ async function configCommand(key, value) {
1099
+ if (key && value) {
1100
+ const global = loadGlobalConfig();
1101
+ const parts = key.split(".");
1102
+ let target = global;
1103
+ for (let i = 0; i < parts.length - 1; i++) {
1104
+ if (!target[parts[i]] || typeof target[parts[i]] !== "object") {
1105
+ target[parts[i]] = {};
1106
+ }
1107
+ target = target[parts[i]];
1108
+ }
1109
+ target[parts[parts.length - 1]] = value;
1110
+ saveGlobalConfig(global);
1111
+ printSuccess(`Set ${key} = ${value}`);
1112
+ return;
1113
+ }
1114
+ const config = loadConfig();
1115
+ if (isJsonMode()) {
1116
+ printJson(config);
1117
+ return;
1118
+ }
1119
+ printHeader("Configuration");
1120
+ printKeyValue(
1121
+ "API Key",
1122
+ config.apiKey ? `${config.apiKey.slice(0, 10)}...` : chalk6.dim("not set")
1123
+ );
1124
+ printKeyValue("Base URL", config.baseUrl);
1125
+ printKeyValue("Agent ID", config.agentId || chalk6.dim("not set"));
1126
+ printKeyValue("Chain", config.chainName || chalk6.dim("not set"));
1127
+ printKeyValue("Chain ID", config.chainId || chalk6.dim("not set"));
1128
+ printKeyValue("Currency", config.currency || chalk6.dim("not set"));
1129
+ printKeyValue("Explorer", config.explorerUrl || chalk6.dim("not set"));
1130
+ printKeyValue("Wallet ID", config.walletId || chalk6.dim("not set"));
1131
+ printKeyValue("Wallet Address", config.walletAddress || chalk6.dim("not set"));
1132
+ printKeyValue("Testnet", config.testnet ? "Yes" : "No");
1133
+ console.log("");
1134
+ console.log(chalk6.dim(" Config sources: ~/.conto/config.json + .env.local"));
1135
+ console.log(chalk6.dim(" Update with: conto config <key> <value>"));
1136
+ console.log("");
1137
+ }
1138
+
1139
+ // src/commands/login.ts
1140
+ async function loginCommand(options = {}) {
1141
+ const existingConfig = loadGlobalConfig();
1142
+ const baseUrl = options.baseUrl || existingConfig.server?.baseUrl || "https://conto.finance";
1143
+ printInfo("Opening browser to authenticate...");
1144
+ try {
1145
+ const { orgApiKey, organizationName } = await browserAuth(baseUrl);
1146
+ const config = loadGlobalConfig();
1147
+ if (!config.server) {
1148
+ config.server = { baseUrl };
1149
+ }
1150
+ config.server.orgApiKey = orgApiKey;
1151
+ config.server.baseUrl = baseUrl;
1152
+ saveGlobalConfig(config);
1153
+ printSuccess(`Authenticated with organization: ${organizationName}`);
1154
+ printInfo("Credentials saved to ~/.conto/config.json");
1155
+ } catch (err) {
1156
+ printError(err instanceof Error ? err.message : "Authentication failed");
1157
+ process.exit(1);
1158
+ }
1159
+ }
1160
+
1161
+ // src/commands/mcp.ts
1162
+ import { spawn } from "child_process";
1163
+ async function mcpCommand() {
1164
+ const config = loadConfig();
1165
+ if (!config.apiKey) {
1166
+ printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
1167
+ process.exit(1);
1168
+ }
1169
+ printInfo("Starting Conto MCP server...");
1170
+ printInfo("Press Ctrl+C to stop.\n");
1171
+ const child = spawn("npx", ["conto-mcp-server"], {
1172
+ stdio: "inherit",
1173
+ env: {
1174
+ ...process.env,
1175
+ CONTO_API_KEY: config.apiKey,
1176
+ CONTO_BASE_URL: config.baseUrl
1177
+ }
1178
+ });
1179
+ child.on("error", (err) => {
1180
+ printError(`Failed to start MCP server: ${err.message}`);
1181
+ printInfo("Install it with: npm install -g conto-mcp-server");
1182
+ process.exit(1);
1183
+ });
1184
+ child.on("exit", (code) => {
1185
+ process.exit(code ?? 0);
1186
+ });
1187
+ }
1188
+
1189
+ // src/cli.ts
1190
+ var program = new Command();
1191
+ program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version("0.1.0").option("--json", "Output in JSON format").hook("preAction", (thisCommand) => {
1192
+ const opts = thisCommand.opts();
1193
+ if (opts.json) {
1194
+ setJsonMode(true);
1195
+ }
1196
+ });
1197
+ program.command("init").description("Run the interactive setup wizard").option("--chain <chain>", "Network (tempo, tempo-testnet, base, solana)").option("--name <name>", "Agent name").option("--type <type>", "Agent type").option("--limit <limit>", "Daily spending limit in USD").option("--base-url <url>", "Conto instance URL").action(async (opts) => {
1198
+ await runInit({
1199
+ chain: opts.chain,
1200
+ name: opts.name,
1201
+ type: opts.type,
1202
+ limit: opts.limit ? Number(opts.limit) : void 0,
1203
+ baseUrl: opts.baseUrl
1204
+ });
1205
+ });
1206
+ program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
1207
+ program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
1208
+ program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Policy check without executing").option("--wallet <walletId>", "Specific wallet to use").action(payCommand);
1209
+ program.command("transactions [id]").description("List recent transactions or view details").option("--limit <n>", "Number of transactions", "10").option("--status <status>", "Filter by status").action(transactionsCommand);
1210
+ program.command("wallets").description("List wallets with balances").action(() => walletsCommand("list"));
1211
+ program.command("fund").description("Show wallet funding instructions").action(() => walletsCommand("fund"));
1212
+ program.command("policies [subcommand] [id] [extra]").description(
1213
+ "Manage spending policies (list, all, create, update, delete, assign, unassign, add-rule, remove-rule)"
1214
+ ).action(
1215
+ (subcommand, id, extra) => policiesCommand(subcommand || "list", id, extra)
1216
+ );
1217
+ program.command("limits").description("Show spending limits and remaining budget").action(limitsCommand);
1218
+ program.command("alerts").description("List alerts").option("--unread", "Show only unread alerts").action(alertsCommand);
1219
+ program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
1220
+ program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
1221
+ program.command("logout").description("Clear stored credentials").action(async () => {
1222
+ const { clearGlobalConfig } = await import("./config-63WIUTLL.js");
1223
+ clearGlobalConfig();
1224
+ const { printSuccess: printSuccess3 } = await import("./output-6522BGYZ.js");
1225
+ printSuccess3("Logged out. Credentials cleared.");
1226
+ });
1227
+ program.command("mcp").description("Start MCP server for AI agent integration").action(mcpCommand);
1228
+ program.parse();