@dawnai/cli 1.0.3 → 1.0.4

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 (2) hide show
  1. package/dist/index.js +83 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import process from 'node:process';
7
7
  import { spawn } from 'node:child_process';
8
- const CLI_VERSION = '1.0.3';
8
+ const CLI_VERSION = '1.0.4';
9
9
  const DAWN_API_BASE_URL = 'https://api.dawn.ai';
10
10
  const FUNDING_LINK_TEMPLATE = process.env.DAWN_HELIO_LINK_TEMPLATE || '';
11
11
  const CLI_HOME = process.env.DAWN_CLI_HOME || path.join(os.homedir(), '.dawn-cli');
@@ -103,6 +103,7 @@ function printUsage() {
103
103
  dawn strategy list
104
104
  dawn strategy create <text>
105
105
  dawn strategy status <id>
106
+ dawn strategy positions <id> [--strategy-id <strategyId>]
106
107
  dawn strategy revise <id> <text>
107
108
  dawn strategy rules <id> list
108
109
  dawn strategy rules <id> approve <rule-index>
@@ -664,12 +665,45 @@ function renderAgentOverview(conversationId, conversation, strategies) {
664
665
  console.log(`- ${strategy.id ?? 'unknown'} | ${strategy.strategyType || 'unknown'} | ${label} | pnl=${formatUsd(strategy.totalPnl || '0')} | terminateAt=${formatTimestamp(strategy.terminateAt)}`);
665
666
  }
666
667
  }
