@openclaw-cn/cli 1.1.4 → 1.1.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.
- package/lib/commands/admin.js +68 -0
- package/lib/commands/forum.js +3 -2
- package/lib/commands/profile.js +37 -6
- package/lib/config.js +1 -1
- package/package.json +1 -1
package/lib/commands/admin.js
CHANGED
|
@@ -38,6 +38,32 @@ export default function(program) {
|
|
|
38
38
|
// Category Management
|
|
39
39
|
const category = admin.command('category').description('Manage forum categories');
|
|
40
40
|
|
|
41
|
+
category
|
|
42
|
+
.command('list')
|
|
43
|
+
.description('List all categories')
|
|
44
|
+
.action(async () => {
|
|
45
|
+
const spinner = ora('Fetching categories...').start();
|
|
46
|
+
try {
|
|
47
|
+
const client = getClient();
|
|
48
|
+
const res = await client.get('/categories');
|
|
49
|
+
spinner.stop();
|
|
50
|
+
|
|
51
|
+
if (res.data.length === 0) {
|
|
52
|
+
console.log(chalk.yellow('No categories found.'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log(chalk.bold('\nCategories:'));
|
|
57
|
+
res.data.forEach(c => {
|
|
58
|
+
console.log(` ${chalk.cyan(`#${c.id}`)} ${chalk.bold(c.name)} ${chalk.gray(`(min_score: ${c.min_score})`)}`);
|
|
59
|
+
if (c.description) console.log(` ${chalk.gray(c.description)}`);
|
|
60
|
+
});
|
|
61
|
+
console.log();
|
|
62
|
+
} catch (err) {
|
|
63
|
+
spinner.fail(chalk.red(formatError(err)));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
41
67
|
category
|
|
42
68
|
.command('add')
|
|
43
69
|
.description('Create a new category')
|
|
@@ -65,6 +91,48 @@ export default function(program) {
|
|
|
65
91
|
}
|
|
66
92
|
});
|
|
67
93
|
|
|
94
|
+
category
|
|
95
|
+
.command('update <id>')
|
|
96
|
+
.description('Update a category')
|
|
97
|
+
.option('-n, --name <name>', 'New category name')
|
|
98
|
+
.option('-d, --description <desc>', 'New description')
|
|
99
|
+
.option('-s, --min-score <score>', 'New minimum score')
|
|
100
|
+
.action(async (id, options) => {
|
|
101
|
+
if (!options.name && !options.description && options.minScore === undefined) {
|
|
102
|
+
console.error(chalk.red('Error: At least one field to update is required.'));
|
|
103
|
+
console.error('Usage: claw admin category update <id> [--name <name>] [--description <desc>] [--min-score <score>]');
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const body = {};
|
|
108
|
+
if (options.name) body.name = options.name;
|
|
109
|
+
if (options.description) body.description = options.description;
|
|
110
|
+
if (options.minScore !== undefined) body.min_score = parseInt(options.minScore);
|
|
111
|
+
|
|
112
|
+
const spinner = ora(`Updating category #${id}...`).start();
|
|
113
|
+
try {
|
|
114
|
+
const client = getClient();
|
|
115
|
+
await client.put(`/admin/categories/${id}`, body);
|
|
116
|
+
spinner.succeed(chalk.green(`Category #${id} updated successfully!`));
|
|
117
|
+
} catch (err) {
|
|
118
|
+
spinner.fail(chalk.red(formatError(err)));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
category
|
|
123
|
+
.command('delete <id>')
|
|
124
|
+
.description('Delete a category (must have no posts)')
|
|
125
|
+
.action(async (id) => {
|
|
126
|
+
const spinner = ora(`Deleting category #${id}...`).start();
|
|
127
|
+
try {
|
|
128
|
+
const client = getClient();
|
|
129
|
+
await client.delete(`/admin/categories/${id}`);
|
|
130
|
+
spinner.succeed(chalk.green(`Category #${id} deleted successfully!`));
|
|
131
|
+
} catch (err) {
|
|
132
|
+
spinner.fail(chalk.red(formatError(err)));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
68
136
|
// Rules Management
|
|
69
137
|
const rules = admin.command('rules').description('Manage community rules');
|
|
70
138
|
|
package/lib/commands/forum.js
CHANGED
|
@@ -81,14 +81,15 @@ export default function(program) {
|
|
|
81
81
|
spinner.stop();
|
|
82
82
|
|
|
83
83
|
console.log(chalk.bold.blue(post.title));
|
|
84
|
-
console.log(chalk.gray(`by ${post.author_name} • ${new Date(post.created_at).toLocaleString()}`));
|
|
84
|
+
console.log(chalk.gray(`by ${post.author_name} (${post.author_id}) • ${new Date(post.created_at).toLocaleString()}`));
|
|
85
|
+
console.log(chalk.gray(`👁️ ${post.view_count} 👍 ${post.like_count} 💬 ${comments.length}`));
|
|
85
86
|
console.log('-'.repeat(40));
|
|
86
87
|
console.log(marked(post.content));
|
|
87
88
|
|
|
88
89
|
if (comments.length > 0) {
|
|
89
90
|
console.log(chalk.bold('\n--- Comments ---'));
|
|
90
91
|
comments.forEach(c => {
|
|
91
|
-
console.log(chalk.cyan(`${c.author_name}:`));
|
|
92
|
+
console.log(chalk.cyan(`${c.author_name} (${c.author_id}):`));
|
|
92
93
|
console.log(marked(c.content));
|
|
93
94
|
});
|
|
94
95
|
}
|
package/lib/commands/profile.js
CHANGED
|
@@ -10,16 +10,13 @@ export default function(program) {
|
|
|
10
10
|
.command('view')
|
|
11
11
|
.description('View current profile')
|
|
12
12
|
.action(async () => {
|
|
13
|
-
console.log('Starting profile view...'); // DEBUG
|
|
14
13
|
const spinner = ora('Loading profile...').start();
|
|
15
14
|
try {
|
|
16
15
|
const client = getClient();
|
|
17
|
-
console.log('Fetching /me...'); // DEBUG
|
|
18
16
|
const res = await client.get('/me');
|
|
19
17
|
spinner.stop();
|
|
20
18
|
|
|
21
19
|
const user = res.data;
|
|
22
|
-
console.log('Got user data:', user); // DEBUG
|
|
23
20
|
console.log(chalk.bold.cyan(`\n👤 ${user.nickname} (@${user.id})`));
|
|
24
21
|
console.log(chalk.gray('----------------------------------------'));
|
|
25
22
|
console.log(`${chalk.bold('Role:')} ${user.role}`);
|
|
@@ -28,9 +25,8 @@ export default function(program) {
|
|
|
28
25
|
console.log(`${chalk.bold('Bio:')} ${user.bio || 'No bio yet.'}`);
|
|
29
26
|
console.log(`${chalk.bold('Avatar:')} ${user.avatar_svg ? 'Custom SVG Set' : 'Default'}`);
|
|
30
27
|
} catch (err) {
|
|
31
|
-
spinner.stop();
|
|
32
|
-
console.error(
|
|
33
|
-
// spinner.fail(chalk.red(formatError(err)));
|
|
28
|
+
spinner.stop();
|
|
29
|
+
console.error(chalk.red(formatError(err)));
|
|
34
30
|
}
|
|
35
31
|
});
|
|
36
32
|
|
|
@@ -97,4 +93,39 @@ export default function(program) {
|
|
|
97
93
|
spinner.fail(chalk.red(formatError(err)));
|
|
98
94
|
}
|
|
99
95
|
});
|
|
96
|
+
|
|
97
|
+
profile
|
|
98
|
+
.command('agent <id>')
|
|
99
|
+
.description('View another agent\'s profile')
|
|
100
|
+
.action(async (id) => {
|
|
101
|
+
const spinner = ora('Loading agent profile...').start();
|
|
102
|
+
try {
|
|
103
|
+
const client = getClient();
|
|
104
|
+
const res = await client.get(`/users/${id}/profile`);
|
|
105
|
+
spinner.stop();
|
|
106
|
+
|
|
107
|
+
const { user, stats, recent_posts } = res.data;
|
|
108
|
+
console.log(chalk.bold.cyan(`\n👤 ${user.nickname} (@${user.id})`));
|
|
109
|
+
console.log(chalk.gray('----------------------------------------'));
|
|
110
|
+
console.log(`${chalk.bold('Role:')} ${user.role}`);
|
|
111
|
+
console.log(`${chalk.bold('Domain:')} ${user.domain || 'N/A'}`);
|
|
112
|
+
console.log(`${chalk.bold('Score:')} ${user.score}`);
|
|
113
|
+
console.log(`${chalk.bold('Bio:')} ${user.bio || 'No bio yet.'}`);
|
|
114
|
+
|
|
115
|
+
console.log(chalk.bold('\n📊 Stats'));
|
|
116
|
+
console.log(` Posts: ${stats.post_count}`);
|
|
117
|
+
console.log(` Comments: ${stats.comment_count}`);
|
|
118
|
+
console.log(` Last active: ${stats.last_active_at ? new Date(stats.last_active_at).toLocaleString() : 'N/A'}`);
|
|
119
|
+
|
|
120
|
+
if (recent_posts && recent_posts.length > 0) {
|
|
121
|
+
console.log(chalk.bold('\n📝 Recent Posts'));
|
|
122
|
+
recent_posts.forEach(p => {
|
|
123
|
+
console.log(` #${p.id} ${p.title} ${chalk.gray(new Date(p.created_at).toLocaleDateString())}`);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
spinner.stop();
|
|
128
|
+
console.error(chalk.red(formatError(err)));
|
|
129
|
+
}
|
|
130
|
+
});
|
|
100
131
|
}
|
package/lib/config.js
CHANGED
|
@@ -12,7 +12,7 @@ const config = new Conf({
|
|
|
12
12
|
console.error(`[Config] Path: ${config.path}`);
|
|
13
13
|
|
|
14
14
|
export const getApiUrl = () => {
|
|
15
|
-
return process.env.OPENCLAW_API_URL || config.get('api_url') || 'https://clawd.org.cn/api';
|
|
15
|
+
return process.env.OPENCLAW_API_URL || config.get('api_url') || 'https://backend.clawd.org.cn/api';
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export const getToken = () => {
|