coderev-cli 1.0.22 → 1.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coderev-cli",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Multi-agent AI code review for git -- parallel agents with confidence scoring",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -848,6 +848,118 @@ program
848
848
  }
849
849
  });
850
850
 
851
+ // ── Rules Marketplace ─────────────────────────────────────────────
852
+ program
853
+ .command('rules <action>')
854
+ .description('Manage rule packs from the coderev marketplace')
855
+ .option('-q, --query <text>', 'Search query')
856
+ .option('-n, --name <name>', 'Rule pack name')
857
+ .option('--version <ver>', 'Version for publish', '1.0.0')
858
+ .option('--desc <text>', 'Description for publish')
859
+ .option('--api-url <url>', 'Marketplace API URL')
860
+ .action(async (action, options) => {
861
+ try {
862
+ const { searchRules, installRule, publishRules, listInstalled, uninstallRule, DEFAULT_API_URL } = require('./rules-market');
863
+ const apiUrl = options.apiUrl || process.env.CODEREV_MARKETPLACE_URL || DEFAULT_API_URL;
864
+
865
+ switch (action) {
866
+ case 'search': {
867
+ console.log(chalk.blue(`🔍 Searching marketplace for "${options.query || ''}"...`));
868
+ const results = await searchRules(options.query || '', apiUrl);
869
+ if (!Array.isArray(results) || results.length === 0) {
870
+ console.log(chalk.yellow('No rule packs found.'));
871
+ } else {
872
+ console.log(chalk.bold(`\nFound ${results.length} rule pack(s):\n`));
873
+ for (const pack of results) {
874
+ console.log(chalk.green(` 📦 ${pack.name}`) + chalk.gray(` v${pack.version}`));
875
+ console.log(` ${pack.description || '(no description)'}`);
876
+ console.log(chalk.gray(` ${pack.rules || 0} rules • ${pack.downloads || 0} downloads • by ${pack.author || 'unknown'}`));
877
+ console.log('');
878
+ }
879
+ console.log(chalk.blue(`Install: coderev rules install <name>`));
880
+ }
881
+ break;
882
+ }
883
+
884
+ case 'install': {
885
+ const name = options.name || options.query;
886
+ if (!name) {
887
+ console.error(chalk.red('✖ Please specify a rule pack name: coderev rules install <name>'));
888
+ process.exit(1);
889
+ }
890
+ console.log(chalk.blue(`📥 Installing "${name}"...`));
891
+ const result = await installRule(name, apiUrl);
892
+ console.log(chalk.green(`✔ Installed ${result.name} v${result.version}`));
893
+ console.log(chalk.gray(` ${result.added}/${result.total} rules added to .coderevrc.json`));
894
+ break;
895
+ }
896
+
897
+ case 'publish': {
898
+ console.log(chalk.blue('📤 Publishing rules to marketplace...'));
899
+ const result = await publishRules(apiUrl, {
900
+ name: options.name,
901
+ version: options.version,
902
+ description: options.desc,
903
+ });
904
+ console.log(chalk.green(`✔ Published "${result.name}" v${options.version} (${result.rules} rules)`));
905
+ break;
906
+ }
907
+
908
+ case 'list': {
909
+ const result = listInstalled();
910
+ if (result.packs.length === 0) {
911
+ console.log(chalk.yellow(result.message));
912
+ } else {
913
+ console.log(chalk.bold(`\n📦 Installed rule packs (${result.packs.length}):\n`));
914
+ for (const pack of result.packs) {
915
+ console.log(chalk.green(` 📦 ${pack.name}`) + chalk.gray(` v${pack.version}`));
916
+ console.log(chalk.gray(` ${pack.rules} rules • installed ${new Date(pack.installedAt).toLocaleDateString()}`));
917
+ }
918
+ }
919
+ break;
920
+ }
921
+
922
+ case 'uninstall': {
923
+ const name = options.name || options.query;
924
+ if (!name) {
925
+ console.error(chalk.red('✖ Please specify a rule pack name: coderev rules uninstall <name>'));
926
+ process.exit(1);
927
+ }
928
+ const result = uninstallRule(name);
929
+ console.log(chalk.green(`✔ Uninstalled "${result.name}"`));
930
+ break;
931
+ }
932
+
933
+ case 'info': {
934
+ const name = options.name || options.query;
935
+ if (!name) {
936
+ console.error(chalk.red('✖ Please specify a rule pack name: coderev rules info <name>'));
937
+ process.exit(1);
938
+ }
939
+ const pack = await apiRequest(apiUrl, `/rules/${encodeURIComponent(name)}`);
940
+ console.log(chalk.bold(`\n📦 ${pack.name}`) + chalk.gray(` v${pack.version}`));
941
+ console.log(` ${pack.description || '(no description)'}`);
942
+ console.log(chalk.gray(` ${pack.rules?.length || 0} rules • by ${pack.author || 'unknown'}`));
943
+ if (pack.rules && pack.rules.length > 0) {
944
+ console.log(chalk.bold('\n Rules:'));
945
+ for (const r of pack.rules) {
946
+ const sev = r.severity === 'error' ? chalk.red(r.severity) : r.severity === 'warning' ? chalk.yellow(r.severity) : chalk.gray(r.severity);
947
+ console.log(` - ${r.name} [${sev}] ${r.message || ''}`);
948
+ }
949
+ }
950
+ break;
951
+ }
952
+
953
+ default:
954
+ console.error(chalk.red(`✖ Unknown action "${action}". Use: search | install | publish | list | uninstall | info`));
955
+ process.exit(1);
956
+ }
957
+ } catch (err) {
958
+ console.error(chalk.red(`✖ ${err.message}`));
959
+ process.exit(1);
960
+ }
961
+ });
962
+
851
963
  program.parse(process.argv);
