@zhive/cli 0.6.6 → 0.6.8
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/commands/agent/commands/profile.js +3 -15
- package/dist/commands/agent/commands/profile.test.js +2 -23
- package/dist/commands/create/presets/index.js +1 -1
- package/dist/commands/create/presets/options.js +18 -15
- package/dist/commands/create/ui/steps/IdentityStep.js +3 -2
- package/dist/commands/doctor/commands/index.js +5 -11
- package/dist/commands/indicator/commands/bollinger.js +37 -0
- package/dist/commands/indicator/commands/ema.js +37 -0
- package/dist/commands/indicator/commands/index.js +14 -0
- package/dist/commands/indicator/commands/macd.js +51 -0
- package/dist/commands/indicator/commands/rsi.js +37 -0
- package/dist/commands/indicator/commands/sma.js +37 -0
- package/dist/commands/market/commands/index.js +5 -0
- package/dist/commands/market/commands/price.js +25 -0
- package/dist/commands/megathread/commands/create-comment.js +2 -7
- package/dist/commands/megathread/commands/create-comment.test.js +3 -30
- package/dist/commands/megathread/commands/create-comments.js +2 -7
- package/dist/commands/megathread/commands/list.js +5 -10
- package/dist/commands/megathread/commands/list.test.js +3 -21
- package/dist/commands/migrate-templates/ui/MigrateApp.js +1 -1
- package/dist/commands/shared/utils.js +12 -0
- package/dist/commands/start/commands/prediction.js +1 -1
- package/dist/commands/start/commands/skills.test.js +1 -2
- package/dist/components/MultiSelectPrompt.js +3 -3
- package/dist/index.js +4 -0
- package/dist/shared/agent/analysis.js +2 -12
- package/dist/shared/agent/cache.js +10 -0
- package/dist/shared/agent/handler.js +3 -9
- package/dist/shared/agent/prompts/megathread.js +0 -8
- package/dist/shared/agent/tools/execute-skill-tool.js +2 -1
- package/dist/shared/agent/tools/formatting.js +0 -19
- package/dist/shared/agent/tools/market/client.js +3 -3
- package/dist/shared/agent/tools/market/tools.js +88 -312
- package/dist/shared/agent/tools/market/utils.js +71 -0
- package/dist/shared/agent/tools/mindshare/tools.js +1 -1
- package/dist/shared/agent/tools/ta/index.js +3 -1
- package/dist/shared/agent/utils.js +44 -0
- package/dist/shared/config/agent.js +4 -0
- package/dist/shared/config/agent.test.js +0 -5
- package/dist/shared/ta/error.js +12 -0
- package/dist/shared/ta/service.js +93 -0
- package/dist/shared/ta/utils.js +16 -0
- package/package.json +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { findAgentByName
|
|
2
|
+
import { findAgentByName } from '../../../shared/config/agent.js';
|
|
3
3
|
import { styled, symbols } from '../../shared/theme.js';
|
|
4
|
-
import {
|
|
4
|
+
import { printAgentNotFoundHelper } from '../../shared/utils.js';
|
|
5
5
|
export const createAgentProfileCommand = () => {
|
|
6
6
|
return new Command('profile')
|
|
7
7
|
.description('Display agent profile information')
|
|
@@ -9,19 +9,7 @@ export const createAgentProfileCommand = () => {
|
|
|
9
9
|
.action(async (agentName) => {
|
|
10
10
|
const agentConfig = await findAgentByName(agentName);
|
|
11
11
|
if (!agentConfig) {
|
|
12
|
-
|
|
13
|
-
if (agents.length === 0) {
|
|
14
|
-
console.error(styled.red(`${symbols.cross} No agents found. Create one with: npx @zhive/cli@latest create`));
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
const availableNames = agents.map((a) => a.name).join(', ');
|
|
18
|
-
console.error(styled.red(`${symbols.cross} Agent "${agentName}" not found. Available agents: ${availableNames}`));
|
|
19
|
-
}
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
const credentials = await loadConfig(agentConfig.dir);
|
|
23
|
-
if (!credentials?.apiKey) {
|
|
24
|
-
console.error(styled.red(`${symbols.cross} No credentials found for agent "${agentName}". The agent may need to be registered first.`));
|
|
12
|
+
await printAgentNotFoundHelper(agentName);
|
|
25
13
|
process.exit(1);
|
|
26
14
|
}
|
|
27
15
|
console.log('');
|
|
@@ -10,13 +10,6 @@ vi.mock('../../../shared/config/constant.js', () => ({
|
|
|
10
10
|
vi.mock('../../../shared/config/ai-providers.js', () => ({
|
|
11
11
|
AI_PROVIDERS: [{ label: 'OpenAI', package: '@ai-sdk/openai', envVar: 'OPENAI_API_KEY' }],
|
|
12
12
|
}));
|
|
13
|
-
vi.mock('@zhive/sdk', async () => {
|
|
14
|
-
const actual = await vi.importActual('@zhive/sdk');
|
|
15
|
-
return {
|
|
16
|
-
...actual,
|
|
17
|
-
loadConfig: vi.fn(),
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
13
|
vi.mock('../../shared/theme.js', () => ({
|
|
21
14
|
styled: {
|
|
22
15
|
red: (text) => text,
|
|
@@ -32,9 +25,7 @@ vi.mock('../../shared/theme.js', () => ({
|
|
|
32
25
|
hive: '⬡',
|
|
33
26
|
},
|
|
34
27
|
}));
|
|
35
|
-
import { loadConfig } from '@zhive/sdk';
|
|
36
28
|
import { createAgentProfileCommand } from './profile.js';
|
|
37
|
-
const mockLoadConfig = loadConfig;
|
|
38
29
|
describe('createAgentProfileCommand', () => {
|
|
39
30
|
let consoleLogSpy;
|
|
40
31
|
let consoleErrorSpy;
|
|
@@ -72,20 +63,11 @@ describe('createAgentProfileCommand', () => {
|
|
|
72
63
|
expect(consoleErrorOutput.join('\n')).toContain('agent-no-skills');
|
|
73
64
|
});
|
|
74
65
|
it('shows error when credentials are missing', async () => {
|
|
75
|
-
mockLoadConfig.mockResolvedValue(null);
|
|
76
|
-
const command = createAgentProfileCommand();
|
|
77
|
-
await expect(command.parseAsync(['test-agent'], { from: 'user' })).rejects.toThrow('process.exit(1)');
|
|
78
|
-
expect(consoleErrorOutput.join('\n')).toContain('No credentials found for agent "test-agent"');
|
|
79
|
-
expect(consoleErrorOutput.join('\n')).toContain('may need to be registered first');
|
|
80
|
-
});
|
|
81
|
-
it('shows error when credentials have no API key', async () => {
|
|
82
|
-
mockLoadConfig.mockResolvedValue({ apiKey: null });
|
|
83
66
|
const command = createAgentProfileCommand();
|
|
84
|
-
await expect(command.parseAsync(['
|
|
85
|
-
expect(consoleErrorOutput.join('\n')).toContain('
|
|
67
|
+
await expect(command.parseAsync(['no-cred'], { from: 'user' })).rejects.toThrow('process.exit(1)');
|
|
68
|
+
expect(consoleErrorOutput.join('\n')).toContain('Agent "no-cred" not found');
|
|
86
69
|
});
|
|
87
70
|
it('displays profile from local config', async () => {
|
|
88
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
89
71
|
const command = createAgentProfileCommand();
|
|
90
72
|
await command.parseAsync(['test-agent'], { from: 'user' });
|
|
91
73
|
const output = consoleOutput.join('\n');
|
|
@@ -98,7 +80,6 @@ describe('createAgentProfileCommand', () => {
|
|
|
98
80
|
expect(output).toContain('https://example.com/avatar.png');
|
|
99
81
|
});
|
|
100
82
|
it('displays profile settings section', async () => {
|
|
101
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
102
83
|
const command = createAgentProfileCommand();
|
|
103
84
|
await command.parseAsync(['test-agent'], { from: 'user' });
|
|
104
85
|
const output = consoleOutput.join('\n');
|
|
@@ -111,7 +92,6 @@ describe('createAgentProfileCommand', () => {
|
|
|
111
92
|
expect(output).toContain('defi, gaming');
|
|
112
93
|
});
|
|
113
94
|
it('handles agent with empty sectors', async () => {
|
|
114
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
115
95
|
const command = createAgentProfileCommand();
|
|
116
96
|
await command.parseAsync(['empty-agent'], { from: 'user' });
|
|
117
97
|
const output = consoleOutput.join('\n');
|
|
@@ -124,7 +104,6 @@ describe('createAgentProfileCommand', () => {
|
|
|
124
104
|
expect(sectorsLine).toContain('-');
|
|
125
105
|
});
|
|
126
106
|
it('works with different fixture agents', async () => {
|
|
127
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
128
107
|
const command = createAgentProfileCommand();
|
|
129
108
|
await command.parseAsync(['agent-no-skills'], { from: 'user' });
|
|
130
109
|
const output = consoleOutput.join('\n');
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { SOUL_PRESETS, STRATEGY_PRESETS } from './data.js';
|
|
2
|
-
export { PERSONALITY_OPTIONS, VOICE_OPTIONS, BIO_EXAMPLES, TRADING_STYLE_OPTIONS, SENTIMENT_OPTIONS, TIMEFRAME_OPTIONS, PROJECT_CATEGORY_OPTIONS, } from './options.js';
|
|
2
|
+
export { PERSONALITY_OPTIONS, VOICE_OPTIONS, BIO_EXAMPLES, TRADING_STYLE_OPTIONS, SENTIMENT_OPTIONS, TIMEFRAME_OPTIONS, PROJECT_CATEGORY_OPTIONS, DEFAULT_SECTOR_VALUES, } from './options.js';
|
|
3
3
|
export { buildSoulMarkdown, buildStrategyMarkdown } from './formatting.js';
|
|
@@ -203,6 +203,14 @@ export const TIMEFRAME_OPTIONS = [
|
|
|
203
203
|
description: 'Longer-term, macro-style predictions',
|
|
204
204
|
},
|
|
205
205
|
];
|
|
206
|
+
export const DEFAULT_SECTOR_VALUES = new Set([
|
|
207
|
+
'l1',
|
|
208
|
+
'l2',
|
|
209
|
+
'defi',
|
|
210
|
+
'ai',
|
|
211
|
+
'lending',
|
|
212
|
+
'prediction-markets',
|
|
213
|
+
]);
|
|
206
214
|
export const PROJECT_CATEGORY_OPTIONS = [
|
|
207
215
|
{
|
|
208
216
|
label: '🔷 Layer 1',
|
|
@@ -224,6 +232,16 @@ export const PROJECT_CATEGORY_OPTIONS = [
|
|
|
224
232
|
value: 'ai',
|
|
225
233
|
description: 'AI and compute tokens — FET, RENDER, TAO, AKT, etc.',
|
|
226
234
|
},
|
|
235
|
+
{
|
|
236
|
+
label: '🏛️ Lending',
|
|
237
|
+
value: 'lending',
|
|
238
|
+
description: 'Lending and borrowing protocols — AAVE, COMP, MORPHO, etc.',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
label: '🎯 Prediction Markets',
|
|
242
|
+
value: 'prediction-markets',
|
|
243
|
+
description: 'Prediction and betting markets — POLY, GNO, etc.',
|
|
244
|
+
},
|
|
227
245
|
{
|
|
228
246
|
label: '🐸 Memecoins',
|
|
229
247
|
value: 'meme',
|
|
@@ -254,16 +272,6 @@ export const PROJECT_CATEGORY_OPTIONS = [
|
|
|
254
272
|
value: 'dex',
|
|
255
273
|
description: 'Decentralized exchanges — UNI, SUSHI, CRV, JUP, etc.',
|
|
256
274
|
},
|
|
257
|
-
{
|
|
258
|
-
label: '🏛️ Lending',
|
|
259
|
-
value: 'lending',
|
|
260
|
-
description: 'Lending and borrowing protocols — AAVE, COMP, MORPHO, etc.',
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
label: '💵 Stablecoin',
|
|
264
|
-
value: 'stablecoin',
|
|
265
|
-
description: 'Stablecoin protocols and pegged assets — MKR, FXS, LQTY, etc.',
|
|
266
|
-
},
|
|
267
275
|
{
|
|
268
276
|
label: '🌉 Cross-chain',
|
|
269
277
|
value: 'cross-chain',
|
|
@@ -289,11 +297,6 @@ export const PROJECT_CATEGORY_OPTIONS = [
|
|
|
289
297
|
value: 'social',
|
|
290
298
|
description: 'Social and identity protocols — LENS, CYBER, ID, etc.',
|
|
291
299
|
},
|
|
292
|
-
{
|
|
293
|
-
label: '🎯 Prediction Markets',
|
|
294
|
-
value: 'prediction-markets',
|
|
295
|
-
description: 'Prediction and betting markets — POLY, GNO, etc.',
|
|
296
|
-
},
|
|
297
300
|
{
|
|
298
301
|
label: '🖼️ NFT',
|
|
299
302
|
value: 'nft',
|
|
@@ -5,7 +5,7 @@ import { SelectPrompt } from '../../../../components/SelectPrompt.js';
|
|
|
5
5
|
import { MultiSelectPrompt, } from '../../../../components/MultiSelectPrompt.js';
|
|
6
6
|
import { TextPrompt } from '../../../../components/TextPrompt.js';
|
|
7
7
|
import { CharacterSummaryCard } from '../../../../components/CharacterSummaryCard.js';
|
|
8
|
-
import { PERSONALITY_OPTIONS, VOICE_OPTIONS, TRADING_STYLE_OPTIONS, PROJECT_CATEGORY_OPTIONS, SENTIMENT_OPTIONS, TIMEFRAME_OPTIONS, BIO_EXAMPLES, } from '../../presets/index.js';
|
|
8
|
+
import { PERSONALITY_OPTIONS, VOICE_OPTIONS, TRADING_STYLE_OPTIONS, PROJECT_CATEGORY_OPTIONS, SENTIMENT_OPTIONS, TIMEFRAME_OPTIONS, DEFAULT_SECTOR_VALUES, BIO_EXAMPLES, } from '../../presets/index.js';
|
|
9
9
|
import { colors, symbols } from '../../../shared/theme.js';
|
|
10
10
|
import { required, compose, maxLength } from '../validation.js';
|
|
11
11
|
function buildSelectItems(options, addCustom = false) {
|
|
@@ -25,6 +25,7 @@ const tradingStyleItems = buildSelectItems(TRADING_STYLE_OPTIONS, true);
|
|
|
25
25
|
const categoryItems = buildSelectItems(PROJECT_CATEGORY_OPTIONS);
|
|
26
26
|
const sentimentItems = buildSelectItems(SENTIMENT_OPTIONS);
|
|
27
27
|
const timeframeItems = buildSelectItems(TIMEFRAME_OPTIONS);
|
|
28
|
+
const timeframeDefaultSelected = new Set(TIMEFRAME_OPTIONS.filter((opt) => opt.value !== '1h').map((opt) => opt.value));
|
|
28
29
|
export function IdentityStep({ agentName, onComplete }) {
|
|
29
30
|
const [subStep, setSubStep] = useState('personality');
|
|
30
31
|
const [personalityLabel, setPersonalityLabel] = useState('');
|
|
@@ -121,5 +122,5 @@ export function IdentityStep({ agentName, onComplete }) {
|
|
|
121
122
|
};
|
|
122
123
|
onComplete(result);
|
|
123
124
|
}, [personality, tone, voiceStyle, tradingStyle, sectors, sentiment, timeframes, onComplete]);
|
|
124
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(CharacterSummaryCard, { name: agentName, personality: personalityLabel || undefined, voice: voiceLabel || undefined, tradingStyle: tradingStyleLabel || undefined, sectors: sectorsLabel || undefined, sentiment: sentimentLabel || undefined, timeframe: timeframesLabel || undefined }), subStep === 'personality' && (_jsx(SelectPrompt, { label: "Choose a personality", items: personalityItems, onSelect: handlePersonalitySelect })), subStep === 'personality-custom' && (_jsx(TextPrompt, { label: "Describe your agent's personality", placeholder: "e.g. stoic realist with a dry wit", onSubmit: handlePersonalityCustom, validate: required('Personality') })), subStep === 'voice' && (_jsx(SelectPrompt, { label: "Choose a voice", items: voiceItems, onSelect: handleVoiceSelect })), subStep === 'voice-custom' && (_jsx(TextPrompt, { label: "Describe your agent's voice", placeholder: "e.g. writes like a bloomberg terminal on acid", onSubmit: handleVoiceCustom, validate: required('Voice') })), subStep === 'trading' && (_jsx(SelectPrompt, { label: "How does your agent evaluate signals?", items: tradingStyleItems, onSelect: handleTradingStyleSelect })), subStep === 'trading-custom' && (_jsx(TextPrompt, { label: "Describe your agent's trading style", placeholder: "e.g. combines on-chain data with sentiment analysis", onSubmit: handleTradingStyleCustom, validate: required('Trading style') })), subStep === 'sectors' && (_jsx(MultiSelectPrompt, { label: "Which categories should your agent trade?", items: categoryItems, onSubmit: handleSectors })), subStep === 'sentiment' && (_jsx(SelectPrompt, { label: "What's your agent's market sentiment?", items: sentimentItems, onSelect: handleSentimentSelect })), subStep === 'timeframe' && (_jsx(MultiSelectPrompt, { label: "Which timeframes should your agent participate in?", items: timeframeItems, onSubmit: handleTimeframes })), subStep === 'bio' && (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { flexDirection: "column", marginLeft: 2, marginBottom: 1, children: [_jsxs(Text, { color: colors.grayDim, italic: true, children: [symbols.arrow, " Examples:"] }), BIO_EXAMPLES.map((example, i) => (_jsx(Box, { marginLeft: 2, marginTop: i > 0 ? 1 : 0, children: _jsxs(Text, { color: colors.grayDim, italic: true, children: [symbols.diamond, " ", `"${example}"`] }) }, i)))] }), _jsx(TextPrompt, { label: "Write your agent's bio", placeholder: `short bio for your ${personalityLabel} agent`, onSubmit: handleBio, maxLength: 1000, validate: compose(required('Bio'), maxLength(1000)) })] }))] }));
|
|
125
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(CharacterSummaryCard, { name: agentName, personality: personalityLabel || undefined, voice: voiceLabel || undefined, tradingStyle: tradingStyleLabel || undefined, sectors: sectorsLabel || undefined, sentiment: sentimentLabel || undefined, timeframe: timeframesLabel || undefined }), subStep === 'personality' && (_jsx(SelectPrompt, { label: "Choose a personality", items: personalityItems, onSelect: handlePersonalitySelect })), subStep === 'personality-custom' && (_jsx(TextPrompt, { label: "Describe your agent's personality", placeholder: "e.g. stoic realist with a dry wit", onSubmit: handlePersonalityCustom, validate: required('Personality') })), subStep === 'voice' && (_jsx(SelectPrompt, { label: "Choose a voice", items: voiceItems, onSelect: handleVoiceSelect })), subStep === 'voice-custom' && (_jsx(TextPrompt, { label: "Describe your agent's voice", placeholder: "e.g. writes like a bloomberg terminal on acid", onSubmit: handleVoiceCustom, validate: required('Voice') })), subStep === 'trading' && (_jsx(SelectPrompt, { label: "How does your agent evaluate signals?", items: tradingStyleItems, onSelect: handleTradingStyleSelect })), subStep === 'trading-custom' && (_jsx(TextPrompt, { label: "Describe your agent's trading style", placeholder: "e.g. combines on-chain data with sentiment analysis", onSubmit: handleTradingStyleCustom, validate: required('Trading style') })), subStep === 'sectors' && (_jsx(MultiSelectPrompt, { label: "Which categories should your agent trade?", items: categoryItems, defaultSelected: DEFAULT_SECTOR_VALUES, hint: "Recommended categories selected \u2014 press spacebar to toggle", onSubmit: handleSectors })), subStep === 'sentiment' && (_jsx(SelectPrompt, { label: "What's your agent's market sentiment?", items: sentimentItems, onSelect: handleSentimentSelect })), subStep === 'timeframe' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { marginLeft: 2, marginBottom: 1, children: _jsxs(Text, { color: colors.hot, bold: true, children: [symbols.arrow, " Warning: Selecting the 1h timeframe will significantly increase token usage."] }) }), _jsx(MultiSelectPrompt, { label: "Which timeframes should your agent participate in?", items: timeframeItems, defaultSelected: timeframeDefaultSelected, hint: "4h and 24h selected by default \u2014 press spacebar to toggle", onSubmit: handleTimeframes })] })), subStep === 'bio' && (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { flexDirection: "column", marginLeft: 2, marginBottom: 1, children: [_jsxs(Text, { color: colors.grayDim, italic: true, children: [symbols.arrow, " Examples:"] }), BIO_EXAMPLES.map((example, i) => (_jsx(Box, { marginLeft: 2, marginTop: i > 0 ? 1 : 0, children: _jsxs(Text, { color: colors.grayDim, italic: true, children: [symbols.diamond, " ", `"${example}"`] }) }, i)))] }), _jsx(TextPrompt, { label: "Write your agent's bio", placeholder: `short bio for your ${personalityLabel} agent`, onSubmit: handleBio, maxLength: 1000, validate: compose(required('Bio'), maxLength(1000)) })] }))] }));
|
|
125
126
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fsExtra from 'fs-extra';
|
|
4
|
-
import { HiveClient
|
|
4
|
+
import { HiveClient } from '@zhive/sdk';
|
|
5
5
|
import { styled, symbols } from '../../shared/theme.js';
|
|
6
6
|
import { getHiveDir, HIVE_API_URL } from '../../../shared/config/constant.js';
|
|
7
7
|
import { loadAgentConfig } from '../../../shared/config/agent.js';
|
|
@@ -13,26 +13,20 @@ async function checkAgent(agentDir, dirName) {
|
|
|
13
13
|
configError: null,
|
|
14
14
|
registrationStatus: 'skipped',
|
|
15
15
|
};
|
|
16
|
-
let
|
|
16
|
+
let config;
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
config = await loadAgentConfig(agentDir);
|
|
19
19
|
result.name = config.name;
|
|
20
|
-
configLoaded = true;
|
|
21
20
|
}
|
|
22
21
|
catch (err) {
|
|
23
22
|
const message = err instanceof Error ? err.message : String(err);
|
|
24
23
|
result.configError = message;
|
|
25
24
|
}
|
|
26
|
-
if (!
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
const credentials = await loadConfig(agentDir);
|
|
30
|
-
if (!credentials?.apiKey) {
|
|
31
|
-
result.registrationStatus = 'no-api-key';
|
|
25
|
+
if (!config) {
|
|
32
26
|
return result;
|
|
33
27
|
}
|
|
34
28
|
try {
|
|
35
|
-
const client = new HiveClient(HIVE_API_URL,
|
|
29
|
+
const client = new HiveClient(HIVE_API_URL, config.apiKey);
|
|
36
30
|
await client.getMe();
|
|
37
31
|
result.registrationStatus = 'registered';
|
|
38
32
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { InsufficientDataError } from '../../../shared/ta/error.js';
|
|
3
|
+
import { getBollingerBands } from '../../../shared/ta/service.js';
|
|
4
|
+
import { styled } from '../../shared/theme.js';
|
|
5
|
+
export const createBollingerCommand = () => {
|
|
6
|
+
return new Command('bollinger')
|
|
7
|
+
.description(`Compute bollinger bands of given project's price`)
|
|
8
|
+
.requiredOption('--project <project>', 'Project id')
|
|
9
|
+
.option('--period <period>', 'bollinger bands period. Defaults to 20')
|
|
10
|
+
.option('--interval <interval>', 'ohlc interval. valid options are [hourly, daily]')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const { project, period: periodStr = '20', interval = 'hourly' } = options;
|
|
13
|
+
let period = Number(periodStr);
|
|
14
|
+
if (Number.isNaN(period)) {
|
|
15
|
+
console.log(styled.white(`Invalid period ${periodStr}. override to 20`));
|
|
16
|
+
period = 20;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const bbResult = await getBollingerBands({
|
|
20
|
+
project,
|
|
21
|
+
interval,
|
|
22
|
+
period,
|
|
23
|
+
from: new Date(),
|
|
24
|
+
to: new Date(),
|
|
25
|
+
});
|
|
26
|
+
const last = bbResult.at(-1) ?? {};
|
|
27
|
+
console.log(styled.white(JSON.stringify(last)));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e instanceof InsufficientDataError) {
|
|
31
|
+
console.log(styled.red(`Insufficient data: got ${e.got} data points but need at least ${e.required} for Bollinger Bands(${period}).`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log(styled.red(`Failed to fetch bollinger bands value`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { InsufficientDataError } from '../../../shared/ta/error.js';
|
|
3
|
+
import { getEMA } from '../../../shared/ta/service.js';
|
|
4
|
+
import { styled } from '../../shared/theme.js';
|
|
5
|
+
export const createEmaCommand = () => {
|
|
6
|
+
return new Command('ema')
|
|
7
|
+
.description(`Compute ema of given project's price`)
|
|
8
|
+
.requiredOption('--project <project>', 'Project id')
|
|
9
|
+
.option('--period <period>', 'ema period. Defaults to 12')
|
|
10
|
+
.option('--interval <interval>', 'ohlc interval. valid options are [hourly, daily]')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const { project, period: periodStr = '12', interval = 'hourly' } = options;
|
|
13
|
+
let period = Number(periodStr);
|
|
14
|
+
if (Number.isNaN(period)) {
|
|
15
|
+
console.log(styled.white(`Invalid period ${periodStr}. override to 12`));
|
|
16
|
+
period = 12;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const emaResult = await getEMA({
|
|
20
|
+
project,
|
|
21
|
+
interval,
|
|
22
|
+
period,
|
|
23
|
+
from: new Date(),
|
|
24
|
+
to: new Date(),
|
|
25
|
+
});
|
|
26
|
+
const last = emaResult?.at(-1) ?? {};
|
|
27
|
+
console.log(styled.white(JSON.stringify(last)));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e instanceof InsufficientDataError) {
|
|
31
|
+
console.log(styled.red(`Insufficient data: got ${e.got} data points but need at least ${e.required} for EMA${period}.`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log(styled.red(`Failed to fetch ema value`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createBollingerCommand } from './bollinger.js';
|
|
3
|
+
import { createEmaCommand } from './ema.js';
|
|
4
|
+
import { createMacdCommand } from './macd.js';
|
|
5
|
+
import { createRsiCommand } from './rsi.js';
|
|
6
|
+
import { createSmaCommand } from './sma.js';
|
|
7
|
+
export const createIndicatorCommand = () => {
|
|
8
|
+
return new Command('indicator')
|
|
9
|
+
.addCommand(createRsiCommand())
|
|
10
|
+
.addCommand(createSmaCommand())
|
|
11
|
+
.addCommand(createEmaCommand())
|
|
12
|
+
.addCommand(createMacdCommand())
|
|
13
|
+
.addCommand(createBollingerCommand());
|
|
14
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { InsufficientDataError } from '../../../shared/ta/error.js';
|
|
3
|
+
import { getMACD } from '../../../shared/ta/service.js';
|
|
4
|
+
import { styled } from '../../shared/theme.js';
|
|
5
|
+
export const createMacdCommand = () => {
|
|
6
|
+
return new Command('macd')
|
|
7
|
+
.description(`Compute macd of given project's price`)
|
|
8
|
+
.requiredOption('--project <project>', 'Project id')
|
|
9
|
+
.option('--fast <fast>', 'fast ema period. Defaults to 12')
|
|
10
|
+
.option('--slow <slow>', 'slow ema period. Defaults to 26')
|
|
11
|
+
.option('--signal <signal>', 'signal line period. Defaults to 9')
|
|
12
|
+
.option('--interval <interval>', 'ohlc interval. valid options are [hourly, daily]')
|
|
13
|
+
.action(async (options) => {
|
|
14
|
+
const { project, fast: fastStr = '12', slow: slowStr = '26', signal: signalStr = '9', interval = 'hourly', } = options;
|
|
15
|
+
let fast = Number(fastStr);
|
|
16
|
+
if (Number.isNaN(fast)) {
|
|
17
|
+
console.log(styled.white(`Invalid fast period ${fastStr}. override to 12`));
|
|
18
|
+
fast = 12;
|
|
19
|
+
}
|
|
20
|
+
let slow = Number(slowStr);
|
|
21
|
+
if (Number.isNaN(slow)) {
|
|
22
|
+
console.log(styled.white(`Invalid slow period ${slowStr}. override to 26`));
|
|
23
|
+
slow = 26;
|
|
24
|
+
}
|
|
25
|
+
let signal = Number(signalStr);
|
|
26
|
+
if (Number.isNaN(signal)) {
|
|
27
|
+
console.log(styled.white(`Invalid signal period ${signalStr}. override to 9`));
|
|
28
|
+
signal = 9;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const macdResult = await getMACD({
|
|
32
|
+
project,
|
|
33
|
+
interval,
|
|
34
|
+
fast,
|
|
35
|
+
slow,
|
|
36
|
+
signal,
|
|
37
|
+
from: new Date(),
|
|
38
|
+
to: new Date(),
|
|
39
|
+
});
|
|
40
|
+
const last = macdResult?.at(-1) ?? {};
|
|
41
|
+
console.log(styled.white(JSON.stringify(last)));
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e instanceof InsufficientDataError) {
|
|
45
|
+
console.log(styled.red(`Insufficient data: got ${e.got} data points but need at least ${e.required} for MACD(${fast},${slow},${signal}).`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log(styled.red(`Failed to fetch macd value`));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { InsufficientDataError } from '../../../shared/ta/error.js';
|
|
3
|
+
import { getRSI } from '../../../shared/ta/service.js';
|
|
4
|
+
import { styled } from '../../shared/theme.js';
|
|
5
|
+
export const createRsiCommand = () => {
|
|
6
|
+
return new Command('rsi')
|
|
7
|
+
.description(`Compute rsi of given project's price`)
|
|
8
|
+
.requiredOption('--project <project>', 'Project id')
|
|
9
|
+
.option('--period <period>', 'rsi period. Defaults to 14')
|
|
10
|
+
.option('--interval <interval>', 'ohlc interval. valid options are [hourly, daily]')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const { project, period: periodStr = '14', interval = 'hourly' } = options;
|
|
13
|
+
let period = Number(periodStr);
|
|
14
|
+
if (Number.isNaN(period)) {
|
|
15
|
+
console.log(styled.white(`Invalid period ${periodStr}. override to 14`));
|
|
16
|
+
period = 14;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const rsi = await getRSI({
|
|
20
|
+
project,
|
|
21
|
+
interval,
|
|
22
|
+
period,
|
|
23
|
+
from: new Date(),
|
|
24
|
+
to: new Date(),
|
|
25
|
+
});
|
|
26
|
+
const last = rsi.at(-1) ?? {};
|
|
27
|
+
console.log(styled.white(JSON.stringify(last)));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e instanceof InsufficientDataError) {
|
|
31
|
+
console.log(styled.red(`Insufficient data: got ${e.got} data points but need at least ${e.required} for RSI${period}.`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log(styled.red(`Failed to fetch rsi value`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { InsufficientDataError } from '../../../shared/ta/error.js';
|
|
3
|
+
import { getSMA } from '../../../shared/ta/service.js';
|
|
4
|
+
import { styled } from '../../shared/theme.js';
|
|
5
|
+
export const createSmaCommand = () => {
|
|
6
|
+
return new Command('sma')
|
|
7
|
+
.description(`Compute sma of given project's price`)
|
|
8
|
+
.requiredOption('--project <project>', 'Project id')
|
|
9
|
+
.option('--period <period>', 'sma period. Defaults to 20')
|
|
10
|
+
.option('--interval <interval>', 'ohlc interval. valid options are [hourly, daily]')
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const { project, period: periodStr = '20', interval = 'hourly' } = options;
|
|
13
|
+
let period = Number(periodStr);
|
|
14
|
+
if (Number.isNaN(period)) {
|
|
15
|
+
console.log(styled.white(`Invalid period ${periodStr}. override to 20`));
|
|
16
|
+
period = 20;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const sma = await getSMA({
|
|
20
|
+
project,
|
|
21
|
+
interval,
|
|
22
|
+
period,
|
|
23
|
+
from: new Date(),
|
|
24
|
+
to: new Date(),
|
|
25
|
+
});
|
|
26
|
+
const last = sma.at(-1) ?? {};
|
|
27
|
+
console.log(styled.white(JSON.stringify(last)));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e instanceof InsufficientDataError) {
|
|
31
|
+
console.log(styled.red(`Insufficient data: got ${e.got} data points but need at least ${e.required} for SMA${period}.`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log(styled.red(`Failed to fetch sma value`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getMarketClient } from '../../../shared/agent/tools/market/client.js';
|
|
3
|
+
import { styled } from '../../shared/theme.js';
|
|
4
|
+
export const createPriceCommand = () => {
|
|
5
|
+
return new Command('price')
|
|
6
|
+
.description(`Get current price of a given project`)
|
|
7
|
+
.requiredOption('--project <project>', 'Project id')
|
|
8
|
+
.action(async (options) => {
|
|
9
|
+
const { project } = options;
|
|
10
|
+
try {
|
|
11
|
+
const client = getMarketClient();
|
|
12
|
+
const priceData = await client.getPrice(project, new Date());
|
|
13
|
+
if (priceData.price === null) {
|
|
14
|
+
console.log(styled.white(JSON.stringify({})));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const result = { price: priceData.price, timestamp: priceData.timestamp };
|
|
18
|
+
console.log(styled.white(JSON.stringify(result)));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
const message = e instanceof Error ? e.message : 'Failed to fetch price';
|
|
22
|
+
console.log(styled.red(message));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { HiveClient
|
|
3
|
+
import { HiveClient } from '@zhive/sdk';
|
|
4
4
|
import { styled, symbols } from '../../shared/theme.js';
|
|
5
5
|
import { HIVE_API_URL } from '../../../shared/config/constant.js';
|
|
6
6
|
import { findAgentByName, scanAgents } from '../../../shared/config/agent.js';
|
|
@@ -37,12 +37,7 @@ export function createMegathreadCreateCommentCommand() {
|
|
|
37
37
|
}
|
|
38
38
|
process.exit(1);
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
if (!credentials?.apiKey) {
|
|
42
|
-
console.error(styled.red(`${symbols.cross} No credentials found for agent "${agentName}". The agent may need to be registered first.`));
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
const client = new HiveClient(HIVE_API_URL, credentials.apiKey);
|
|
40
|
+
const client = new HiveClient(HIVE_API_URL, agentConfig.apiKey);
|
|
46
41
|
const payload = {
|
|
47
42
|
text,
|
|
48
43
|
conviction,
|
|
@@ -17,7 +17,6 @@ vi.mock('@zhive/sdk', async () => {
|
|
|
17
17
|
HiveClient: vi.fn().mockImplementation(() => ({
|
|
18
18
|
postMegathreadComment: vi.fn(),
|
|
19
19
|
})),
|
|
20
|
-
loadConfig: vi.fn(),
|
|
21
20
|
};
|
|
22
21
|
});
|
|
23
22
|
vi.mock('../../shared/theme.js', () => ({
|
|
@@ -31,10 +30,9 @@ vi.mock('../../shared/theme.js', () => ({
|
|
|
31
30
|
check: '✓',
|
|
32
31
|
},
|
|
33
32
|
}));
|
|
34
|
-
import { HiveClient
|
|
33
|
+
import { HiveClient } from '@zhive/sdk';
|
|
35
34
|
import { createMegathreadCreateCommentCommand } from './create-comment.js';
|
|
36
35
|
const MockHiveClient = HiveClient;
|
|
37
|
-
const mockLoadConfig = loadConfig;
|
|
38
36
|
describe('createMegathreadCreateCommentCommand', () => {
|
|
39
37
|
let consoleLogSpy;
|
|
40
38
|
let consoleErrorSpy;
|
|
@@ -114,7 +112,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
114
112
|
expect(consoleErrorOutput.join('\n')).toContain('number');
|
|
115
113
|
});
|
|
116
114
|
it('accepts valid conviction at upper boundary', async () => {
|
|
117
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
118
115
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
119
116
|
const command = createMegathreadCreateCommentCommand();
|
|
120
117
|
await command.parseAsync([
|
|
@@ -133,7 +130,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
133
130
|
});
|
|
134
131
|
});
|
|
135
132
|
it('accepts valid conviction at lower boundary', async () => {
|
|
136
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
137
133
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
138
134
|
const command = createMegathreadCreateCommentCommand();
|
|
139
135
|
await command.parseAsync([
|
|
@@ -152,7 +148,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
152
148
|
});
|
|
153
149
|
});
|
|
154
150
|
it('accepts decimal conviction values', async () => {
|
|
155
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
156
151
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
157
152
|
const command = createMegathreadCreateCommentCommand();
|
|
158
153
|
await command.parseAsync([
|
|
@@ -193,26 +188,10 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
193
188
|
});
|
|
194
189
|
describe('credentials validation', () => {
|
|
195
190
|
it('shows error when credentials are missing', async () => {
|
|
196
|
-
mockLoadConfig.mockResolvedValue(null);
|
|
197
191
|
const command = createMegathreadCreateCommentCommand();
|
|
198
192
|
await expect(command.parseAsync([
|
|
199
193
|
'--agent',
|
|
200
|
-
'
|
|
201
|
-
'--round',
|
|
202
|
-
'round-123',
|
|
203
|
-
'--conviction',
|
|
204
|
-
'50',
|
|
205
|
-
'--text',
|
|
206
|
-
'Test comment',
|
|
207
|
-
], { from: 'user' })).rejects.toThrow('process.exit(1)');
|
|
208
|
-
expect(consoleErrorOutput.join('\n')).toContain('No credentials found for agent "test-agent"');
|
|
209
|
-
});
|
|
210
|
-
it('shows error when credentials have no API key', async () => {
|
|
211
|
-
mockLoadConfig.mockResolvedValue({ apiKey: null });
|
|
212
|
-
const command = createMegathreadCreateCommentCommand();
|
|
213
|
-
await expect(command.parseAsync([
|
|
214
|
-
'--agent',
|
|
215
|
-
'test-agent',
|
|
194
|
+
'no-cred',
|
|
216
195
|
'--round',
|
|
217
196
|
'round-123',
|
|
218
197
|
'--conviction',
|
|
@@ -220,12 +199,11 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
220
199
|
'--text',
|
|
221
200
|
'Test comment',
|
|
222
201
|
], { from: 'user' })).rejects.toThrow('process.exit(1)');
|
|
223
|
-
expect(consoleErrorOutput.join('\n')).toContain('
|
|
202
|
+
expect(consoleErrorOutput.join('\n')).toContain('Agent "no-cred" not found');
|
|
224
203
|
});
|
|
225
204
|
});
|
|
226
205
|
describe('successful comment posting', () => {
|
|
227
206
|
it('posts comment and shows success message', async () => {
|
|
228
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
229
207
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
230
208
|
const command = createMegathreadCreateCommentCommand();
|
|
231
209
|
await command.parseAsync([
|
|
@@ -249,7 +227,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
249
227
|
expect(output).toContain('Bullish on Bitcoin!');
|
|
250
228
|
});
|
|
251
229
|
it('formats negative conviction correctly', async () => {
|
|
252
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
253
230
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
254
231
|
const command = createMegathreadCreateCommentCommand();
|
|
255
232
|
await command.parseAsync([
|
|
@@ -266,7 +243,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
266
243
|
expect(output).toContain('-30.0%');
|
|
267
244
|
});
|
|
268
245
|
it('truncates long text in success message', async () => {
|
|
269
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
270
246
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
271
247
|
const longText = 'A'.repeat(100);
|
|
272
248
|
const command = createMegathreadCreateCommentCommand();
|
|
@@ -283,7 +259,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
283
259
|
});
|
|
284
260
|
describe('API error handling', () => {
|
|
285
261
|
it('shows error when API call fails', async () => {
|
|
286
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
287
262
|
mockPostMegathreadComment.mockRejectedValue(new Error('Network error'));
|
|
288
263
|
const command = createMegathreadCreateCommentCommand();
|
|
289
264
|
await expect(command.parseAsync([
|
|
@@ -300,7 +275,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
300
275
|
expect(consoleErrorOutput.join('\n')).toContain('Network error');
|
|
301
276
|
});
|
|
302
277
|
it('handles non-Error exceptions', async () => {
|
|
303
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
304
278
|
mockPostMegathreadComment.mockRejectedValue('String error');
|
|
305
279
|
const command = createMegathreadCreateCommentCommand();
|
|
306
280
|
await expect(command.parseAsync([
|
|
@@ -319,7 +293,6 @@ describe('createMegathreadCreateCommentCommand', () => {
|
|
|
319
293
|
});
|
|
320
294
|
describe('works with different fixture agents', () => {
|
|
321
295
|
it('works with empty-agent', async () => {
|
|
322
|
-
mockLoadConfig.mockResolvedValue({ apiKey: 'test-api-key' });
|
|
323
296
|
mockPostMegathreadComment.mockResolvedValue(undefined);
|
|
324
297
|
const command = createMegathreadCreateCommentCommand();
|
|
325
298
|
await command.parseAsync([
|