@vibecheckai/cli 3.3.0 → 3.4.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.
@@ -1,305 +1,13 @@
1
1
  /**
2
- * API Client for Vibecheck Dashboard Integration
2
+ * API Client - MCP Server Re-export
3
3
  *
4
- * Handles communication with the web dashboard API for:
5
- * - Creating scan records
6
- * - Updating scan progress
7
- * - Submitting scan results
8
- * - Broadcasting real-time updates
9
- */
10
-
11
- "use strict";
12
-
13
- const https = require("https");
14
- const http = require("http");
15
- const { logger } = require("./logger.cjs");
16
-
17
- // Configuration
18
- const API_BASE_URL = process.env.VIBECHECK_API_URL || "https://api.vibecheckai.dev";
19
- const API_TIMEOUT = 30000; // 30 seconds
20
-
21
- /**
22
- * Make HTTP request to API
23
- */
24
- async function makeRequest(path, options = {}) {
25
- const url = new URL(path, API_BASE_URL);
26
- const isHttps = url.protocol === "https:";
27
- const client = isHttps ? https : http;
28
-
29
- const defaultOptions = {
30
- method: "POST",
31
- headers: {
32
- "Content-Type": "application/json",
33
- "User-Agent": "vibecheck-cli/3.3.0",
34
- },
35
- timeout: API_TIMEOUT,
36
- };
37
-
38
- const requestOptions = {
39
- ...defaultOptions,
40
- ...options,
41
- hostname: url.hostname,
42
- port: url.port || (isHttps ? 443 : 80),
43
- path: url.pathname + url.search,
44
- };
45
-
46
- // Add Authorization header if API key is available
47
- const apiKey = process.env.VIBECHECK_API_KEY || getApiKey();
48
- if (apiKey) {
49
- requestOptions.headers.Authorization = `Bearer ${apiKey}`;
50
- }
51
-
52
- return new Promise((resolve, reject) => {
53
- const req = client.request(requestOptions, (res) => {
54
- let data = "";
55
-
56
- res.on("data", (chunk) => {
57
- data += chunk;
58
- });
59
-
60
- res.on("end", () => {
61
- try {
62
- const jsonData = data ? JSON.parse(data) : {};
63
- resolve({
64
- ok: res.statusCode >= 200 && res.statusCode < 300,
65
- status: res.statusCode,
66
- data: jsonData,
67
- });
68
- } catch (err) {
69
- resolve({
70
- ok: false,
71
- status: res.statusCode,
72
- data: { error: "Invalid JSON response" },
73
- });
74
- }
75
- });
76
- });
77
-
78
- req.on("error", (err) => {
79
- logger.debug(`API request failed: ${err.message}`);
80
- resolve({
81
- ok: false,
82
- error: err.message,
83
- data: { error: err.message },
84
- });
85
- });
86
-
87
- req.on("timeout", () => {
88
- req.destroy();
89
- resolve({
90
- ok: false,
91
- error: "Request timeout",
92
- data: { error: "Request timeout" },
93
- });
94
- });
95
-
96
- if (options.body) {
97
- req.write(JSON.stringify(options.body));
98
- }
99
-
100
- req.end();
101
- });
102
- }
103
-
104
- /**
105
- * Get API key from environment or config
106
- */
107
- function getApiKey() {
108
- // Try various environment variables
109
- const envVars = [
110
- "VIBECHECK_API_KEY",
111
- "VIBECHECK_TOKEN",
112
- "API_KEY",
113
- "TOKEN",
114
- ];
115
-
116
- for (const envVar of envVars) {
117
- if (process.env[envVar]) {
118
- return process.env[envVar];
119
- }
120
- }
121
-
122
- // Try to read from config file
123
- try {
124
- const fs = require("fs");
125
- const path = require("path");
126
- const os = require("os");
127
-
128
- const configPaths = [
129
- path.join(os.homedir(), ".vibecheck", "config.json"),
130
- path.join(process.cwd(), ".vibecheckrc.json"),
131
- path.join(process.cwd(), "vibecheck.config.json"),
132
- ];
133
-
134
- for (const configPath of configPaths) {
135
- if (fs.existsSync(configPath)) {
136
- const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
137
- if (config.apiKey || config.token) {
138
- return config.apiKey || config.token;
139
- }
140
- }
141
- }
142
- } catch (err) {
143
- // Ignore config file errors
144
- }
145
-
146
- return null;
147
- }
148
-
149
- // =============================================================================
150
- // SECURITY: Input Validation
151
- // =============================================================================
152
-
153
- /**
154
- * Validate scanId format to prevent path injection.
155
- *
156
- * SECURITY FIX: scanId is interpolated into URLs like `/api/scans/${scanId}/progress`.
157
- * Without validation, an attacker could inject path segments:
158
- * scanId = "../../admin/delete"
159
- * → URL becomes "/api/scans/../../admin/delete/progress"
4
+ * This module re-exports from the canonical bin/runners/lib/api-client.js
5
+ * DO NOT add implementation here.
160
6
  *
161
- * @param {string} scanId - The scan ID to validate
162
- * @returns {string} - The validated scanId
163
- * @throws {Error} - If scanId is invalid
164
- */
165
- function validateScanId(scanId) {
166
- if (!scanId || typeof scanId !== 'string') {
167
- throw new Error('scanId is required and must be a string');
168
- }
169
-
170
- // Only allow alphanumeric, hyphens, underscores (no dots, slashes, etc.)
171
- // Max length 64 to prevent abuse
172
- if (!/^[a-zA-Z0-9_-]{1,64}$/.test(scanId)) {
173
- throw new Error('Invalid scanId format - must be alphanumeric with hyphens/underscores only, max 64 chars');
174
- }
175
-
176
- return scanId;
177
- }
178
-
179
- /**
180
- * Create a new scan record
181
- */
182
- async function createScan(options) {
183
- const {
184
- repositoryId,
185
- repositoryUrl,
186
- localPath,
187
- branch = "main",
188
- enableLLM = false,
189
- } = options;
190
-
191
- const response = await makeRequest("/api/scans", {
192
- body: {
193
- repositoryId,
194
- repositoryUrl,
195
- localPath,
196
- branch,
197
- enableLLM,
198
- },
199
- });
200
-
201
- if (!response.ok) {
202
- throw new Error(`Failed to create scan: ${response.data?.error || response.error}`);
203
- }
204
-
205
- return response.data.data;
206
- }
207
-
208
- /**
209
- * Update scan progress
7
+ * @see ../../../bin/runners/lib/api-client.js for the canonical implementation
210
8
  */
