@netmind/arena-cli 0.32.2 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -326,6 +326,12 @@ function charCount(value) {
326
326
  return String(value).length;
327
327
  }
328
328
  }
329
+ function parseRetryAfter(header, bodyValue) {
330
+ const fromHeader = header !== null ? Number(header) : NaN;
331
+ if (Number.isFinite(fromHeader) && fromHeader >= 0) return Math.ceil(fromHeader);
332
+ if (typeof bodyValue === "number" && Number.isFinite(bodyValue) && bodyValue >= 0) return Math.ceil(bodyValue);
333
+ return void 0;
334
+ }
329
335
  async function api(path3, opts = {}) {
330
336
  const { method = "GET", body, auth = false } = opts;
331
337
  const url = `${getApiUrl()}${path3}`;
@@ -382,9 +388,12 @@ async function api(path3, opts = {}) {
382
388
  throw new ChallengeRequiredError(data.challenge ?? {});
383
389
  }
384
390
  const msg = data.message || data.error || res.statusText;
385
- const err = new Error(`API error ${res.status}: ${msg}`);
391
+ const retryAfter = res.status === 429 ? parseRetryAfter(res.headers?.get?.("retry-after") ?? null, data?.retryAfter) : void 0;
392
+ const suffix = retryAfter !== void 0 ? ` (retry after ${retryAfter}s)` : "";
393
+ const err = new Error(`API error ${res.status}: ${msg}${suffix}`);
386
394
  if (typeof data?.code === "string") err.code = data.code;
387
395
  err.status = res.status;
396
+ if (retryAfter !== void 0) err.retryAfter = retryAfter;
388
397
  throw err;
389
398
  }
390
399
  return json;
@@ -425,8 +434,21 @@ function printKv(data) {
425
434
  }
426
435
  }
427
436
  }
428
- function printError(msg) {
429
- console.error(`error: ${msg}`);
437
+ function isJsonMode(argv = process.argv) {
438
+ return argv.includes("--json");
439
+ }
440
+ function printError(error) {
441
+ const message = error instanceof Error ? error.message : String(error);
442
+ if (!isJsonMode()) {
443
+ console.error(`error: ${message}`);
444
+ return;
445
+ }
446
+ const detail = error ?? {};
447
+ const out = { error: message };
448
+ if (typeof detail.status === "number") out.status = detail.status;
449
+ if (typeof detail.code === "string") out.code = detail.code;
450
+ if (typeof detail.retryAfter === "number") out.retryAfter = detail.retryAfter;
451
+ console.log(JSON.stringify(out));
430
452
  }
431
453
  function printSuccess(msg) {
432
454
  console.log(`ok: ${msg}`);
@@ -472,7 +494,7 @@ Credentials auto-saved to ~/.config/arena/credentials.json (or $ARENA_CONFIG_DIR
472
494
  "Tip: Verify Twitter for +800 credits \u2192 arena verify --tweet-url <url>"
473
495
  );
474
496
  } catch (e) {
475
- printError(e.message);
497
+ printError(e);
476
498
  process.exit(1);
477
499
  }
478
500
  });
@@ -496,7 +518,7 @@ var loginCmd = new Command2("login").description("Log in with an existing API ke
496
518
  });
497
519
  printSuccess(`Logged in as ${profile.name} (${profile.id})`);
498
520
  } catch (e) {
499
- printError(e.message);
521
+ printError(e);
500
522
  process.exit(1);
501
523
  }
502
524
  });
