guardvibe 2.0.3 → 2.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.
- package/build/cli.js +91 -52
- package/package.json +1 -1
package/build/cli.js
CHANGED
|
@@ -50,9 +50,8 @@ function setupPlatform(name) {
|
|
|
50
50
|
}
|
|
51
51
|
if (existing.mcpServers["guardvibe"]) {
|
|
52
52
|
console.log(` [OK] GuardVibe already configured in ${platform.description}`);
|
|
53
|
-
// Still ensure
|
|
54
|
-
|
|
55
|
-
setupClaudeHooksAndGuide();
|
|
53
|
+
// Still ensure security guidance and .gitignore are set up
|
|
54
|
+
setupSecurityGuide(name);
|
|
56
55
|
return true;
|
|
57
56
|
}
|
|
58
57
|
existing.mcpServers["guardvibe"] = GUARDVIBE_MCP_CONFIG;
|
|
@@ -66,77 +65,117 @@ function setupPlatform(name) {
|
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
67
|
console.log(` [OK] Added MCP server to ${platform.description}`);
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
setupClaudeHooksAndGuide();
|
|
72
|
-
}
|
|
68
|
+
// Set up platform-specific security guidance + universal security rules
|
|
69
|
+
setupSecurityGuide(name);
|
|
73
70
|
return true;
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
// ── Universal security rules (shared across all AI platforms) ────────
|
|
73
|
+
const SECURITY_RULES = `## Security Rules (enforced by GuardVibe MCP)
|
|
74
|
+
|
|
75
|
+
### Mandatory checks
|
|
76
|
+
- AFTER writing any API route, Server Action, or database query: use the guardvibe scan_file MCP tool on the file
|
|
77
|
+
- BEFORE committing: use the guardvibe scan_staged MCP tool
|
|
78
|
+
- When GuardVibe reports HIGH or CRITICAL: fix immediately before moving on
|
|
79
|
+
- BEFORE creating a PR: use scan_changed_files to review all changes
|
|
80
|
+
|
|
81
|
+
### Writing secure code
|
|
82
|
+
- Every API route handler MUST have auth check before DB access
|
|
83
|
+
- Every POST endpoint MUST have input validation (zod/joi schema)
|
|
84
|
+
- Never pass user input to innerHTML, eval, exec, or raw SQL
|
|
85
|
+
- Never pass user-controlled URLs to fetch() without allowlist validation
|
|
86
|
+
- Always use select: in Prisma/Drizzle queries from Server Actions (never return full objects to client)
|
|
87
|
+
- Always validate redirect URLs against trusted domain allowlist
|
|
88
|
+
- Set security headers (CSP, HSTS, X-Frame-Options, X-Content-Type-Options)
|
|
89
|
+
- Verify webhook signatures before processing events
|
|
90
|
+
- Use parameterized queries, never string concatenation/template literals for SQL
|
|
91
|
+
|
|
92
|
+
### When in doubt
|
|
93
|
+
- Use the guardvibe explain_remediation MCP tool with the rule ID for detailed fix guidance
|
|
94
|
+
- Use the guardvibe check_code MCP tool to verify a code snippet is secure before applying
|
|
95
|
+
`;
|
|
96
|
+
function setupSecurityGuide(platformName) {
|
|
97
|
+
// 1. Platform-specific guidance file
|
|
98
|
+
if (platformName === "claude")
|
|
99
|
+
setupClaudeGuide();
|
|
100
|
+
else if (platformName === "cursor")
|
|
101
|
+
setupCursorGuide();
|
|
102
|
+
else if (platformName === "gemini")
|
|
103
|
+
setupGeminiGuide();
|
|
104
|
+
// 2. Platform-specific .gitignore entries
|
|
105
|
+
const gitignoreEntries = {
|
|
106
|
+
claude: [".claude.json", ".claude/", "CLAUDE.md"],
|
|
107
|
+
cursor: [".cursor/", ".cursorrules"],
|
|
108
|
+
gemini: ["GEMINI.md"],
|
|
109
|
+
};
|
|
110
|
+
const entries = gitignoreEntries[platformName] || [];
|
|
111
|
+
if (entries.length > 0)
|
|
112
|
+
addToGitignore(entries);
|
|
113
|
+
}
|
|
114
|
+
function setupClaudeGuide() {
|
|
115
|
+
// Claude Code hooks
|
|
77
116
|
const claudeSettingsDir = join(process.cwd(), ".claude");
|
|
78
|
-
if (!existsSync(claudeSettingsDir))
|
|
117
|
+
if (!existsSync(claudeSettingsDir))
|
|
79
118
|
mkdirSync(claudeSettingsDir, { recursive: true });
|
|
80
|
-
}
|
|
81
119
|
const claudeSettingsPath = join(claudeSettingsDir, "settings.json");
|
|
82
120
|
const existingSettings = readJsonFile(claudeSettingsPath) || {};
|
|
83
|
-
if (!existingSettings.hooks)
|
|
121
|
+
if (!existingSettings.hooks)
|
|
84
122
|
existingSettings.hooks = {};
|
|
85
|
-
}
|
|
86
|
-
// Real security hook: scan edited files automatically after every Edit/Write
|
|
87
|
-
// Claude Code passes tool_input as JSON on stdin — extract file_path with jq
|
|
88
123
|
if (!existingSettings.hooks.PostToolUse) {
|
|
89
124
|
existingSettings.hooks.PostToolUse = [
|
|
90
125
|
{
|
|
91
126
|
matcher: "Edit|Write",
|
|
92
|
-
hooks: [
|
|
93
|
-
{
|
|
127
|
+
hooks: [{
|
|
94
128
|
type: "command",
|
|
95
129
|
command: "jq -r '.tool_input.file_path' | xargs npx -y guardvibe check --format markdown 2>/dev/null || true"
|
|
96
|
-
}
|
|
97
|
-
]
|
|
130
|
+
}]
|
|
98
131
|
}
|
|
99
132
|
];
|
|
100
133
|
}
|
|
101
134
|
writeJsonFile(claudeSettingsPath, existingSettings);
|
|
102
135
|
console.log(` [OK] Claude Code hooks configured (.claude/settings.json)`);
|
|
103
|
-
//
|
|
136
|
+
// CLAUDE.md
|
|
104
137
|
const claudeMdPath = join(process.cwd(), "CLAUDE.md");
|
|
105
|
-
const guardvibeBlock = `
|
|
106
|
-
## Security Rules (enforced by GuardVibe MCP)
|
|
107
|
-
|
|
108
|
-
### Mandatory checks
|
|
109
|
-
- BEFORE writing any API route, Server Action, or database query: call \`scan_file\` on the file after editing
|
|
110
|
-
- BEFORE committing: call \`scan_staged\` to catch issues in staged files
|
|
111
|
-
- When GuardVibe reports HIGH or CRITICAL: fix immediately before moving on
|
|
112
|
-
|
|
113
|
-
### Writing secure code
|
|
114
|
-
- Every API route handler MUST have auth check before DB access
|
|
115
|
-
- Every POST endpoint MUST have input validation (zod/joi schema)
|
|
116
|
-
- Never pass user input to \`innerHTML\`, \`eval\`, \`exec\`, or raw SQL
|
|
117
|
-
- Never pass user-controlled URLs to \`fetch()\` without allowlist validation
|
|
118
|
-
- Always use \`select:\` in Prisma queries from Server Actions (never return full objects)
|
|
119
|
-
- Always validate redirect URLs against trusted domain allowlist
|
|
120
|
-
- Set security headers in next.config.ts (CSP, HSTS, X-Frame-Options)
|
|
121
|
-
|
|
122
|
-
### When in doubt
|
|
123
|
-
- Use \`explain_remediation\` with the rule ID for detailed fix guidance
|
|
124
|
-
- Use \`scan_changed_files\` with base branch before creating PR
|
|
125
|
-
- Use \`check_code\` to verify a code snippet is secure before applying
|
|
126
|
-
`;
|
|
127
138
|
if (existsSync(claudeMdPath)) {
|
|
128
139
|
const content = readFileSync(claudeMdPath, "utf-8");
|
|
129
140
|
if (!content.includes("GuardVibe")) {
|
|
130
|
-
writeFileSync(claudeMdPath, content +
|
|
131
|
-
console.log(` [OK] GuardVibe
|
|
141
|
+
writeFileSync(claudeMdPath, content + "\n" + SECURITY_RULES, "utf-8");
|
|
142
|
+
console.log(` [OK] GuardVibe rules added to CLAUDE.md`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
writeFileSync(claudeMdPath, `# Project Guidelines\n\n${SECURITY_RULES}`, "utf-8");
|
|
147
|
+
console.log(` [OK] Created CLAUDE.md with security rules`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function setupCursorGuide() {
|
|
151
|
+
// .cursorrules — Cursor reads this file for AI instructions
|
|
152
|
+
const cursorrules = join(process.cwd(), ".cursorrules");
|
|
153
|
+
if (existsSync(cursorrules)) {
|
|
154
|
+
const content = readFileSync(cursorrules, "utf-8");
|
|
155
|
+
if (!content.includes("GuardVibe")) {
|
|
156
|
+
writeFileSync(cursorrules, content + "\n" + SECURITY_RULES, "utf-8");
|
|
157
|
+
console.log(` [OK] GuardVibe rules added to .cursorrules`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
writeFileSync(cursorrules, SECURITY_RULES, "utf-8");
|
|
162
|
+
console.log(` [OK] Created .cursorrules with security rules`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function setupGeminiGuide() {
|
|
166
|
+
// GEMINI.md — Gemini CLI reads this for project context
|
|
167
|
+
const geminiMd = join(process.cwd(), "GEMINI.md");
|
|
168
|
+
if (existsSync(geminiMd)) {
|
|
169
|
+
const content = readFileSync(geminiMd, "utf-8");
|
|
170
|
+
if (!content.includes("GuardVibe")) {
|
|
171
|
+
writeFileSync(geminiMd, content + "\n" + SECURITY_RULES, "utf-8");
|
|
172
|
+
console.log(` [OK] GuardVibe rules added to GEMINI.md`);
|
|
132
173
|
}
|
|
133
174
|
}
|
|
134
175
|
else {
|
|
135
|
-
writeFileSync(
|
|
136
|
-
console.log(` [OK] Created
|
|
176
|
+
writeFileSync(geminiMd, `# Project Guidelines\n\n${SECURITY_RULES}`, "utf-8");
|
|
177
|
+
console.log(` [OK] Created GEMINI.md with security rules`);
|
|
137
178
|
}
|
|
138
|
-
// Add generated files to .gitignore so they don't get committed
|
|
139
|
-
addToGitignore([".claude.json", ".claude/", "CLAUDE.md"]);
|
|
140
179
|
}
|
|
141
180
|
function addToGitignore(entries) {
|
|
142
181
|
const gitignorePath = join(process.cwd(), ".gitignore");
|
|
@@ -148,7 +187,7 @@ function addToGitignore(entries) {
|
|
|
148
187
|
const missing = entries.filter(e => !content.split("\n").some(line => line.trim() === e));
|
|
149
188
|
if (missing.length === 0)
|
|
150
189
|
return;
|
|
151
|
-
const block = `\n# GuardVibe
|
|
190
|
+
const block = `\n# GuardVibe (auto-added by guardvibe init)\n${missing.join("\n")}\n`;
|
|
152
191
|
writeFileSync(gitignorePath, content.trimEnd() + block, "utf-8");
|
|
153
192
|
console.log(` [OK] Added ${missing.join(", ")} to .gitignore`);
|
|
154
193
|
}
|
|
@@ -553,9 +592,9 @@ function printUsage() {
|
|
|
553
592
|
--help, -h Show this help message
|
|
554
593
|
|
|
555
594
|
MCP Platforms:
|
|
556
|
-
claude Claude Code (.claude.json
|
|
557
|
-
|
|
558
|
-
|
|
595
|
+
claude Claude Code (.claude.json + CLAUDE.md + hooks)
|
|
596
|
+
cursor Cursor (.cursor/mcp.json + .cursorrules)
|
|
597
|
+
gemini Gemini CLI (~/.gemini/settings.json + GEMINI.md)
|
|
559
598
|
all All platforms at once
|
|
560
599
|
|
|
561
600
|
Supported File Types:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "guardvibe",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Security MCP for vibe coding. 277 rules, 24 tools for Next.js, Supabase, Clerk, Stripe, Prisma, tRPC, Hono, GraphQL, Convex, Turso, Uploadthing, AI SDK, and the full AI-generated stack.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|