vorpl-setup 0.1.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 (2) hide show
  1. package/index.js +160 -0
  2. package/package.json +15 -0
package/index.js ADDED
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Vorpl Setup CLI
4
+ *
5
+ * One command to install and configure Vorpl for Claude Code.
6
+ *
7
+ * Usage: npx vorpl-setup <API_KEY>
8
+ */
9
+
10
+ const { execSync } = require('child_process');
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const os = require('os');
14
+ const https = require('https');
15
+
16
+ const API_KEY = process.argv[2];
17
+ const DATA_DIR = path.join(os.homedir(), '.vorpl');
18
+ const CONFIG_PATH = path.join(DATA_DIR, 'config.json');
19
+
20
+ function log(msg) { console.log(` ${msg}`); }
21
+ function success(msg) { console.log(` \x1b[32m${msg}\x1b[0m`); }
22
+ function warn(msg) { console.log(` \x1b[33m${msg}\x1b[0m`); }
23
+ function fail(msg) { console.log(` \x1b[31m${msg}\x1b[0m`); }
24
+
25
+ function validateKey(key) {
26
+ return new Promise(resolve => {
27
+ const req = https.request({
28
+ hostname: 'api.vorpl.ai',
29
+ path: '/health',
30
+ method: 'GET',
31
+ headers: { 'Authorization': `Bearer ${key}` },
32
+ timeout: 5000,
33
+ }, res => resolve(res.statusCode === 200));
34
+ req.on('error', () => resolve(false));
35
+ req.on('timeout', () => { req.destroy(); resolve(false); });
36
+ req.end();
37
+ });
38
+ }
39
+
40
+ function runCmd(cmd, description) {
41
+ try {
42
+ execSync(cmd, { stdio: 'pipe', timeout: 30000 });
43
+ return true;
44
+ } catch (e) {
45
+ return false;
46
+ }
47
+ }
48
+
49
+ async function main() {
50
+ console.log('\n Vorpl Setup\n ───────────\n');
51
+
52
+ // ── Validate API key ───────────────────────────────────
53
+ if (!API_KEY || !API_KEY.startsWith('vpl_')) {
54
+ fail('Usage: npx vorpl-setup <YOUR_API_KEY>');
55
+ log('');
56
+ log('Get your API key at https://vorpl.ai/dashboard/settings');
57
+ console.log('');
58
+ process.exit(1);
59
+ }
60
+
61
+ log('Validating API key ...');
62
+ const valid = await validateKey(API_KEY);
63
+ if (valid) {
64
+ success('API key valid.');
65
+ } else {
66
+ warn('Could not validate key (API may be starting up). Continuing anyway.');
67
+ }
68
+
69
+ // ── Check Claude Code is installed ─────────────────────
70
+ log('Checking Claude Code ...');
71
+ const hasClaude = runCmd('claude --version');
72
+ if (!hasClaude) {
73
+ fail('Claude Code CLI not found. Install it first: https://claude.ai/download');
74
+ process.exit(1);
75
+ }
76
+ success('Claude Code found.');
77
+
78
+ // ── Add marketplace ────────────────────────────────────
79
+ log('Adding Vorpl marketplace ...');
80
+ const marketplaceAdded = runCmd('claude plugin marketplace add https://vorpl.ai');
81
+ if (marketplaceAdded) {
82
+ success('Marketplace added.');
83
+ } else {
84
+ warn('Marketplace may already exist. Continuing.');
85
+ }
86
+
87
+ // ── Install plugin ─────────────────────────────────────
88
+ log('Installing Vorpl plugin ...');
89
+ const pluginInstalled = runCmd('claude plugin install vorpl@vorpl');
90
+ if (pluginInstalled) {
91
+ success('Plugin installed.');
92
+ } else {
93
+ warn('Plugin may already be installed. Continuing.');
94
+ }
95
+
96
+ // ── Create data directory ──────────────────────────────
97
+ log('Setting up data directory ...');
98
+ const dirs = [
99
+ path.join(DATA_DIR, 'logs', 'events'),
100
+ path.join(DATA_DIR, 'logs', 'observations'),
101
+ path.join(DATA_DIR, 'logs', 'patterns'),
102
+ path.join(DATA_DIR, 'logs', 'aggregates'),
103
+ path.join(DATA_DIR, 'rules', 'personal'),
104
+ path.join(DATA_DIR, 'rules', 'collective'),
105
+ path.join(DATA_DIR, 'patterns', 'local'),
106
+ path.join(DATA_DIR, 'patterns', 'pending-upload'),
107
+ path.join(DATA_DIR, 'metrics'),
108
+ path.join(DATA_DIR, 'cache'),
109
+ ];
110
+
111
+ for (const dir of dirs) {
112
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
113
+ }
114
+
115
+ // ── Write config ───────────────────────────────────────
116
+ log('Saving configuration ...');
117
+ let config = {};
118
+ if (fs.existsSync(CONFIG_PATH)) {
119
+ try { config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')); } catch {}
120
+ }
121
+
122
+ config = {
123
+ enabled: true,
124
+ api_key: API_KEY,
125
+ auth_status: 'authenticated',
126
+ max_active_rules: 25,
127
+ rule_injection_budget_tokens: 400,
128
+ log_retention_days: 30,
129
+ installation_id: config.installation_id || require('crypto').randomUUID(),
130
+ schema_version: '1.0',
131
+ session_count: config.session_count || 0,
132
+ sync_endpoint: 'https://api.vorpl.ai',
133
+ last_analysis_timestamp: config.last_analysis_timestamp || null,
134
+ ...config,
135
+ api_key: API_KEY, // Always overwrite with the new key
136
+ auth_status: 'authenticated',
137
+ };
138
+
139
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
140
+ success('Configuration saved.');
141
+
142
+ // ── Done ───────────────────────────────────────────────
143
+ console.log(`
144
+ ─────────────────────────────────────
145
+ ${'\x1b[32m'}Vorpl is ready!${'\x1b[0m'}
146
+ ─────────────────────────────────────
147
+
148
+ Start a new Claude Code session and Vorpl
149
+ will begin learning from your work automatically.
150
+
151
+ Commands:
152
+ /vorpl — Check status
153
+ /vorpl-stats — See learned rules
154
+ /vorpl-update — Check for updates
155
+
156
+ Dashboard: https://vorpl.ai/dashboard
157
+ `);
158
+ }
159
+
160
+ main();
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "vorpl-setup",
3
+ "version": "0.1.0",
4
+ "description": "One-command Vorpl setup for Claude Code",
5
+ "bin": {
6
+ "vorpl-setup": "index.js"
7
+ },
8
+ "keywords": [
9
+ "vorpl",
10
+ "claude-code",
11
+ "ai",
12
+ "coding"
13
+ ],
14
+ "license": "MIT"
15
+ }