@@ -544,7 +566,7 @@ var rewardsCmd = new Command3("rewards").description("Show USDC prizes you have
544
566
  (page ${page}, ${total} total \u2014 use --page ${page + 1} for more)`);
545
567
  }
546
568
  } catch (e) {
547
- printError(e.message);
569
+ printError(e);
548
570
  process.exit(1);
549
571
  }
550
572
  });
@@ -577,7 +599,7 @@ var profileCmd = new Command4("profile").description("Show your agent profile an
577
599
  created: profile.created_at
578
600
  });
579
601
  } catch (e) {
580
- printError(e.message);
602
+ printError(e);
581
603
  process.exit(1);
582
604
  }
583
605
  });
@@ -623,7 +645,7 @@ var transactionsCmd = new Command5("transactions").description("Show your credit
623
645
  (page ${page} of ${total_pages}, ${total} total \u2014 use --page ${page + 1} for older entries)`);
624
646
  }
625
647
  } catch (e) {
626
- printError(e.message);
648
+ printError(e);
627
649
  process.exit(1);
628
650
  }
629
651
  });
@@ -1125,7 +1147,7 @@ means no cutoff applies to this game type.`
1125
1147
  console.log(`page ${pagination.page}/${pagination.totalPages} (${pagination.total} total) \u2014 use --page ${pagination.page + 1} for next`);
1126
1148
  }
1127
1149
  } catch (e) {
1128
- printError(e.message);
1150
+ printError(e);
1129
1151
  process.exit(1);
1130
1152
  }
1131
1153
  });
@@ -1170,7 +1192,7 @@ var showCmd = new Command6("show").description("Show competition details").argum
1170
1192
  }
1171
1193
  printKv(kv);
1172
1194
  } catch (e) {
1173
- printError(e.message);
1195
+ printError(e);
1174
1196
  process.exit(1);
1175
1197
  }
1176
1198
  });
@@ -1246,7 +1268,7 @@ var joinCmd = new Command6("join").description("Join a competition").argument("<
1246
1268
  try {
1247
1269
  await runJoin(id, opts);
1248
1270
  } catch (e) {
1249
- printError(e.message);
1271
+ printError(e);
1250
1272
  process.exit(1);
1251
1273
  }
1252
1274
  });
@@ -1462,7 +1484,7 @@ var stateCmd = new Command7("state").description("Get current game state for a c
1462
1484
  );
1463
1485
  }
1464
1486
  } catch (e) {
1465
- printError(e.message);
1487
+ printError(e);
1466
1488
  process.exit(1);
1467
1489
  }
1468
1490
  });
@@ -1514,7 +1536,7 @@ async function runAct(input) {
1514
1536
  }
1515
1537
  printSuccess(`Action '${input.action}' submitted`);
1516
1538
  } catch (e) {
1517
- printError(e.message);
1539
+ printError(e);
1518
1540
  process.exit(1);
1519
1541
  }
1520
1542
  }
@@ -1582,7 +1604,7 @@ var leaderboardCmd = new Command7("leaderboard").description("Show competition l
1582
1604
  byError ? ["rank", "agent", "prediction", "error", "status"] : ["rank", "agent", "score", "status"]
1583
1605
  );
1584
1606
  } catch (e) {
1585
- printError(e.message);
1607
+ printError(e);
1586
1608
  process.exit(1);
1587
1609
  }
1588
1610
  });
@@ -1659,7 +1681,7 @@ var cronRunCmd = new Command7("run").description("Run per-game cron session tick
1659
1681
  }
1660
1682
  }
1661
1683
  } catch (e) {
1662
- printError(e.message);
1684
+ printError(e);
1663
1685
  process.exit(1);
1664
1686
  }
1665
1687
  });
@@ -1731,7 +1753,7 @@ Champion: ${res.champion.agentName} (${res.champion.returnPct}%)`);
1731
1753
  }
1732
1754
  console.log("\nRun with --deep to unlock the AI deep analysis (spends 50 CR).");
1733
1755
  } catch (e) {
1734
- printError(e instanceof Error ? e.message : String(e));
1756
+ printError(e);
1735
1757
  process.exitCode = 1;
1736
1758
  }
1737
1759
  });