668
+ function renderStrategyPositions(conversationId, strategy, positions) {
669
+ const strategyId = String(strategy.id ?? 'unknown');
670
+ const strategyType = strategy.strategyType || 'unknown';
671
+ const strategyState = strategy.isRunning ? 'running' : 'stopped';
672
+ const walletId = strategy.walletId || 'unknown';
673
+ console.log(`Strategy positions for conversation ${conversationId}`);
674
+ console.log('='.repeat(`Strategy positions for conversation ${conversationId}`.length));
675
+ printKeyValue('Strategy ID', strategyId);
676
+ printKeyValue('Mode', strategyType);
677
+ printKeyValue('State', strategyState);
678
+ printKeyValue('Wallet', shortId(walletId));
679
+ printKeyValue('Position count', String(positions.length));
680
+ if (!positions.length) {
681
+ console.log('\nNo positions found for this strategy.');
682
+ return;
683
+ }
684
+ const totalCurrent = positions.reduce((sum, position) => sum + formatNumeric(position.currentValue), 0);
685
+ const totalCost = positions.reduce((sum, position) => sum + formatNumeric(position.costBasis), 0);
686
+ const totalPnl = positions.reduce((sum, position) => sum + formatNumeric(position.unrealizedPnl), 0);
687
+ printSection('Summary');
688
+ printKeyValue('Total current value', formatUsd(totalCurrent));
689
+ printKeyValue('Total cost basis', formatUsd(totalCost));
690
+ printKeyValue('Total unrealized PnL', `${formatUsd(totalPnl)} (${formatPercent(totalCost === 0 ? 0 : (totalPnl / totalCost) * 100)})`);
691
+ printSection('Positions');
692
+ const sorted = [...positions].sort((a, b) => formatNumeric(b.currentValue) - formatNumeric(a.currentValue));
693
+ for (const position of sorted) {
694
+ const title = position.marketTitle ||
695
+ position.groupItemTitle ||
696
+ `asset:${shortId(position.assetId || position.id)}`;
697
+ console.log(`- ${title} | value=${formatUsd(position.currentValue || '0')} | cost=${formatUsd(position.costBasis || '0')} | pnl=${formatUsd(position.unrealizedPnl || '0')} (${formatPercent(position.unrealizedPnlPercentage || '0')}) | amount=${formatNumeric(position.amount).toFixed(4)}`);
698
+ }
699
+ }
667
700
  async function handleStrategy(args) {
668
701
  if (args.includes('--help') || args.includes('-h')) {
669
702
  console.log(`Usage:
670
703
  dawn strategy list
671
704
  dawn strategy create <text>
672
705
  dawn strategy status <id>
706
+ dawn strategy positions <id> [--strategy-id <strategyId>]
673
707
  dawn strategy revise <id> <text>
674
708
  dawn strategy rules <id> list
675
709
  dawn strategy rules <id> approve <rule-index>
@@ -689,7 +723,16 @@ async function handleStrategy(args) {
689
723
  if (!primaryCommand) {
690
724
  throw new Error('Missing strategy command.');
691
725
  }
692
- if (!['list', 'create', 'status', 'revise', 'rules', 'code', 'launch'].includes(primaryCommand)) {
726
+ if (![
727
+ 'list',
728
+ 'create',
729
+ 'status',
730
+ 'positions',
731
+ 'revise',
732
+ 'rules',
733
+ 'code',
734
+ 'launch',
735
+ ].includes(primaryCommand)) {
693
736
  throw new Error(`Unknown strategy command: ${primaryCommand}. Run \`dawn strategy --help\` for available commands.`);
694
737
  }
695
738
  let subcommand = primaryCommand;
@@ -753,6 +796,15 @@ async function handleStrategy(args) {
753
796
  subcommand = '__status';
754
797
  rest.splice(0, rest.length, conversationId);
755
798
  }
799
+ if (primaryCommand === 'positions') {
800
+ const conversationId = rest[0];
801
+ const { flags } = parseFlags(rest.slice(1));
802
+ if (!conversationId) {
803
+ throw new Error('Usage: dawn strategy positions <id> [--strategy-id <strategyId>]');
804
+ }
805
+ subcommand = '__positions';
806
+ rest.splice(0, rest.length, conversationId, typeof flags['strategy-id'] === 'string' ? flags['strategy-id'] : '');
807
+ }
756
808
  if (primaryCommand === 'revise') {
757
809
  const conversationId = rest[0];
758
810
  const text = rest.slice(1).join(' ').trim();
@@ -963,6 +1015,35 @@ async function handleStrategy(args) {
963
1015
  console.log(`Sent edit request to strategy ${conversationId}.`);
964
1016
  return;
965
1017
  }
1018
+ if (subcommand === '__positions') {
1019
+ const conversationId = rest[0];
1020
+ const requestedStrategyId = rest[1];
1021
+ if (!conversationId) {
1022
+ throw new Error('Usage: dawn strategy positions <id> [--strategy-id <strategyId>]');
1023
+ }
1024
+ const strategiesRaw = (await apiFetch(config, `/strategy/conversation/${conversationId}`));
1025
+ const strategies = Array.isArray(strategiesRaw) ? strategiesRaw : [];
1026
+ if (!strategies.length) {
1027
+ throw new Error(`No strategies found for conversation ${conversationId}.`);
1028
+ }
1029
+ const selectedStrategy = (requestedStrategyId
1030
+ ? strategies.find((strategy) => String(strategy.id) === requestedStrategyId)
1031
+ : null) ||
1032
+ strategies.find((strategy) => strategy.isRunning) ||
1033
+ strategies[0];
1034
+ if (!selectedStrategy?.id) {
1035
+ throw new Error('Could not determine strategy for this conversation.');
1036
+ }
1037
+ if (!selectedStrategy.walletId) {
1038
+ throw new Error(`Could not determine wallet for strategy ${selectedStrategy.id}.`);
1039
+ }
1040
+ const response = (await apiFetch(config, `/v1/vault-metadata/${selectedStrategy.walletId}/positions?strategyIds=${encodeURIComponent(String(selectedStrategy.id))}`));
1041
+ const positions = Array.isArray(response?.positions)
1042
+ ? response.positions
1043
+ : [];
1044
+ renderStrategyPositions(conversationId, selectedStrategy, positions);
1045
+ return;
1046
+ }
966
1047
  if (subcommand === 'launch') {
967
1048
  const conversationId = rest[0];
968
1049
  const { flags } = parseFlags(rest.slice(1));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dawnai/cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "User-facing Dawn CLI",
6
6
  "license": "MIT",