@zhive/cli 0.6.2 → 0.6.3
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.
- package/dist/{services/agent → agent}/analysis.js +5 -5
- package/dist/agent/app.js +122 -0
- package/dist/agent/commands/registry.js +12 -0
- package/dist/agent/components/AsciiTicker.js +81 -0
- package/dist/agent/components/CommandInput.js +65 -0
- package/dist/agent/components/HoneycombBoot.js +291 -0
- package/dist/agent/components/Spinner.js +37 -0
- package/dist/agent/hooks/useAgent.js +480 -0
- package/dist/{services/agent/prompts → agent}/memory-prompt.js +22 -20
- package/dist/{services/agent/helpers → agent}/model.js +2 -2
- package/dist/agent/process-lifecycle.js +18 -0
- package/dist/{services/agent/prompts → agent}/prompt.js +54 -80
- package/dist/agent/run-headless.js +189 -0
- package/dist/agent/theme.js +41 -0
- package/dist/{services/agent → agent}/tools/market/client.js +1 -1
- package/dist/{services/agent → agent}/tools/mindshare/client.js +1 -1
- package/dist/agent/types.js +1 -0
- package/dist/{services/config/agent.js → agents.js} +2 -2
- package/dist/avatar.js +34 -0
- package/dist/backtest/default-backtest-data.js +200 -0
- package/dist/backtest/fetch.js +41 -0
- package/dist/backtest/import.js +106 -0
- package/dist/backtest/index.js +10 -0
- package/dist/backtest/results.js +113 -0
- package/dist/backtest/runner.js +134 -0
- package/dist/backtest/storage.js +11 -0
- package/dist/backtest/types.js +1 -0
- package/dist/commands/install.js +50 -0
- package/dist/commands/megathread/commands/create-comment.js +1 -4
- package/dist/commands/megathread/commands/create-comment.test.js +1 -19
- package/dist/commands/megathread/commands/list.test.js +1 -0
- package/dist/commands/start/commands/prediction.js +1 -2
- package/dist/commands/start/hooks/utils.js +3 -3
- package/dist/commands/start/ui/PollText.js +23 -0
- package/dist/commands/start/ui/PredictionsPanel.js +88 -0
- package/dist/commands/start/ui/SpinnerContext.js +20 -0
- package/dist/components/InputGuard.js +6 -0
- package/dist/components/stdout-spinner.js +48 -0
- package/dist/{services/config/config.js → config.js} +7 -1
- package/dist/create/CreateApp.js +153 -0
- package/dist/create/ai-generate.js +147 -0
- package/dist/create/generate.js +73 -0
- package/dist/create/steps/ApiKeyStep.js +97 -0
- package/dist/create/steps/AvatarStep.js +16 -0
- package/dist/create/steps/BioStep.js +14 -0
- package/dist/create/steps/DoneStep.js +14 -0
- package/dist/create/steps/IdentityStep.js +163 -0
- package/dist/create/steps/NameStep.js +71 -0
- package/dist/create/steps/ScaffoldStep.js +58 -0
- package/dist/create/steps/SoulStep.js +58 -0
- package/dist/create/steps/StrategyStep.js +58 -0
- package/dist/create/validate-api-key.js +47 -0
- package/dist/create/welcome.js +304 -0
- package/dist/list/ListApp.js +79 -0
- package/dist/{services/agent/env.js → load-agent-env.js} +1 -1
- package/dist/migrate-templates/MigrateApp.js +131 -0
- package/dist/migrate-templates/migrate.js +86 -0
- package/dist/presets.js +613 -0
- package/dist/shared/agent/handler.js +1 -5
- package/dist/shared/config/constant.js +2 -2
- package/dist/start/AgentProcessManager.js +98 -0
- package/dist/start/Dashboard.js +92 -0
- package/dist/start/SelectAgentApp.js +81 -0
- package/dist/start/StartApp.js +189 -0
- package/dist/start/patch-headless.js +101 -0
- package/dist/start/patch-managed-mode.js +142 -0
- package/dist/start/start-command.js +24 -0
- package/dist/theme.js +54 -0
- package/package.json +2 -2
- package/dist/CLAUDE.md +0 -7
- package/dist/backtest/CLAUDE.md +0 -7
- package/dist/cli.js +0 -20
- package/dist/services/config/constant.js +0 -8
- package/dist/shared/agent/config.js +0 -75
- package/dist/shared/agent/env.js +0 -30
- package/dist/shared/agent/helpers/model.js +0 -92
- package/dist/shared/ai-providers.js +0 -66
- /package/dist/{services/agent/prompts → agent}/chat-prompt.js +0 -0
- /package/dist/{services/agent → agent}/config.js +0 -0
- /package/dist/{services/agent/tools → agent}/edit-section.js +0 -0
- /package/dist/{services/agent/tools → agent}/fetch-rules.js +0 -0
- /package/dist/{services/agent → agent}/helpers.js +0 -0
- /package/dist/{services/agent/skills/types.js → agent/objects.js} +0 -0
- /package/dist/{services/agent → agent}/skills/index.js +0 -0
- /package/dist/{services/agent → agent}/skills/skill-parser.js +0 -0
- /package/dist/{services/agent → agent/skills}/types.js +0 -0
- /package/dist/{services/agent → agent}/tools/index.js +0 -0
- /package/dist/{services/agent → agent}/tools/market/index.js +0 -0
- /package/dist/{services/agent → agent}/tools/market/tools.js +0 -0
- /package/dist/{services/agent → agent}/tools/mindshare/index.js +0 -0
- /package/dist/{services/agent → agent}/tools/mindshare/tools.js +0 -0
- /package/dist/{services/agent → agent}/tools/read-skill-tool.js +0 -0
- /package/dist/{services/agent → agent}/tools/ta/index.js +0 -0
- /package/dist/{services/agent → agent}/tools/ta/indicators.js +0 -0
- /package/dist/{services/ai-providers.js → ai-providers.js} +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default backtest dataset bundled with the CLI.
|
|
3
|
+
* Contains 10 threads from Bitcoin, Ethereum, Solana, and Dogecoin.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_BACKTEST_DATA = {
|
|
6
|
+
metadata: {
|
|
7
|
+
id: 'default',
|
|
8
|
+
name: 'Default Backtest Dataset',
|
|
9
|
+
created_at: '2026-02-26T00:00:00Z',
|
|
10
|
+
},
|
|
11
|
+
threads: [
|
|
12
|
+
{
|
|
13
|
+
project_id: 'ethereum',
|
|
14
|
+
project_name: 'Ethereum',
|
|
15
|
+
project_symbol: '$ETH',
|
|
16
|
+
project_categories: [
|
|
17
|
+
'smart-contract-platform',
|
|
18
|
+
'layer-1',
|
|
19
|
+
'ethereum-ecosystem',
|
|
20
|
+
'proof-of-stake-pos',
|
|
21
|
+
'world-liberty-financial-portfolio',
|
|
22
|
+
],
|
|
23
|
+
project_description: 'Ethereum is a global, open-source platform for decentralized applications.',
|
|
24
|
+
text: 'Balaji Srinivasan describes a "Global Privacy Era" as crypto\'s third phase, where the next decade of Web3 focuses on protecting user data and financial sovereignty through strong encryption rather than scalability or speed. Ethereum is highlighted as part of this shift from fully transparent ledgers to more confidential, programmable computation.',
|
|
25
|
+
timestamp: '2025-12-31T20:00:00Z',
|
|
26
|
+
price_on_fetch: 2969.01,
|
|
27
|
+
price_on_eval: 2971.55,
|
|
28
|
+
citations: [{ title: '2006719380713869499' }, { title: '2006683920881037680' }],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
project_id: 'solana',
|
|
32
|
+
project_name: 'Solana',
|
|
33
|
+
project_symbol: '$SOL',
|
|
34
|
+
project_categories: [
|
|
35
|
+
'smart-contract-platform',
|
|
36
|
+
'solana-ecosystem',
|
|
37
|
+
'layer-1',
|
|
38
|
+
'alleged-sec-securities',
|
|
39
|
+
'proof-of-stake-pos',
|
|
40
|
+
'made-in-usa',
|
|
41
|
+
'coinlist-launchpad',
|
|
42
|
+
],
|
|
43
|
+
project_description: 'Solana is a high-performance Layer 1 blockchain designed for mass adoption by providing a fast, secure, and low-cost environment for decentralized applications.',
|
|
44
|
+
text: 'ORE partners with PrivacyCash to launch an official shielded pool on Solana, enabling live private transfers of ORE as a native store-of-value token. Builders also announce Pandora OS v2.0 with stealth transfers and one-time unlinkable addresses on Solana mainnet, signaling major new privacy initiatives on the network.',
|
|
45
|
+
timestamp: '2026-01-01T01:00:00Z',
|
|
46
|
+
price_on_fetch: 124.98,
|
|
47
|
+
price_on_eval: 124.94,
|
|
48
|
+
citations: [{ title: '2006787547519918102' }, { title: '2006787600028410119' }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
project_id: 'solana',
|
|
52
|
+
project_name: 'Solana',
|
|
53
|
+
project_symbol: '$SOL',
|
|
54
|
+
project_categories: [
|
|
55
|
+
'smart-contract-platform',
|
|
56
|
+
'solana-ecosystem',
|
|
57
|
+
'layer-1',
|
|
58
|
+
'alleged-sec-securities',
|
|
59
|
+
'proof-of-stake-pos',
|
|
60
|
+
'made-in-usa',
|
|
61
|
+
'coinlist-launchpad',
|
|
62
|
+
],
|
|
63
|
+
project_description: 'Solana is a high-performance Layer 1 blockchain designed for mass adoption by providing a fast, secure, and low-cost environment for decentralized applications.',
|
|
64
|
+
text: 'Solana is introducing the c-spl confidential token standard in Q1 2026, enabling encrypted balances and native private transfers. This privacy infrastructure targets institutional adoption by allowing banks and enterprises to conduct confidential onchain transactions, potentially unlocking complex financial instruments for the $16B in Solana stablecoins.',
|
|
65
|
+
timestamp: '2026-01-01T06:00:00Z',
|
|
66
|
+
price_on_fetch: 125.06,
|
|
67
|
+
price_on_eval: 124.43,
|
|
68
|
+
citations: [{ title: '2006857900543848485' }, { title: '2006862849327435958' }],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
project_id: 'bitcoin',
|
|
72
|
+
project_name: 'Bitcoin',
|
|
73
|
+
project_symbol: '$BTC',
|
|
74
|
+
project_categories: [
|
|
75
|
+
'smart-contract-platform',
|
|
76
|
+
'layer-1',
|
|
77
|
+
'proof-of-work-pow',
|
|
78
|
+
'bitcoin-ecosystem',
|
|
79
|
+
],
|
|
80
|
+
project_description: "Bitcoin is the world's first decentralized cryptocurrency, created in 2009 by the pseudonymous Satoshi Nakamoto.",
|
|
81
|
+
text: 'BlackRock transferred 1,134 BTC (~$101.4M) and 7,255 ETH (~$22.1M) to Coinbase/ Coinbase Prime and is described as selling millions in crypto ahead of a key PMI data release. The move coincides with $2.2B in BTC and ETH options expiry, drawing market attention to potential selling pressure on Bitcoin and Ethereum.',
|
|
82
|
+
timestamp: '2026-01-01T19:00:00Z',
|
|
83
|
+
price_on_fetch: 88053,
|
|
84
|
+
price_on_eval: 88266,
|
|
85
|
+
citations: [{ title: '2007064336708354389' }, { title: '2007066963671924967' }],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
project_id: 'solana',
|
|
89
|
+
project_name: 'Solana',
|
|
90
|
+
project_symbol: '$SOL',
|
|
91
|
+
project_categories: [
|
|
92
|
+
'smart-contract-platform',
|
|
93
|
+
'solana-ecosystem',
|
|
94
|
+
'layer-1',
|
|
95
|
+
'alleged-sec-securities',
|
|
96
|
+
'proof-of-stake-pos',
|
|
97
|
+
'made-in-usa',
|
|
98
|
+
'coinlist-launchpad',
|
|
99
|
+
],
|
|
100
|
+
project_description: 'Solana is a high-performance Layer 1 blockchain designed for mass adoption by providing a fast, secure, and low-cost environment for decentralized applications.',
|
|
101
|
+
text: 'Tweets highlight Solana\'s active memecoin culture, with users trading and promoting tokens like $KITKAT, $wif, SolanaWhale, and Epileptic, and tools such as MemeMax and 24/7 "Solana Memecoin Hunting" communities emerging. References to Trump\'s 2025 Solana memecoin and expectations for 2026 ("Make Solana Memecoins great again") show sustained speculative interest and growing infrastructure around Solana memecoin trading.',
|
|
102
|
+
timestamp: '2026-01-02T01:00:00Z',
|
|
103
|
+
price_on_fetch: 126.59,
|
|
104
|
+
price_on_eval: 127.47,
|
|
105
|
+
citations: [{ title: '2007142205451055298' }, { title: '2007150298876522740' }],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
project_id: 'dogecoin',
|
|
109
|
+
project_name: 'Dogecoin',
|
|
110
|
+
project_symbol: '$DOGE',
|
|
111
|
+
project_categories: [
|
|
112
|
+
'smart-contract-platform',
|
|
113
|
+
'meme-token',
|
|
114
|
+
'dog-themed-coins',
|
|
115
|
+
'elon-musk-inspired-coins',
|
|
116
|
+
'proof-of-work-pow',
|
|
117
|
+
'4chan-themed',
|
|
118
|
+
],
|
|
119
|
+
project_description: 'Dogecoin is a cryptocurrency based on the popular "Doge" Internet meme and features a Shiba Inu on its logo.',
|
|
120
|
+
text: 'Tweets highlight growing focus on a proposed Bitwise Dogecoin ETF (ticker "BWOW"), emphasizing that it carries high risk, significant volatility, and potential for complete loss of investment, and is not registered under the 1940 Act. Market chatter also notes a January 9 final decision deadline for a Dogecoin ETF and rising Dogecoin price and open interest into 2026.',
|
|
121
|
+
timestamp: '2026-01-02T07:00:00Z',
|
|
122
|
+
price_on_fetch: 0.128493,
|
|
123
|
+
price_on_eval: 0.132792,
|
|
124
|
+
citations: [{ title: '2007168051129840065' }, { title: '2007118652018196634' }],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
project_id: 'bitcoin',
|
|
128
|
+
project_name: 'Bitcoin',
|
|
129
|
+
project_symbol: '$BTC',
|
|
130
|
+
project_categories: [
|
|
131
|
+
'smart-contract-platform',
|
|
132
|
+
'layer-1',
|
|
133
|
+
'proof-of-work-pow',
|
|
134
|
+
'bitcoin-ecosystem',
|
|
135
|
+
],
|
|
136
|
+
project_description: "Bitcoin is the world's first decentralized cryptocurrency, created in 2009 by the pseudonymous Satoshi Nakamoto.",
|
|
137
|
+
text: 'Bitcoin users mark Proof of Keys Day, coinciding with the 17th anniversary of the Genesis Block, by urging holders to withdraw BTC from exchanges into cold storage and verify self-custody. Tweets emphasize the slogan "Not your keys, not your coins" and frame the day as a security checkup for Bitcoin holdings.',
|
|
138
|
+
timestamp: '2026-01-02T15:00:00Z',
|
|
139
|
+
price_on_fetch: 89551,
|
|
140
|
+
price_on_eval: 90310,
|
|
141
|
+
citations: [{ title: '2007362498282901908' }, { title: '2007373924133417089' }],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
project_id: 'solana',
|
|
145
|
+
project_name: 'Solana',
|
|
146
|
+
project_symbol: '$SOL',
|
|
147
|
+
project_categories: [
|
|
148
|
+
'smart-contract-platform',
|
|
149
|
+
'solana-ecosystem',
|
|
150
|
+
'layer-1',
|
|
151
|
+
'alleged-sec-securities',
|
|
152
|
+
'proof-of-stake-pos',
|
|
153
|
+
'made-in-usa',
|
|
154
|
+
'coinlist-launchpad',
|
|
155
|
+
],
|
|
156
|
+
project_description: 'Solana is a high-performance Layer 1 blockchain designed for mass adoption by providing a fast, secure, and low-cost environment for decentralized applications.',
|
|
157
|
+
text: "Circle mints $750M USDC on Solana, marking the first injection of fresh USDC stablecoin liquidity on the network in 2026. This follows $56.25B USDC minted on Solana in 2025, reinforcing Solana's growing role as a major stablecoin and DeFi liquidity hub.",
|
|
158
|
+
timestamp: '2026-01-02T17:00:00Z',
|
|
159
|
+
price_on_fetch: 130.55,
|
|
160
|
+
price_on_eval: 131.54,
|
|
161
|
+
citations: [{ title: '2007386708032270424' }, { title: '2007383683783963093' }],
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
project_id: 'ethereum',
|
|
165
|
+
project_name: 'Ethereum',
|
|
166
|
+
project_symbol: '$ETH',
|
|
167
|
+
project_categories: [
|
|
168
|
+
'smart-contract-platform',
|
|
169
|
+
'layer-1',
|
|
170
|
+
'ethereum-ecosystem',
|
|
171
|
+
'proof-of-stake-pos',
|
|
172
|
+
'world-liberty-financial-portfolio',
|
|
173
|
+
],
|
|
174
|
+
project_description: 'Ethereum is a global, open-source platform for decentralized applications.',
|
|
175
|
+
text: 'Ethereum spot ETFs record $174M in net inflows on Jan. 2, their strongest day since early December, after about $2B in outflows from November through December. Products from Grayscale and BlackRock lead the renewed institutional demand, signaling a shift back to risk-on sentiment for ETH in early 2026.',
|
|
176
|
+
timestamp: '2026-01-03T02:00:00Z',
|
|
177
|
+
price_on_fetch: 3129.52,
|
|
178
|
+
price_on_eval: 3114.78,
|
|
179
|
+
citations: [{ title: '2007536719055167799' }, { title: '2007492243502858607' }],
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
project_id: 'ethereum',
|
|
183
|
+
project_name: 'Ethereum',
|
|
184
|
+
project_symbol: '$ETH',
|
|
185
|
+
project_categories: [
|
|
186
|
+
'smart-contract-platform',
|
|
187
|
+
'layer-1',
|
|
188
|
+
'ethereum-ecosystem',
|
|
189
|
+
'proof-of-stake-pos',
|
|
190
|
+
'world-liberty-financial-portfolio',
|
|
191
|
+
],
|
|
192
|
+
project_description: 'Ethereum is a global, open-source platform for decentralized applications.',
|
|
193
|
+
text: 'Ethereum set a new all-time high with about 2.2-2.23 million transactions processed in a single day around Dec 29, 2025, with several subsequent days near that level. This record onchain activity indicates strong and growing network demand and utility across DeFi, NFTs, and emerging L2 ecosystems amid ongoing upgrades.',
|
|
194
|
+
timestamp: '2026-01-03T03:00:00Z',
|
|
195
|
+
price_on_fetch: 3125.17,
|
|
196
|
+
price_on_eval: 3110.91,
|
|
197
|
+
citations: [{ title: '2007529962350207036' }, { title: '2007525811075665958' }],
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HiveClient } from '@hive-org/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches locked threads from the API and converts them to BacktestData format.
|
|
4
|
+
* Only threads with price_on_eval are included (guaranteed by the API).
|
|
5
|
+
*/
|
|
6
|
+
export async function fetchBacktestThreads(limit, baseUrl) {
|
|
7
|
+
try {
|
|
8
|
+
const client = new HiveClient(baseUrl);
|
|
9
|
+
const threads = await client.getLockedThreads(limit);
|
|
10
|
+
const backtestThreads = threads
|
|
11
|
+
.filter((t) => t.price_on_eval !== undefined && t.price_on_eval !== null)
|
|
12
|
+
.map((t) => ({
|
|
13
|
+
project_id: t.project_id,
|
|
14
|
+
project_name: t.project_name,
|
|
15
|
+
project_symbol: t.project_symbol,
|
|
16
|
+
project_categories: t.project_categories,
|
|
17
|
+
project_description: t.project_description,
|
|
18
|
+
text: t.text,
|
|
19
|
+
timestamp: t.timestamp,
|
|
20
|
+
price_on_fetch: t.price_on_fetch,
|
|
21
|
+
price_on_eval: t.price_on_eval,
|
|
22
|
+
citations: t.citations,
|
|
23
|
+
}));
|
|
24
|
+
if (backtestThreads.length === 0) {
|
|
25
|
+
return { success: false, error: 'No resolved threads with price data found' };
|
|
26
|
+
}
|
|
27
|
+
const data = {
|
|
28
|
+
metadata: {
|
|
29
|
+
id: `api-${Date.now()}`,
|
|
30
|
+
name: `API fetch (${backtestThreads.length} threads)`,
|
|
31
|
+
created_at: new Date().toISOString(),
|
|
32
|
+
},
|
|
33
|
+
threads: backtestThreads,
|
|
34
|
+
};
|
|
35
|
+
return { success: true, data };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
return { success: false, error: message };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Schema for validating imported JSON file.
|
|
5
|
+
*/
|
|
6
|
+
const citationSchema = z.object({
|
|
7
|
+
url: z.string().optional(),
|
|
8
|
+
title: z.string(),
|
|
9
|
+
});
|
|
10
|
+
const importThreadSchema = z.object({
|
|
11
|
+
project_id: z.string().min(1, 'project_id is required'),
|
|
12
|
+
project_name: z.string().min(1, 'project_name is required'),
|
|
13
|
+
text: z.string().min(1, 'text is required'),
|
|
14
|
+
timestamp: z.string().optional(),
|
|
15
|
+
price_on_fetch: z.number().positive('price_on_fetch must be positive'),
|
|
16
|
+
price_on_eval: z.number().positive('price_on_eval must be positive'),
|
|
17
|
+
project_symbol: z.string().optional(),
|
|
18
|
+
project_categories: z.array(z.string()).optional(),
|
|
19
|
+
project_description: z.string().optional(),
|
|
20
|
+
citations: z.array(citationSchema).optional(),
|
|
21
|
+
});
|
|
22
|
+
const importFileSchema = z.object({
|
|
23
|
+
name: z.string().optional(),
|
|
24
|
+
threads: z.array(importThreadSchema).min(1, 'At least one thread is required'),
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Import and validate a backtest JSON file.
|
|
28
|
+
*/
|
|
29
|
+
export async function importBacktestFile(filePath) {
|
|
30
|
+
// Check if file exists
|
|
31
|
+
const exists = await fs.pathExists(filePath);
|
|
32
|
+
if (!exists) {
|
|
33
|
+
return { success: false, error: `File not found: ${filePath}` };
|
|
34
|
+
}
|
|
35
|
+
// Read file content
|
|
36
|
+
let content;
|
|
37
|
+
try {
|
|
38
|
+
content = await fs.readJson(filePath);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
42
|
+
return { success: false, error: `Failed to parse JSON: ${message}` };
|
|
43
|
+
}
|
|
44
|
+
// Validate structure
|
|
45
|
+
const parseResult = importFileSchema.safeParse(content);
|
|
46
|
+
if (!parseResult.success) {
|
|
47
|
+
const issues = parseResult.error.issues
|
|
48
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
49
|
+
.join('; ');
|
|
50
|
+
return { success: false, error: `Validation failed: ${issues}` };
|
|
51
|
+
}
|
|
52
|
+
const importData = parseResult.data;
|
|
53
|
+
// Convert to BacktestThread format
|
|
54
|
+
const threads = importData.threads.map((t) => convertImportThread(t));
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
name: importData.name,
|
|
58
|
+
threads,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert an import thread to a BacktestThread.
|
|
63
|
+
*/
|
|
64
|
+
function convertImportThread(input) {
|
|
65
|
+
const thread = {
|
|
66
|
+
project_id: input.project_id,
|
|
67
|
+
project_name: input.project_name,
|
|
68
|
+
project_symbol: input.project_symbol,
|
|
69
|
+
project_categories: input.project_categories,
|
|
70
|
+
project_description: input.project_description,
|
|
71
|
+
text: input.text,
|
|
72
|
+
timestamp: input.timestamp ?? new Date().toISOString(),
|
|
73
|
+
price_on_fetch: input.price_on_fetch,
|
|
74
|
+
price_on_eval: input.price_on_eval,
|
|
75
|
+
citations: input.citations ?? [],
|
|
76
|
+
};
|
|
77
|
+
return thread;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate a single thread input (for interactive mode).
|
|
81
|
+
*/
|
|
82
|
+
export function validateThreadInput(input) {
|
|
83
|
+
const errors = [];
|
|
84
|
+
if (!input.project_id || input.project_id.trim() === '') {
|
|
85
|
+
errors.push('project_id is required');
|
|
86
|
+
}
|
|
87
|
+
if (!input.project_name || input.project_name.trim() === '') {
|
|
88
|
+
errors.push('project_name is required');
|
|
89
|
+
}
|
|
90
|
+
if (!input.text || input.text.trim() === '') {
|
|
91
|
+
errors.push('text is required');
|
|
92
|
+
}
|
|
93
|
+
if (typeof input.price_on_fetch !== 'number' || input.price_on_fetch <= 0) {
|
|
94
|
+
errors.push('price_on_fetch must be a positive number');
|
|
95
|
+
}
|
|
96
|
+
if (typeof input.price_on_eval !== 'number' || input.price_on_eval <= 0) {
|
|
97
|
+
errors.push('price_on_eval must be a positive number');
|
|
98
|
+
}
|
|
99
|
+
return errors;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a BacktestThread from validated input.
|
|
103
|
+
*/
|
|
104
|
+
export function createThread(input) {
|
|
105
|
+
return convertImportThread(input);
|
|
106
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Import
|
|
2
|
+
export { importBacktestFile, validateThreadInput, createThread } from './import.js';
|
|
3
|
+
// Storage
|
|
4
|
+
export { DEFAULT_BACKTEST_ID, loadDefaultBacktest } from './storage.js';
|
|
5
|
+
// Fetch
|
|
6
|
+
export { fetchBacktestThreads } from './fetch.js';
|
|
7
|
+
// Runner
|
|
8
|
+
export { runBacktest } from './runner.js';
|
|
9
|
+
// Results
|
|
10
|
+
export { formatConviction, formatPercentage, getDirectionIndicator, formatThreadResult, formatSummary, getAccuracyGrade, buildTextReport, } from './results.js';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a number with sign for display.
|
|
3
|
+
*/
|
|
4
|
+
export function formatConviction(value) {
|
|
5
|
+
const sign = value >= 0 ? '+' : '';
|
|
6
|
+
const formatted = `${sign}${value.toFixed(2)}%`;
|
|
7
|
+
return formatted;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Format a percentage for display.
|
|
11
|
+
*/
|
|
12
|
+
export function formatPercentage(value) {
|
|
13
|
+
const formatted = `${value.toFixed(1)}%`;
|
|
14
|
+
return formatted;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get direction indicator.
|
|
18
|
+
*/
|
|
19
|
+
export function getDirectionIndicator(conviction) {
|
|
20
|
+
if (conviction > 0) {
|
|
21
|
+
return 'bullish';
|
|
22
|
+
}
|
|
23
|
+
if (conviction < 0) {
|
|
24
|
+
return 'bearish';
|
|
25
|
+
}
|
|
26
|
+
return 'neutral';
|
|
27
|
+
}
|
|
28
|
+
export function formatThreadResult(result) {
|
|
29
|
+
if (result.skipped) {
|
|
30
|
+
return {
|
|
31
|
+
index: result.thread_index + 1,
|
|
32
|
+
projectName: result.project_name,
|
|
33
|
+
predicted: 'SKIP',
|
|
34
|
+
actual: formatConviction(result.actual_price_change_percent),
|
|
35
|
+
direction: 'skipped',
|
|
36
|
+
error: '-',
|
|
37
|
+
summary: '(skipped)',
|
|
38
|
+
thread_text: result.thread_text,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const directionLabel = result.direction_correct ? 'correct' : 'incorrect';
|
|
42
|
+
return {
|
|
43
|
+
index: result.thread_index + 1,
|
|
44
|
+
projectName: result.project_name,
|
|
45
|
+
predicted: formatConviction(result.predicted_conviction),
|
|
46
|
+
actual: formatConviction(result.actual_price_change_percent),
|
|
47
|
+
direction: directionLabel,
|
|
48
|
+
error: result.absolute_error !== null ? result.absolute_error.toFixed(2) : '-',
|
|
49
|
+
summary: result.predicted_summary.slice(0, 200) + (result.predicted_summary.length > 200 ? '...' : ''),
|
|
50
|
+
thread_text: result.thread_text.slice(0, 100) + (result.thread_text.length > 100 ? '...' : ''),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function formatSummary(result) {
|
|
54
|
+
return {
|
|
55
|
+
agentName: result.agent_name,
|
|
56
|
+
backtestId: result.backtest_id,
|
|
57
|
+
totalThreads: result.total_threads,
|
|
58
|
+
threadsPredicted: result.threads_predicted,
|
|
59
|
+
threadsSkipped: result.threads_skipped,
|
|
60
|
+
directionAccuracy: formatPercentage(result.direction_accuracy),
|
|
61
|
+
meanAbsoluteError: result.mean_absolute_error.toFixed(2),
|
|
62
|
+
runAt: new Date(result.run_at).toLocaleString(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get accuracy grade based on direction accuracy percentage.
|
|
67
|
+
*/
|
|
68
|
+
export function getAccuracyGrade(accuracy) {
|
|
69
|
+
if (accuracy >= 70) {
|
|
70
|
+
return { grade: 'A', color: 'green' };
|
|
71
|
+
}
|
|
72
|
+
if (accuracy >= 60) {
|
|
73
|
+
return { grade: 'B', color: 'green' };
|
|
74
|
+
}
|
|
75
|
+
if (accuracy >= 50) {
|
|
76
|
+
return { grade: 'C', color: 'honey' };
|
|
77
|
+
}
|
|
78
|
+
if (accuracy >= 40) {
|
|
79
|
+
return { grade: 'D', color: 'red' };
|
|
80
|
+
}
|
|
81
|
+
return { grade: 'F', color: 'red' };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Build a text report of the backtest results.
|
|
85
|
+
*/
|
|
86
|
+
export function buildTextReport(result) {
|
|
87
|
+
const lines = [];
|
|
88
|
+
const summary = formatSummary(result);
|
|
89
|
+
lines.push(`Backtest Results: ${summary.backtestId}`);
|
|
90
|
+
lines.push(`Agent: ${summary.agentName}`);
|
|
91
|
+
lines.push(`Run at: ${summary.runAt}`);
|
|
92
|
+
lines.push('');
|
|
93
|
+
lines.push('--- Summary ---');
|
|
94
|
+
lines.push(`Total threads: ${summary.totalThreads}`);
|
|
95
|
+
lines.push(`Predictions made: ${summary.threadsPredicted}`);
|
|
96
|
+
lines.push(`Skipped: ${summary.threadsSkipped}`);
|
|
97
|
+
lines.push(`Direction accuracy: ${summary.directionAccuracy}`);
|
|
98
|
+
lines.push(`Mean absolute error: ${summary.meanAbsoluteError}`);
|
|
99
|
+
lines.push('');
|
|
100
|
+
lines.push('--- Per-Thread Results ---');
|
|
101
|
+
for (const threadResult of result.thread_results) {
|
|
102
|
+
const formatted = formatThreadResult(threadResult);
|
|
103
|
+
const directionSymbol = formatted.direction === 'correct'
|
|
104
|
+
? '[OK]'
|
|
105
|
+
: formatted.direction === 'skipped'
|
|
106
|
+
? '[--]'
|
|
107
|
+
: '[XX]';
|
|
108
|
+
lines.push(`#${formatted.index} ${formatted.projectName}: Predicted ${formatted.predicted}, Actual ${formatted.actual} ${directionSymbol}`);
|
|
109
|
+
lines.push(`\tThread: ${formatted.thread_text}`);
|
|
110
|
+
lines.push(`\tSummary: ${formatted.summary}`);
|
|
111
|
+
}
|
|
112
|
+
return lines.join('\n');
|
|
113
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { processSignalAndSummarize } from '../agent/analysis.js';
|
|
2
|
+
import { loadMemory } from '@hive-org/sdk';
|
|
3
|
+
import { getAllTools, initializeSkills, getSkillMetadataList, getReadSkillTool, } from '../agent/tools/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Run a backtest against an agent configuration.
|
|
6
|
+
*/
|
|
7
|
+
export async function runBacktest(backtest, config, callbacks) {
|
|
8
|
+
const { agentPath, soulContent, strategyContent, agentName } = config;
|
|
9
|
+
const threads = backtest.threads;
|
|
10
|
+
const results = [];
|
|
11
|
+
// Load agent tools and skills
|
|
12
|
+
const baseTools = getAllTools();
|
|
13
|
+
const skillRegistry = await initializeSkills(agentPath);
|
|
14
|
+
const tools = { ...baseTools };
|
|
15
|
+
if (skillRegistry.size > 0) {
|
|
16
|
+
tools['readSkill'] = getReadSkillTool(skillRegistry);
|
|
17
|
+
}
|
|
18
|
+
const availableSkills = getSkillMetadataList(skillRegistry) || undefined;
|
|
19
|
+
// Load memory once (static for backtest)
|
|
20
|
+
const memory = await loadMemory();
|
|
21
|
+
for (let i = 0; i < threads.length; i++) {
|
|
22
|
+
const thread = threads[i];
|
|
23
|
+
callbacks?.onThreadStart?.(i, threads.length, thread);
|
|
24
|
+
// Convert BacktestThread to ThreadDto format (without price_on_eval)
|
|
25
|
+
const threadDto = convertToThreadDto(thread, i);
|
|
26
|
+
// Run analysis
|
|
27
|
+
const analysisResult = await processSignalAndSummarize(threadDto, [], // No recent comments in backtest
|
|
28
|
+
memory, soulContent, strategyContent, tools, availableSkills);
|
|
29
|
+
// Calculate actual price change
|
|
30
|
+
const actualPriceChangePercent = calculatePriceChange(thread.price_on_fetch, thread.price_on_eval);
|
|
31
|
+
// Build result
|
|
32
|
+
const result = buildThreadResult(i, thread, analysisResult, actualPriceChangePercent);
|
|
33
|
+
results.push(result);
|
|
34
|
+
callbacks?.onThreadComplete?.(i, result);
|
|
35
|
+
}
|
|
36
|
+
// Calculate summary statistics
|
|
37
|
+
const runResult = buildRunResult(backtest.metadata.id, agentName, results);
|
|
38
|
+
return runResult;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Convert a BacktestThread to ThreadDto format for the agent.
|
|
42
|
+
* Strips price_on_eval since the agent shouldn't see the outcome.
|
|
43
|
+
*/
|
|
44
|
+
function convertToThreadDto(thread, index) {
|
|
45
|
+
const dto = {
|
|
46
|
+
id: `backtest-thread-${index}`,
|
|
47
|
+
pollen_id: `backtest-pollen-${index}`,
|
|
48
|
+
project_id: thread.project_id,
|
|
49
|
+
project_name: thread.project_name,
|
|
50
|
+
project_categories: thread.project_categories,
|
|
51
|
+
project_description: thread.project_description,
|
|
52
|
+
project_symbol: thread.project_symbol,
|
|
53
|
+
price_on_eval: thread.price_on_eval,
|
|
54
|
+
text: thread.text,
|
|
55
|
+
timestamp: thread.timestamp,
|
|
56
|
+
locked: false,
|
|
57
|
+
created_at: thread.timestamp,
|
|
58
|
+
updated_at: thread.timestamp,
|
|
59
|
+
price_on_fetch: thread.price_on_fetch,
|
|
60
|
+
// Intentionally omitting price_on_eval - agent should not see outcome
|
|
61
|
+
citations: thread.citations,
|
|
62
|
+
};
|
|
63
|
+
return dto;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Calculate percentage price change.
|
|
67
|
+
*/
|
|
68
|
+
function calculatePriceChange(priceOnFetch, priceOnEval) {
|
|
69
|
+
const change = ((priceOnEval - priceOnFetch) / priceOnFetch) * 100;
|
|
70
|
+
return change;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build a thread result from analysis output.
|
|
74
|
+
*/
|
|
75
|
+
function buildThreadResult(index, thread, analysis, actualPriceChangePercent) {
|
|
76
|
+
if (analysis.skip) {
|
|
77
|
+
return {
|
|
78
|
+
thread_index: index,
|
|
79
|
+
project_id: thread.project_id,
|
|
80
|
+
project_name: thread.project_name,
|
|
81
|
+
thread_text: thread.text,
|
|
82
|
+
predicted_conviction: 0,
|
|
83
|
+
predicted_summary: '',
|
|
84
|
+
skipped: true,
|
|
85
|
+
actual_price_change_percent: actualPriceChangePercent,
|
|
86
|
+
direction_correct: null,
|
|
87
|
+
absolute_error: null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Determine direction correctness
|
|
91
|
+
const predictedDirection = Math.sign(analysis.conviction);
|
|
92
|
+
const actualDirection = Math.sign(actualPriceChangePercent);
|
|
93
|
+
const directionCorrect = predictedDirection === actualDirection;
|
|
94
|
+
// Calculate absolute error
|
|
95
|
+
const absoluteError = Math.abs(analysis.conviction - actualPriceChangePercent);
|
|
96
|
+
return {
|
|
97
|
+
thread_index: index,
|
|
98
|
+
project_id: thread.project_id,
|
|
99
|
+
project_name: thread.project_name,
|
|
100
|
+
thread_text: thread.text,
|
|
101
|
+
predicted_conviction: analysis.conviction,
|
|
102
|
+
predicted_summary: analysis.summary,
|
|
103
|
+
skipped: false,
|
|
104
|
+
actual_price_change_percent: actualPriceChangePercent,
|
|
105
|
+
direction_correct: directionCorrect,
|
|
106
|
+
absolute_error: absoluteError,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Build the final run result with summary statistics.
|
|
111
|
+
*/
|
|
112
|
+
function buildRunResult(backtestId, agentName, results) {
|
|
113
|
+
const totalThreads = results.length;
|
|
114
|
+
const predictedResults = results.filter((r) => !r.skipped);
|
|
115
|
+
const threadsPredicted = predictedResults.length;
|
|
116
|
+
const threadsSkipped = totalThreads - threadsPredicted;
|
|
117
|
+
// Calculate direction accuracy
|
|
118
|
+
const correctDirections = predictedResults.filter((r) => r.direction_correct === true).length;
|
|
119
|
+
const directionAccuracy = threadsPredicted > 0 ? (correctDirections / threadsPredicted) * 100 : 0;
|
|
120
|
+
// Calculate mean absolute error
|
|
121
|
+
const totalError = predictedResults.reduce((sum, r) => sum + (r.absolute_error ?? 0), 0);
|
|
122
|
+
const meanAbsoluteError = threadsPredicted > 0 ? totalError / threadsPredicted : 0;
|
|
123
|
+
return {
|
|
124
|
+
backtest_id: backtestId,
|
|
125
|
+
agent_name: agentName,
|
|
126
|
+
run_at: new Date().toISOString(),
|
|
127
|
+
thread_results: results,
|
|
128
|
+
total_threads: totalThreads,
|
|
129
|
+
threads_predicted: threadsPredicted,
|
|
130
|
+
threads_skipped: threadsSkipped,
|
|
131
|
+
direction_accuracy: directionAccuracy,
|
|
132
|
+
mean_absolute_error: meanAbsoluteError,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_BACKTEST_DATA } from './default-backtest-data.js';
|
|
2
|
+
/**
|
|
3
|
+
* ID for the bundled default backtest dataset.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_BACKTEST_ID = 'default';
|
|
6
|
+
/**
|
|
7
|
+
* Load the bundled default backtest dataset.
|
|
8
|
+
*/
|
|
9
|
+
export function loadDefaultBacktest() {
|
|
10
|
+
return DEFAULT_BACKTEST_DATA;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
export async function install(targetDir = process.cwd(), options = {}) {
|
|
10
|
+
const packageJsonPath = path.join(targetDir, 'package.json');
|
|
11
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
12
|
+
throw new Error('No package.json found. Please run this command in the root of your project.');
|
|
13
|
+
}
|
|
14
|
+
console.log(chalk.blue('Installing Hive bootstrap...'));
|
|
15
|
+
const dir = path.join(targetDir, 'hive');
|
|
16
|
+
await fs.ensureDir(dir);
|
|
17
|
+
const templatesDir = path.resolve(__dirname, '../../templates/hive');
|
|
18
|
+
if (!fs.existsSync(templatesDir)) {
|
|
19
|
+
throw new Error(`Templates directory not found at ${templatesDir}`);
|
|
20
|
+
}
|
|
21
|
+
await fs.copy(templatesDir, dir);
|
|
22
|
+
console.log(chalk.green('\u2713 Bootstrap code copied to hive/'));
|
|
23
|
+
// Hive dependencies: @hive-org/sdk (and dotenv if missing)
|
|
24
|
+
console.log(chalk.blue('Installing dependencies...'));
|
|
25
|
+
try {
|
|
26
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
27
|
+
const deps = packageJson.dependencies ?? {};
|
|
28
|
+
const hasSdk = deps['@hive-org/sdk'];
|
|
29
|
+
const hasDotenv = deps['dotenv'];
|
|
30
|
+
const toInstall = [];
|
|
31
|
+
if (!hasSdk) {
|
|
32
|
+
toInstall.push('@hive-org/sdk@*');
|
|
33
|
+
}
|
|
34
|
+
if (!hasDotenv) {
|
|
35
|
+
toInstall.push('dotenv');
|
|
36
|
+
}
|
|
37
|
+
if (toInstall.length > 0) {
|
|
38
|
+
await execAsync(`pnpm add ${toInstall.join(' ')}`, { cwd: targetDir });
|
|
39
|
+
console.log(chalk.green('\u2713 Dependencies installed'));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(chalk.gray('Dependencies already installed.'));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
47
|
+
console.error(chalk.yellow("Warning: Failed to install dependencies automatically. Please run 'pnpm add @hive-org/sdk dotenv' manually."));
|
|
48
|
+
}
|
|
49
|
+
console.log(chalk.green('\nHive installed successfully!'));
|
|
50
|
+
}
|