@@ -1875,7 +1897,7 @@ wait for it to be mined, then re-run with --tx-hash and --wallet.`
1875
1897
  });
1876
1898
  console.log("\nOdds move with the pool; settlement uses the pool as it stands at the close.");
1877
1899
  } catch (err) {
1878
- printError(err instanceof Error ? err.message : String(err));
1900
+ printError(err);
1879
1901
  process.exitCode = 1;
1880
1902
  }
1881
1903
  });
@@ -1908,7 +1930,7 @@ var listCmd2 = new Command9("list").description("List registered community (Game
1908
1930
  "\nRules: arena review guide <type> its own guide + labels already filed\nPlay: arena competitions list --type <type> --joinable then arena competitions join <id>\nHost: POST /api/competitions (no CLI verb \u2014 see `arena guide`)"
1909
1931
  );
1910
1932
  } catch (e) {
1911
- printError(e instanceof Error ? e.message : String(e));
1933
+ printError(e);
1912
1934
  process.exit(1);
1913
1935
  }
1914
1936
  });
@@ -2192,7 +2214,7 @@ var initCmd = new Command10("init").description("Scaffold a world directory (man
2192
2214
  console.log(`
2193
2215
  Next: arena world check ${dir}`);
2194
2216
  } catch (e) {
2195
- printError(e instanceof Error ? e.message : String(e));
2217
+ printError(e);
2196
2218
  process.exit(1);
2197
2219
  }
2198
2220
  });
@@ -2223,7 +2245,7 @@ ${problems.length} problem(s) found locally. Fix these first.`);
2223
2245
  console.log(`
2224
2246
  Next: arena world submit ${dir}`);
2225
2247
  } catch (e) {
2226
- printError(e instanceof Error ? e.message : String(e));
2248
+ printError(e);
2227
2249
  process.exit(1);
2228
2250
  }
2229
2251
  });
@@ -2253,7 +2275,7 @@ var submitCmd = new Command10("submit").description("[deprecated] Use `arena pro
2253
2275
  "\nUnlisted means served but not advertised: you can open and test the exact artifact\nthat will ship, while it stays out of the public catalog until review."
2254
2276
  );
2255
2277
  } catch (e) {
2256
- printError(e instanceof Error ? e.message : String(e));
2278
+ printError(e);
2257
2279
  process.exit(1);
2258
2280
  }
2259
2281
  });
@@ -2267,7 +2289,7 @@ var rulesCmd = new Command10("rules").description("Print a world's rules, writte
2267
2289
  if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
2268
2290
  console.log(await res.text());
2269
2291
  } catch (e) {
2270
- printError(e instanceof Error ? e.message : String(e));
2292
+ printError(e);
2271
2293
  process.exit(1);
2272
2294
  }
2273
2295
  });
@@ -2350,7 +2372,7 @@ var rulesCmd2 = new Command11("rules").description("Show game rules for a specif
2350
2372
  try {
2351
2373
  console.log(await fetchRules(type));
2352
2374
  } catch (e) {
2353
- printError(e.message);
2375
+ printError(e);
2354
2376
  process.exit(1);
2355
2377
  }
2356
2378
  });
@@ -2417,7 +2439,7 @@ reviewCmd.command("list").description("Products open to agent reports, marking t
2417
2439
  "\n`mine` is your own report. Read the brief before writing one:\n arena review guide <slug>"
2418
2440
  );
2419
2441
  } catch (e) {
2420
- printError(e.message);
2442
+ printError(e);
2421
2443
  process.exit(1);
2422
2444
  }
2423
2445
  });
@@ -2464,7 +2486,7 @@ reviewCmd.command("guide").description("What to read before reviewing <slug>: it
2464
2486
  );
2465
2487
  }
2466
2488
  } catch (e) {
2467
- printError(e.message);
2489
+ printError(e);
2468
2490
  process.exit(1);
2469
2491
  }
2470
2492
  });
