@yagyeshvyas/vibeguard 1.0.0 → 1.2.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/ci/vibeguard.yml CHANGED
@@ -1,41 +1,42 @@
1
- name: VibeGuard
2
-
3
- # Runs VibeGuard on every push and pull request. Fails the job when a CRITICAL
4
- # issue is found, and uploads a SARIF report to GitHub code scanning so findings
5
- # show up inline on the PR.
6
- #
7
- # Scope reminder: VibeGuard catches high-frequency, well-defined issues (secrets,
8
- # injection, misconfig). It is not a full security review.
9
-
10
- on:
11
- push:
12
- branches: [main, master]
13
- pull_request:
14
-
15
- permissions:
16
- contents: read
17
- security-events: write # required to upload SARIF
18
-
19
- jobs:
20
- vibeguard:
21
- runs-on: ubuntu-latest
22
- steps:
23
- - uses: actions/checkout@v4
24
-
25
- - uses: actions/setup-node@v4
26
- with:
27
- node-version: 20
28
-
29
- # Produce a SARIF report for GitHub code scanning (does not fail the job).
30
- - name: VibeGuard scan (SARIF)
31
- run: npx -y vibeguard scan . --sarif --no-deps > vibeguard.sarif || true
32
-
33
- - name: Upload SARIF
34
- if: always()
35
- uses: github/codeql-action/upload-sarif@v3
36
- with:
37
- sarif_file: vibeguard.sarif
38
-
39
- # Gate the build: fail only on CRITICAL findings.
40
- - name: VibeGuard gate (block on CRITICAL)
41
- run: npx -y vibeguard scan . --precommit
1
+ name: VibeGuard
2
+
3
+ # Runs VibeGuard on every push and pull request. Fails the job when a CRITICAL
4
+ # issue is found, and uploads a SARIF report to GitHub code scanning so findings
5
+ # show up inline on the PR.
6
+ #
7
+ # Scope reminder: VibeGuard catches high-frequency, well-defined issues (secrets,
8
+ # injection, misconfig). It is not a full security review.
9
+
10
+ on:
11
+ push:
12
+ branches: [main, master]
13
+ pull_request:
14
+
15
+ permissions:
16
+ contents: read
17
+ security-events: write # required to upload SARIF
18
+
19
+ jobs:
20
+ vibeguard:
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-node@v4
26
+ with:
27
+ node-version: 20
28
+
29
+ # Produce a SARIF report for GitHub code scanning (does not fail the job).
30
+ - name: VibeGuard scan (SARIF)
31
+ run: npx -y vibeguard scan . --sarif --no-deps > vibeguard.sarif || true
32
+
33
+ - name: Upload SARIF
34
+ if: always()
35
+ uses: github/codeql-action/upload-sarif@v3
36
+ with:
37
+ sarif_file: vibeguard.sarif
38
+
39
+ # Gate the build: fail on CRITICAL findings, and on a degraded scan
40
+ # (--strict) so an incomplete/parse-failed scan can't pass as clean.
41
+ - name: VibeGuard gate (block on CRITICAL)
42
+ run: npx -y vibeguard scan . --precommit --strict
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yagyeshvyas/vibeguard",
3
- "version": "1.0.0",
4
- "description": "Offline security scanner for AI-generated code. 693 rules, 75 MCP tools, AST taint analysis, shell guard. Zero telemetry, zero dependencies.",
3
+ "version": "1.2.0",
4
+ "description": "Security scanner + AI agent firewall. Blocks secret/PII exfiltration in real time. 699 rules, 78 MCP tools (agent-scan, mcp-audit, guard-action), AST taint analysis. Offline, zero telemetry, zero dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "author": "Yagyesh Vyas <https://www.linkedin.com/in/yagyeshvyas/>",
@@ -33,8 +33,9 @@
33
33
  "coverage": "c8 node test/run.js",
34
34
  "counts": "node scripts/counts.js",
35
35
  "benchmark": "node test/benchmark/run.js",
