@conto_finance/create-conto-agent 0.1.2 → 0.3.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 CHANGED
@@ -1,10 +1,11 @@
1
1
  import {
2
+ CLI_PACKAGE_VERSION,
2
3
  browserAuth,
3
4
  createApiClient,
4
5
  fetchChains,
5
6
  getChain,
6
7
  runInit
7
- } from "./chunk-AWKUQSTP.js";
8
+ } from "./chunk-ICDSTI2Z.js";
8
9
  import {
9
10
  isJsonMode,
10
11
  printAmount,
@@ -18,12 +19,12 @@ import {
18
19
  printTable,
19
20
  setJsonMode,
20
21
  truncateAddress
21
- } from "./chunk-6TRDZ4JG.js";
22
+ } from "./chunk-K4LBO234.js";
22
23
  import {
23
24
  loadConfig,
24
25
  loadGlobalConfig,
25
26
  saveGlobalConfig
26
- } from "./chunk-NK52PCTE.js";
27
+ } from "./chunk-OS5PZNRM.js";
27
28
 
28
29
  // src/cli.ts
29
30
  import { Command } from "commander";
@@ -49,6 +50,7 @@ async function statusCommand() {
49
50
  printKeyValue("Name", info.agent.name);
50
51
  printKeyValue("Type", info.agent.agentType);
51
52
  printKeyValue("Status", info.agent.status);
53
+ printKeyValue("Server", config.baseUrl);
52
54
  printKeyValue("Wallets", String(info.walletCount));
53
55
  if (walletsData.wallets.length > 0) {
54
56
  printHeader("Wallets");
@@ -86,6 +88,153 @@ function progressBar(pct, width = 20) {
86
88
  return `${color}[${"\u2588".repeat(filled)}${"\u2591".repeat(empty)}]\x1B[0m`;
87
89
  }
88
90
 
91
+ // src/commands/doctor.ts
92
+ import chalk from "chalk";
93
+ function mark(status) {
94
+ if (status === "ok") return chalk.green("\u2713");
95
+ if (status === "warn") return chalk.yellow("\u26A0");
96
+ return chalk.red("\u2717");
97
+ }
98
+ async function doctorCommand() {
99
+ const config = loadConfig();
100
+ const checks = [];
101
+ checks.push({
102
+ name: "Base URL",
103
+ status: "ok",
104
+ detail: config.baseUrl
105
+ });
106
+ if (!config.apiKey) {
107
+ checks.push({
108
+ name: "SDK key",
109
+ status: "fail",
110
+ detail: 'No CONTO_API_KEY found. Run "npx create-conto-agent" or "conto login".'
111
+ });
112
+ report(checks, null);
113
+ process.exit(1);
114
+ }
115
+ checks.push({
116
+ name: "SDK key",
117
+ status: "ok",
118
+ detail: `${config.apiKey.slice(0, 16)}... (from ${process.env.CONTO_API_KEY ? "environment" : ".env.local or ~/.conto/config.json"})`
119
+ });
120
+ const api = createApiClient({ baseUrl: config.baseUrl, apiKey: config.apiKey });
121
+ let setup;
122
+ try {
123
+ setup = await api.getSetup();
124
+ } catch (err) {
125
+ const message = err instanceof Error ? err.message : "Request failed";
126
+ checks.push({
127
+ name: "Authentication",
128
+ status: "fail",
129
+ detail: `${config.baseUrl}/api/sdk/setup: ${message}`
130
+ });
131
+ report(checks, null);
132
+ process.exit(1);
133
+ }
134
+ checks.push({
135
+ name: "Authentication",
136
+ status: "ok",
137
+ detail: `Authenticated as agent "${setup.agent.name}"`
138
+ });
139
+ checks.push({
140
+ name: "Agent status",
141
+ status: setup.agent.status === "ACTIVE" ? "ok" : "fail",
142
+ detail: setup.agent.status === "ACTIVE" ? "ACTIVE" : `${setup.agent.status}. Activate the agent in the dashboard.`
143
+ });
144
+ const scopes = setup.scopes || [];
145
+ const canRequest = scopes.includes("payments:request");
146
+ const canExecute = scopes.includes("payments:execute");
147
+ checks.push({
148
+ name: "Scope payments:request",
149
+ status: canRequest ? "ok" : "fail",
150
+ detail: canRequest ? "Granted" : "Missing. This key cannot request payments."
151
+ });
152
+ checks.push({
153
+ name: "Scope payments:execute",
154
+ status: canExecute ? "ok" : "warn",
155
+ detail: canExecute ? "Granted" : 'Missing. "conto pay" can request but not execute. Create a new standard SDK key.'
156
+ });
157
+ const wallets = setup.wallets || [];
158
+ if (wallets.length === 0) {
159
+ checks.push({
160
+ name: "Wallet",
161
+ status: "fail",
162
+ detail: 'No wallet linked to this agent. Run "npx create-conto-agent" or link one in the dashboard.'
163
+ });
164
+ }
165
+ for (const w of wallets) {
166
+ const chainLabel = `${w.chainName} (${w.chainId})${w.isTestnet ? " testnet" : ""}`;
167
+ checks.push({
168
+ name: `Wallet ${shortAddress(w.address)}`,
169
+ status: w.status === "ACTIVE" ? "ok" : "warn",
170
+ detail: `${chainLabel}, ${w.custodyType} custody, status ${w.status}`
171
+ });
172
+ const executionMode = w.executionMode || (w.isExecutable ? "managed" : "manual");
173
+ checks.push({
174
+ name: " Execution",
175
+ status: executionMode === "managed" ? "ok" : "warn",
176
+ detail: executionMode === "managed" ? "Managed by custody provider (real transfers)" : executionMode === "manual" ? "Manual: agent signs its own transactions, then confirms via API" : "Simulated: no custody provider linked. Transfers are mocked in dev and blocked in production."
177
+ });
178
+ checks.push({
179
+ name: " Balance",
180
+ status: w.balance > 0 ? "ok" : "warn",
181
+ detail: w.balance > 0 ? `${printAmount(w.balance, w.currency)}` : `0 ${w.currency}. Fund this wallet before paying${w.isTestnet ? " (testnet faucet available via init)" : ""}.`
182
+ });
183
+ if (w.limits?.daily != null) {
184
+ checks.push({
185
+ name: " Daily limit",
186
+ status: "ok",
187
+ detail: `${printAmount(w.spent?.today ?? 0, "USD")} spent of ${printAmount(w.limits.daily, "USD")}`
188
+ });
189
+ }
190
+ }
191
+ const caps = setup.capabilities;
192
+ if (caps) {
193
+ checks.push({
194
+ name: "Payment readiness",
195
+ status: caps.canAutoExecute ? "ok" : caps.canRequestPayments ? "warn" : "fail",
196
+ detail: caps.canAutoExecute ? "Key and wallet can request and execute payments" : caps.canRequestPayments ? "Requests work; execution is limited (see checks above)" : "This key cannot request payments"
197
+ });
198
+ }
199
+ report(checks, setup);
200
+ const failed = checks.some((c) => c.status === "fail");
201
+ if (failed) process.exit(1);
202
+ }
203
+ function shortAddress(address) {
204
+ if (!address || address.length <= 14) return address;
205
+ return `${address.slice(0, 8)}...${address.slice(-6)}`;
206
+ }
207
+ function report(checks, setup) {
208
+ if (isJsonMode()) {
209
+ printJson({
210
+ ok: !checks.some((c) => c.status === "fail"),
211
+ checks: checks.map((c) => ({ name: c.name.trim(), status: c.status, detail: c.detail })),
212
+ setup
213
+ });
214
+ return;
215
+ }
216
+ printHeader("Conto Doctor");
217
+ for (const c of checks) {
218
+ console.log(` ${mark(c.status)} ${chalk.bold(c.name)}`);
219
+ console.log(` ${chalk.dim(c.detail)}`);
220
+ }
221
+ console.log("");
222
+ const fails = checks.filter((c) => c.status === "fail").length;
223
+ const warns = checks.filter((c) => c.status === "warn").length;
224
+ if (fails === 0 && warns === 0) {
225
+ console.log(chalk.green(" All checks passed."));
226
+ } else if (fails === 0) {
227
+ console.log(
228
+ chalk.yellow(
229
+ ` ${warns} warning${warns === 1 ? "" : "s"}. Payments may still work; read the notes above.`
230
+ )
231
+ );
232
+ } else {
233
+ console.log(chalk.red(` ${fails} check${fails === 1 ? "" : "s"} failed.`));
234
+ }
235
+ console.log("");
236
+ }
237
+
89
238
  // src/commands/balance.ts
90
239
  async function balanceCommand() {
91
240
  const config = loadConfig();
@@ -130,7 +279,7 @@ async function balanceCommand() {
130
279
  }
131
280
 
132
281
  // src/commands/pay.ts
133
- import chalk from "chalk";
282
+ import chalk2 from "chalk";
134
283
  async function payCommand(address, amountStr, options) {
135
284
  const config = loadConfig();
136
285
  if (!config.apiKey) {
@@ -173,11 +322,11 @@ async function payCommand(address, amountStr, options) {
173
322
  printError("Payment denied by policy");
174
323
  if (request.violations) {
175
324
  for (const v of request.violations) {
176
- console.log(chalk.red(` ${v.message}`));
325
+ console.log(chalk2.red(` ${v.message}`));
177
326
  }
178
327
  }
179
328
  if (request.reasons.length > 0) {
180
- console.log(chalk.dim(`
329
+ console.log(chalk2.dim(`
181
330
  Reasons: ${request.reasons.join(", ")}`));
182
331
  }
183
332
  process.exit(1);
@@ -189,7 +338,20 @@ async function payCommand(address, amountStr, options) {
189
338
  }
190
339
  printPending("Payment requires manual approval");
191
340
  printKeyValue("Request ID", request.requestId);
192
- console.log(chalk.dim(" Approve in the Conto dashboard to execute."));
341
+ console.log(chalk2.dim(" Approve in the Conto dashboard to execute."));
342
+ return;
343
+ }
344
+ if (request.status !== "APPROVED") {
345
+ if (isJsonMode()) {
346
+ printJson(request);
347
+ return;
348
+ }
349
+ printPending(`Payment is ${request.status}`);
350
+ printKeyValue("Request ID", request.requestId);
351
+ if (request.reasons.length > 0) {
352
+ console.log(chalk2.dim(` Reasons: ${request.reasons.join(", ")}`));
353
+ }
354
+ console.log(chalk2.dim(" Check the Conto dashboard for next steps."));
193
355
  return;
194
356
  }
195
357
  if (options.dryRun) {
@@ -211,7 +373,11 @@ async function payCommand(address, amountStr, options) {
211
373
  printJson(result);
212
374
  return;
213
375
  }
214
- printSuccess("Payment sent!");
376
+ if (result.simulated) {
377
+ printSuccess("Payment recorded (simulated: no onchain transfer)");
378
+ } else {
379
+ printSuccess("Payment sent!");
380
+ }
215
381
  printKeyValue("TX Hash", result.txHash);
216
382
  printKeyValue("Amount", printAmount(result.amount, result.currency));
217
383
  printKeyValue("Recipient", result.recipient);
@@ -219,11 +385,25 @@ async function payCommand(address, amountStr, options) {
219
385
  printKeyValue("Explorer", result.explorerUrl);
220
386
  console.log("");
221
387
  } catch (err) {
388
+ const code = err.code;
222
389
  const message = err instanceof Error ? err.message : "Payment failed";
223
390
  if (isJsonMode()) {
224
- printJson({ error: message });
225
- } else {
226
- printError(message);
391
+ printJson({ error: message, code });
392
+ process.exit(1);
393
+ }
394
+ printError(message);
395
+ if (code === "INSUFFICIENT_SCOPE") {
396
+ console.log(
397
+ chalk2.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
398
+ );
399
+ console.log(chalk2.dim(" or create a new standard SDK key (includes payments:execute)."));
400
+ } else if (code === "SIMULATED_EXECUTION_BLOCKED" || code === "CUSTODY_NOT_CONFIGURED") {
401
+ console.log(
402
+ chalk2.dim(
403
+ " The wallet has no custody provider linked, so it cannot execute real transfers."
404
+ )
405
+ );
406
+ console.log(chalk2.dim(' Run "conto doctor" for wallet details.'));
227
407
  }
228
408
  process.exit(1);
229
409
  }
@@ -304,7 +484,7 @@ async function transactionsCommand(id, options) {
304
484
  }
305
485
 
306
486
  // src/commands/wallets.ts
307
- import chalk2 from "chalk";
487
+ import chalk3 from "chalk";
308
488
  async function walletsCommand(subcommand) {
309
489
  const config = loadConfig();
310
490
  if (!config.apiKey) {
@@ -368,20 +548,20 @@ async function walletsCommand(subcommand) {
368
548
  console.log("");
369
549
  if (chainEntry?.faucetAvailable && config.testnet) {
370
550
  console.log(
371
- chalk2.cyan(
551
+ chalk3.cyan(
372
552
  ' This is a testnet wallet. Use "conto fund --faucet" to get free test tokens.'
373
553
  )
374
554
  );
375
555
  console.log("");
376
556
  } else {
377
- console.log(` To fund your agent wallet, send ${chalk2.bold(w.currency || "USD")} to:
557
+ console.log(` To fund your agent wallet, send ${chalk3.bold(w.currency || "USD")} to:
378
558
  `);
379
- console.log(chalk2.bold(` ${w.address}`));
559
+ console.log(chalk3.bold(` ${w.address}`));
380
560
  console.log("");
381
561
  const instructions = getFundingInstructions(w.currency || "USD", chainEntry);
382
562
  console.log(` How to get ${w.currency || "USD"}:`);
383
563
  for (const instruction of instructions) {
384
- console.log(` ${chalk2.dim("\u2022")} ${instruction}`);
564
+ console.log(` ${chalk3.dim("\u2022")} ${instruction}`);
385
565
  }
386
566
  console.log("");
387
567
  if (chainEntry) {
@@ -401,6 +581,13 @@ async function walletsCommand(subcommand) {
401
581
  }
402
582
  }
403
583
  function getFundingInstructions(currency, chain) {
584
+ if (currency === "USDC.e" && chain?.chainId === "4217") {
585
+ return [
586
+ "Bridge USDC into Tempo to receive USDC.e",
587
+ "Transfer USDC.e from another Tempo wallet",
588
+ "Swap supported Tempo assets into USDC.e"
589
+ ];
590
+ }
404
591
  if (currency === "pathUSD") {
405
592
  return [
406
593
  "Swap USDC \u2192 pathUSD on Tempo DEX",
@@ -426,7 +613,7 @@ function getFundingInstructions(currency, chain) {
426
613
  }
427
614
 
428
615
  // src/commands/policies.ts
429
- import chalk3 from "chalk";
616
+ import chalk4 from "chalk";
430
617
  import * as p from "@clack/prompts";
431
618
  var POLICY_TYPES = [
432
619
  {
@@ -728,21 +915,21 @@ async function listAgentPolicies(api) {
728
915
  }
729
916
  printHeader("Agent Policies");
730
917
  for (const policy of policies) {
731
- const scope = policy.assignedVia === "agent" ? chalk3.cyan("[agent]") : chalk3.dim("[org-wide]");
918
+ const scope = policy.assignedVia === "agent" ? chalk4.cyan("[agent]") : chalk4.dim("[org-wide]");
732
919
  console.log(
733
920
  `
734
- ${chalk3.bold(policy.name)} ${scope} ${chalk3.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
921
+ ${chalk4.bold(policy.name)} ${scope} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
735
922
  );
736
- console.log(` ${chalk3.dim("ID:")} ${policy.id}`);
923
+ console.log(` ${chalk4.dim("ID:")} ${policy.id}`);
737
924
  console.log(
738
- ` ${chalk3.dim("Active:")} ${policy.isActive ? chalk3.green("Yes") : chalk3.red("No")}`
925
+ ` ${chalk4.dim("Active:")} ${policy.isActive ? chalk4.green("Yes") : chalk4.red("No")}`
739
926
  );
740
927
  if (policy.rules.length > 0) {
741
- console.log(` ${chalk3.dim("Rules:")}`);
928
+ console.log(` ${chalk4.dim("Rules:")}`);
742
929
  for (const rule of policy.rules) {
743
930
  const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
744
931
  console.log(
745
- ` ${chalk3.dim("\u2022")} ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
932
+ ` ${chalk4.dim("\u2022")} ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
746
933
  );
747
934
  }
748
935
  }
@@ -764,18 +951,18 @@ async function listAllPolicies(api) {
764
951
  const agentCount = policy._count?.agentPolicies ?? "?";
765
952
  console.log(
766
953
  `
767
- ${chalk3.bold(policy.name)} ${chalk3.dim(`(${policy.policyType}, priority: ${policy.priority}, ${agentCount} agents)`)}`
954
+ ${chalk4.bold(policy.name)} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority}, ${agentCount} agents)`)}`
768
955
  );
769
- console.log(` ${chalk3.dim("ID:")} ${policy.id}`);
956
+ console.log(` ${chalk4.dim("ID:")} ${policy.id}`);
770
957
  console.log(
771
- ` ${chalk3.dim("Active:")} ${policy.isActive ? chalk3.green("Yes") : chalk3.red("No")}`
958
+ ` ${chalk4.dim("Active:")} ${policy.isActive ? chalk4.green("Yes") : chalk4.red("No")}`
772
959
  );
773
960
  if (policy.rules.length > 0) {
774
- console.log(` ${chalk3.dim("Rules:")}`);
961
+ console.log(` ${chalk4.dim("Rules:")}`);
775
962
  for (const rule of policy.rules) {
776
963
  const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
777
964
  console.log(
778
- ` ${chalk3.dim("\u2022")} [${rule.id.slice(-6)}] ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
965
+ ` ${chalk4.dim("\u2022")} [${rule.id.slice(-6)}] ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
779
966
  );
780
967
  }
781
968
  }
@@ -957,8 +1144,8 @@ async function promptForRule(policyType) {
957
1144
  };
958
1145
  }
959
1146
  function printPolicyHelp() {
960
- console.log(chalk3.bold("\n Conto Policy Management\n"));
961
- console.log(chalk3.bold(" Commands:"));
1147
+ console.log(chalk4.bold("\n Conto Policy Management\n"));
1148
+ console.log(chalk4.bold(" Commands:"));
962
1149
  console.log(" conto policies List agent policies");
963
1150
  console.log(" conto policies all List all org policies");
964
1151
  console.log(" conto policies create Create a new policy");
@@ -969,11 +1156,11 @@ function printPolicyHelp() {
969
1156
  console.log(" conto policies add-rule <id> Add a rule");
970
1157
  console.log(" conto policies remove-rule <id> <rid> Remove a rule");
971
1158
  console.log(" conto policies help This help page");
972
- console.log(chalk3.bold("\n Policy Types:"));
1159
+ console.log(chalk4.bold("\n Policy Types:"));
973
1160
  for (const pt of POLICY_TYPES) {
974
- console.log(` ${chalk3.cyan(pt.value.padEnd(22))} ${chalk3.dim(pt.hint)}`);
1161
+ console.log(` ${chalk4.cyan(pt.value.padEnd(22))} ${chalk4.dim(pt.hint)}`);
975
1162
  }
976
- console.log(chalk3.bold("\n Common Rule Types:"));
1163
+ console.log(chalk4.bold("\n Common Rule Types:"));
977
1164
  const commonRules = [
978
1165
  ["MAX_AMOUNT", "Max per-transaction amount (e.g. 500)"],
979
1166
  ["DAILY_LIMIT", "Max total spend per day (e.g. 1000)"],
@@ -987,33 +1174,33 @@ function printPolicyHelp() {
987
1174
  ["DATE_RANGE", 'JSON: {"start":"2025-01-01","end":"2025-12-31"}']
988
1175
  ];
989
1176
  for (const [rule, desc] of commonRules) {
990
- console.log(` ${chalk3.cyan(rule.padEnd(28))} ${chalk3.dim(desc)}`);
1177
+ console.log(` ${chalk4.cyan(rule.padEnd(28))} ${chalk4.dim(desc)}`);
991
1178
  }
992
- console.log(chalk3.bold("\n Value Examples:"));
1179
+ console.log(chalk4.bold("\n Value Examples:"));
993
1180
  console.log(" Spend limits: 500");
994
1181
  console.log(' Address lists: ["0xabc...","0xdef..."]');
995
1182
  console.log(' Country codes: ["CU","IR","KP","SY","RU"]');
996
1183
  console.log(" Trust score: 50 (0-100)");
997
1184
  console.log(' Date range: {"start":"2025-01-01","end":"2025-12-31"}');
998
1185
  console.log(' Categories: ["API_PROVIDER","CLOUD","SAAS"]');
999
- console.log(chalk3.bold("\n Operators:"));
1186
+ console.log(chalk4.bold("\n Operators:"));
1000
1187
  console.log(" LTE (<= at most) GTE (>= at least) EQUALS NOT_EQUALS");
1001
1188
  console.log(" IN_LIST NOT_IN_LIST BETWEEN DENY");
1002
- console.log(chalk3.bold("\n Actions:"));
1003
- console.log(` ${chalk3.green("ALLOW")} Payment proceeds if rule passes`);
1004
- console.log(` ${chalk3.red("DENY")} Payment is blocked`);
1005
- console.log(` ${chalk3.yellow("REQUIRE_APPROVAL")} Payment needs human approval`);
1006
- console.log(chalk3.bold("\n Examples:"));
1007
- console.log(chalk3.dim(" # Create a $500/day spend limit"));
1189
+ console.log(chalk4.bold("\n Actions:"));
1190
+ console.log(` ${chalk4.green("ALLOW")} Payment proceeds if rule passes`);
1191
+ console.log(` ${chalk4.red("DENY")} Payment is blocked`);
1192
+ console.log(` ${chalk4.yellow("REQUIRE_APPROVAL")} Payment needs human approval`);
1193
+ console.log(chalk4.bold("\n Examples:"));
1194
+ console.log(chalk4.dim(" # Create a $500/day spend limit"));
1008
1195
  console.log(" conto policies create");
1009
- console.log(chalk3.dim(" # Add a weekly limit rule to an existing policy"));
1196
+ console.log(chalk4.dim(" # Add a weekly limit rule to an existing policy"));
1010
1197
  console.log(" conto policies add-rule cmn4abc123");
1011
- console.log(chalk3.dim(" # Deactivate a policy without deleting"));
1198
+ console.log(chalk4.dim(" # Deactivate a policy without deleting"));
1012
1199
  console.log(" conto policies update cmn4abc123");
1013
- console.log(chalk3.dim(" # View all policies as JSON"));
1200
+ console.log(chalk4.dim(" # View all policies as JSON"));
1014
1201
  console.log(" conto policies all --json");
1015
1202
  console.log(`
1016
- ${chalk3.dim("Full docs: https://docs.conto.finance/cli/policies")}
1203
+ ${chalk4.dim("Full docs: https://conto.finance/docs/cli/policies")}
1017
1204
  `);
1018
1205
  }
1019
1206
  function formatRuleValue(ruleType, value) {
@@ -1030,7 +1217,7 @@ function formatRuleValue(ruleType, value) {
1030
1217
  }
1031
1218
 
1032
1219
  // src/commands/limits.ts
1033
- import chalk4 from "chalk";
1220
+ import chalk5 from "chalk";
1034
1221
  async function limitsCommand() {
1035
1222
  const config = loadConfig();
1036
1223
  if (!config.apiKey) {
@@ -1054,21 +1241,21 @@ async function limitsCommand() {
1054
1241
  printHeader("Spending Limits");
1055
1242
  for (const l of limits) {
1056
1243
  console.log(`
1057
- ${chalk4.bold(l.walletName)}`);
1244
+ ${chalk5.bold(l.walletName)}`);
1058
1245
  const dailyPct = l.daily.limit > 0 ? Math.round(l.daily.spent / l.daily.limit * 100) : 0;
1059
1246
  console.log(
1060
- ` ${chalk4.dim("Daily:")} ${bar(dailyPct)} ${printAmount(l.daily.spent, "USD")} / ${printAmount(l.daily.limit, "USD")} ${chalk4.dim(`(${printAmount(l.daily.remaining, "USD")} remaining)`)}`
1247
+ ` ${chalk5.dim("Daily:")} ${bar(dailyPct)} ${printAmount(l.daily.spent, "USD")} / ${printAmount(l.daily.limit, "USD")} ${chalk5.dim(`(${printAmount(l.daily.remaining, "USD")} remaining)`)}`
1061
1248
  );
1062
1249
  if (l.weekly) {
1063
1250
  const weeklyPct = l.weekly.limit > 0 ? Math.round(l.weekly.spent / l.weekly.limit * 100) : 0;
1064
1251
  console.log(
1065
- ` ${chalk4.dim("Weekly:")} ${bar(weeklyPct)} ${printAmount(l.weekly.spent, "USD")} / ${printAmount(l.weekly.limit, "USD")} ${chalk4.dim(`(${printAmount(l.weekly.remaining, "USD")} remaining)`)}`
1252
+ ` ${chalk5.dim("Weekly:")} ${bar(weeklyPct)} ${printAmount(l.weekly.spent, "USD")} / ${printAmount(l.weekly.limit, "USD")} ${chalk5.dim(`(${printAmount(l.weekly.remaining, "USD")} remaining)`)}`
1066
1253
  );
1067
1254
  }
1068
1255
  if (l.monthly) {
1069
1256
  const monthlyPct = l.monthly.limit > 0 ? Math.round(l.monthly.spent / l.monthly.limit * 100) : 0;
1070
1257
  console.log(
1071
- ` ${chalk4.dim("Monthly:")} ${bar(monthlyPct)} ${printAmount(l.monthly.spent, "USD")} / ${printAmount(l.monthly.limit, "USD")} ${chalk4.dim(`(${printAmount(l.monthly.remaining, "USD")} remaining)`)}`
1258
+ ` ${chalk5.dim("Monthly:")} ${bar(monthlyPct)} ${printAmount(l.monthly.spent, "USD")} / ${printAmount(l.monthly.limit, "USD")} ${chalk5.dim(`(${printAmount(l.monthly.remaining, "USD")} remaining)`)}`
1072
1259
  );
1073
1260
  }
1074
1261
  printKeyValue(" Per-TX max", printAmount(l.perTransaction, "USD"));
@@ -1092,7 +1279,7 @@ function bar(pct, width = 15) {
1092
1279
  }
1093
1280
 
1094
1281
  // src/commands/alerts.ts
1095
- import chalk5 from "chalk";
1282
+ import chalk6 from "chalk";
1096
1283
  async function alertsCommand(options = {}) {
1097
1284
  const config = loadConfig();
1098
1285
  if (!config.apiKey) {
@@ -1140,20 +1327,20 @@ async function alertsCommand(options = {}) {
1140
1327
  function severityColor(severity) {
1141
1328
  switch (severity.toUpperCase()) {
1142
1329
  case "CRITICAL":
1143
- return chalk5.red.bold(severity);
1330
+ return chalk6.red.bold(severity);
1144
1331
  case "HIGH":
1145
- return chalk5.red(severity);
1332
+ return chalk6.red(severity);
1146
1333
  case "MEDIUM":
1147
- return chalk5.yellow(severity);
1334
+ return chalk6.yellow(severity);
1148
1335
  case "LOW":
1149
- return chalk5.dim(severity);
1336
+ return chalk6.dim(severity);
1150
1337
  default:
1151
1338
  return severity;
1152
1339
  }
1153
1340
  }
1154
1341
 
1155
1342
  // src/commands/config.ts
1156
- import chalk6 from "chalk";
1343
+ import chalk7 from "chalk";
1157
1344
  async function configCommand(key, value) {
1158
1345
  if (key && value) {
1159
1346
  const global = loadGlobalConfig();
@@ -1178,20 +1365,20 @@ async function configCommand(key, value) {
1178
1365
  printHeader("Configuration");
1179
1366
  printKeyValue(
1180
1367
  "API Key",
1181
- config.apiKey ? `${config.apiKey.slice(0, 10)}...` : chalk6.dim("not set")
1368
+ config.apiKey ? `${config.apiKey.slice(0, 10)}...` : chalk7.dim("not set")
1182
1369
  );
1183
1370
  printKeyValue("Base URL", config.baseUrl);
1184
- printKeyValue("Agent ID", config.agentId || chalk6.dim("not set"));
1185
- printKeyValue("Chain", config.chainName || chalk6.dim("not set"));
1186
- printKeyValue("Chain ID", config.chainId || chalk6.dim("not set"));
1187
- printKeyValue("Currency", config.currency || chalk6.dim("not set"));
1188
- printKeyValue("Explorer", config.explorerUrl || chalk6.dim("not set"));
1189
- printKeyValue("Wallet ID", config.walletId || chalk6.dim("not set"));
1190
- printKeyValue("Wallet Address", config.walletAddress || chalk6.dim("not set"));
1371
+ printKeyValue("Agent ID", config.agentId || chalk7.dim("not set"));
1372
+ printKeyValue("Chain", config.chainName || chalk7.dim("not set"));
1373
+ printKeyValue("Chain ID", config.chainId || chalk7.dim("not set"));
1374
+ printKeyValue("Currency", config.currency || chalk7.dim("not set"));
1375
+ printKeyValue("Explorer", config.explorerUrl || chalk7.dim("not set"));
1376
+ printKeyValue("Wallet ID", config.walletId || chalk7.dim("not set"));
1377
+ printKeyValue("Wallet Address", config.walletAddress || chalk7.dim("not set"));
1191
1378
  printKeyValue("Testnet", config.testnet ? "Yes" : "No");
1192
1379
  console.log("");
1193
- console.log(chalk6.dim(" Config sources: ~/.conto/config.json + .env.local"));
1194
- console.log(chalk6.dim(" Update with: conto config <key> <value>"));
1380
+ console.log(chalk7.dim(" Config sources: ~/.conto/config.json + .env.local"));
1381
+ console.log(chalk7.dim(" Update with: conto config <key> <value>"));
1195
1382
  console.log("");
1196
1383
  }
1197
1384
 
@@ -1225,10 +1412,13 @@ async function mcpCommand() {
1225
1412
  printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
1226
1413
  process.exit(1);
1227
1414
  }
1228
- printInfo("Starting Conto MCP server...");
1229
- printInfo("Press Ctrl+C to stop.\n");
1230
- const child = spawn("npx", ["@conto_finance/mcp-server"], {
1415
+ console.error(`Starting Conto MCP server (${config.baseUrl})...`);
1416
+ console.error(`Using SDK key ${config.apiKey.slice(0, 16)}...`);
1417
+ console.error("Press Ctrl+C to stop.\n");
1418
+ const isWindows = process.platform === "win32";
1419
+ const child = spawn(isWindows ? "npx.cmd" : "npx", ["--yes", "@conto_finance/mcp-server"], {
1231
1420
  stdio: "inherit",
1421
+ shell: isWindows,
1232
1422
  env: {
1233
1423
  ...process.env,
1234
1424
  CONTO_API_KEY: config.apiKey,
@@ -1236,8 +1426,8 @@ async function mcpCommand() {
1236
1426
  }
1237
1427
  });
1238
1428
  child.on("error", (err) => {
1239
- printError(`Failed to start MCP server: ${err.message}`);
1240
- printInfo("Install it with: npm install -g @conto_finance/mcp-server");
1429
+ console.error(`Failed to start MCP server: ${err.message}`);
1430
+ console.error("Install it with: npm install -g @conto_finance/mcp-server");
1241
1431
  process.exit(1);
1242
1432
  });
1243
1433
  child.on("exit", (code) => {
@@ -1247,22 +1437,32 @@ async function mcpCommand() {
1247
1437
 
1248
1438
  // src/cli.ts
1249
1439
  var program = new Command();
1250
- program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version("0.1.0").option("--json", "Output in JSON format").hook("preAction", (thisCommand) => {
1440
+ program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (thisCommand) => {
1251
1441
  const opts = thisCommand.opts();
1252
1442
  if (opts.json) {
1253
1443
  setJsonMode(true);
1254
1444
  }
1255
1445
  });
1256
- 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) => {
1446
+ program.command("init").description("Run the setup wizard (interactive, or headless with --sandbox/--api-key)").option(
1447
+ "--chain <chain>",
1448
+ "Chain ID from /api/chains (for example 42431, 4217, 8453, solana-mainnet)"
1449
+ ).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").option("--sandbox", "Create an anonymous test-mode sandbox (headless, no account needed)").option("--api-key <key>", "Existing organization API key (skips browser authentication)").option("--no-install", "Skip installing the conto CLI into the project").action(async (opts, command) => {
1450
+ if (command.parent?.opts()?.json) {
1451
+ setJsonMode(true);
1452
+ }
1257
1453
  await runInit({
1258
1454
  chain: opts.chain,
1259
1455
  name: opts.name,
1260
1456
  type: opts.type,
1261
1457
  limit: opts.limit ? Number(opts.limit) : void 0,
1262
- baseUrl: opts.baseUrl
1458
+ baseUrl: opts.baseUrl,
1459
+ install: opts.install,
1460
+ sandbox: opts.sandbox === true,
1461
+ apiKey: opts.apiKey
1263
1462
  });
1264
1463
  });
1265
1464
  program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
1465
+ program.command("doctor").description("Diagnose setup: auth, key scopes, wallet, chain, balance, base URL").action(doctorCommand);
1266
1466
  program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
1267
1467
  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);
1268
1468
  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);
@@ -1278,23 +1478,23 @@ program.command("alerts").description("List alerts").option("--unread", "Show on
1278
1478
  program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
1279
1479
  program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
1280
1480
  program.command("logout").description("Clear stored credentials").action(async () => {
1281
- const { clearGlobalConfig } = await import("./config-CFVDT6M4.js");
1481
+ const { clearGlobalConfig } = await import("./config-EKAEJVZR.js");
1282
1482
  clearGlobalConfig();
1283
- const { printSuccess: printSuccess3 } = await import("./output-VT23PY74.js");
1483
+ const { printSuccess: printSuccess3 } = await import("./output-IN47X4NU.js");
1284
1484
  printSuccess3("Logged out. Credentials cleared.");
1285
1485
  });
1286
1486
  program.command("mcp").description("Start MCP server for AI agent integration").action(mcpCommand);
1287
1487
  program.command("docs [topic]").description("Open Conto documentation (cli, policies, sdk, api)").action(async (topic) => {
1288
1488
  const open = (await import("open")).default;
1289
1489
  const urls = {
1290
- cli: "https://docs.conto.finance/cli/quickstart",
1291
- policies: "https://docs.conto.finance/cli/policies",
1292
- commands: "https://docs.conto.finance/cli/commands",
1293
- sdk: "https://docs.conto.finance/sdk/installation",
1294
- api: "https://docs.conto.finance/api"
1490
+ cli: "https://conto.finance/docs/cli/quickstart",
1491
+ policies: "https://conto.finance/docs/cli/policies",
1492
+ commands: "https://conto.finance/docs/cli/commands",
1493
+ sdk: "https://conto.finance/docs/sdk/installation",
1494
+ api: "https://conto.finance/docs/api"
1295
1495
  };
1296
1496
  const url = urls[topic || "cli"] || urls.cli;
1297
- const { printInfo: printInfo3 } = await import("./output-VT23PY74.js");
1497
+ const { printInfo: printInfo3 } = await import("./output-IN47X4NU.js");
1298
1498
  printInfo3(`Opening ${url}`);
1299
1499
  open(url);
1300
1500
  });
@@ -6,7 +6,7 @@ import {
6
6
  saveGlobalConfig,
7
7
  writeContoConfig,
8
8
  writeEnvLocal
9
- } from "./chunk-NK52PCTE.js";
9
+ } from "./chunk-OS5PZNRM.js";
10
10
  export {
11
11
  clearGlobalConfig,
12
12
  loadConfig,