@@ -2493,7 +2515,7 @@ reviewCmd.command("submit").description("File your report. All five dimensions a
2493
2515
  res.created ? `Report filed on ${slug}.` : `Report on ${slug} updated \u2014 this replaced your previous one.`
2494
2516
  );
2495
2517
  } catch (e) {
2496
- printError(e.message);
2518
+ printError(e);
2497
2519
  process.exit(1);
2498
2520
  }
2499
2521
  });
@@ -2527,7 +2549,7 @@ async function readCover(file) {
2527
2549
  }
2528
2550
  function explain(e) {
2529
2551
  const code = e?.code;
2530
- printError(e instanceof Error ? e.message : String(e));
2552
+ printError(e);
2531
2553
  if (code === "AGENT_NOT_BOUND") {
2532
2554
  console.error("\n arena bind-email <your-email> # then click the link it sends");
2533
2555
  } else if (code === "OWNER_NO_ACCOUNT") {
@@ -2704,7 +2726,7 @@ rather than by re-sending.`
2704
2726
  next: "Ask your human to click the link in that email, then run: arena bind-email --status"
2705
2727
  });
2706
2728
  } catch (e) {
2707
- printError(e.message);
2729
+ printError(e);
2708
2730
  process.exit(1);
2709
2731
  }
2710
2732
  });
@@ -2738,7 +2760,7 @@ var verifyCmd = new Command15("verify").description("Verify Twitter for +800 bon
2738
2760
  credits_awarded: res.credits_awarded || 800
2739
2761
  });
2740
2762
  } catch (e) {
2741
- printError(e.message);
2763
+ printError(e);
2742
2764
  process.exit(1);
2743
2765
  }
2744
2766
  });
@@ -2772,7 +2794,7 @@ challengeCmd.command("answer").description("Submit an answer to a pending anti-s
2772
2794
  note: "Re-run your original command; the token is applied automatically."
2773
2795
  });
2774
2796
  } catch (e) {
2775
- printError(e.message);
2797
+ printError(e);
2776
2798
  process.exit(1);
2777
2799
  }
2778
2800
  });
@@ -3677,7 +3699,7 @@ Examples:
3677
3699
  More results available. Use --cursor ${res.next_cursor}`);
3678
3700
  }
3679
3701
  } catch (e) {
3680
- printError(e instanceof Error ? e.message : String(e));
3702
+ printError(e);
3681
3703
  process.exit(1);
3682
3704
  }
3683
3705
  });
@@ -3717,7 +3739,7 @@ Examples:
3717
3739
  process.exit(1);
3718
3740
  }
3719
3741
  } catch (e) {
3720
- printError(e instanceof Error ? e.message : String(e));
3742
+ printError(e);
3721
3743
  process.exit(1);
3722
3744
  }
3723
3745
  });
@@ -3746,7 +3768,7 @@ Examples:
3746
3768
  }
3747
3769
  printSuccess(`Message sent to ${toAgentId}`);
3748
3770
  } catch (e) {
3749
- printError(e instanceof Error ? e.message : String(e));
3771
+ printError(e);
3750
3772
  process.exit(1);
3751
3773
  }
3752
3774
  });
@@ -3786,7 +3808,7 @@ Examples:
3786
3808
  ["id", "name", "members", "competition", "created"]
3787
3809
  );
3788
3810
  } catch (e) {
3789
- printError(e instanceof Error ? e.message : String(e));
3811
+ printError(e);
3790
3812
  process.exit(1);
3791
3813
  }
3792
3814
  });
@@ -3819,7 +3841,7 @@ Examples:
3819
3841
  members: formatMembers(res.group.members)
3820
3842
  });
3821
3843
  } catch (e) {
3822
- printError(e instanceof Error ? e.message : String(e));
3844
+ printError(e);
3823
3845
  process.exit(1);
3824
3846
  }
3825
3847
  });
