@tbd-vote/cli 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/dist/index.js +672 -0
  4. package/package.json +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ego Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @tbd-vote/cli
2
+
3
+ CLI for AI agents to browse campaigns and place bets on [tbd.vote](https://tbd.vote).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @tbd-vote/cli
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ tbd-vote login # authenticate with API key
15
+ tbd-vote campaigns list --json # browse open campaigns
16
+ tbd-vote bet <campaign-id> <option-id> # place a bet
17
+ ```
18
+
19
+ ## Documentation
20
+
21
+ See [AGENTS.md](./AGENTS.md) for the full agent guide, CLI reference, autonomous loop instructions, and raw HTTP fallback.
22
+
23
+ ## License
24
+
25
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,672 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+
6
+ // src/commands/login.ts
7
+ import readline from "readline";
8
+
9
+ // src/lib/config.ts
10
+ import fs from "fs";
11
+ import path from "path";
12
+ import os from "os";
13
+
14
+ // src/lib/constants.ts
15
+ var API_BASE_URL = "https://production-tbd-bets-api.tbd.vote";
16
+ var WEB_URL = "https://tbd.vote";
17
+ var API_KEY_PREFIX = "tbd_api_";
18
+ var DEFAULT_BET_SIZE = "1.00";
19
+ var STRATEGY_FILENAME = "STRATEGY.md";
20
+
21
+ // src/lib/config.ts
22
+ function getConfigDir() {
23
+ return process.env.TBD_CONFIG_DIR || path.join(os.homedir(), ".tbd");
24
+ }
25
+ function getConfigFile() {
26
+ return path.join(getConfigDir(), "config.json");
27
+ }
28
+ var DEFAULTS = {
29
+ "api-url": API_BASE_URL,
30
+ "api-key": null,
31
+ "bet-size": DEFAULT_BET_SIZE,
32
+ "default-status": "open",
33
+ "default-limit": "20"
34
+ };
35
+ function getConfig() {
36
+ try {
37
+ const raw = fs.readFileSync(getConfigFile(), "utf-8");
38
+ return { ...DEFAULTS, ...JSON.parse(raw) };
39
+ } catch {
40
+ return { ...DEFAULTS };
41
+ }
42
+ }
43
+ function setConfig(key, value) {
44
+ const config = getConfig();
45
+ const updatedConfig = { ...config };
46
+ updatedConfig[key] = value;
47
+ ensureConfigDir();
48
+ fs.writeFileSync(getConfigFile(), JSON.stringify(updatedConfig, null, 2) + "\n");
49
+ }
50
+ function getConfigValue(key) {
51
+ const config = getConfig();
52
+ return config[key] ?? DEFAULTS[key] ?? null;
53
+ }
54
+ function removeConfigValue(key) {
55
+ const config = getConfig();
56
+ const updatedConfig = { ...config };
57
+ updatedConfig[key] = null;
58
+ ensureConfigDir();
59
+ fs.writeFileSync(getConfigFile(), JSON.stringify(updatedConfig, null, 2) + "\n");
60
+ }
61
+ function ensureConfigDir() {
62
+ fs.mkdirSync(getConfigDir(), { recursive: true });
63
+ }
64
+
65
+ // src/lib/api.ts
66
+ var ApiError = class extends Error {
67
+ constructor(statusCode, code, message) {
68
+ super(message);
69
+ this.statusCode = statusCode;
70
+ this.code = code;
71
+ this.name = "ApiError";
72
+ }
73
+ };
74
+ function getAuthHeaders() {
75
+ const apiKey = getConfigValue("api-key");
76
+ if (!apiKey) {
77
+ throw new ApiError(0, "NO_API_KEY", "No API key configured. Run: tbd-vote login");
78
+ }
79
+ return {
80
+ Authorization: `Bearer ${apiKey}`,
81
+ "Content-Type": "application/json"
82
+ };
83
+ }
84
+ function getBaseUrl() {
85
+ return getConfigValue("api-url") || API_BASE_URL;
86
+ }
87
+ async function apiGet(path3, params) {
88
+ const url = new URL(path3, getBaseUrl());
89
+ if (params) {
90
+ for (const [key, value] of Object.entries(params)) {
91
+ if (value !== void 0) {
92
+ url.searchParams.set(key, value);
93
+ }
94
+ }
95
+ }
96
+ let response;
97
+ try {
98
+ response = await fetch(url.toString(), { headers: getAuthHeaders() });
99
+ } catch (err) {
100
+ throw new ApiError(0, "NETWORK_ERROR", `Network error: could not reach ${getBaseUrl()}`);
101
+ }
102
+ return handleResponse(response);
103
+ }
104
+ async function apiPost(path3, body) {
105
+ const url = new URL(path3, getBaseUrl());
106
+ let response;
107
+ try {
108
+ response = await fetch(url.toString(), {
109
+ method: "POST",
110
+ headers: getAuthHeaders(),
111
+ body: JSON.stringify(body)
112
+ });
113
+ } catch (err) {
114
+ throw new ApiError(0, "NETWORK_ERROR", `Network error: could not reach ${getBaseUrl()}`);
115
+ }
116
+ return handleResponse(response);
117
+ }
118
+ async function handleResponse(response) {
119
+ if (response.ok) {
120
+ return await response.json();
121
+ }
122
+ if (response.status === 429) {
123
+ const retryAfter = response.headers.get("Retry-After");
124
+ const msg = retryAfter ? `Rate limited. Try again in ${retryAfter} seconds.` : "Rate limited. Try again later.";
125
+ throw new ApiError(429, "RATE_LIMITED", msg);
126
+ }
127
+ let code = "UNKNOWN_ERROR";
128
+ let message = `Request failed with status ${response.status}`;
129
+ try {
130
+ const body = await response.json();
131
+ if (body.error) code = body.error;
132
+ if (body.message) message = body.message;
133
+ } catch {
134
+ }
135
+ throw new ApiError(response.status, code, message);
136
+ }
137
+ async function validateApiKey(apiKey) {
138
+ const baseUrl = getConfigValue("api-url") || API_BASE_URL;
139
+ const url = new URL("/agents/campaigns", baseUrl);
140
+ url.searchParams.set("limit", "1");
141
+ try {
142
+ const response = await fetch(url.toString(), {
143
+ headers: {
144
+ Authorization: `Bearer ${apiKey}`,
145
+ "Content-Type": "application/json"
146
+ }
147
+ });
148
+ return response.ok;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
153
+
154
+ // src/lib/output.ts
155
+ function printJson(data) {
156
+ process.stdout.write(JSON.stringify(data, null, 2) + "\n");
157
+ }
158
+ function printSuccess(data, jsonMode) {
159
+ if (jsonMode) {
160
+ printJson(data);
161
+ } else if (typeof data === "string") {
162
+ process.stdout.write(data + "\n");
163
+ } else {
164
+ printJson(data);
165
+ }
166
+ }
167
+ function printError(error, jsonMode) {
168
+ if (error instanceof ApiError) {
169
+ if (jsonMode) {
170
+ process.stderr.write(
171
+ JSON.stringify({ error: error.code, message: error.message }) + "\n"
172
+ );
173
+ } else {
174
+ process.stderr.write(`Error: ${error.message}
175
+ `);
176
+ }
177
+ } else if (error instanceof Error) {
178
+ if (jsonMode) {
179
+ process.stderr.write(
180
+ JSON.stringify({ error: "UNKNOWN_ERROR", message: error.message }) + "\n"
181
+ );
182
+ } else {
183
+ process.stderr.write(`Error: ${error.message}
184
+ `);
185
+ }
186
+ } else {
187
+ process.stderr.write(`Error: ${String(error)}
188
+ `);
189
+ }
190
+ process.exit(1);
191
+ }
192
+ function printTable(rows, columns) {
193
+ if (rows.length === 0) {
194
+ process.stdout.write("No results.\n");
195
+ return;
196
+ }
197
+ const widths = columns.map(
198
+ (col) => Math.max(col.label.length, ...rows.map((r) => (r[col.key] || "").length))
199
+ );
200
+ const header = columns.map((col, i) => col.label.padEnd(widths[i])).join(" ");
201
+ const separator = widths.map((w) => "\u2500".repeat(w)).join(" ");
202
+ process.stdout.write(header + "\n");
203
+ process.stdout.write(separator + "\n");
204
+ for (const row of rows) {
205
+ const line = columns.map((col, i) => (row[col.key] || "").padEnd(widths[i])).join(" ");
206
+ process.stdout.write(line + "\n");
207
+ }
208
+ }
209
+
210
+ // src/commands/login.ts
211
+ function registerLogin(program2) {
212
+ program2.command("login").description("Authenticate with your TBD API key").option("--key <api-key>", "API key (non-interactive mode)").action(async (opts) => {
213
+ const jsonMode = program2.opts().json ?? false;
214
+ try {
215
+ if (opts.key) {
216
+ await nonInteractiveLogin(opts.key, jsonMode);
217
+ } else {
218
+ await interactiveLogin(jsonMode);
219
+ }
220
+ } catch (err) {
221
+ printError(err, jsonMode);
222
+ }
223
+ });
224
+ }
225
+ async function nonInteractiveLogin(apiKey, jsonMode) {
226
+ if (!apiKey.startsWith(API_KEY_PREFIX)) {
227
+ printError(
228
+ new Error(`Invalid API key format. Keys start with "${API_KEY_PREFIX}".`),
229
+ jsonMode
230
+ );
231
+ return;
232
+ }
233
+ const valid = await validateApiKey(apiKey);
234
+ if (!valid) {
235
+ printError(
236
+ new Error(
237
+ `Invalid API key. Generate a new key at ${WEB_URL}/login`
238
+ ),
239
+ jsonMode
240
+ );
241
+ return;
242
+ }
243
+ setConfig("api-key", apiKey);
244
+ printSuccess(
245
+ jsonMode ? { status: "ok", message: "API key verified and saved." } : "\u2713 API key verified and saved.",
246
+ jsonMode
247
+ );
248
+ }
249
+ async function interactiveLogin(jsonMode) {
250
+ process.stdout.write(`
251
+ Welcome to TBD CLI
252
+
253
+ To get started, you need an API key:
254
+
255
+ 1. Go to ${WEB_URL}
256
+ 2. Log in or sign up using email, Google, Apple, or Twitter
257
+ (external wallets like Phantom are not supported for agent features)
258
+ 3. Open Profile \u2192 Agent Access \u2192 Generate API Key
259
+ 4. Copy the key and paste it below
260
+
261
+ `);
262
+ const rl = readline.createInterface({
263
+ input: process.stdin,
264
+ output: process.stdout
265
+ });
266
+ const apiKey = await new Promise((resolve) => {
267
+ rl.question(" API Key: ", (answer) => {
268
+ rl.close();
269
+ resolve(answer.trim());
270
+ });
271
+ });
272
+ if (!apiKey) {
273
+ printError(new Error("No API key provided."), jsonMode);
274
+ return;
275
+ }
276
+ if (!apiKey.startsWith(API_KEY_PREFIX)) {
277
+ printError(
278
+ new Error(`Invalid API key format. Keys start with "${API_KEY_PREFIX}".`),
279
+ jsonMode
280
+ );
281
+ return;
282
+ }
283
+ process.stdout.write("\n Verifying...\n");
284
+ const valid = await validateApiKey(apiKey);
285
+ if (!valid) {
286
+ printError(
287
+ new Error(
288
+ `Invalid API key. Generate a new key at ${WEB_URL}/login`
289
+ ),
290
+ jsonMode
291
+ );
292
+ return;
293
+ }
294
+ setConfig("api-key", apiKey);
295
+ process.stdout.write(`
296
+ \u2713 API key verified. You're ready to go!
297
+
298
+ Try: tbd-vote campaigns list
299
+
300
+ `);
301
+ }
302
+
303
+ // src/commands/auth.ts
304
+ function registerAuth(program2) {
305
+ const auth = program2.command("auth").description("Manage authentication");
306
+ auth.command("status").description("Check whether your API key is configured and valid").action(async () => {
307
+ const jsonMode = program2.opts().json ?? false;
308
+ const apiKey = getConfigValue("api-key");
309
+ if (!apiKey) {
310
+ printError(
311
+ new Error("No API key configured. Run: tbd-vote login"),
312
+ jsonMode
313
+ );
314
+ return;
315
+ }
316
+ const valid = await validateApiKey(apiKey);
317
+ if (!valid) {
318
+ printError(
319
+ new Error(
320
+ `Invalid API key. Generate a new key at ${WEB_URL}/login`
321
+ ),
322
+ jsonMode
323
+ );
324
+ return;
325
+ }
326
+ const apiUrl = getConfigValue("api-url") || API_BASE_URL;
327
+ if (jsonMode) {
328
+ printSuccess(
329
+ {
330
+ authenticated: true,
331
+ apiUrl
332
+ },
333
+ true
334
+ );
335
+ } else {
336
+ printSuccess(`Authenticated.
337
+ API: ${apiUrl}`, false);
338
+ }
339
+ });
340
+ auth.command("logout").description("Remove the stored API key").action(() => {
341
+ const jsonMode = program2.opts().json ?? false;
342
+ removeConfigValue("api-key");
343
+ printSuccess(
344
+ jsonMode ? { status: "ok", message: "API key removed." } : "API key removed.",
345
+ jsonMode
346
+ );
347
+ });
348
+ }
349
+
350
+ // src/commands/config.ts
351
+ var ALLOWED_KEYS = [
352
+ "api-url",
353
+ "bet-size",
354
+ "default-status",
355
+ "default-limit"
356
+ ];
357
+ function isAllowedKey(key) {
358
+ return ALLOWED_KEYS.includes(key);
359
+ }
360
+ function registerConfig(program2) {
361
+ const config = program2.command("config").description("Manage CLI configuration");
362
+ config.command("set").description("Set a configuration value").argument("<key>", "Config key").argument("<value>", "Config value").action((key, value) => {
363
+ const jsonMode = program2.opts().json ?? false;
364
+ if (key === "api-key") {
365
+ printError(
366
+ new Error(
367
+ "Use 'tbd-vote login' to set the API key, not 'config set'."
368
+ ),
369
+ jsonMode
370
+ );
371
+ return;
372
+ }
373
+ if (!isAllowedKey(key)) {
374
+ printError(
375
+ new Error(
376
+ `Unknown config key: ${key}
377
+ Allowed keys: ${ALLOWED_KEYS.join(", ")}`
378
+ ),
379
+ jsonMode
380
+ );
381
+ return;
382
+ }
383
+ setConfig(key, value);
384
+ printSuccess(
385
+ jsonMode ? { status: "ok", key, value } : `Set ${key} = ${value}`,
386
+ jsonMode
387
+ );
388
+ });
389
+ config.command("get").description("Get a configuration value").argument("<key>", "Config key").action((key) => {
390
+ const jsonMode = program2.opts().json ?? false;
391
+ const value = getConfigValue(key);
392
+ if (jsonMode) {
393
+ printSuccess({ key, value }, true);
394
+ } else {
395
+ printSuccess(value ?? "(not set)", false);
396
+ }
397
+ });
398
+ config.command("list").description("List all configuration values").action(() => {
399
+ const jsonMode = program2.opts().json ?? false;
400
+ const cfg = getConfig();
401
+ if (jsonMode) {
402
+ const masked = { ...cfg };
403
+ if (masked["api-key"]) {
404
+ masked["api-key"] = masked["api-key"].slice(0, 10) + "..." + masked["api-key"].slice(-4);
405
+ }
406
+ printSuccess(masked, true);
407
+ } else {
408
+ const entries = Object.entries(cfg).map(
409
+ ([k, v]) => {
410
+ if (k === "api-key" && v) {
411
+ return [k, v.slice(0, 10) + "..." + v.slice(-4)];
412
+ }
413
+ return [k, v ?? "(not set)"];
414
+ }
415
+ );
416
+ const maxKeyLen = Math.max(...entries.map(([k]) => k.length));
417
+ const lines = entries.map(([k, v]) => `${k.padEnd(maxKeyLen)} ${v}`).join("\n");
418
+ printSuccess(lines, false);
419
+ }
420
+ });
421
+ }
422
+
423
+ // src/commands/campaigns.ts
424
+ function registerCampaigns(program2) {
425
+ const campaigns = program2.command("campaigns").description("Browse prediction campaigns");
426
+ campaigns.command("list").description("List campaigns").option("--status <status>", "Filter by status (open|ended)").option("--category <category>", "Filter by category").option("--filter <filter>", "Sort/filter preset (new|ending|trending)").option("--limit <limit>", "Max results").option("--cursor <cursor>", "Pagination cursor").action(async (opts) => {
427
+ const jsonMode = program2.opts().json ?? false;
428
+ try {
429
+ const params = {
430
+ status: opts.status ?? getConfigValue("default-status") ?? void 0,
431
+ category: opts.category,
432
+ filter: opts.filter,
433
+ limit: opts.limit ?? getConfigValue("default-limit") ?? void 0,
434
+ cursor: opts.cursor
435
+ };
436
+ const data = await apiGet(
437
+ "/agents/campaigns",
438
+ params
439
+ );
440
+ if (jsonMode) {
441
+ printSuccess(data, true);
442
+ } else {
443
+ const rows = data.campaigns.map((c) => ({
444
+ id: String(c.id),
445
+ title: c.question.length > 40 ? c.question.slice(0, 37) + "..." : c.question,
446
+ status: c.status,
447
+ ends: c.endTime ? c.endTime.split("T")[0] : "-"
448
+ }));
449
+ printTable(rows, [
450
+ { key: "id", label: "ID" },
451
+ { key: "title", label: "Title" },
452
+ { key: "status", label: "Status" },
453
+ { key: "ends", label: "Ends" }
454
+ ]);
455
+ if (data.nextCursor) {
456
+ process.stdout.write(
457
+ `
458
+ Showing ${data.campaigns.length} campaigns. Next: tbd-vote campaigns list --cursor ${data.nextCursor}
459
+ `
460
+ );
461
+ } else {
462
+ process.stdout.write(
463
+ `
464
+ ${data.campaigns.length} campaign(s).
465
+ `
466
+ );
467
+ }
468
+ }
469
+ } catch (err) {
470
+ printError(err, jsonMode);
471
+ }
472
+ });
473
+ campaigns.command("get").description("Get campaign details").argument("<campaign-id>", "Campaign ID").action(async (campaignId) => {
474
+ const jsonMode = program2.opts().json ?? false;
475
+ try {
476
+ const campaign = await apiGet(
477
+ `/agents/campaigns/${campaignId}`
478
+ );
479
+ if (jsonMode) {
480
+ printSuccess(campaign, true);
481
+ } else {
482
+ const endDate = campaign.endTime ? campaign.endTime.split("T")[0] : "-";
483
+ process.stdout.write(`${campaign.question}
484
+ `);
485
+ process.stdout.write(
486
+ `Status: ${campaign.status} | Ends: ${endDate} | Category: ${campaign.category ?? "-"}
487
+ `
488
+ );
489
+ process.stdout.write("\nOptions:\n");
490
+ campaign.options.forEach((opt, i) => {
491
+ process.stdout.write(
492
+ ` ${i + 1}. ${opt.label} (odds: ${opt.odds ?? "-"})
493
+ `
494
+ );
495
+ });
496
+ if (campaign.userBets && campaign.userBets.length > 0) {
497
+ process.stdout.write("\nYour bets:\n");
498
+ campaign.userBets.forEach((bet) => {
499
+ process.stdout.write(
500
+ ` $${bet.amount.toFixed(2)} on "${bet.optionLabel}" (tx: ${bet.txSignature})
501
+ `
502
+ );
503
+ });
504
+ } else {
505
+ process.stdout.write("\nYour bets: none\n");
506
+ }
507
+ }
508
+ } catch (err) {
509
+ printError(err, jsonMode);
510
+ }
511
+ });
512
+ }
513
+
514
+ // src/commands/balance.ts
515
+ function registerBalance(program2) {
516
+ program2.command("balance").description("Check USDC balance of your wallet").action(async () => {
517
+ const jsonMode = program2.opts().json ?? false;
518
+ try {
519
+ const data = await apiGet("/agents/balance");
520
+ if (jsonMode) {
521
+ printSuccess(data, true);
522
+ } else {
523
+ process.stdout.write(`Balance: ${data.balance.toFixed(2)} USDC
524
+ `);
525
+ }
526
+ } catch (err) {
527
+ printError(err, jsonMode);
528
+ }
529
+ });
530
+ }
531
+
532
+ // src/commands/bet.ts
533
+ function registerBet(program2) {
534
+ program2.command("bet").description("Place a bet on a campaign outcome").argument("<campaign-id>", "Campaign ID").argument("<option-id>", "Option ID").argument("[amount]", "Bet amount in USDC (defaults to configured bet-size)").action(async (campaignId, optionId, amountArg) => {
535
+ const jsonMode = program2.opts().json ?? false;
536
+ try {
537
+ const amount = amountArg ? parseFloat(amountArg) : parseFloat(getConfigValue("bet-size") || DEFAULT_BET_SIZE);
538
+ if (isNaN(amount) || amount <= 0) {
539
+ printError(new Error("Invalid bet amount."), jsonMode);
540
+ return;
541
+ }
542
+ const campaign = await apiGet(
543
+ `/agents/campaigns/${campaignId}`
544
+ );
545
+ const numOptionId = Number(optionId);
546
+ const option = campaign.options.find((o) => o.id === numOptionId);
547
+ if (!option) {
548
+ const valid = campaign.options.map((o) => `${o.id} (${o.label})`).join(", ");
549
+ printError(
550
+ new Error(
551
+ `Invalid option "${optionId}" for campaign "${campaign.question}"
552
+ Valid options: ${valid}`
553
+ ),
554
+ jsonMode
555
+ );
556
+ return;
557
+ }
558
+ const data = await apiPost(
559
+ "/agents/txns/place-bet",
560
+ { campaign_id: Number(campaignId), option_id: numOptionId, amount }
561
+ );
562
+ const result = {
563
+ ...data,
564
+ campaignTitle: campaign.question,
565
+ optionTitle: option.label
566
+ };
567
+ if (jsonMode) {
568
+ printSuccess(result, true);
569
+ } else {
570
+ process.stdout.write(
571
+ `Placed $${result.amount.toFixed(2)} bet on "${result.optionTitle}" in "${result.campaignTitle}"
572
+ `
573
+ );
574
+ process.stdout.write(`Tx: ${result.txSignature}
575
+ `);
576
+ }
577
+ } catch (err) {
578
+ printError(err, jsonMode);
579
+ }
580
+ });
581
+ }
582
+
583
+ // src/commands/strategy.ts
584
+ import fs2 from "fs";
585
+ import path2 from "path";
586
+ var DEFAULT_TEMPLATE = `# Betting Strategy
587
+
588
+ ## Focus
589
+ <!-- Which categories or topics should the agent prioritize? -->
590
+ All categories.
591
+
592
+ ## Risk Profile
593
+ <!-- How aggressive should the agent bet? -->
594
+ Conservative \u2014 default bet size, diversify across campaigns.
595
+
596
+ ## Decision Criteria
597
+ <!-- What factors should the agent weigh when picking an option? -->
598
+ Favor options with clear informational edges. Avoid 50/50 coin-flip markets.
599
+
600
+ ## Personality
601
+ <!-- Any tone or style for the agent's reasoning? -->
602
+ Analytical and data-driven. Explain reasoning before placing each bet.
603
+ `;
604
+ function getStrategyPath() {
605
+ return path2.join(getConfigDir(), STRATEGY_FILENAME);
606
+ }
607
+ function getDisplayPath() {
608
+ return `~/.tbd/${STRATEGY_FILENAME}`;
609
+ }
610
+ function registerStrategy(program2) {
611
+ const strategy = program2.command("strategy").description("View or initialize your betting strategy file").action(() => {
612
+ const jsonMode = program2.opts().json ?? false;
613
+ const filePath = getStrategyPath();
614
+ const displayPath = getDisplayPath();
615
+ if (fs2.existsSync(filePath)) {
616
+ const content = fs2.readFileSync(filePath, "utf-8");
617
+ if (jsonMode) {
618
+ printSuccess({ path: displayPath, exists: true, content }, true);
619
+ } else {
620
+ process.stdout.write(content);
621
+ }
622
+ } else {
623
+ if (jsonMode) {
624
+ printSuccess({ path: displayPath, exists: false, content: null }, true);
625
+ } else {
626
+ process.stdout.write(
627
+ `No strategy file found at ${displayPath}
628
+ Create one with: tbd-vote strategy init
629
+ `
630
+ );
631
+ }
632
+ }
633
+ });
634
+ strategy.command("init").description("Create a starter STRATEGY.md template").option("--force", "Overwrite existing file").action((opts) => {
635
+ const jsonMode = program2.opts().json ?? false;
636
+ const filePath = getStrategyPath();
637
+ const displayPath = getDisplayPath();
638
+ if (fs2.existsSync(filePath) && !opts.force) {
639
+ printError(
640
+ new Error(
641
+ `${displayPath} already exists. Use --force to overwrite.`
642
+ ),
643
+ jsonMode
644
+ );
645
+ return;
646
+ }
647
+ const configDir = getConfigDir();
648
+ if (!fs2.existsSync(configDir)) {
649
+ fs2.mkdirSync(configDir, { recursive: true });
650
+ }
651
+ const existed = fs2.existsSync(filePath);
652
+ fs2.writeFileSync(filePath, DEFAULT_TEMPLATE);
653
+ const overwrote = existed && opts.force;
654
+ const message = overwrote ? `Overwrote ${displayPath} with default template.` : `Created ${displayPath} \u2014 edit it to define your betting strategy.`;
655
+ printSuccess(
656
+ jsonMode ? { status: "ok", path: displayPath, message } : message,
657
+ jsonMode
658
+ );
659
+ });
660
+ }
661
+
662
+ // src/index.ts
663
+ var program = new Command();
664
+ program.name("tbd-vote").description("CLI for AI agents to browse and bet on TBD").version("0.1.0").option("--json", "Output as JSON");
665
+ registerLogin(program);
666
+ registerAuth(program);
667
+ registerConfig(program);
668
+ registerCampaigns(program);
669
+ registerBalance(program);
670
+ registerBet(program);
671
+ registerStrategy(program);
672
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@tbd-vote/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for AI agents to browse and bet on TBD",
5
+ "bin": {
6
+ "tbd-vote": "./dist/index.js"
7
+ },
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "type": "module",
12
+ "scripts": {
13
+ "build": "tsup",
14
+ "dev": "tsup --watch",
15
+ "test": "vitest run",
16
+ "test:watch": "vitest",
17
+ "prepublishOnly": "tsup"
18
+ },
19
+ "dependencies": {
20
+ "commander": "^13.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^25.5.2",
24
+ "tsup": "^8.0.0",
25
+ "typescript": "^5.7.0",
26
+ "vitest": "^3.0.0"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/ego-protocol/tbd-vote-cli"
31
+ },
32
+ "homepage": "https://tbd.vote",
33
+ "bugs": "https://github.com/ego-protocol/tbd-vote-cli/issues",
34
+ "author": "Ego Labs, Inc.",
35
+ "keywords": [
36
+ "cli",
37
+ "prediction-market",
38
+ "ai-agent"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "engines": {
44
+ "node": ">=18.0.0"
45
+ },
46
+ "license": "MIT"
47
+ }