Skip to content

Commit d772eca

Browse files
committed
fix: setup docs, error integration, response shapes, bump to 0.2.2
1 parent a935531 commit d772eca

5 files changed

Lines changed: 15 additions & 41 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "context-markets-cli",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"type": "module",
55
"description": "CLI for trading on Context prediction markets",
66
"author": "Context",

skills/api-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ Response:
754754
{
755755
"status": "new_wallet",
756756
"address": "0xAddress",
757-
"privateKey": "(saved to ~/.config/context/config.env)",
757+
"saved": true,
758+
"configPath": "~/.config/context/config.env",
758759
"nextSteps": ["string"]
759760
}
760761
```

skills/onboarding.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ If you don't have a private key yet:
2222
**JSON mode** (`context setup --output json`): The key is always saved to the config file automatically, since agents can't manually back up keys. The key is never included in JSON output.
2323

2424
```bash
25-
context setup --output json
25+
context setup --output json --api-key <key>
2626
```
2727

2828
```json
@@ -85,12 +85,9 @@ context deposit 500
8585

8686
```json
8787
{
88-
"success": true,
89-
"txHash": "0x...",
90-
"user": "0xYourAddress",
91-
"token": "0x...",
92-
"amount": "500000000",
93-
"relayer": "0x..."
88+
"status": "deposited",
89+
"amount_usdc": 500,
90+
"tx_hash": "0x..."
9491
}
9592
```
9693

src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ Options:
136136
--chain <chain> Target chain (default: mainnet)
137137
--yes Skip confirmations
138138
--save Save wallet to config file (for --output json)
139+
(always on in --output json mode)
139140
140141
Agent workflow (non-interactive):
141-
context setup --output json --save Generate wallet, save to config
142+
context setup --output json Generate wallet, save to config
142143
context approve --output json Approve contracts
143144
context deposit <amount> --output json Deposit USDC`);
144145
break;

src/commands/setup.ts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44

55
import * as p from "@clack/prompts";
66
import chalk from "chalk";
7-
import { ContextApiError, type AccountStatus } from "context-markets";
7+
import type { AccountStatus } from "context-markets";
88
import { formatEther } from "viem";
99
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
1010
import { tradingClient, type ClientFlags } from "../client.js";
1111
import { out, fail, getOutputMode, requirePositional, type ParsedArgs } from "../format.js";
1212
import { loadConfig, saveConfig, configPath } from "../config.js";
13+
import { cleanErrorMessage } from "../error.js";
1314
import { confirmAction } from "../ui/prompt.js";
1415

1516
const MIN_ETH_FOR_GAS = 1_000_000_000_000n; // 0.000001 ETH — just enough for a few txs
1617
const PRIVATE_KEY_PATTERN = /^0x[0-9a-fA-F]{64}$/;
1718

18-
function isRecord(value: unknown): value is Record<string, unknown> {
19-
return typeof value === "object" && value !== null;
20-
}
21-
2219
export default async function handleSetup(parsed: ParsedArgs): Promise<void> {
2320
const { subcommand, positional, flags } = parsed;
2421

@@ -44,30 +41,6 @@ export default async function handleSetup(parsed: ParsedArgs): Promise<void> {
4441
// Shared approve → mint → deposit flow
4542
// ---------------------------------------------------------------------------
4643

47-
/** Dig through error cause chain to find the most useful message */
48-
function formatError(err: unknown): string {
49-
if (!(err instanceof Error)) return String(err);
50-
51-
// Walk the cause chain to find the deepest message
52-
let deepest = err;
53-
let current: unknown = err;
54-
while (current instanceof Error && current.cause) {
55-
current = current.cause;
56-
if (current instanceof Error) deepest = current;
57-
}
58-
59-
if (err instanceof ContextApiError) {
60-
const body = err.body;
61-
if (isRecord(body) && typeof body.message === "string") return body.message;
62-
if (typeof body === "string") return body;
63-
}
64-
65-
// Use the deepest cause message if it's more specific
66-
const deepMsg = deepest.message.split("\n")[0];
67-
const topMsg = err.message.split("\n")[0];
68-
return deepMsg !== topMsg && deepMsg.length > 5 ? `${topMsg}: ${deepMsg}` : topMsg;
69-
}
70-
7144
/**
7245
* Check ETH balance and wait for funding if needed.
7346
* Takes pre-fetched status to avoid redundant API calls.
@@ -126,7 +99,8 @@ async function approveWithRetry(ctx: ReturnType<typeof tradingClient>): Promise<
12699
return true;
127100
} catch (err) {
128101
s.stop("Approval failed");
129-
p.log.warning(formatError(err));
102+
const msg = cleanErrorMessage(err instanceof Error ? err.message : String(err));
103+
p.log.warning(msg);
130104

131105
const action = await p.select({
132106
message: "What would you like to do?",
@@ -254,7 +228,8 @@ async function onboardingFlow(ctx: ReturnType<typeof tradingClient>): Promise<bo
254228
deposited = true;
255229
} catch (err) {
256230
sp.stop("Deposit failed");
257-
p.log.warning(formatError(err));
231+
const msg = cleanErrorMessage(err instanceof Error ? err.message : String(err));
232+
p.log.warning(msg);
258233

259234
const action = await p.select({
260235
message: "What would you like to do?",

0 commit comments

Comments
 (0)