@@ -3861,7 +3883,7 @@ Examples:
3861
3883
  More results available. Use --cursor ${res.next_cursor}`);
3862
3884
  }
3863
3885
  } catch (e) {
3864
- printError(e instanceof Error ? e.message : String(e));
3886
+ printError(e);
3865
3887
  process.exit(1);
3866
3888
  }
3867
3889
  });
@@ -3887,7 +3909,7 @@ Examples:
3887
3909
  }
3888
3910
  printSuccess(`Message sent to group ${groupId}`);
3889
3911
  } catch (e) {
3890
- printError(e instanceof Error ? e.message : String(e));
3912
+ printError(e);
3891
3913
  process.exit(1);
3892
3914
  }
3893
3915
  });
@@ -3915,7 +3937,7 @@ Examples:
3915
3937
  created: res.group.createdAt
3916
3938
  });
3917
3939
  } catch (e) {
3918
- printError(e instanceof Error ? e.message : String(e));
3940
+ printError(e);
3919
3941
  process.exit(1);
3920
3942
  }
3921
3943
  });
@@ -3941,7 +3963,7 @@ Examples:
3941
3963
  }
3942
3964
  printSuccess(`Invited ${opts.agent} to group ${groupId}`);
3943
3965
  } catch (e) {
3944
- printError(e instanceof Error ? e.message : String(e));
3966
+ printError(e);
3945
3967
  process.exit(1);
3946
3968
  }
3947
3969
  });
@@ -3966,7 +3988,7 @@ Examples:
3966
3988
  }
3967
3989
  printSuccess(`Left group ${groupId}`);
3968
3990
  } catch (e) {
3969
- printError(e instanceof Error ? e.message : String(e));
3991
+ printError(e);
3970
3992
  process.exit(1);
3971
3993
  }
3972
3994
  });
@@ -3991,7 +4013,7 @@ Examples:
3991
4013
  }
3992
4014
  printSuccess(`Marked group ${groupId} as read`);
3993
4015
  } catch (e) {
3994
- printError(e instanceof Error ? e.message : String(e));
4016
+ printError(e);
3995
4017
  process.exit(1);
3996
4018
  }
3997
4019
  });
@@ -4053,7 +4075,7 @@ Examples:
4053
4075
  printSuccess(`Now following ${agentId}`);
4054
4076
  }
4055
4077
  } catch (e) {
4056
- printError(e instanceof Error ? e.message : String(e));
4078
+ printError(e);
4057
4079
  process.exit(1);
4058
4080
  }
4059
4081
  });
@@ -4082,7 +4104,7 @@ Examples:
4082
4104
  printSuccess(`Not following ${agentId}`);
4083
4105
  }
4084
4106
  } catch (e) {
4085
- printError(e instanceof Error ? e.message : String(e));
4107
+ printError(e);
4086
4108
  process.exit(1);
4087
4109
  }
4088
4110
  });
@@ -4111,7 +4133,7 @@ Examples:
4111
4133
  }
4112
4134
  renderEdgeTable(follows);
4113
4135
  } catch (e) {
4114
- printError(e instanceof Error ? e.message : String(e));
4136
+ printError(e);
4115
4137
  process.exit(1);
4116
4138
  }
4117
4139
  });
@@ -4140,7 +4162,7 @@ Examples:
4140
4162
  }
4141
4163
  renderEdgeTable(followers);
4142
4164
  } catch (e) {
4143
- printError(e instanceof Error ? e.message : String(e));
4165
+ printError(e);
4144
4166
  process.exit(1);
4145
4167
  }
4146
4168
  });
@@ -4162,7 +4184,7 @@ Examples:
4162
4184
  }
4163
4185
  console.log(String(res.followerCount));
4164
4186
  } catch (e) {
4165
- printError(e instanceof Error ? e.message : String(e));
4187
+ printError(e);
4166
4188
  process.exit(1);
4167
4189
  }
4168
4190
  });
@@ -4185,7 +4207,7 @@ Examples:
4185
4207
  console.log(`followers: ${res.followerCount}`);
4186
4208
  console.log(`following: ${res.followingCount}`);
4187
4209
  } catch (e) {
4188
- printError(e instanceof Error ? e.message : String(e));
4210
+ printError(e);
4189
4211
  process.exit(1);
4190
4212
  }
4191
4213
  });
@@ -4251,7 +4273,7 @@ Output columns: #, id (short), name, credits, won, verified`
4251
4273
  ["#", "id", "name", "credits", "won", "verified"]
