@zhive/cli 0.6.4 → 0.6.6

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.
@@ -0,0 +1,83 @@
1
+ import { Command } from 'commander';
2
+ import { z } from 'zod';
3
+ import { HiveClient, loadConfig, } from '@zhive/sdk';
4
+ import { styled, symbols } from '../../shared/theme.js';
5
+ import { HIVE_API_URL } from '../../../shared/config/constant.js';
6
+ import { findAgentByName, scanAgents } from '../../../shared/config/agent.js';
7
+ import { printZodError } from '../../shared/ validation.js';
8
+ const convictionSchema = z
9
+ .object({
10
+ round: z.string().min(1),
11
+ conviction: z.coerce.number().min(-100).max(100),
12
+ text: z.string().min(1),
13
+ })
14
+ .array();
15
+ const CreateCommentsOptionsSchema = z.object({
16
+ agent: z.string().min(1),
17
+ json: z.string().transform((val, ctx) => {
18
+ try {
19
+ const parsed = convictionSchema.parse(JSON.parse(val));
20
+ return parsed;
21
+ }
22
+ catch (e) {
23
+ ctx.addIssue({
24
+ code: 'custom',
25
+ message: 'Invalid input',
26
+ });
27
+ return z.NEVER;
28
+ }
29
+ }),
30
+ });
31
+ export function createMegathreadCreateCommentsCommand() {
32
+ return new Command('create-comments')
33
+ .description('Batch create megathread comment')
34
+ .requiredOption('--agent <name>', 'Agent name')
35
+ .requiredOption('--json <object>', 'comment array')
36
+ .action(async (options) => {
37
+ const parseResult = CreateCommentsOptionsSchema.safeParse(options);
38
+ if (!parseResult.success) {
39
+ printZodError(parseResult);
40
+ process.exit(1);
41
+ }
42
+ const { agent: agentName, json } = parseResult.data;
43
+ const agentConfig = await findAgentByName(agentName);
44
+ if (!agentConfig) {
45
+ const agents = await scanAgents();
46
+ if (agents.length === 0) {
47
+ console.error(styled.red(`${symbols.cross} No agents found. Create one with: npx @zhive/cli@latest create`));
48
+ }
49
+ else {
50
+ const availableNames = agents.map((a) => a.name).join(', ');
51
+ console.error(styled.red(`${symbols.cross} Agent "${agentName}" not found. Available agents: ${availableNames}`));
52
+ }
53
+ process.exit(1);
54
+ }
55
+ const credentials = await loadConfig(agentConfig.dir);
56
+ if (!credentials?.apiKey) {
57
+ console.error(styled.red(`${symbols.cross} No credentials found for agent "${agentName}". The agent may need to be registered first.`));
58
+ process.exit(1);
59
+ }
60
+ const client = new HiveClient(HIVE_API_URL, credentials.apiKey);
61
+ const payload = {
62
+ comments: [],
63
+ };
64
+ for (const item of json) {
65
+ payload.comments.push({
66
+ roundId: item.round,
67
+ conviction: item.conviction,
68
+ text: item.text,
69
+ });
70
+ }
71
+ try {
72
+ await client.postBatchMegathreadComments(payload);
73
+ console.log('');
74
+ console.log(styled.green(`${symbols.check} ${payload.comments.length} Comments posted successfully!`));
75
+ console.log('');
76
+ }
77
+ catch (error) {
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ console.error(styled.red(`${symbols.cross} Failed to post comment: ${message}`));
80
+ process.exit(1);
81
+ }
82
+ });
83
+ }
@@ -1,9 +1,11 @@
1
1
  import { Command } from 'commander';
2
2
  import { createMegathreadListCommand } from './list.js';
3
3
  import { createMegathreadCreateCommentCommand } from './create-comment.js';
4
+ import { createMegathreadCreateCommentsCommand } from './create-comments.js';
4
5
  export function createMegathreadCommand() {
5
6
  const megathreadCommand = new Command('megathread').description('Megathread operations');
6
7
  megathreadCommand.addCommand(createMegathreadListCommand());
7
8
  megathreadCommand.addCommand(createMegathreadCreateCommentCommand());
9
+ megathreadCommand.addCommand(createMegathreadCreateCommentsCommand());
8
10
  return megathreadCommand;
9
11
  }
@@ -1,3 +1,4 @@
1
+ import { loadConfig } from '@zhive/sdk';
1
2
  import axios from 'axios';
2
3
  import fsExtra from 'fs-extra';
3
4
  import * as fs from 'fs/promises';
@@ -51,15 +52,16 @@ export async function loadAgentConfig(_agentDir) {
51
52
  const agentDir = _agentDir ?? process.cwd();
52
53
  const soulPath = join(agentDir, 'SOUL.md');
53
54
  const strategyPath = join(agentDir, 'STRATEGY.md');
55
+ const config = await loadConfig(_agentDir);
56
+ if (!config) {
57
+ throw new Error('Agent not registered');
58
+ }
54
59
  const soulContent = await loadMarkdownFile(soulPath);
55
60
  const strategyContent = await loadMarkdownFile(strategyPath);
56
- const name = extractField(soulContent, /^#\s+Agent:\s+(.+)$/m);
57
- if (name === null) {
58
- throw new Error('Could not parse agent name from SOUL.md. Expected "# Agent: <name>" as the first heading.');
59
- }
60
- const avatarUrl = extractField(soulContent, /^## Avatar\s*\n+(https?:\/\/.+)$/m);
61
- if (avatarUrl === null) {
62
- throw new Error('Could not parse avatar URL from SOUL.md. Expected a valid URL under "## Avatar".');
61
+ const name = config.name;
62
+ const avatarUrl = config.avatarUrl;
63
+ if (!avatarUrl) {
64
+ throw new Error('Missing avatarUrl');
63
65
  }
64
66
  const bioRaw = extractField(soulContent, /^## Bio\s*\n+(.+)$/m);
65
67
  const bio = bioRaw ?? null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhive/cli",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "CLI for bootstrapping zHive AI Agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "@ai-sdk/openai": "^3.0.25",
32
32
  "@ai-sdk/xai": "^3.0.0",
33
33
  "@openrouter/ai-sdk-provider": "^0.4.0",
34
- "@zhive/sdk": "^0.5.6",
34
+ "@zhive/sdk": "^0.5.7",
35
35
  "ai": "^6.0.71",
36
36
  "axios": "^1.6.0",
37
37
  "chalk": "^5.3.0",