@vibecheckai/cli 3.0.3 → 3.0.4

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 (69) hide show
  1. package/bin/cli-hygiene.js +241 -0
  2. package/bin/guardrail.js +834 -0
  3. package/bin/runners/cli-utils.js +1070 -0
  4. package/bin/runners/context/ai-task-decomposer.js +337 -0
  5. package/bin/runners/context/analyzer.js +462 -0
  6. package/bin/runners/context/api-contracts.js +427 -0
  7. package/bin/runners/context/context-diff.js +342 -0
  8. package/bin/runners/context/context-pruner.js +291 -0
  9. package/bin/runners/context/dependency-graph.js +414 -0
  10. package/bin/runners/context/generators/claude.js +107 -0
  11. package/bin/runners/context/generators/codex.js +108 -0
  12. package/bin/runners/context/generators/copilot.js +119 -0
  13. package/bin/runners/context/generators/cursor.js +514 -0
  14. package/bin/runners/context/generators/mcp.js +151 -0
  15. package/bin/runners/context/generators/windsurf.js +180 -0
  16. package/bin/runners/context/git-context.js +302 -0
  17. package/bin/runners/context/index.js +1042 -0
  18. package/bin/runners/context/insights.js +173 -0
  19. package/bin/runners/context/mcp-server/generate-rules.js +337 -0
  20. package/bin/runners/context/mcp-server/index.js +1176 -0
  21. package/bin/runners/context/mcp-server/package.json +24 -0
  22. package/bin/runners/context/memory.js +200 -0
  23. package/bin/runners/context/monorepo.js +215 -0
  24. package/bin/runners/context/multi-repo-federation.js +404 -0
  25. package/bin/runners/context/patterns.js +253 -0
  26. package/bin/runners/context/proof-context.js +972 -0
  27. package/bin/runners/context/security-scanner.js +303 -0
  28. package/bin/runners/context/semantic-search.js +350 -0
  29. package/bin/runners/context/shared.js +264 -0
  30. package/bin/runners/context/team-conventions.js +310 -0
  31. package/bin/runners/lib/ai-bridge.js +416 -0
  32. package/bin/runners/lib/analysis-core.js +271 -0
  33. package/bin/runners/lib/analyzers.js +541 -0
  34. package/bin/runners/lib/audit-bridge.js +391 -0
  35. package/bin/runners/lib/auth-truth.js +193 -0
  36. package/bin/runners/lib/auth.js +215 -0
  37. package/bin/runners/lib/backup.js +62 -0
  38. package/bin/runners/lib/billing.js +107 -0
  39. package/bin/runners/lib/claims.js +118 -0
  40. package/bin/runners/lib/cli-ui.js +540 -0
  41. package/bin/runners/lib/compliance-bridge-new.js +0 -0
  42. package/bin/runners/lib/compliance-bridge.js +165 -0
  43. package/bin/runners/lib/contracts/auth-contract.js +194 -0
  44. package/bin/runners/lib/contracts/env-contract.js +178 -0
  45. package/bin/runners/lib/contracts/external-contract.js +198 -0
  46. package/bin/runners/lib/contracts/guard.js +168 -0
  47. package/bin/runners/lib/contracts/index.js +89 -0
  48. package/bin/runners/lib/contracts/plan-validator.js +311 -0
  49. package/bin/runners/lib/contracts/route-contract.js +192 -0
  50. package/bin/runners/lib/detect.js +89 -0
  51. package/bin/runners/lib/doctor/autofix.js +254 -0
  52. package/bin/runners/lib/doctor/index.js +37 -0
  53. package/bin/runners/lib/doctor/modules/dependencies.js +325 -0
  54. package/bin/runners/lib/doctor/modules/index.js +46 -0
  55. package/bin/runners/lib/doctor/modules/network.js +250 -0
  56. package/bin/runners/lib/doctor/modules/project.js +312 -0
  57. package/bin/runners/lib/doctor/modules/runtime.js +224 -0
  58. package/bin/runners/lib/doctor/modules/security.js +348 -0
  59. package/bin/runners/lib/doctor/modules/system.js +213 -0
  60. package/bin/runners/lib/doctor/modules/vibecheck.js +394 -0
  61. package/bin/runners/lib/doctor/reporter.js +262 -0
  62. package/bin/runners/lib/doctor/service.js +262 -0
  63. package/bin/runners/lib/doctor/types.js +113 -0
  64. package/bin/runners/lib/doctor/ui.js +263 -0
  65. package/bin/runners/lib/doctor-enhanced.js +233 -0
  66. package/bin/runners/lib/doctor-v2.js +608 -0
  67. package/bin/runners/lib/enforcement.js +72 -0
  68. package/bin/vibecheck.js +0 -0
  69. package/package.json +8 -9
