@zhive/cli 0.5.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 (189) hide show
  1. package/README.md +118 -0
  2. package/dist/agent/analysis.js +160 -0
  3. package/dist/agent/app.js +122 -0
  4. package/dist/agent/chat-prompt.js +65 -0
  5. package/dist/agent/commands/registry.js +12 -0
  6. package/dist/agent/components/AsciiTicker.js +81 -0
  7. package/dist/agent/components/CommandInput.js +65 -0
  8. package/dist/agent/components/HoneycombBoot.js +291 -0
  9. package/dist/agent/components/Spinner.js +37 -0
  10. package/dist/agent/config.js +75 -0
  11. package/dist/agent/edit-section.js +59 -0
  12. package/dist/agent/fetch-rules.js +21 -0
  13. package/dist/agent/helpers.js +22 -0
  14. package/dist/agent/hooks/useAgent.js +480 -0
  15. package/dist/agent/memory-prompt.js +47 -0
  16. package/dist/agent/model.js +92 -0
  17. package/dist/agent/objects.js +1 -0
  18. package/dist/agent/process-lifecycle.js +18 -0
  19. package/dist/agent/prompt.js +353 -0
  20. package/dist/agent/run-headless.js +189 -0
  21. package/dist/agent/skills/index.js +2 -0
  22. package/dist/agent/skills/skill-parser.js +149 -0
  23. package/dist/agent/skills/types.js +1 -0
  24. package/dist/agent/theme.js +41 -0
  25. package/dist/agent/tools/index.js +76 -0
  26. package/dist/agent/tools/market/client.js +41 -0
  27. package/dist/agent/tools/market/index.js +3 -0
  28. package/dist/agent/tools/market/tools.js +518 -0
  29. package/dist/agent/tools/mindshare/client.js +124 -0
  30. package/dist/agent/tools/mindshare/index.js +3 -0
  31. package/dist/agent/tools/mindshare/tools.js +563 -0
  32. package/dist/agent/tools/read-skill-tool.js +30 -0
  33. package/dist/agent/tools/ta/index.js +1 -0
  34. package/dist/agent/tools/ta/indicators.js +201 -0
  35. package/dist/agent/types.js +1 -0
  36. package/dist/agents.js +110 -0
  37. package/dist/ai-providers.js +66 -0
  38. package/dist/avatar.js +34 -0
  39. package/dist/backtest/default-backtest-data.js +200 -0
  40. package/dist/backtest/fetch.js +41 -0
  41. package/dist/backtest/import.js +106 -0
  42. package/dist/backtest/index.js +10 -0
  43. package/dist/backtest/results.js +113 -0
  44. package/dist/backtest/runner.js +134 -0
  45. package/dist/backtest/storage.js +11 -0
  46. package/dist/backtest/types.js +1 -0
  47. package/dist/commands/create/ai-generate.js +126 -0
  48. package/dist/commands/create/commands/index.js +10 -0
  49. package/dist/commands/create/generate.js +73 -0
  50. package/dist/commands/create/presets/data.js +225 -0
  51. package/dist/commands/create/presets/formatting.js +81 -0
  52. package/dist/commands/create/presets/index.js +3 -0
  53. package/dist/commands/create/presets/options.js +307 -0
  54. package/dist/commands/create/presets/types.js +1 -0
  55. package/dist/commands/create/presets.js +613 -0
  56. package/dist/commands/create/ui/CreateApp.js +172 -0
  57. package/dist/commands/create/ui/steps/ApiKeyStep.js +89 -0
  58. package/dist/commands/create/ui/steps/AvatarStep.js +16 -0
  59. package/dist/commands/create/ui/steps/DoneStep.js +14 -0
  60. package/dist/commands/create/ui/steps/IdentityStep.js +125 -0
  61. package/dist/commands/create/ui/steps/NameStep.js +148 -0
  62. package/dist/commands/create/ui/steps/ScaffoldStep.js +59 -0
  63. package/dist/commands/create/ui/steps/SoulStep.js +21 -0
  64. package/dist/commands/create/ui/steps/StrategyStep.js +20 -0
  65. package/dist/commands/create/ui/steps/StreamingGenerationStep.js +56 -0
  66. package/dist/commands/create/ui/validation.js +34 -0
  67. package/dist/commands/create/validate-api-key.js +27 -0
  68. package/dist/commands/install.js +50 -0
  69. package/dist/commands/list/commands/index.js +7 -0
  70. package/dist/commands/list/ui/ListApp.js +79 -0
  71. package/dist/commands/migrate-templates/commands/index.js +9 -0
  72. package/dist/commands/migrate-templates/migrate.js +87 -0
  73. package/dist/commands/migrate-templates/ui/MigrateApp.js +132 -0
  74. package/dist/commands/run/commands/index.js +17 -0
  75. package/dist/commands/run/run-headless.js +111 -0
  76. package/dist/commands/shared/theme.js +57 -0
  77. package/dist/commands/shared/welcome.js +304 -0
  78. package/dist/commands/start/commands/backtest.js +35 -0
  79. package/dist/commands/start/commands/index.js +62 -0
  80. package/dist/commands/start/commands/prediction.js +73 -0
  81. package/dist/commands/start/commands/skills.js +44 -0
  82. package/dist/commands/start/commands/skills.test.js +140 -0
  83. package/dist/commands/start/hooks/types.js +1 -0
  84. package/dist/commands/start/hooks/useAgent.js +177 -0
  85. package/dist/commands/start/hooks/useChat.js +266 -0
  86. package/dist/commands/start/hooks/usePollActivity.js +45 -0
  87. package/dist/commands/start/hooks/utils.js +152 -0
  88. package/dist/commands/start/services/backtest/default-backtest-data.js +200 -0
  89. package/dist/commands/start/services/backtest/fetch.js +42 -0
  90. package/dist/commands/start/services/backtest/import.js +109 -0
  91. package/dist/commands/start/services/backtest/index.js +10 -0
  92. package/dist/commands/start/services/backtest/results.js +113 -0
  93. package/dist/commands/start/services/backtest/runner.js +103 -0
  94. package/dist/commands/start/services/backtest/storage.js +11 -0
  95. package/dist/commands/start/services/backtest/types.js +1 -0
  96. package/dist/commands/start/services/command-registry.js +13 -0
  97. package/dist/commands/start/ui/AsciiTicker.js +81 -0
  98. package/dist/commands/start/ui/CommandInput.js +65 -0
  99. package/dist/commands/start/ui/HoneycombBoot.js +291 -0
  100. package/dist/commands/start/ui/PollText.js +23 -0
  101. package/dist/commands/start/ui/PredictionsPanel.js +88 -0
  102. package/dist/commands/start/ui/SelectAgentApp.js +93 -0
  103. package/dist/commands/start/ui/Spinner.js +29 -0
  104. package/dist/commands/start/ui/SpinnerContext.js +20 -0
  105. package/dist/commands/start/ui/app.js +36 -0
  106. package/dist/commands/start-all/AgentProcessManager.js +98 -0
  107. package/dist/commands/start-all/commands/index.js +24 -0
  108. package/dist/commands/start-all/ui/Dashboard.js +91 -0
  109. package/dist/components/AsciiTicker.js +81 -0
  110. package/dist/components/CharacterSummaryCard.js +33 -0
  111. package/dist/components/CodeBlock.js +11 -0
  112. package/dist/components/ColoredStats.js +18 -0
  113. package/dist/components/Header.js +10 -0
  114. package/dist/components/HoneycombLoader.js +190 -0
  115. package/dist/components/InputGuard.js +6 -0
  116. package/dist/components/MultiSelectPrompt.js +45 -0
  117. package/dist/components/SelectPrompt.js +20 -0
  118. package/dist/components/Spinner.js +16 -0
  119. package/dist/components/StepIndicator.js +31 -0
  120. package/dist/components/StreamingText.js +50 -0
  121. package/dist/components/TextPrompt.js +28 -0
  122. package/dist/components/stdout-spinner.js +48 -0
  123. package/dist/config.js +28 -0
  124. package/dist/create/CreateApp.js +153 -0
  125. package/dist/create/ai-generate.js +147 -0
  126. package/dist/create/generate.js +73 -0
  127. package/dist/create/steps/ApiKeyStep.js +97 -0
  128. package/dist/create/steps/AvatarStep.js +16 -0
  129. package/dist/create/steps/BioStep.js +14 -0
  130. package/dist/create/steps/DoneStep.js +14 -0
  131. package/dist/create/steps/IdentityStep.js +163 -0
  132. package/dist/create/steps/NameStep.js +71 -0
  133. package/dist/create/steps/ScaffoldStep.js +58 -0
  134. package/dist/create/steps/SoulStep.js +58 -0
  135. package/dist/create/steps/StrategyStep.js +58 -0
  136. package/dist/create/validate-api-key.js +47 -0
  137. package/dist/create/welcome.js +304 -0
  138. package/dist/index.js +60 -0
  139. package/dist/list/ListApp.js +79 -0
  140. package/dist/load-agent-env.js +30 -0
  141. package/dist/migrate-templates/MigrateApp.js +131 -0
  142. package/dist/migrate-templates/migrate.js +86 -0
  143. package/dist/presets.js +613 -0
  144. package/dist/shared/agent/agent-runtime.js +144 -0
  145. package/dist/shared/agent/analysis.js +171 -0
  146. package/dist/shared/agent/helpers.js +1 -0
  147. package/dist/shared/agent/prompts/chat-prompt.js +60 -0
  148. package/dist/shared/agent/prompts/megathread.js +202 -0
  149. package/dist/shared/agent/prompts/memory-prompt.js +47 -0
  150. package/dist/shared/agent/prompts/prompt.js +18 -0
  151. package/dist/shared/agent/skills/index.js +2 -0
  152. package/dist/shared/agent/skills/skill-parser.js +167 -0
  153. package/dist/shared/agent/skills/skill-parser.test.js +190 -0
  154. package/dist/shared/agent/skills/types.js +1 -0
  155. package/dist/shared/agent/tools/edit-section.js +60 -0
  156. package/dist/shared/agent/tools/execute-skill-tool.js +134 -0
  157. package/dist/shared/agent/tools/fetch-rules.js +22 -0
  158. package/dist/shared/agent/tools/formatting.js +48 -0
  159. package/dist/shared/agent/tools/index.js +87 -0
  160. package/dist/shared/agent/tools/market/client.js +41 -0
  161. package/dist/shared/agent/tools/market/index.js +3 -0
  162. package/dist/shared/agent/tools/market/tools.js +497 -0
  163. package/dist/shared/agent/tools/mindshare/client.js +124 -0
  164. package/dist/shared/agent/tools/mindshare/index.js +3 -0
  165. package/dist/shared/agent/tools/mindshare/tools.js +167 -0
  166. package/dist/shared/agent/tools/read-skill-tool.js +30 -0
  167. package/dist/shared/agent/tools/ta/index.js +1 -0
  168. package/dist/shared/agent/tools/ta/indicators.js +201 -0
  169. package/dist/shared/agent/types.js +1 -0
  170. package/dist/shared/agent/utils.js +43 -0
  171. package/dist/shared/config/agent.js +177 -0
  172. package/dist/shared/config/ai-providers.js +156 -0
  173. package/dist/shared/config/config.js +22 -0
  174. package/dist/shared/config/constant.js +8 -0
  175. package/dist/shared/config/env-loader.js +30 -0
  176. package/dist/shared/types.js +1 -0
  177. package/dist/start/AgentProcessManager.js +98 -0
  178. package/dist/start/Dashboard.js +92 -0
  179. package/dist/start/SelectAgentApp.js +81 -0
  180. package/dist/start/StartApp.js +189 -0
  181. package/dist/start/patch-headless.js +101 -0
  182. package/dist/start/patch-managed-mode.js +142 -0
  183. package/dist/start/start-command.js +24 -0
  184. package/dist/theme.js +54 -0
  185. package/package.json +68 -0
  186. package/templates/components/HoneycombBoot.tsx +343 -0
  187. package/templates/fetch-rules.ts +23 -0
  188. package/templates/skills/mindshare/SKILL.md +197 -0
  189. package/templates/skills/ta/SKILL.md +179 -0