211
- async function updateScanProgress(scanId, progress, status = null) {
212
- const validatedId = validateScanId(scanId);
213
-
214
- const response = await makeRequest(`/api/scans/${validatedId}/progress`, {
215
- body: {
216
- progress,
217
- status,
218
- },
219
- });
220
9
 
221
- if (!response.ok) {
222
- logger.debug(`Failed to update scan progress: ${response.data?.error || response.error}`);
223
- }
224
-
225
- return response.data;
226
- }
227
-
228
- /**
229
- * Submit scan results
230
- */
231
- async function submitScanResults(scanId, results) {
232
- const validatedId = validateScanId(scanId);
233
-
234
- const {
235
- verdict,
236
- score,
237
- findings,
238
- filesScanned,
239
- linesScanned,
240
- durationMs,
241
- metadata = {},
242
- } = results;
243
-
244
- const response = await makeRequest(`/api/scans/${validatedId}/complete`, {
245
- body: {
246
- verdict,
247
- score,
248
- findings,
249
- filesScanned,
250
- linesScanned,
251
- durationMs,
252
- metadata,
253
- },
254
- });
255
-
256
- if (!response.ok) {
257
- throw new Error(`Failed to submit scan results: ${response.data?.error || response.error}`);
258
- }
259
-
260
- return response.data;
261
- }
262
-
263
- /**
264
- * Report scan error
265
- */
266
- async function reportScanError(scanId, error) {
267
- const validatedId = validateScanId(scanId);
268
-
269
- const response = await makeRequest(`/api/scans/${validatedId}/error`, {
270
- body: {
271
- error: error.message || String(error),
272
- stack: error.stack,
273
- },
274
- });
275
-
276
- if (!response.ok) {
277
- logger.debug(`Failed to report scan error: ${response.data?.error || response.error}`);
278
- }
279
-
280
- return response.data;
281
- }
282
-
283
- /**
284
- * Check if API is available
285
- */
286
- async function isApiAvailable() {
287
- try {
288
- const response = await makeRequest("/api/health", {
289
- method: "GET",
290
- timeout: 5000,
291
- });
292
- return response.ok;
293
- } catch (err) {
294
- return false;
295
- }
296
- }
10
+ "use strict";
297
11
 
298
- module.exports = {
299
- createScan,
300
- updateScanProgress,
301
- submitScanResults,
302
- reportScanError,
303
- isApiAvailable,
304
- getApiKey,
305
- };
12
+ // Re-export everything from the canonical api-client
13
+ module.exports = require('../../bin/runners/lib/api-client.js');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibecheck-mcp-server",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Professional MCP server for vibecheck - Intelligent development environment vibechecks",
5
5
  "type": "module",
6
6
  "main": "index.js",