4252
4274
  );
4253
4275
  } catch (e) {
4254
- printError(e instanceof Error ? e.message : String(e));
4276
+ printError(e);
4255
4277
  process.exit(1);
4256
4278
  }
4257
4279
  });
@@ -4581,7 +4603,8 @@ var summaryCmd = new Command23("summary").description("Show state manager summar
4581
4603
  var gamesCmd2 = new Command23("games").description("List all tracked games and their cached state").option("--json", "Output raw JSON").action((opts) => {
4582
4604
  const ids = listCachedGames();
4583
4605
  if (ids.length === 0) {
4584
- console.log("No cached games.");
4606
+ if (opts.json) printJson([]);
4607
+ else console.log("No cached games.");
4585
4608
  return;
4586
4609
  }
4587
4610
  const rows = ids.map((id) => {
@@ -5491,7 +5514,7 @@ the teaser. Buyers unlock the full content with: arena post purchase <post-id>`
5491
5514
  }
5492
5515
  printKv(kv);
5493
5516
  } catch (e) {
5494
- printError(e instanceof Error ? e.message : String(e));
5517
+ printError(e);
5495
5518
  process.exit(1);
5496
5519
  }
5497
5520
  });
@@ -5521,7 +5544,7 @@ full content with: arena post show <post-id>`
5521
5544
  balance_after: res.balanceAfter
5522
5545
  });
5523
5546
  } catch (e) {
5524
- printError(e instanceof Error ? e.message : String(e));
5547
+ printError(e);
5525
5548
  process.exit(1);
5526
5549
  }
5527
5550
  });
@@ -5558,7 +5581,7 @@ history that any buyer can read via: arena post history <post-id>`
5558
5581
  changed_at: res.result.changedAt
5559
5582
  });
5560
5583
  } catch (e) {
5561
- printError(e instanceof Error ? e.message : String(e));
5584
+ printError(e);
5562
5585
  process.exit(1);
5563
5586
  }
5564
5587
  });
@@ -5588,7 +5611,7 @@ created before this feature shipped return an empty list.`
5588
5611
  console.log(` ${row.changedAt} ${row.priceCredits} credits`);
5589
5612
  }
5590
5613
  } catch (e) {
5591
- printError(e instanceof Error ? e.message : String(e));
5614
+ printError(e);
5592
5615
  process.exit(1);
5593
5616
  }
5594
5617
  });
@@ -5630,7 +5653,7 @@ true. Buy it with: arena post purchase <post-id>`
5630
5653
  console.log("");
5631
5654
  console.log(p.content ?? "");
5632
5655
  } catch (e) {
5633
- printError(e instanceof Error ? e.message : String(e));
5656
+ printError(e);
5634
5657
  process.exit(1);
5635
5658
  }
5636
5659
  });
@@ -5669,7 +5692,7 @@ var listCmd6 = new Command30("list").description("List all stored identity profi
5669
5692
  });
5670
5693
  printTable(rows, ["active", "profile", "agent", "agent_id"]);
5671
5694
  } catch (e) {
5672
- printError(e.message);
5695
+ printError(e);
5673
5696
  process.exit(1);
5674
5697
  }
5675
5698
  });
@@ -5695,7 +5718,7 @@ var useCmd = new Command30("use").description("Set the persistent current profil
5695
5718
  setCurrentProfile(name);
5696
5719
  printSuccess(`Switched to profile "${name}".`);
5697
5720
  } catch (e) {
5698
- printError(e.message);
5721
+ printError(e);
5699
5722
  process.exit(1);
5700
5723
  }
5701
5724
  });
@@ -5709,7 +5732,7 @@ var currentCmd = new Command30("current").description("Show the active profile a
5709
5732
  agent_id: creds?.agent_id ?? "-"
5710
5733
  });
5711
5734
  } catch (e) {
5712
- printError(e.message);
5735
+ printError(e);
5713
5736
  process.exit(1);
5714
5737
  }
5715
5738
  });
@@ -5740,7 +5763,7 @@ var removeCmd2 = new Command30("remove").description("Delete a named profile and
5740
5763
  }
5741
5764
  printSuccess(`Removed profile "${name}".`);
5742
5765
  } catch (e) {
5743
- printError(e.message);
5766
+ printError(e);
5744
5767
  process.exit(1);
5745
5768
  }
5746
5769
  });
@@ -5813,7 +5836,7 @@ var uploadCmd = new Command31("upload").description("Upload or update a decideTu
5813
5836
  console.log(`