@@ -0,0 +1,427 @@
1
+ /**
2
+ * API Contract Extraction Module
3
+ * Extracts OpenAPI and GraphQL schemas for context
4
+ */
5
+
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+
9
+ /**
10
+ * Find files recursively (local helper)
11
+ */
12
+ function findFiles(dir, extensions, maxDepth = 5, currentDepth = 0) {
13
+ if (currentDepth >= maxDepth || !fs.existsSync(dir)) return [];
14
+
15
+ const files = [];
16
+ try {
17
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
18
+ for (const entry of entries) {
19
+ const fullPath = path.join(dir, entry.name);
20
+ if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
21
+ files.push(...findFiles(fullPath, extensions, maxDepth, currentDepth + 1));
22
+ } else if (entry.isFile() && extensions.some(ext => entry.name.endsWith(ext))) {
23
+ files.push(fullPath);
24
+ }
25
+ }
26
+ } catch {}
27
+ return files;
28
+ }
29
+
30
+ /**
31
+ * Extract OpenAPI/Swagger specifications
32
+ */
33
+ function extractOpenAPISpecs(projectPath) {
34
+ const specs = [];
35
+
36
+ // Look for OpenAPI files
37
+ const openAPIFiles = findFiles(projectPath, [
38
+ ".json", ".yaml", ".yml"
39
+ ]).filter(file => {
40
+ const content = fs.readFileSync(file, "utf-8");
41
+ return content.includes("openapi") || content.includes("swagger");
42
+ });
43
+
44
+ for (const file of openAPIFiles) {
45
+ try {
46
+ const content = fs.readFileSync(file, "utf-8");
47
+ let spec;
48
+
49
+ if (file.endsWith(".json")) {
50
+ spec = JSON.parse(content);
51
+ } else {
52
+ // Simple YAML parser for basic specs
53
+ spec = parseSimpleYAML(content);
54
+ }
55
+
56
+ if (spec && (spec.openapi || spec.swagger)) {
57
+ // Extract key information
58
+ const extracted = {
59
+ file: path.relative(projectPath, file).replace(/\\/g, "/"),
60
+ version: spec.openapi || spec.swagger,
61
+ title: spec.info?.title || "Untitled API",
62
+ description: spec.info?.description || "",
63
+ baseUrl: spec.servers?.[0]?.url || "",
64
+ paths: Object.keys(spec.paths || {}),
65
+ schemas: Object.keys(spec.components?.schemas || {}),
66
+ endpoints: [],
67
+ };
68
+
69
+ // Extract endpoint details
70
+ for (const [path, methods] of Object.entries(spec.paths || {})) {
71
+ for (const [method, details] of Object.entries(methods)) {
72
+ if (typeof details === "object" && details.operationId) {
73
+ extracted.endpoints.push({
74
+ method: method.toUpperCase(),
75
+ path,
76
+ operationId: details.operationId,
77
+ summary: details.summary || "",
78
+ tags: details.tags || [],
79
+ });
80
+ }
81
+ }
82
+ }
83
+
84
+ specs.push(extracted);
85
+ }
86
+ } catch {}
87
+ }
88
+
89
+ return specs;
90
+ }
91
+
92
+ /**
93
+ * Simple YAML parser for basic specs
94
+ */
95
+ function parseSimpleYAML(content) {
96
+ const lines = content.split("\n");
97
+ const result = {};
98
+ let currentSection = result;
99
+ const sectionStack = [result];
100
+ let indent = 0;
101
+
102
+ for (const line of lines) {
103
+ if (line.trim() === "" || line.trim().startsWith("#")) continue;
104
+
105
+ const currentIndent = line.match(/^ */)[0].length;
106
+ const trimmed = line.trim();
107
+
108
+ if (trimmed.includes(":")) {
109
+ const [key, ...valueParts] = trimmed.split(":");
110
+ const value = valueParts.join(":").trim();
111
+
112
+ // Adjust section stack based on indentation
113
+ if (currentIndent < indent) {
114
+ sectionStack.pop();
115
+ currentSection = sectionStack[sectionStack.length - 1];
116
+ }
117
+
118
+ if (value) {
119
+ // Simple value
120
+ currentSection[key.trim()] = value.replace(/['"]/g, "");
121
+ } else {
122
+ // New section
123
+ currentSection[key.trim()] = {};
124
+ sectionStack.push(currentSection[key.trim()]);
125
+ currentSection = currentSection[key.trim()];
126
+ }
127
+
128
+ indent = currentIndent;
129
+ }
130
+ }
131
+
132
+ return result;
133
+ }
134
+
135
+ /**
136
+ * Extract GraphQL schemas
137
+ */
138
+ function extractGraphQLSchemas(projectPath) {
139
+ const schemas = [];
140
+
141
+ // Look for GraphQL files
142
+ const graphqlFiles = findFiles(projectPath, [
143
+ ".graphql", ".gql"
144
+ ]);
145
+
146
+ // Also check for schema definitions in JS/TS files
147
+ const jsFiles = findFiles(projectPath, [
148
+ ".ts", ".tsx", ".js", ".jsx"
149
+ ]).filter(file => {
150
+ const content = fs.readFileSync(file, "utf-8");
151
+ return content.includes("gql`") || content.includes("GraphQLSchema") || content.includes("typeDefs");
152
+ });
153
+
154
+ // Process .graphql files
155
+ for (const file of graphqlFiles) {
156
+ try {
157
+ const content = fs.readFileSync(file, "utf-8");
158
+ const types = extractGraphQLTypes(content);
159
+
160
+ schemas.push({
161
+ file: path.relative(projectPath, file).replace(/\\/g, "/"),
162
+ type: "schema",
163
+ types,
164
+ queries: types.filter(t => t.type === "Query" || t.name.startsWith("query")),
165
+ mutations: types.filter(t => t.type === "Mutation" || t.name.startsWith("mutation")),
166
+ subscriptions: types.filter(t => t.type === "Subscription" || t.name.startsWith("subscription")),
167
+ });
168
+ } catch {}
169
+ }
170
+
171
+ // Process JS/TS files with embedded schemas
172
+ for (const file of jsFiles) {
173
+ try {
174
+ const content = fs.readFileSync(file, "utf-8");
175
+ const extracted = extractEmbeddedGraphQL(content);
176
+
177
+ if (extracted.schemas.length > 0) {
178
+ schemas.push({
179
+ file: path.relative(projectPath, file).replace(/\\/g, "/"),
180
+ type: "embedded",
181
+ schemas: extracted.schemas,
182
+ resolvers: extracted.resolvers,
183
+ });
184
+ }
185
+ } catch {}
186
+ }
187
+
188
+ return schemas;
189
+ }
190
+
191
+ /**
192
+ * Extract types from GraphQL schema
193
+ */
194
+ function extractGraphQLTypes(content) {
195
+ const types = [];
196
+ const lines = content.split("\n");
197
+ let currentType = null;
198
+
199
+ for (const line of lines) {
200
+ const trimmed = line.trim();
201
+
202
+ if (trimmed.startsWith("type ") || trimmed.startsWith("interface ") ||
203
+ trimmed.startsWith("input ") || trimmed.startsWith("enum ")) {
204
+ const parts = trimmed.split(/\s+/);
205
+ currentType = {
206
+ type: parts[0],
207
+ name: parts[1],
208
+ fields: [],
209
+ };
210
+ types.push(currentType);
211
+ } else if (currentType && trimmed && !trimmed.startsWith("#")) {
212
+ if (trimmed === "}") {
213
+ currentType = null;
214
+ } else if (trimmed.includes(":")) {
215
+ const [fieldName, fieldType] = trimmed.split(":").map(s => s.trim());
216
+ if (fieldName && fieldType) {
217
+ currentType.fields.push({
218
+ name: fieldName,
219
+ type: fieldType.replace(/[!]/g, ""),
220
+ required: fieldType.includes("!"),
221
+ });
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ return types;
228
+ }
229
+
230
+ /**
231
+ * Extract embedded GraphQL from JS/TS
232
+ */
233
+ function extractEmbeddedGraphQL(content) {
234
+ const schemas = [];
235
+ const resolvers = [];
236
+
237
+ // Extract template literals
238
+ const gqlMatches = content.match(/gql`([^`]+)`/g) || [];
239
+
240
+ for (const match of gqlMatches) {
241
+ const schema = match.replace(/gql`([^`]+)`/, "$1");
242
+ const types = extractGraphQLTypes(schema);
243
+
244
+ schemas.push({
245
+ content: schema,
246
+ types,
247
+ });
248
+ }
249
+
250
+ // Look for typeDefs assignments
251
+ const typeDefMatches = content.match(/typeDefs\s*[:=]\s*`([^`]+)`/g) || [];
252
+
253
+ for (const match of typeDefMatches) {
254
+ const schema = match.replace(/typeDefs\s*[:=]\s*`([^`]+)`/, "$1");
255
+ const types = extractGraphQLTypes(schema);
256
+
257
+ schemas.push({
258
+ content: schema,
259
+ types,
260
+ });
261
+ }
262
+
263
+ // Look for resolvers
264
+ const resolverMatches = content.match(/resolvers\s*[:=]\s*{([^}]+)}/gs) || [];
265
+
266
+ for (const match of resolverMatches) {
267
+ resolvers.push({
268
+ content: match,
269
+ });
270
+ }
271
+
272
+ return { schemas, resolvers };
273
+ }
274
+
275
+ /**
276
+ * Extract API route patterns from Express/Next.js
277
+ */
278
+ function extractAPIRoutes(projectPath) {
279
+ const routes = [];
280
+
281
+ // Look for API route files
282
+ const apiFiles = findFiles(projectPath, [
283
+ ".ts", ".tsx", ".js", ".jsx"
284
+ ]).filter(file => {
285
+ const relativePath = path.relative(projectPath, file).replace(/\\/g, "/");
286
+ return relativePath.includes("/api/") || relativePath.includes("/routes/");
287
+ });
288
+
289
+ for (const file of apiFiles) {
290
+ try {
291
+ const content = fs.readFileSync(file, "utf-8");
292
+ const extracted = extractRouteInfo(content, file);
293
+
294
+ if (extracted.routes.length > 0) {
295
+ routes.push({
296
+ file: path.relative(projectPath, file).replace(/\\/g, "/"),
297
+ routes: extracted.routes,
298
+ middleware: extracted.middleware,
299
+ validation: extracted.validation,
300
+ });
301
+ }
302
+ } catch {}
303
+ }
304
+
305
+ return routes;
306
+ }
307
+
308
+ /**
309
+ * Extract route information from file
310
+ */
311
+ function extractRouteInfo(content, filePath) {
312
+ const routes = [];
313
+ const middleware = [];
314
+ const validation = [];
315
+
316
+ // Extract Express routes
317
+ const expressMatches = content.match(/\.(get|post|put|delete|patch)\s*\(\s*['"]([^'"]+)['"]/g) || [];
318
+
319
+ for (const match of expressMatches) {
320
+ const parts = match.match(/\.(get|post|put|delete|patch)\s*\(\s*['"]([^'"]+)['"]/);
321
+ if (parts) {
322
+ routes.push({
323
+ method: parts[1].toUpperCase(),
324
+ path: parts[2],
325
+ framework: "Express",
326
+ });
327
+ }
328
+ }
329
+
330
+ // Extract Next.js API routes
331
+ if (filePath.includes("/api/")) {
332
+ const relativePath = path.relative(process.cwd(), filePath).replace(/\\/g, "/");
333
+ const routePath = relativePath
334
+ .replace(/\/api\//, "/")
335
+ .replace(/\.(ts|tsx|js|jsx)$/, "");
336
+
337
+ // Look for HTTP method exports
338
+ const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
339
+ for (const method of methods) {
340
+ if (content.includes(`export async function ${method}`) ||
341
+ content.includes(`export function ${method}`)) {
342
+ routes.push({
343
+ method,
344
+ path: routePath,
345
+ framework: "Next.js",
346
+ });
347
+ }
348
+ }
349
+ }
350
+
351
+ // Extract middleware usage
352
+ if (content.includes("cors")) middleware.push("cors");
353
+ if (content.includes("helmet")) middleware.push("helmet");
354
+ if (content.includes("auth")) middleware.push("auth");
355
+ if (content.includes("validate") || content.includes("zod")) validation.push("zod");
356
+ if (content.includes("joi")) validation.push("joi");
357
+
358
+ return { routes, middleware, validation };
359
+ }
360
+
361
+ /**
362
+ * Generate API context summary
363
+ */
364
+ function generateAPIContext(projectPath) {
365
+ const openAPI = extractOpenAPISpecs(projectPath);
366
+ const graphql = extractGraphQLSchemas(projectPath);
367
+ const routes = extractAPIRoutes(projectPath);
368
+
369
+ return {
370
+ summary: {
371
+ hasOpenAPI: openAPI.length > 0,
372
+ openAPICount: openAPI.length,
373
+ hasGraphQL: graphql.length > 0,
374
+ graphqlCount: graphql.length,
375
+ hasCustomRoutes: routes.length > 0,
376
+ routeCount: routes.reduce((sum, r) => sum + r.routes.length, 0),
377
+ },
378
+ openAPI,
379
+ graphql,
380
+ routes,
381
+ recommendations: generateAPIRecommendations(openAPI, graphql, routes),
382
+ };
383
+ }
384
+
385
+ /**
386
+ * Generate API recommendations
387
+ */
388
+ function generateAPIRecommendations(openAPI, graphql, routes) {
389
+ const recommendations = [];
390
+
391
+ if (openAPI.length === 0 && graphql.length === 0 && routes.length > 0) {
392
+ recommendations.push({
393
+ type: "documentation",
394
+ message: "Consider adding OpenAPI/Swagger specification for better API documentation",
395
+ });
396
+ }
397
+
398
+ if (routes.length > 0) {
399
+ const hasValidation = routes.some(r => r.validation.length > 0);
400
+ if (!hasValidation) {
401
+ recommendations.push({
402
+ type: "validation",
403
+ message: "Add input validation to API routes (zod, joi, etc.)",
404
+ });
405
+ }
406
+ }
407
+
408
+ const totalEndpoints = openAPI.reduce((sum, s) => sum + s.endpoints.length, 0) +
409
+ graphql.reduce((sum, s) => sum + (s.queries?.length || 0) + (s.mutations?.length || 0), 0) +
410
+ routes.reduce((sum, r) => sum + r.routes.length, 0);
411
+
412
+ if (totalEndpoints > 20) {
413
+ recommendations.push({
414
+ type: "organization",
415
+ message: "Consider organizing APIs into modules or microservices",
416
+ });
417
+ }
418
+
419
+ return recommendations;
420
+ }
421
+
422
+ module.exports = {
423
+ extractOpenAPISpecs,
424
+ extractGraphQLSchemas,
425
+ extractAPIRoutes,
426
+ generateAPIContext,
427
+ };