852
964
 
853
965
  // ── Helpers ───────────────────────────────────────────────────
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Rules Market — SaaS cloud rule repository for coderev.
3
+ *
4
+ * Commands:
5
+ * coderev rules search <query> Search the rule marketplace
6
+ * coderev rules install <name> Install a rule pack from the marketplace
7
+ * coderev rules publish Publish local rules to the marketplace
8
+ * coderev rules list List installed rule packs
9
+ *
10
+ * API Base: configurable via .coderevrc.json → marketplace.apiUrl
11
+ * Default: https://rules.coderev.dev/api
12
+ */
13
+
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+ const https = require('https');
17
+ const http = require('http');
18
+
19
+ const DEFAULT_API_URL = 'https://rules.coderev.dev/api';
20
+ const MARKETPLACE_DIR = '.coderev-marketplace';
21
+ const INSTALLED_MANIFEST = 'installed.json';
22
+
23
+ // ── API Client ───────────────────────────────────────────
24
+
25
+ /**
26
+ * Make an HTTP request to the marketplace API.
27
+ */
28
+ function apiRequest(apiUrl, endpoint, method = 'GET', body = null) {
29
+ const url = new URL(`${apiUrl}${endpoint}`);
30
+ const isHttps = url.protocol === 'https:';
31
+ const transport = isHttps ? https : http;
32
+
33
+ return new Promise((resolve, reject) => {
34
+ const options = {
35
+ hostname: url.hostname,
36
+ port: url.port || (isHttps ? 443 : 80),
37
+ path: url.pathname + url.search,
38
+ method,
39
+ headers: {
40
+ 'Accept': 'application/json',
41
+ 'User-Agent': 'coderev-cli',
42
+ ...(body ? { 'Content-Type': 'application/json' } : {}),
43
+ },
44
+ timeout: 15000,
45
+ };
46
+
47
+ const req = transport.request(options, (res) => {
48
+ let data = '';
49
+ res.on('data', (chunk) => (data += chunk));
50
+ res.on('end', () => {
51
+ try {
52
+ const json = JSON.parse(data);
53
+ if (res.statusCode >= 400) {
54
+ reject(new Error(json.error || `API error: ${res.statusCode}`));
55
+ } else {
56
+ resolve(json);
57
+ }
58
+ } catch (e) {
59
+ reject(new Error(`Invalid API response: ${data.slice(0, 200)}`));
60
+ }
61
+ });
62
+ });
63
+
64
+ req.on('timeout', () => {
65
+ req.destroy();
66
+ reject(new Error('API request timed out'));
67
+ });
68
+ req.on('error', (err) => reject(new Error(`API connection failed: ${err.message}`)));
69
+
70
+ if (body) req.write(JSON.stringify(body));
71
+ req.end();
72
+ });
73
+ }
74
+
75
+ // ── Marketplace Directory ────────────────────────────────
76
+
77
+ function getMarketplaceDir() {
78
+ return path.join(process.cwd(), MARKETPLACE_DIR);
79
+ }
80
+
81
+ function getInstalledManifest() {
82
+ const dir = getMarketplaceDir();
83
+ const manifestPath = path.join(dir, INSTALLED_MANIFEST);
84
+ if (!fs.existsSync(manifestPath)) return { packs: [] };
85
+ return JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
86
+ }
87
+
88
+ function saveInstalledManifest(manifest) {
89
+ const dir = getMarketplaceDir();
90
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
91
+ fs.writeFileSync(path.join(dir, INSTALLED_MANIFEST), JSON.stringify(manifest, null, 2));
92
+ }
93
+
94
+ // ── Search ───────────────────────────────────────────────
95
+
96
+ async function searchRules(query, apiUrl) {
97
+ const endpoint = query
98
+ ? `/rules?q=${encodeURIComponent(query)}`
99
+ : '/rules';
100
+ const result = await apiRequest(apiUrl, endpoint);
101
+ return result.rules || result;
102
+ }
103
+
104
+ // ── Install ──────────────────────────────────────────────
105
+
106
+ async function installRule(packName, apiUrl) {
107
+ // Fetch rule pack from marketplace
108
+ const pack = await apiRequest(apiUrl, `/rules/${encodeURIComponent(packName)}`);
109
+
110
+ if (!pack || !pack.rules) {
111
+ throw new Error(`Rule pack "${packName}" not found or empty`);
112
+ }
113
+
114
+ // Merge into local .coderevrc.json
115
+ const configPath = path.join(process.cwd(), '.coderevrc.json');
116
+ let config = {};
117
+ if (fs.existsSync(configPath)) {
118
+ config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
119
+ }
120
+
121
+ // Ensure custom rules array exists
122
+ if (!config.rules) config.rules = {};
123
+ if (!config.rules.custom) config.rules.custom = [];
124
+
125
+ // Add pack rules (skip duplicates by name)
126
+ let added = 0;
127
+ for (const rule of pack.rules) {
128
+ const exists = config.rules.custom.some(r => r.name === rule.name);
129
+ if (!exists) {
130
+ config.rules.custom.push({
131
+ ...rule,
132
+ _source: packName,
133
+ _version: pack.version,
134
+ });
135
+ added++;
136
+ }
137
+ }
138
+
139
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
140
+
141
+ // Record installation
142
+ const manifest = getInstalledManifest();
143
+ const existing = manifest.packs.findIndex(p => p.name === packName);
144
+ if (existing >= 0) {
145
+ manifest.packs[existing] = {
146
+ name: packName,
147
+ version: pack.version,
148
+ rules: pack.rules.length,
149
+ installedAt: new Date().toISOString(),
150
+ };
151
+ } else {
152
+ manifest.packs.push({
153
+ name: packName,
154
+ version: pack.version,
155
+ rules: pack.rules.length,
156
+ installedAt: new Date().toISOString(),
157
+ });
158
+ }
159
+ saveInstalledManifest(manifest);
160
+
161
+ return { name: packName, version: pack.version, added, total: pack.rules.length };
162
+ }
163
+
164
+ // ── Publish ───────────────────────────────────────────────
165
+
166
+ async function publishRules(apiUrl, options = {}) {
167
+ const configPath = path.join(process.cwd(), '.coderevrc.json');
168
+ if (!fs.existsSync(configPath)) {
169
+ throw new Error('No .coderevrc.json found. Run `coderev init` first.');
170
+ }
171
+
172
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
173
+ const rules = config.rules?.custom || [];
174
+
175
+ if (rules.length === 0) {
176
+ throw new Error('No custom rules found in .coderevrc.json');
177
+ }
178
+
179
+ const packName = options.name || path.basename(process.cwd());
180
+ const payload = {
181
+ name: packName,
182
+ version: options.version || '1.0.0',
183
+ description: options.description || `Rules from ${packName}`,
184
+ rules: rules.map(r => ({
185
+ name: r.name,
186
+ pattern: r.pattern,
187
+ severity: r.severity || 'warning',
188
+ message: r.message,
189
+ filePattern: r.filePattern,
190
+ category: r.category || 'style',
191
+ })),
192
+ };
193
+
194
+ const result = await apiRequest(apiUrl, '/rules', 'POST', payload);
195
+
196
+ return { name: packName, version: payload.version, rules: rules.length, published: true };
197
+ }
198
+
199
+ // ── List Installed ───────────────────────────────────────
200
+
201
+ function listInstalled() {
202
+ const manifest = getInstalledManifest();
203
+
204
+ if (manifest.packs.length === 0) {
205
+ return { packs: [], message: 'No rule packs installed. Use `coderev rules search` to find rules.' };
206
+ }
207
+
208
+ return { packs: manifest.packs };
209
+ }
210
+
211
+ // ── Uninstall ─────────────────────────────────────────────
212
+
213
+ function uninstallRule(packName) {
214
+ const manifest = getInstalledManifest();
215
+ const idx = manifest.packs.findIndex(p => p.name === packName);
216
+ if (idx < 0) {
217
+ throw new Error(`Rule pack "${packName}" is not installed.`);
218
+ }
219
+
220
+ manifest.packs.splice(idx, 1);
221
+ saveInstalledManifest(manifest);
222
+
223
+ // Also remove from .coderevrc.json
224
+ const configPath = path.join(process.cwd(), '.coderevrc.json');
225
+ if (fs.existsSync(configPath)) {
226
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
227
+ if (config.rules?.custom) {
228
+ config.rules.custom = config.rules.custom.filter(r => r._source !== packName);
229
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
230
+ }
231
+ }
232
+
233
+ return { name: packName, removed: true };
234
+ }
235
+
236
+ // ── Search Local ──────────────────────────────────────────
237
+
238
+ function searchLocalRules(query) {
239
+ const manifest = getInstalledManifest();
240
+ if (!query) return manifest.packs;
241
+
242
+ const q = query.toLowerCase();
243
+ return manifest.packs.filter(
244
+ p => p.name.toLowerCase().includes(q)
245
+ );
246
+ }
247
+
248
+ module.exports = {
249
+ searchRules,
250
+ installRule,
251
+ publishRules,
252
+ listInstalled,
253
+ uninstallRule,
254
+ searchLocalRules,
255
+ DEFAULT_API_URL,
256
+ getMarketplaceDir,
257
+ };