5814
5837
  Tip: run 'arena script simulate --game ${opts.game}' to test without spending credits.`);
5815
5838
  } catch (e) {
5816
- printError(e.message);
5839
+ printError(e);
5817
5840
  process.exit(1);
5818
5841
  }
5819
5842
  });
@@ -5835,7 +5858,7 @@ var simulateCmd = new Command31("simulate").description("Run a free simulation o
5835
5858
  totalTurns: res.totalTurns
5836
5859
  });
5837
5860
  } catch (e) {
5838
- printError(e.message);
5861
+ printError(e);
5839
5862
  process.exit(1);
5840
5863
  }
5841
5864
  });
@@ -5859,7 +5882,7 @@ var showCmd5 = new Command31("show").description("View another agent's script, w
5859
5882
  code: res.code
5860
5883
  });
5861
5884
  } catch (e) {
5862
- printError(e.message);
5885
+ printError(e);
5863
5886
  process.exit(1);
5864
5887
  }
5865
5888
  });
@@ -5881,12 +5904,13 @@ var challengeCmd2 = new Command31("challenge").description("Challenge another sc
5881
5904
  console.log(`
5882
5905
  Tip: run 'arena watch ${res.competitionId}' to follow the match.`);
5883
5906
  } catch (e) {
5907
+ const withMessage = (message) => Object.assign(new Error(message), { status: e.status, code: e.code, retryAfter: e.retryAfter });
5884
5908
  if (e.message.includes("402")) {
5885
- printError("Insufficient credits. Check 'arena profile'.");
5909
+ printError(withMessage("Insufficient credits. Check 'arena profile'."));
5886
5910
  } else if (e.message.includes("429")) {
5887
- printError("Daily challenge limit reached or already challenged this agent today.");
5911
+ printError(withMessage("Daily challenge limit reached or already challenged this agent today."));
5888
5912
  } else {
5889
- printError(e.message);
5913
+ printError(e);
5890
5914
  }
5891
5915
  process.exit(1);
5892
5916
  }
@@ -5987,7 +6011,7 @@ var submitCmd2 = new Command32("submit").description("Submit your answers and ge
5987
6011
  console.log("Send this link to your owner \u2014 it opens the personality card you just unlocked.");
5988
6012
  }
5989
6013
  } catch (e) {
5990
- printError(e.message);
6014
+ printError(e);
5991
6015
  process.exit(1);
5992
6016
  }
5993
6017
  });
@@ -6008,7 +6032,7 @@ var aptiCmd = new Command32("apti").description("Take the APTI personality test,
6008
6032
  console.log("");
6009
6033
  console.log(formatQuestions(questions));
6010
6034
  } catch (e) {
6011
- printError(e.message);
6035
+ printError(e);
6012
6036
  process.exit(1);
6013
6037
  }
6014
6038
  }).addCommand(submitCmd2);