36
+ "integrity": "node scripts/gen-integrity.js",
36
37
  "postinstall": "node scripts/postinstall.js",
37
- "prepublishOnly": "node test/run.js && npm run lint"
38
+ "prepublishOnly": "node scripts/gen-integrity.js && node test/run.js && npm run lint"
38
39
  },
39
40
  "keywords": [
40
41
  "security",
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * src/action-guard.js — Agent Action Firewall.
5
+ *
6
+ * The real-time "nothing leaks" guard. Inspects an agent action BEFORE it runs
7
+ * and blocks it if it would exfiltrate secrets or personal data, run a
8
+ * dangerous command, or send sensitive data to an untrusted destination.
9
+ *
10
+ * One inspection API over every action an agent can take:
11
+ * { type: 'shell', command }
12
+ * { type: 'network', url, body?, method? }
13
+ * { type: 'file-write', path, content }
14
+ * { type: 'prompt', content, provider? } // text going to an LLM
15
+ * { type: 'mcp', tool, args } // an MCP tool call
16
+ *
17
+ * Core guarantee (best-effort, not a sandbox): a hardcoded API key or a piece
18
+ * of personal data (email, SSN, credit card, phone) MUST NOT leave the machine
19
+ * to an external host without an explicit allow. Secrets to any external
20
+ * destination are BLOCKED, unconditionally.
21
+ *
22
+ * 100% local. Zero network. Zero dependencies. Fail-closed on the block path.
23
+ */
24
+
25
+ const { checkCommand, SECRET_PATTERNS } = require('./shell-guard');
26
+ const { detectPII, redactText } = require('./pii');
27
+
28
+ // Hosts that are the local machine or a private network — sending data there is
29
+ // not exfiltration off the box.
30
+ const LOCAL_HOST_RE = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|::1|\[::1\])$/i;
31
+ const PRIVATE_IP_RE = /^(?:10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.)/;
32
+ // Cloud metadata endpoints — credential theft targets, ALWAYS untrusted.
33
+ const METADATA_HOST_RE = /^(?:169\.254\.169\.254|metadata\.google\.internal|metadata\.goog)$/i;
34
+
35
+ function hostOf(url) {
36
+ if (typeof url !== 'string') return null;
37
+ const m = url.match(/^[a-z][a-z0-9+.-]*:\/\/([^/?#]+)/i);
38
+ if (!m) return null;
39
+ return m[1].replace(/:\d+$/, '').toLowerCase(); // strip port
40
+ }
41
+
42
+ function isExternalHost(host) {
43
+ if (!host) return false;
44
+ if (METADATA_HOST_RE.test(host)) return true; // metadata = worst-case external
45
+ if (LOCAL_HOST_RE.test(host)) return false;
46
+ if (PRIVATE_IP_RE.test(host)) return false;
47
+ return true;
48
+ }
49
+
50
+ // Shannon entropy in bits/char — high for random secrets, low for words/ids.
51
+ function shannonEntropy(s) {
52
+ const freq = Object.create(null);
53
+ for (const c of s) freq[c] = (freq[c] || 0) + 1;
54
+ let e = 0;
55
+ for (const k in freq) { const p = freq[k] / s.length; e -= p * Math.log2(p); }
56
+ return e;
57
+ }
58
+
59
+ // A value that is structured, not a secret — don't treat these as unknown keys.
60
+ function looksStructured(v) {
61
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v)) return true; // UUID
62
+ if (/^[0-9a-f]+$/i.test(v) && [32, 40, 64].includes(v.length)) return true; // md5/sha1/sha256 hash
63
+ if (/^\d+$/.test(v)) return true; // pure number / id
64
+ return false;
65
+ }
66
+
67
+ // A field NAMED like a credential carrying a high-entropy value = a secret, even
68
+ // if it matches no known vendor pattern. Precise: the secret-ish NAME plus real
69
+ // entropy avoids flagging random hashes/ids that aren't labelled secrets.
70
+ // High-confidence credential field names only. Deliberately excludes ambiguous
71
+ // names (token, bearer, session, auth) that are commonly legitimate auth values
72
+ // sent to APIs — those would false-positive and break real traffic. Known vendor
73
+ // key formats (sk_live_, ghp_, …) are still caught by SECRET_PATTERNS regardless
74
+ // of field name.
75
+ const NAMED_SECRET_RE =
76
+ /["']?([\w-]*(?:api[_-]?key|secret|private[_-]?key|access[_-]?key|password|passwd|credential)[\w-]*)["']?\s*[:=]\s*["']?([A-Za-z0-9+/=_.\-]{12,})["']?/gi;
77
+
78
+ function findNamedSecrets(text) {
79
+ const out = [];
80
+ let m;
81
+ NAMED_SECRET_RE.lastIndex = 0;
82
+ while ((m = NAMED_SECRET_RE.exec(text)) !== null) {
83
+ const name = m[1];
84
+ const val = m[2];
85
+ if (looksStructured(val)) continue;
86
+ // Env-var references / placeholders are not real values.
87
+ if (/^(?:process\.env|import\.meta|os\.environ|\$\{|xxx|changeme|your[_-]?)/i.test(val)) continue;
88
+ if (shannonEntropy(val) < 3.2) continue; // low entropy → likely not a secret
89
+ out.push(name);
90
+ }
91
+ return [...new Set(out)];
92
+ }
93
+
94
+ // Find secrets + PII in any outbound string.
95
+ function scanForLeaks(text) {
96
+ const out = { secrets: [], pii: [], namedSecrets: [] };
97
+ if (!text || typeof text !== 'string') return out;
98
+ for (const { re, type } of SECRET_PATTERNS) {
99
+ if (re.test(text)) out.secrets.push(type);
100
+ }
101
+ out.secrets = [...new Set(out.secrets)];
102
+ const pii = detectPII(text, {});
103
+ out.pii = pii.types || [];
104
+ out.namedSecrets = findNamedSecrets(text);
105
+ return out;
106
+ }
107
+
108
+ const RANK = { block: 2, warn: 1, allow: 0 };
109
+
110
+ // Inspect a single action. `policy.trustedHosts` (array) explicitly allows
111
+ // sending sensitive data to those hosts (e.g. your own API). `policy.piiMode`
112
+ // = 'block' (default for external) or 'warn'.
113
+ function inspectAction(action = {}, policy = {}) {
114
+ const trusted = new Set((policy.trustedHosts || []).map((h) => String(h).toLowerCase()));
115
+ const piiMode = policy.piiMode === 'warn' ? 'warn' : 'block';
116
+ const type = action.type || 'generic';
117
+ const violations = [];
118
+ const add = (level, kind, detail) => violations.push({ level, kind, detail });
119
+
120
+ const leakToDest = (text, host, destLabel) => {
121
+ // External = off this machine AND not on the caller's explicit allowlist.
122
+ const external = isExternalHost(host) && !trusted.has(host);
123
+ if (!external) return;
124
+ const { secrets, pii, namedSecrets } = scanForLeaks(text);
125
+ if (secrets.length) {
126
+ add('block', 'secret-exfiltration', `${secrets.join(', ')} would be sent to ${destLabel}`);
127
+ }
128
+ if (namedSecrets.length) {
129
+ add('block', 'named-secret-exfiltration', `credential field(s) ${namedSecrets.join(', ')} (high-entropy value) would be sent to ${destLabel}`);
130
+ }
131
+ if (pii.length) {
132
+ add(piiMode, 'pii-exfiltration', `personal data (${pii.join(', ')}) would be sent to ${destLabel}`);
133
+ }
134
+ };
135
+
136
+ switch (type) {
137
+ case 'shell': {
138
+ const r = checkCommand(action.command || '');
139
+ if (r.blocked) {
140
+ // checkCommand already covers rm -rf, secret exfil, sensitive paths, etc.
141
+ const sev = r.severity === 'critical' ? 'block' : 'block';
142
+ add(sev, r.violations && r.violations[0] ? r.violations[0].type : 'dangerous-command', r.reason);
143
+ }
144
+ break;
145
+ }
146
+ case 'network': {
147
+ const host = hostOf(action.url);
148
+ const dest = host || action.url || 'an external host';
149
+ // The URL itself can carry a secret (?token=...) or PII.
150
+ leakToDest(String(action.url || ''), host, dest);
151
+ leakToDest(typeof action.body === 'string' ? action.body : JSON.stringify(action.body || ''), host, dest);
152
+ if (host && METADATA_HOST_RE.test(host)) {
153
+ add('block', 'metadata-access', `request to cloud metadata endpoint ${host} — credential theft`);
154
+ }
155
+ break;
156
+ }
157
+ case 'file-write': {
158
+ const { secrets, pii } = scanForLeaks(String(action.content || ''));
159
+ const p = String(action.path || '');
160
+ const publicPath = /(?:^|\/)(?:public|static|dist|www|build)\//i.test(p);
161
+ if (secrets.length && publicPath) {
162
+ add('block', 'secret-to-public-file', `${secrets.join(', ')} written to a web-served path (${p})`);
163
+ } else if (secrets.length) {
164
+ add('warn', 'secret-in-file', `${secrets.join(', ')} written to ${p} — ensure it is gitignored and not shipped`);
165
+ }
166
+ if (pii.length && publicPath) {
167
+ add('block', 'pii-to-public-file', `personal data (${pii.join(', ')}) written to a web-served path (${p})`);
168
+ }
169
+ break;
170
+ }
171
+ case 'prompt':
172
+ case 'llm': {
173
+ const { secrets, pii, namedSecrets } = scanForLeaks(String(action.content || ''));
174
+ const provider = action.provider || 'an LLM provider';
175
+ if (secrets.length) add('block', 'secret-to-llm', `${secrets.join(', ')} in text sent to ${provider}`);
176
+ if (namedSecrets.length) add('block', 'named-secret-to-llm', `credential field(s) ${namedSecrets.join(', ')} in text sent to ${provider}`);
177
+ if (pii.length) add(piiMode, 'pii-to-llm', `personal data (${pii.join(', ')}) sent to ${provider} — redact first`);
178
+ break;
179
+ }
180
+ case 'mcp': {
181
+ const blob = JSON.stringify(action.args || {}) + ' ' + String(action.tool || '');
182
+ const { secrets, pii } = scanForLeaks(blob);
183
+ if (secrets.length) add('block', 'secret-in-mcp-call', `${secrets.join(', ')} passed to MCP tool ${action.tool || ''}`);
184
+ if (pii.length) add('warn', 'pii-in-mcp-call', `personal data (${pii.join(', ')}) passed to MCP tool ${action.tool || ''}`);
185
+ break;
186
+ }
187
+ default: {
188
+ // Generic: scan any provided text; treat as external unless a host says otherwise.
189
+ const { secrets, pii } = scanForLeaks(String(action.content || action.text || ''));
190
+ if (secrets.length) add('block', 'secret-exposure', secrets.join(', '));
191
+ if (pii.length) add('warn', 'pii-exposure', pii.join(', '));
192
+ }
193
+ }
194
+
195
+ // Verdict = the most severe violation. Fail-closed: default allow only when
196
+ // nothing matched.
197
+ let verdict = 'allow';
198
+ for (const v of violations) if (RANK[v.level] > RANK[verdict]) verdict = v.level;
199
+
200
+ return {
201
+ action: verdict, // 'allow' | 'warn' | 'block'
202
+ blocked: verdict === 'block',
203
+ type,
204
+ violations,
205
+ reason: violations.length ? violations[0].detail : null,
206
+ };
207
+ }
208
+
209
+ // Redact secrets + PII from a string so it CAN be sent safely (defense-in-depth
210
+ // companion to blocking — sanitize instead of drop when the caller opts in).
211
+ function sanitizeOutbound(text) {
212
+ if (!text || typeof text !== 'string') return text;
213
+ let out = redactText(text).redacted; // redactText returns { redacted, ... }
214
+ for (const { re } of SECRET_PATTERNS) {
215
+ out = out.replace(new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g'), '[REDACTED-SECRET]');
216
+ }
217
+ return out;
218
+ }
219
+
220
+ module.exports = { inspectAction, scanForLeaks, sanitizeOutbound, isExternalHost, hostOf, findNamedSecrets, shannonEntropy };
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * src/agent-scan.js — AI Agent Security Posture.
5
+ *
6
+ * One command that answers the question generic SAST can't: "is my AI-agent
7
+ * setup safe?" It aggregates VibeGuard's agent-era checks into a single graded
8
+ * posture, grouped by the threat categories that actually matter for people
9
+ * building with LLMs, agents, and MCP:
10
+ *
11
+ * - MCP trust — the MCP servers the agent trusts (src/mcp-audit.js)
12
+ * - AI data leakage — PII / secrets sent to LLM providers (src/ai-guard.js + ai.*key* rules)
13
+ * - LLM output → sink— model output reaching exec/eval/SQL/DOM/file (ai.llm-output-*)
14
+ * - Prompt injection — user input in system prompt / missing guards (ai.prompt-*)
15
+ * - Agent capability — uncapped loops, unrestricted tool access (ai.agent-*)
16
+ * - Supply chain — hallucinated packages (ai.hallucinated-import)
17
+ *
18
+ * Pure orchestration of already-tested modules — no new detection engine, no
19
+ * network (slopsquat's registry check stays opt-in elsewhere). Offline.
20
+ */
21
+
22
+ const path = require('path');
23
+
24
+ // Category assignment for agent-relevant rule IDs. Anything ai.* not matched
25
+ // falls into 'other-ai'. mcp-audit + ai-guard feed their own categories.
26
+ const CATEGORY_RULES = {
27
+ 'llm-output-to-sink': [
28
+ 'ai.llm-output-exec', 'ai.llm-output-shell', 'ai.llm-output-sql',
29
+ 'ai.llm-output-sql-v2', 'ai.llm-output-dom', 'ai.llm-output-file',
30
+ 'ai.eval-llm-output',
31
+ ],
32
+ 'prompt-injection': [
33
+ 'ai.no-prompt-injection-guard', 'ai.prompt-injection-marker',
34
+ 'ai.prompt-extraction', 'ai.prompt-leak-via-error', 'ai.cursorrule-injection',
35
+ 'ai.model-id-injection', 'ai.model-id-user-input',
36
+ ],
37
+ 'agent-capability': [
38
+ 'ai.agent-loop-no-cap', 'ai.agent-no-max-steps', 'ai.agent-can-access-secrets',
39
+ 'ai.agent-can-deploy', 'ai.agent-can-install-packages', 'ai.agent-can-modify-auth',
40
+ 'ai.disabled-sandbox', 'ai.data-exfil-agent', 'ai.agent-memory-poisoning',
41
+ 'ai.memory-poisoning', 'ai.adversarial-no-filter', 'ai.no-content-filter',
42
+ 'ai.no-content-filter-bypass',
43
+ ],
44
+ 'ai-data-leakage': [
45
+ 'ai.openai-key-public', 'ai.anthropic-key-public', 'ai.browser-api-key',
46
+ 'ai.key-in-url', 'ai.agent-env-key-direct', 'ai.missing-max-tokens',
47
+ ],
48
+ 'supply-chain': ['ai.hallucinated-import'],
49
+ 'mcp-trust': [
50
+ 'ai.mcp-command-injection', 'ai.mcp-description-injection-deep',
51
+ 'ai.mcp-path-traversal', 'ai.mcp-ssrf', 'ai.mcp-tool-no-auth',
52
+ 'ai.obfuscated-description',
53
+ ],
54
+ };
55
+
56
+ const RULE_TO_CATEGORY = (() => {
57
+ const m = {};
58
+ for (const [cat, ids] of Object.entries(CATEGORY_RULES)) for (const id of ids) m[id] = cat;
59
+ return m;
60
+ })();
61
+
62
+ const SEV_ORDER = { critical: 0, high: 1, medium: 2, low: 3 };
63
+
64
+ function categoryOf(ruleId) {
65
+ if (RULE_TO_CATEGORY[ruleId]) return RULE_TO_CATEGORY[ruleId];
66
+ if (ruleId.startsWith('ai.')) return 'other-ai';
67
+ return null;
68
+ }
69
+
70
+ function gradeFor(counts) {
71
+ if (counts.critical > 0) return 'F';
72
+ if (counts.high >= 3) return 'D';
73
+ if (counts.high > 0) return 'C';
74
+ if (counts.medium >= 3) return 'C';
75
+ if (counts.medium > 0) return 'B';
76
+ return 'A';
77
+ }
78
+
79
+ function agentScan(root, opts = {}) {
80
+ const { scan, walk } = require('./scanner');
81
+ const { auditMcp } = require('./mcp-audit');
82
+ const { auditAIData } = require('./ai-guard');
83
+
84
+ const items = []; // normalized: { category, severity, ruleId, file, line, message, fix }
85
+
86
+ // 1. Code scan — keep only agent-relevant (ai.*) findings.
87
+ const scanRes = scan(root, { deps: false });
88
+ for (const f of scanRes.findings) {
89
+ const cat = categoryOf(f.ruleId);
90
+ if (!cat) continue;
91
+ items.push({
92
+ category: cat, severity: f.severity, ruleId: f.ruleId,
93
+ file: f.file, line: f.line, message: f.message, fix: f.fix,
94
+ });
95
+ }
96
+
97
+ // 2. MCP trust.
98
+ const mcp = auditMcp(root, { pin: !!opts.pin });
99
+ for (const f of mcp.findings) {
100
+ items.push({
101
+ category: 'mcp-trust', severity: f.severity, ruleId: f.id,
102
+ file: f.config, line: 1, message: f.message, fix: f.fix, server: f.server,
103
+ });
104
+ }
105
+
106
+ // 3. AI data leakage — PII / user data flowing to LLM providers.
107
+ let aiData = { findings: [] };
108
+ try {
109
+ const files = walk(root, []);
110
+ aiData = auditAIData(root, files);
111
+ } catch { /* best-effort */ }
112
+ for (const f of aiData.findings) {
113
+ items.push({
114
+ category: 'ai-data-leakage', severity: f.severity, ruleId: 'ai-guard.pii-to-llm',
115
+ file: f.file, line: f.line, message: f.message, fix: f.fix,
116
+ });
117
+ }
118
+
119
+ // Aggregate.
120
+ const counts = { critical: 0, high: 0, medium: 0, low: 0 };
121
+ const categories = {};
122
+ for (const it of items) {
123
+ counts[it.severity] = (counts[it.severity] || 0) + 1;
124
+ (categories[it.category] = categories[it.category] || []).push(it);
125
+ }
126
+ const grade = gradeFor(counts);
127
+ items.sort((a, b) => SEV_ORDER[a.severity] - SEV_ORDER[b.severity]);
128
+
129
+ return {
130
+ root: path.resolve(root),
131
+ grade,
132
+ counts,
133
+ total: items.length,
134
+ categories,
135
+ items,
136
+ mcpServers: mcp.servers.length,
137
+ mcpDrifted: mcp.drifted,
138
+ scannedFiles: scanRes.scannedFiles,
139
+ engine: scanRes.engine,
140
+ generatedAt: new Date().toISOString(),
141
+ };
142
+ }
143
+
144
+ const CATEGORY_LABEL = {
145
+ 'mcp-trust': 'MCP trust',
146
+ 'ai-data-leakage': 'AI data leakage',
147
+ 'llm-output-to-sink': 'LLM output → dangerous sink',
148
+ 'prompt-injection': 'Prompt injection',
149
+ 'agent-capability': 'Agent capability / loops',
150
+ 'supply-chain': 'Supply chain (hallucinated deps)',
151
+ 'other-ai': 'Other AI risks',
152
+ };
153
+
154
+ function renderAgentScan(result) {
155
+ const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
156
+ const c = (x) => (useColor ? x : '');
157
+ const R = c('\x1b[0m'), B = c('\x1b[1m'), DIM = c('\x1b[2m');
158
+ const RED = c('\x1b[31m'), YEL = c('\x1b[33m'), GRN = c('\x1b[32m'), CYAN = c('\x1b[36m');
159
+ const gradeColor = result.grade === 'A' ? GRN : (result.grade === 'F' || result.grade === 'D') ? RED : YEL;
160
+ const sevColor = { critical: RED, high: YEL, medium: YEL, low: DIM };
161
+
162
+ const out = [];
163
+ out.push(`${B}${CYAN}VibeGuard — AI Agent Security Posture${R} ${DIM}(offline)${R}`);
164
+ out.push(` ${DIM}${result.scannedFiles} files · ${result.mcpServers} MCP server(s) · engine: ${result.engine ? result.engine.mode : '?'}${R}`);
165
+ out.push(` ${B}Agent Risk Grade: ${gradeColor}${result.grade}${R} ${DIM}(${result.counts.critical} critical, ${result.counts.high} high, ${result.counts.medium} medium)${R}`);
166
+ if (result.mcpDrifted && result.mcpDrifted.length) {
167
+ out.push(` ${RED}⚠ MCP definition drift: ${result.mcpDrifted.join(', ')} — re-review (rug-pull risk)${R}`);
168
+ }
169
+ out.push('');
170
+
171
+ if (result.total === 0) {
172
+ out.push(` ${GRN}No agent-specific security risks found.${R}`);
173
+ return out.join('\n');
174
+ }
175
+
176
+ for (const cat of Object.keys(CATEGORY_LABEL)) {
177
+ const list = result.categories[cat];
178
+ if (!list || !list.length) continue;
179
+ out.push(`${B}${CATEGORY_LABEL[cat]}${R} ${DIM}(${list.length})${R}`);
180
+ for (const it of list.slice(0, 10)) {
181
+ const col = sevColor[it.severity] || '';
182
+ const loc = it.file ? `${it.file}:${it.line}` : '';
183
+ out.push(` ${col}${it.severity.toUpperCase().padEnd(8)}${R} [${it.ruleId}] ${DIM}${loc}${R}`);
184
+ out.push(` ${it.message}`);
185
+ }
186
+ if (list.length > 10) out.push(` ${DIM}… ${list.length - 10} more${R}`);
187
+ out.push('');
188
+ }
189
+ return out.join('\n');
190
+ }
191
+
192
+ module.exports = { agentScan, renderAgentScan, categoryOf, gradeFor, CATEGORY_RULES };
package/src/auto.js CHANGED
@@ -210,8 +210,12 @@ function autoStart(rootDir, opts) {
210
210
  }
211
211
  }
212
212
 
213
- // 5. Arm shell guard (install shell hook)
213
+ // 5. Arm shell guard (install shell hook) — requires consent
214
214
  if (!opts.noShell && !opts.ci) {
215
+ // Skip shell guard in auto unless --yes is passed (consent).
216
+ if (!opts.yes) {
217
+ steps.push({ step: 'shell-guard', installed: false, reason: 'skipped (use --yes to enable)' });
218
+ } else {
215
219
  try {
216
220
  const srcDir = path.join(__dirname);
217
221
  const home = os.homedir();
@@ -268,6 +272,7 @@ function autoStart(rootDir, opts) {
268
272
  } catch (e) {
269
273
  steps.push({ step: 'shell-guard', error: e.message });
270
274
  }
275
+ }
271
276
  }
272
277
 
273
278
  // Add .vibeguard/ to .gitignore