@@ -0,0 +1,149 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import * as path from 'node:path';
3
+ /**
4
+ * Parse YAML frontmatter from SKILL.md content.
5
+ * Expected format:
6
+ * ---
7
+ * name: skill-name
8
+ * description: Skill description
9
+ * ---
10
+ * Body content...
11
+ */
12
+ export function parseFrontmatter(content) {
13
+ const trimmed = content.trim();
14
+ if (!trimmed.startsWith('---')) {
15
+ throw new Error('SKILL.md must start with YAML frontmatter (---)');
16
+ }
17
+ const endIndex = trimmed.indexOf('---', 3);
18
+ if (endIndex === -1) {
19
+ throw new Error('SKILL.md frontmatter is not closed (missing closing ---)');
20
+ }
21
+ const frontmatterContent = trimmed.slice(3, endIndex).trim();
22
+ const body = trimmed.slice(endIndex + 3).trim();
23
+ const metadata = {
24
+ name: '',
25
+ description: '',
26
+ };
27
+ const lines = frontmatterContent.split('\n');
28
+ let currentKey = null;
29
+ let currentValue = '';
30
+ for (const line of lines) {
31
+ const trimmedLine = line.trim();
32
+ if (trimmedLine.startsWith('name:')) {
33
+ if (currentKey !== null) {
34
+ setMetadataField(metadata, currentKey, currentValue.trim());
35
+ }
36
+ currentKey = 'name';
37
+ currentValue = trimmedLine.slice(5).trim();
38
+ }
39
+ else if (trimmedLine.startsWith('description:')) {
40
+ if (currentKey !== null) {
41
+ setMetadataField(metadata, currentKey, currentValue.trim());
42
+ }
43
+ currentKey = 'description';
44
+ const value = trimmedLine.slice(12).trim();
45
+ if (value === '>' || value === '|') {
46
+ currentValue = '';
47
+ }
48
+ else {
49
+ currentValue = value;
50
+ }
51
+ }
52
+ else if (currentKey !== null && (line.startsWith(' ') || line.startsWith('\t'))) {
53
+ currentValue += ' ' + trimmedLine;
54
+ }
55
+ }
56
+ if (currentKey !== null) {
57
+ setMetadataField(metadata, currentKey, currentValue.trim());
58
+ }
59
+ if (metadata.name === '') {
60
+ throw new Error('SKILL.md frontmatter must include "name" field');
61
+ }
62
+ if (metadata.description === '') {
63
+ throw new Error('SKILL.md frontmatter must include "description" field');
64
+ }
65
+ return { metadata, body };
66
+ }
67
+ function setMetadataField(metadata, key, value) {
68
+ if (key === 'name') {
69
+ metadata.name = value;
70
+ }
71
+ else if (key === 'description') {
72
+ metadata.description = value;
73
+ }
74
+ }
75
+ /**
76
+ * Check if a directory exists.
77
+ */
78
+ async function directoryExists(dirPath) {
79
+ try {
80
+ const stat = await fs.stat(dirPath);
81
+ return stat.isDirectory();
82
+ }
83
+ catch {
84
+ return false;
85
+ }
86
+ }
87
+ /**
88
+ * Check if a file exists.
89
+ */
90
+ async function fileExists(filePath) {
91
+ try {
92
+ const stat = await fs.stat(filePath);
93
+ return stat.isFile();
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ /**
100
+ * Discover and load a single skill from a directory.
101
+ * Skills are knowledge-only documents (no tools).
102
+ */
103
+ export async function loadSkill(skillPath) {
104
+ const skillMdPath = path.join(skillPath, 'SKILL.md');
105
+ const exists = await fileExists(skillMdPath);
106
+ if (!exists) {
107
+ return null;
108
+ }
109
+ try {
110
+ const content = await fs.readFile(skillMdPath, 'utf-8');
111
+ const { metadata, body } = parseFrontmatter(content);
112
+ const id = path.basename(skillPath);
113
+ const skill = {
114
+ id,
115
+ path: skillPath,
116
+ metadata,
117
+ body,
118
+ };
119
+ return skill;
120
+ }
121
+ catch (err) {
122
+ const message = err instanceof Error ? err.message : String(err);
123
+ console.error(`Failed to load skill from ${skillPath}: ${message}`);
124
+ return null;
125
+ }
126
+ }
127
+ /**
128
+ * Discover all skills in a directory.
129
+ * Each subdirectory containing SKILL.md is treated as a skill.
130
+ */
131
+ export async function discoverSkills(skillsDir) {
132
+ const exists = await directoryExists(skillsDir);
133
+ if (!exists) {
134
+ return [];
135
+ }
136
+ const entries = await fs.readdir(skillsDir, { withFileTypes: true });
137
+ const skills = [];
138
+ for (const entry of entries) {
139
+ if (!entry.isDirectory()) {
140
+ continue;
141
+ }
142
+ const skillPath = path.join(skillsDir, entry.name);
143
+ const skill = await loadSkill(skillPath);
144
+ if (skill !== null) {
145
+ skills.push(skill);
146
+ }
147
+ }
148
+ return skills;
149
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ export const colors = {
2
+ honey: '#F5A623',
3
+ honeyDark: '#D4891A',
4
+ honeyBright: '#FFD700',
5
+ white: '#FFFFFF',
6
+ gray: '#A6A6A6',
7
+ grayDim: '#555555',
8
+ green: '#27C587',
9
+ red: '#E14B4B',
10
+ wax: '#C45C5C',
11
+ cyan: '#22D3EE',
12
+ hot: '#FB923C',
13
+ controversial: '#C084FC',
14
+ };
15
+ export const symbols = {
16
+ hive: '\u2B21', // ⬡
17
+ diamond: '\u25C6', // ◆
18
+ diamondOpen: '\u25C7', // ◇
19
+ dot: '\u25CF', // ●
20
+ check: '\u2713', // ✓
21
+ cross: '\u2717', // ✗
22
+ arrow: '\u203A', // ›
23
+ circle: '\u25CB', // ○
24
+ };
25
+ export const border = {
26
+ horizontal: '\u2500', // ─
27
+ vertical: '\u2502', // │
28
+ topLeft: '\u250C', // ┌
29
+ topRight: '\u2510', // ┐
30
+ bottomLeft: '\u2514', // └
31
+ bottomRight: '\u2518', // ┘
32
+ teeLeft: '\u251C', // ├
33
+ teeRight: '\u2524', // ┤
34
+ };
35
+ export const animation = {
36
+ DATA_CHARS: '01\u25AA\u25AB\u2591\u2592',
37
+ HEX_CHARS: '\u2B21\u2B22',
38
+ TICK_MS: 120,
39
+ HEX_W: 8,
40
+ HEX_H: 4,
41
+ };
@@ -0,0 +1,76 @@
1
+ import * as path from 'node:path';
2
+ import { discoverSkills } from '../skills/skill-parser.js';
3
+ import { createReadSkillTool } from './read-skill-tool.js';
4
+ import { marketTools } from './market/index.js';
5
+ import { mindshareTools } from './mindshare/index.js';
6
+ /**
7
+ * Get all tools that are always available to agents.
8
+ * Tools are bundled with the CLI and don't require skill installation.
9
+ * Skills provide knowledge/guidance on when and how to use these tools.
10
+ */
11
+ export function getAllTools() {
12
+ const tools = {};
13
+ for (const [name, tool] of Object.entries(marketTools)) {
14
+ const namespacedName = `market_${name}`;
15
+ tools[namespacedName] = tool;
16
+ }
17
+ for (const [name, tool] of Object.entries(mindshareTools)) {
18
+ const namespacedName = `mindshare_${name}`;
19
+ tools[namespacedName] = tool;
20
+ }
21
+ return tools;
22
+ }
23
+ /**
24
+ * Initialize skills from agent's skills/ directory.
25
+ * Skills are knowledge-only documents that help agents understand
26
+ * when and how to use the always-available tools.
27
+ * Returns a registry map that should be passed to other skill functions.
28
+ */
29
+ export async function initializeSkills(agentPath) {
30
+ const skillRegistry = new Map();
31
+ const skillsPath = path.join(agentPath, 'skills');
32
+ const agentSkills = await discoverSkills(skillsPath);
33
+ for (const skill of agentSkills) {
34
+ skillRegistry.set(skill.id, skill);
35
+ }
36
+ return skillRegistry;
37
+ }
38
+ /**
39
+ * Get a skill metadata list for prompt injection.
40
+ * Shows skill ID and description to help the agent decide what to use.
41
+ */
42
+ export function getSkillMetadataList(skillRegistry) {
43
+ if (skillRegistry.size === 0) {
44
+ return '';
45
+ }
46
+ const lines = Array.from(skillRegistry.values())
47
+ .map((s) => `- ${s.id}: ${s.metadata.description}`)
48
+ .join('\n');
49
+ const output = `Available skills:\n${lines}`;
50
+ return output;
51
+ }
52
+ /**
53
+ * Get the readSkill tool for agent to read skill knowledge.
54
+ */
55
+ export function getReadSkillTool(skillRegistry) {
56
+ const readSkillTool = createReadSkillTool(skillRegistry);
57
+ return readSkillTool;
58
+ }
59
+ /**
60
+ * Get a skill definition by ID.
61
+ */
62
+ export function getSkill(skillRegistry, id) {
63
+ return skillRegistry.get(id);
64
+ }
65
+ /**
66
+ * Get all registered skills.
67
+ */
68
+ export function getAllSkills(skillRegistry) {
69
+ return Array.from(skillRegistry.values());
70
+ }
71
+ /**
72
+ * Check if any skills are registered.
73
+ */
74
+ export function hasSkills(skillRegistry) {
75
+ return skillRegistry.size > 0;
76
+ }
@@ -0,0 +1,41 @@
1
+ import { HIVE_API_URL } from '../../../config.js';
2
+ /**
3
+ * Client for the backend Market API.
4
+ */
5
+ export class MarketClient {
6
+ constructor(baseUrl = HIVE_API_URL) {
7
+ this._baseUrl = baseUrl;
8
+ }
9
+ async getPrice(projectId, timestamp) {
10
+ const url = `${this._baseUrl}/market/price/${encodeURIComponent(projectId)}?timestamp=${encodeURIComponent(timestamp)}`;
11
+ const response = await fetch(url);
12
+ if (!response.ok) {
13
+ const text = await response.text();
14
+ throw new Error(`Market price request failed: ${response.status} - ${text}`);
15
+ }
16
+ const data = (await response.json());
17
+ return data;
18
+ }
19
+ async getOHLC(id, from, to, interval = 'daily') {
20
+ const params = new URLSearchParams({
21
+ from,
22
+ to,
23
+ interval,
24
+ });
25
+ const url = `${this._baseUrl}/market/ohlc/${encodeURIComponent(id)}?${params.toString()}`;
26
+ const response = await fetch(url);
27
+ if (!response.ok) {
28
+ const text = await response.text();
29
+ throw new Error(`Market OHLC request failed: ${response.status} - ${text}`);
30
+ }
31
+ const data = (await response.json());
32
+ return data;
33
+ }
34
+ }
35
+ let clientInstance = null;
36
+ export function getMarketClient() {
37
+ if (clientInstance === null) {
38
+ clientInstance = new MarketClient();
39
+ }
40
+ return clientInstance;
41
+ }
@@ -0,0 +1,3 @@
1
+ export { marketTools } from './tools.js';
2
+ export { getPriceTool, getOHLCTool, getSMATool, getEMATool, getRSITool, getMACDTool, getBollingerTool, } from './tools.js';
3
+ export { MarketClient, getMarketClient } from './client.js';