vibecheck-mcp-server 2.0.1
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/README.md +191 -0
- package/agent-checkpoint.js +364 -0
- package/architect-tools.js +707 -0
- package/audit-mcp.js +206 -0
- package/codebase-architect-tools.js +838 -0
- package/guardrail-2.0-tools.js +748 -0
- package/guardrail-tools.js +1075 -0
- package/hygiene-tools.js +428 -0
- package/index-v1.js +698 -0
- package/index.js +1409 -0
- package/index.old.js +4137 -0
- package/intelligence-tools.js +664 -0
- package/intent-drift-tools.js +873 -0
- package/mdc-generator.js +298 -0
- package/package.json +47 -0
- package/premium-tools.js +1275 -0
- package/test-mcp.js +108 -0
- package/test-tools.js +36 -0
- package/tier-auth.js +147 -0
package/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Guardrail MCP Server
|
|
2
|
+
|
|
3
|
+
Professional Model Context Protocol server for Guardrail AI.
|
|
4
|
+
|
|
5
|
+
> "Stop shipping pretend features."
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g guardrail-mcp-server
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
See [MCP-INSTALLATION-GUIDE.md](../docs/MCP-INSTALLATION-GUIDE.md) for editor-specific setup.
|
|
16
|
+
|
|
17
|
+
## Development
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd mcp-server
|
|
21
|
+
npm install
|
|
22
|
+
npm start
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Premium Command Palette Tools
|
|
26
|
+
|
|
27
|
+
These tools provide a top-notch, zero-friction UX:
|
|
28
|
+
|
|
29
|
+
### Ship Check Commands
|
|
30
|
+
- `run_ship` - Guardrail: Ship Check (GO/NO-GO)
|
|
31
|
+
- `run_reality` - Guardrail: Run Reality Mode
|
|
32
|
+
- `run_mockproof` - Guardrail: Run MockProof Gate
|
|
33
|
+
- `run_airlock` - Guardrail: Run Airlock (SupplyChain)
|
|
34
|
+
|
|
35
|
+
### Report & Artifact Commands
|
|
36
|
+
- `get_last_run` - Guardrail: Open Last Run Report
|
|
37
|
+
- `open_artifact` - Open Report/Replay/Trace/SARIF/Badge
|
|
38
|
+
- `rerun_last_check` - Guardrail: Re-run Last Check
|
|
39
|
+
- `export_sarif` - Export findings as SARIF
|
|
40
|
+
|
|
41
|
+
### Setup & Policy Commands
|
|
42
|
+
- `run_doctor` - Guardrail: Doctor (Fix my setup)
|
|
43
|
+
- `edit_policies` - Guardrail: Policies (Quick Edit)
|
|
44
|
+
- `get_status` - Get server status and workspace info
|
|
45
|
+
- `policy_patch` - Apply atomic policy changes
|
|
46
|
+
|
|
47
|
+
### Fix Mode Commands
|
|
48
|
+
- `enter_fix_mode` - Enter Fix Mode for blocker resolution
|
|
49
|
+
- `fix_mode_status` - Get Fix Mode checklist status
|
|
50
|
+
- `mark_fix_complete` - Mark blocker as fixed
|
|
51
|
+
- `exit_fix_mode` - Exit and re-run ship check
|
|
52
|
+
|
|
53
|
+
### Evidence & Diagnostics
|
|
54
|
+
- `explain_finding` - Get detailed finding explanation
|
|
55
|
+
|
|
56
|
+
## AI Guardrail Tools (Prompt Firewall + Output Verification)
|
|
57
|
+
|
|
58
|
+
These tools provide AI safety and verification capabilities:
|
|
59
|
+
|
|
60
|
+
| Tool | Description |
|
|
61
|
+
|------|-------------|
|
|
62
|
+
| `guardrail.verify` | ๐ก๏ธ Verify AI agent output before applying - checks secrets, dangerous commands, path traversal |
|
|
63
|
+
| `guardrail.quality` | ๐ Code quality analysis - complexity, maintainability, technical debt metrics |
|
|
64
|
+
| `guardrail.smells` | ๐ Code smell detection - anti-patterns, naming issues, structural problems |
|
|
65
|
+
| `guardrail.hallucination` | ๐ Hallucination check - verify claims against actual source code |
|
|
66
|
+
| `guardrail.breaking` | โ ๏ธ Breaking change detection - API changes, removed methods, type changes |
|
|
67
|
+
| `guardrail.mdc` | ๐ MDC Generator - source-anchored documentation generation |
|
|
68
|
+
| `guardrail.coverage` | ๐งช Test coverage mapping - identify untested components |
|
|
69
|
+
|
|
70
|
+
### Example Usage
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
// Verify AI-generated code before applying
|
|
74
|
+
{
|
|
75
|
+
"tool": "guardrail.verify",
|
|
76
|
+
"arguments": {
|
|
77
|
+
"input": "{\"format\":\"guardrail-v1\",\"diff\":\"...\",\"commands\":[]}",
|
|
78
|
+
"mode": "build"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Check code quality
|
|
83
|
+
{
|
|
84
|
+
"tool": "guardrail.quality",
|
|
85
|
+
"arguments": {
|
|
86
|
+
"projectPath": ".",
|
|
87
|
+
"threshold": 70
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Detect code smells
|
|
92
|
+
{
|
|
93
|
+
"tool": "guardrail.smells",
|
|
94
|
+
"arguments": {
|
|
95
|
+
"projectPath": ".",
|
|
96
|
+
"severity": "high"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Agent Checkpoint Tools
|
|
102
|
+
|
|
103
|
+
Pre-write validation that blocks AI agents until issues are fixed:
|
|
104
|
+
|
|
105
|
+
| Tool | Description |
|
|
106
|
+
|------|-------------|
|
|
107
|
+
| `guardrail_checkpoint` | ๐ก๏ธ Validate code before writing - blocks on TODOs, mocks, console.log, etc. |
|
|
108
|
+
| `guardrail_set_strictness` | โ๏ธ Set checkpoint strictness: chill, standard, strict, paranoid |
|
|
109
|
+
| `guardrail_checkpoint_status` | ๐ Get current checkpoint status and blocking violations |
|
|
110
|
+
|
|
111
|
+
## Architect Tools
|
|
112
|
+
|
|
113
|
+
AI agents consult the Architect before writing code:
|
|
114
|
+
|
|
115
|
+
| Tool | Description |
|
|
116
|
+
|------|-------------|
|
|
117
|
+
| `guardrail_architect_review` | ๐๏ธ Review code against architecture patterns |
|
|
118
|
+
| `guardrail_architect_suggest` | ๐ก Get architectural guidance before writing code |
|
|
119
|
+
| `guardrail_architect_patterns` | ๐ List all active architecture patterns |
|
|
120
|
+
| `guardrail_architect_set_strictness` | โ๏ธ Set architect strictness level |
|
|
121
|
+
|
|
122
|
+
## Codebase Architect Tools
|
|
123
|
+
|
|
124
|
+
Deep codebase knowledge for AI agents:
|
|
125
|
+
|
|
126
|
+
| Tool | Description |
|
|
127
|
+
|------|-------------|
|
|
128
|
+
| `guardrail_architect_context` | ๐ง Load full codebase context (tech stack, conventions, patterns) |
|
|
129
|
+
| `guardrail_architect_guide` | ๐๏ธ Get guidance for creating/modifying code |
|
|
130
|
+
| `guardrail_architect_validate` | โ
Validate code against codebase patterns |
|
|
131
|
+
| `guardrail_architect_dependencies` | ๐ Understand file relationships and impact |
|
|
132
|
+
|
|
133
|
+
## Guardrail 2.0 Tools (Consolidated)
|
|
134
|
+
|
|
135
|
+
Six core tools for the complete workflow:
|
|
136
|
+
|
|
137
|
+
| Tool | Description |
|
|
138
|
+
|------|-------------|
|
|
139
|
+
| `checkpoint` | ๐ก๏ธ Block AI agents until issues are fixed (pre/post write) |
|
|
140
|
+
| `check` | ๐ Verify code is real, wired, honest |
|
|
141
|
+
| `ship` | ๐ Go/No-Go decision (GO / WARN / NO-GO) |
|
|
142
|
+
| `fix` | ๐ง Fix blocking issues safely |
|
|
143
|
+
| `status` | ๐ Health + version info |
|
|
144
|
+
| `set_strictness` | โ๏ธ Set checkpoint strictness level |
|
|
145
|
+
|
|
146
|
+
## Intent Drift Guard Tools
|
|
147
|
+
|
|
148
|
+
Capture intent before writing code, monitor for drift:
|
|
149
|
+
|
|
150
|
+
| Tool | Description |
|
|
151
|
+
|------|-------------|
|
|
152
|
+
| `guardrail_intent_start` | ๐ฏ Start a new step with explicit intent |
|
|
153
|
+
| `guardrail_intent_check` | โ
Check if code changes align with stated intent |
|
|
154
|
+
| `guardrail_intent_validate_prompt` | ๐ Validate new prompts against locked intent |
|
|
155
|
+
| `guardrail_intent_status` | ๐ Get current Intent Drift Guard status |
|
|
156
|
+
| `guardrail_intent_complete` | โ
Complete step and generate proof artifact |
|
|
157
|
+
| `guardrail_intent_lock` | ๐ Lock intent to prevent scope expansion |
|
|
158
|
+
| `guardrail_intent_unlock` | ๐ Unlock intent, allow scope changes |
|
|
159
|
+
|
|
160
|
+
## Core Analysis Tools
|
|
161
|
+
|
|
162
|
+
- `validate_project` - Validate project structure and API endpoints
|
|
163
|
+
- `check_design_system` - Validate design system consistency
|
|
164
|
+
- `check_project_drift` - Check for architecture drift
|
|
165
|
+
- `setup_design_system` - Set up and lock design system
|
|
166
|
+
- `register_api_endpoint` - Register API endpoint
|
|
167
|
+
- `get_project_health` - Get project health score
|
|
168
|
+
- `get_guardrails_rules` - Get guardrails rules
|
|
169
|
+
- `architect_analyze` - Intelligent project analysis
|
|
170
|
+
- `build_knowledge_base` - Build codebase knowledge
|
|
171
|
+
- `semantic_search` - Search code by meaning
|
|
172
|
+
- `security_scan` - Full security scan
|
|
173
|
+
- `ship_check` - Ship readiness check
|
|
174
|
+
- `get_deploy_verdict` - Get deploy GO/NO-GO decision
|
|
175
|
+
|
|
176
|
+
## Resources
|
|
177
|
+
|
|
178
|
+
- `guardrails://rules` - Guardrails rules document
|
|
179
|
+
- `guardrails://templates` - Available templates
|
|
180
|
+
- `guardrails://design-tokens` - Design system tokens
|
|
181
|
+
|
|
182
|
+
## Documentation
|
|
183
|
+
|
|
184
|
+
See [MCP-PREMIUM-TOOLS.md](../docs/MCP-PREMIUM-TOOLS.md) for detailed tool documentation.
|
|
185
|
+
|
|
186
|
+
## Privacy & Trust
|
|
187
|
+
|
|
188
|
+
- Runs locally
|
|
189
|
+
- Artifacts saved to `.Guardrail/`
|
|
190
|
+
- No upload unless you export/share
|
|
191
|
+
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Guardrails - MCP Server Integration
|
|
3
|
+
*
|
|
4
|
+
* This MCP tool intercepts file writes from AI agents and validates
|
|
5
|
+
* them against checkpoint rules BEFORE the write happens.
|
|
6
|
+
*
|
|
7
|
+
* When an agent (Cursor, Windsurf, etc.) tries to write code,
|
|
8
|
+
* this tool validates it first and blocks if violations found.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
|
|
14
|
+
// Strictness level rules
|
|
15
|
+
const STRICTNESS_LEVELS = ["chill", "standard", "strict", "paranoid"];
|
|
16
|
+
|
|
17
|
+
// Built-in checkpoint rules
|
|
18
|
+
const CHECKPOINT_RULES = {
|
|
19
|
+
chill: [
|
|
20
|
+
{
|
|
21
|
+
id: "no-todo",
|
|
22
|
+
pattern: /\/\/\s*TODO[:\s].*$/gim,
|
|
23
|
+
message: "TODO comment - complete before moving on",
|
|
24
|
+
block: true,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "no-fixme",
|
|
28
|
+
pattern: /\/\/\s*FIXME[:\s].*$/gim,
|
|
29
|
+
message: "FIXME comment - fix it now",
|
|
30
|
+
block: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "no-mock-data",
|
|
34
|
+
pattern:
|
|
35
|
+
/(?:const|let|var)\s+(?:mock|fake|dummy|sample)(?:Data|Users?|Items?)\s*=/gi,
|
|
36
|
+
message: "Mock data detected",
|
|
37
|
+
block: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "no-placeholder",
|
|
41
|
+
pattern: /['"`](?:TODO|PLACEHOLDER|REPLACE_ME|CHANGEME|XXX)['"`]/gi,
|
|
42
|
+
message: "Placeholder string",
|
|
43
|
+
block: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "no-lorem",
|
|
47
|
+
pattern: /lorem\s+ipsum/gi,
|
|
48
|
+
message: "Lorem ipsum placeholder",
|
|
49
|
+
block: true,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
standard: [
|
|
53
|
+
{
|
|
54
|
+
id: "no-console-log",
|
|
55
|
+
pattern: /console\.log\s*\(/g,
|
|
56
|
+
message: "console.log - remove or use proper logging",
|
|
57
|
+
block: true,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "no-debugger",
|
|
61
|
+
pattern: /\bdebugger\b/g,
|
|
62
|
+
message: "debugger statement",
|
|
63
|
+
block: true,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "no-localhost",
|
|
67
|
+
pattern: /['"`]https?:\/\/localhost[:\d]*[^'"`]*['"`]/g,
|
|
68
|
+
message: "Hardcoded localhost",
|
|
69
|
+
block: true,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "no-empty-catch",
|
|
73
|
+
pattern: /catch\s*\([^)]*\)\s*\{\s*\}/g,
|
|
74
|
+
message: "Empty catch block",
|
|
75
|
+
block: true,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
strict: [
|
|
79
|
+
{
|
|
80
|
+
id: "no-any",
|
|
81
|
+
pattern: /:\s*any\b/g,
|
|
82
|
+
message: "any type - use proper TypeScript type",
|
|
83
|
+
block: true,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "no-ts-ignore",
|
|
87
|
+
pattern: /@ts-ignore/g,
|
|
88
|
+
message: "@ts-ignore - fix the type error",
|
|
89
|
+
block: true,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "no-eslint-disable",
|
|
93
|
+
pattern: /eslint-disable/g,
|
|
94
|
+
message: "ESLint disabled - fix the lint error",
|
|
95
|
+
block: true,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
paranoid: [
|
|
99
|
+
{
|
|
100
|
+
id: "no-nested-ternary",
|
|
101
|
+
pattern: /\?[^:]+\?[^:]+:/g,
|
|
102
|
+
message: "Nested ternary - use if/else",
|
|
103
|
+
block: true,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "no-inline-styles",
|
|
107
|
+
pattern: /style\s*=\s*\{\s*\{/g,
|
|
108
|
+
message: "Inline styles - use CSS",
|
|
109
|
+
block: false,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Current state
|
|
115
|
+
let currentStrictness = "standard";
|
|
116
|
+
let blockedFiles = new Map();
|
|
117
|
+
let stats = { checked: 0, blocked: 0, passed: 0 };
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get all rules for a strictness level (includes all lower levels)
|
|
121
|
+
*/
|
|
122
|
+
function getRulesForLevel(level) {
|
|
123
|
+
const levelIndex = STRICTNESS_LEVELS.indexOf(level);
|
|
124
|
+
let rules = [];
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i <= levelIndex; i++) {
|
|
127
|
+
const levelRules = CHECKPOINT_RULES[STRICTNESS_LEVELS[i]] || [];
|
|
128
|
+
rules = [...rules, ...levelRules];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return rules;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Validate content against checkpoint rules
|
|
136
|
+
*/
|
|
137
|
+
function validateContent(filePath, content) {
|
|
138
|
+
const rules = getRulesForLevel(currentStrictness);
|
|
139
|
+
const violations = [];
|
|
140
|
+
const lines = content.split("\n");
|
|
141
|
+
|
|
142
|
+
for (const rule of rules) {
|
|
143
|
+
rule.pattern.lastIndex = 0;
|
|
144
|
+
let match;
|
|
145
|
+
|
|
146
|
+
while ((match = rule.pattern.exec(content)) !== null) {
|
|
147
|
+
const beforeMatch = content.substring(0, match.index);
|
|
148
|
+
const lineNumber = beforeMatch.split("\n").length;
|
|
149
|
+
const line = lines[lineNumber - 1] || "";
|
|
150
|
+
|
|
151
|
+
// Check for ignore directive
|
|
152
|
+
if (line.includes("@guardrail-ignore")) continue;
|
|
153
|
+
|
|
154
|
+
violations.push({
|
|
155
|
+
rule: rule.id,
|
|
156
|
+
message: rule.message,
|
|
157
|
+
line: lineNumber,
|
|
158
|
+
code: line.trim(),
|
|
159
|
+
block: rule.block,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (match[0].length === 0) break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return violations;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Format violations for output
|
|
171
|
+
*/
|
|
172
|
+
function formatViolations(filePath, violations) {
|
|
173
|
+
const blockers = violations.filter((v) => v.block);
|
|
174
|
+
|
|
175
|
+
if (blockers.length === 0) {
|
|
176
|
+
return { blocked: false, message: "โ
Checkpoint passed" };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let output = "\n๐ CHECKPOINT BLOCKED\n";
|
|
180
|
+
output += "โ".repeat(50) + "\n";
|
|
181
|
+
output += `File: ${filePath}\n\n`;
|
|
182
|
+
|
|
183
|
+
for (const v of blockers) {
|
|
184
|
+
output += ` โ Line ${v.line}: ${v.message}\n`;
|
|
185
|
+
output += ` ${v.code}\n\n`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
output += "โ".repeat(50) + "\n";
|
|
189
|
+
output += "Fix these issues before proceeding.\n";
|
|
190
|
+
|
|
191
|
+
return { blocked: true, message: output };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* MCP Tool Definitions for Agent Guardrails
|
|
196
|
+
*/
|
|
197
|
+
const AGENT_CHECKPOINT_TOOLS = [
|
|
198
|
+
{
|
|
199
|
+
name: "guardrail_checkpoint",
|
|
200
|
+
description: `๐ก๏ธ AGENT CHECKPOINT - Validates code before writing.
|
|
201
|
+
|
|
202
|
+
IMPORTANT: Call this tool BEFORE writing any code to check for:
|
|
203
|
+
- TODOs, FIXMEs that must be completed
|
|
204
|
+
- Mock/placeholder data that must be replaced
|
|
205
|
+
- console.log/debugger statements
|
|
206
|
+
- Type errors (any, @ts-ignore)
|
|
207
|
+
|
|
208
|
+
If this returns blocked=true, you MUST fix the issues before proceeding.
|
|
209
|
+
Do NOT skip this checkpoint.`,
|
|
210
|
+
inputSchema: {
|
|
211
|
+
type: "object",
|
|
212
|
+
properties: {
|
|
213
|
+
file_path: {
|
|
214
|
+
type: "string",
|
|
215
|
+
description: "Path to the file being written",
|
|
216
|
+
},
|
|
217
|
+
content: {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "The content to validate",
|
|
220
|
+
},
|
|
221
|
+
strictness: {
|
|
222
|
+
type: "string",
|
|
223
|
+
enum: ["chill", "standard", "strict", "paranoid"],
|
|
224
|
+
description: "Validation strictness level (default: standard)",
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
required: ["file_path", "content"],
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "guardrail_set_strictness",
|
|
232
|
+
description: `Set the checkpoint strictness level:
|
|
233
|
+
- chill: TODOs, FIXMEs, mock data, placeholders
|
|
234
|
+
- standard: + console.log, debugger, localhost URLs
|
|
235
|
+
- strict: + any types, @ts-ignore, eslint-disable
|
|
236
|
+
- paranoid: + nested ternaries, inline styles`,
|
|
237
|
+
inputSchema: {
|
|
238
|
+
type: "object",
|
|
239
|
+
properties: {
|
|
240
|
+
level: {
|
|
241
|
+
type: "string",
|
|
242
|
+
enum: ["chill", "standard", "strict", "paranoid"],
|
|
243
|
+
description: "The strictness level",
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
required: ["level"],
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "guardrail_checkpoint_status",
|
|
251
|
+
description: "Get current checkpoint status and any blocking violations",
|
|
252
|
+
inputSchema: {
|
|
253
|
+
type: "object",
|
|
254
|
+
properties: {},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Handle MCP tool calls
|
|
261
|
+
*/
|
|
262
|
+
async function handleCheckpointTool(name, args) {
|
|
263
|
+
switch (name) {
|
|
264
|
+
case "guardrail_checkpoint": {
|
|
265
|
+
const { file_path, content, strictness } = args;
|
|
266
|
+
|
|
267
|
+
if (strictness) {
|
|
268
|
+
currentStrictness = strictness;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
stats.checked++;
|
|
272
|
+
const violations = validateContent(file_path, content);
|
|
273
|
+
const result = formatViolations(file_path, violations);
|
|
274
|
+
|
|
275
|
+
if (result.blocked) {
|
|
276
|
+
stats.blocked++;
|
|
277
|
+
blockedFiles.set(file_path, violations);
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
content: [
|
|
281
|
+
{
|
|
282
|
+
type: "text",
|
|
283
|
+
text: result.message,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
isError: true, // Signal to agent this is a blocker
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
stats.passed++;
|
|
291
|
+
blockedFiles.delete(file_path);
|
|
292
|
+
|
|
293
|
+
return {
|
|
294
|
+
content: [
|
|
295
|
+
{
|
|
296
|
+
type: "text",
|
|
297
|
+
text: `โ
Checkpoint PASSED for ${file_path}\n\nYou may proceed with writing this file.`,
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
case "guardrail_set_strictness": {
|
|
304
|
+
const { level } = args;
|
|
305
|
+
currentStrictness = level;
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
content: [
|
|
309
|
+
{
|
|
310
|
+
type: "text",
|
|
311
|
+
text: `๐ก๏ธ Checkpoint strictness set to: ${level.toUpperCase()}\n\nActive rules:\n${getRulesForLevel(
|
|
312
|
+
level,
|
|
313
|
+
)
|
|
314
|
+
.map((r) => `- ${r.id}: ${r.message}`)
|
|
315
|
+
.join("\n")}`,
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
case "guardrail_checkpoint_status": {
|
|
322
|
+
const blockedList = Array.from(blockedFiles.entries());
|
|
323
|
+
|
|
324
|
+
let status = `๐ก๏ธ Agent Guardrails Status\n`;
|
|
325
|
+
status += `โโโโโโโโโโโโโโโโโโโโโโโโโโโ\n`;
|
|
326
|
+
status += `Strictness: ${currentStrictness.toUpperCase()}\n`;
|
|
327
|
+
status += `Files checked: ${stats.checked}\n`;
|
|
328
|
+
status += `Passed: ${stats.passed}\n`;
|
|
329
|
+
status += `Blocked: ${stats.blocked}\n\n`;
|
|
330
|
+
|
|
331
|
+
if (blockedList.length > 0) {
|
|
332
|
+
status += `โ ๏ธ Currently blocked files:\n`;
|
|
333
|
+
for (const [file, violations] of blockedList) {
|
|
334
|
+
status += `\n๐ ${file}\n`;
|
|
335
|
+
for (const v of violations.filter((v) => v.block)) {
|
|
336
|
+
status += ` Line ${v.line}: ${v.message}\n`;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
status += `โ
No blocked files - all clear!\n`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
content: [{ type: "text", text: status }],
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
default:
|
|
349
|
+
return {
|
|
350
|
+
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
351
|
+
isError: true,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export {
|
|
357
|
+
AGENT_CHECKPOINT_TOOLS,
|
|
358
|
+
handleCheckpointTool,
|
|
359
|
+
validateContent,
|
|
360
|
+
formatViolations,
|
|
361
|
+
getRulesForLevel,
|
|
362
|
+
CHECKPOINT_RULES,
|
|
363
|
+
STRICTNESS_LEVELS,
|
|
364
|
+
};
|