Skip to content

Commit 56a9780

Browse files
Copilotfuxingloh
andcommitted
feat: implement use-agently doctor command (USE-8)
Co-authored-by: fuxingloh <4266087+fuxingloh@users.noreply.github.com>
1 parent 1d075cb commit 56a9780

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ npm install -g use-agently
1616
# Initialize a new wallet
1717
use-agently init
1818

19+
# Run environment checks
20+
use-agently doctor
21+
1922
# Check your wallet info
2023
use-agently whoami
2124

@@ -40,6 +43,23 @@ use-agently init
4043
use-agently init --regenerate # Backup existing config and generate a new wallet
4144
```
4245

46+
### `doctor`
47+
48+
Run environment checks to verify your setup is working correctly.
49+
50+
```bash
51+
use-agently doctor
52+
use-agently doctor --rpc https://mainnet.base.org # Use a custom RPC URL for network check
53+
```
54+
55+
Checks:
56+
57+
- Wallet is configured
58+
- Wallet is loadable (private key is valid)
59+
- Network is reachable (Base RPC)
60+
61+
Exits with a non-zero status code if any check fails.
62+
4363
### `whoami`
4464

4565
Show current wallet type and address.

packages/use-agently/src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { whoamiCommand } from "./commands/whoami.js";
44
import { balanceCommand } from "./commands/balance.js";
55
import { agentsCommand } from "./commands/agents.js";
66
import { a2aCommand } from "./commands/a2a.js";
7+
import { doctorCommand } from "./commands/doctor.js";
78

89
export const cli = new Command();
910

@@ -14,3 +15,4 @@ cli.addCommand(whoamiCommand);
1415
cli.addCommand(balanceCommand);
1516
cli.addCommand(agentsCommand);
1617
cli.addCommand(a2aCommand);
18+
cli.addCommand(doctorCommand);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Command } from "commander";
2+
import { createPublicClient, http } from "viem";
3+
import { base } from "viem/chains";
4+
import { loadConfig } from "../config.js";
5+
import { loadWallet } from "../wallets/wallet.js";
6+
7+
const PASS = "✓";
8+
const FAIL = "✗";
9+
10+
interface Check {
11+
name: string;
12+
ok: boolean;
13+
message?: string;
14+
}
15+
16+
export const doctorCommand = new Command("doctor")
17+
.description("Run environment checks and report any issues")
18+
.option("--rpc <url>", "Custom RPC URL to use for network check")
19+
.action(async (options: { rpc?: string }) => {
20+
const checks: Check[] = [];
21+
22+
// Check 1: config file exists and has a wallet
23+
const config = await loadConfig();
24+
const hasWallet = !!config?.wallet;
25+
checks.push({
26+
name: "Wallet configured",
27+
ok: hasWallet,
28+
message: hasWallet ? undefined : "No wallet found. Run `use-agently init` to create one.",
29+
});
30+
31+
// Check 2: wallet is loadable (private key is valid)
32+
let walletOk = false;
33+
let walletMessage: string | undefined;
34+
if (hasWallet) {
35+
try {
36+
const wallet = loadWallet(config.wallet);
37+
walletOk = !!wallet;
38+
} catch (err) {
39+
walletMessage = err instanceof Error ? err.message : String(err);
40+
}
41+
} else {
42+
walletMessage = "Skipped (no wallet configured).";
43+
}
44+
checks.push({ name: "Wallet loadable", ok: walletOk, message: walletMessage });
45+
46+
// Check 3: network reachable (RPC endpoint)
47+
let networkOk = false;
48+
let networkMessage: string | undefined;
49+
try {
50+
const client = createPublicClient({ chain: base, transport: http(options.rpc) });
51+
await client.getChainId();
52+
networkOk = true;
53+
} catch (err) {
54+
networkMessage = err instanceof Error ? err.message : String(err);
55+
}
56+
checks.push({ name: "Network reachable (Base RPC)", ok: networkOk, message: networkMessage });
57+
58+
// Print results
59+
let allOk = true;
60+
for (const check of checks) {
61+
const icon = check.ok ? PASS : FAIL;
62+
console.log(`${icon} ${check.name}${check.message ? `: ${check.message}` : ""}`);
63+
if (!check.ok) allOk = false;
64+
}
65+
66+
if (!allOk) {
67+
process.exit(1);
68+
}
69+
});

skills/use-agently/SKILL.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ This generates a local EVM private key and saves it to `~/.use-agently/config.js
3232
## Core Workflow
3333

3434
1. **Initialize**: `use-agently init` — Create a local EVM wallet
35-
2. **Fund**: Send USDC (on Base) to the wallet address shown
36-
3. **Discover**: `use-agently agents` — Browse available agents on Agently
37-
4. **Communicate**: `use-agently a2a <agent-url> -m "message"` — Send messages to agents
38-
5. **Check balance**: `use-agently balance` — Monitor on-chain funds
35+
2. **Verify**: `use-agently doctor` — Check your environment is set up correctly
36+
3. **Fund**: Send USDC (on Base) to the wallet address shown
37+
4. **Discover**: `use-agently agents` — Browse available agents on Agently
38+
5. **Communicate**: `use-agently a2a <agent-url> -m "message"` — Send messages to agents
39+
6. **Check balance**: `use-agently balance` — Monitor on-chain funds
3940

4041
## Commands
4142

@@ -48,6 +49,15 @@ use-agently init --regenerate # Backup existing config and create new wall
4849

4950
Wallet config is stored at `~/.use-agently/config.json`. Using `--regenerate` creates a timestamped backup before generating a new wallet.
5051

52+
### Environment Check
53+
54+
```bash
55+
use-agently doctor # Run all environment checks
56+
use-agently doctor --rpc <url> # Use a custom RPC URL for the network check
57+
```
58+
59+
Checks wallet configuration, wallet validity, and network reachability. Exits with a non-zero status code if any check fails.
60+
5161
### Wallet Info
5262

5363
```bash

0 commit comments

Comments
 (0)