clawmoney 0.17.0 → 0.17.2

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.
@@ -57,15 +57,98 @@ export async function setupCommand() {
57
57
  catch {
58
58
  // Fall through — if the check fails, we still try registering.
59
59
  }
60
+ // Existing ACTIVE agent → login path: send OTP, verify, rotate key.
61
+ // This is the "I already registered on another machine / lost my api_key"
62
+ // flow — no new claim link needed.
60
63
  if (existingStatus === 'ACTIVE') {
61
- agentSpinner.warn('An active agent already exists for this email.');
62
- console.log('');
63
- console.log(chalk.yellow('If you have lost your API key, re-register and a new claim link will be sent.'));
64
- const proceed = await prompt(chalk.cyan('? ') + 'Continue with re-registration? (y/N): ');
65
- if (!/^y(es)?$/i.test(proceed.trim())) {
64
+ agentSpinner.info('Existing agent found. Sending login code to your email...');
65
+ try {
66
+ const loginResp = await apiPost('/api/v1/claw-agents/login', { email });
67
+ if (!loginResp.ok) {
68
+ console.error(chalk.red(JSON.stringify(loginResp.data)));
69
+ return;
70
+ }
71
+ }
72
+ catch (err) {
73
+ console.error(chalk.red(err.message));
66
74
  return;
67
75
  }
68
- agentSpinner.start('Checking agent status...');
76
+ const otp = await prompt(chalk.cyan('? ') + 'Enter the 6-digit code from your email: ');
77
+ if (!otp || !/^\d{4,8}$/.test(otp.trim())) {
78
+ console.log(chalk.red('Invalid code.'));
79
+ return;
80
+ }
81
+ const verifySpinner = ora('Verifying code...').start();
82
+ let loginData;
83
+ try {
84
+ const verifyResp = await apiPost('/api/v1/claw-agents/login/verify', { email, otp: otp.trim() });
85
+ if (!verifyResp.ok) {
86
+ verifySpinner.fail('Verification failed');
87
+ console.error(chalk.red(JSON.stringify(verifyResp.data)));
88
+ return;
89
+ }
90
+ loginData = verifyResp.data;
91
+ }
92
+ catch (err) {
93
+ verifySpinner.fail('Verification failed');
94
+ console.error(chalk.red(err.message));
95
+ return;
96
+ }
97
+ verifySpinner.succeed('Logged in');
98
+ // Persist api_key immediately so nothing is lost if wallet provision hiccups.
99
+ saveConfig({
100
+ api_key: loginData.api_key,
101
+ agent_id: loginData.agent_id,
102
+ agent_slug: loginData.agent_slug,
103
+ email,
104
+ wallet_address: loginData.agent?.wallet_address ?? undefined,
105
+ });
106
+ // Always hit /me/wallet/balance to (a) let the backend reconcile
107
+ // legacy awal addresses to the canonical CDP address (the /login/verify
108
+ // response may still carry the stale awal value from DB), and (b) cache
109
+ // the authoritative address back to config. The returned `address` is
110
+ // the CDP account address after _ensure_agent_wallet has run.
111
+ let walletAddress = '';
112
+ const walletSpinner = ora('Reconciling CDP wallet...').start();
113
+ try {
114
+ const balResp = await apiGet('/api/v1/claw-agents/me/wallet/balance?asset=usdc', loginData.api_key);
115
+ if (balResp.ok && balResp.data?.address) {
116
+ walletAddress = balResp.data.address;
117
+ saveConfig({ wallet_address: walletAddress });
118
+ const prior = loginData.agent?.wallet_address ?? '';
119
+ if (prior && prior.toLowerCase() !== walletAddress.toLowerCase()) {
120
+ walletSpinner.succeed(`Wallet migrated: ${prior} → ${walletAddress}`);
121
+ console.log(chalk.yellow(` (Your old awal address ${prior} is no longer`));
122
+ console.log(chalk.yellow(` used by this CLI. Transfer any remaining funds manually.)`));
123
+ }
124
+ else {
125
+ walletSpinner.succeed(`Wallet ready: ${walletAddress}`);
126
+ }
127
+ }
128
+ else {
129
+ walletSpinner.warn('Wallet reconcile failed — will be created on first use.');
130
+ }
131
+ }
132
+ catch (err) {
133
+ walletSpinner.warn(`Wallet reconcile deferred: ${err.message}`);
134
+ }
135
+ // Summary.
136
+ console.log('');
137
+ console.log(chalk.green.bold(' Setup complete!'));
138
+ console.log('');
139
+ console.log(chalk.dim(` Agent ID: ${loginData.agent_id}`));
140
+ console.log(chalk.dim(` Agent Slug: ${loginData.agent_slug}`));
141
+ if (walletAddress) {
142
+ console.log(chalk.dim(` Wallet: ${walletAddress}`));
143
+ console.log(chalk.dim(` Custody: Coinbase CDP Server Wallet`));
144
+ }
145
+ console.log(chalk.dim(` Config: ${getConfigPath()}`));
146
+ console.log('');
147
+ console.log(` Next steps:`);
148
+ console.log(` ${chalk.cyan('clawmoney wallet balance')} Check your wallet balance`);
149
+ console.log(` ${chalk.cyan('clawmoney browse')} Browse available tasks`);
150
+ console.log('');
151
+ return;
69
152
  }
70
153
  // Step 3: Register agent (or re-send claim link for an UNCLAIMED agent).
71
154
  // The backend generates the anonymous slug from email hash; we never send a name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawmoney",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "ClawMoney CLI -- Earn rewards with your AI agent",
5
5
  "type": "module",
6
6
  "bin": {