ralph-gate 0.1.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/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +866 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +374 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Uzair Akram
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Ralph Gate
|
|
2
|
+
|
|
3
|
+
**Structured verification gates for Claude Code** - Prevent premature completion with ordered validation checks.
|
|
4
|
+
|
|
5
|
+
Ralph Gate is a minimal TypeScript plugin that provides verification gates for Claude Code, preventing false completion by running ordered verification commands before allowing the agent to stop.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Fail-Fast Execution**: Stops at first blocking failure to save time
|
|
10
|
+
- **Ordered Gates**: Run checks from cheapest to most expensive
|
|
11
|
+
- **Non-Blocking Gates**: Support for warning-only checks that don't stop execution
|
|
12
|
+
- **Hook Integration**: Seamlessly integrates with Claude Code's stop hook
|
|
13
|
+
- **Hook Progress Streaming**: Stream gate output to stderr so hooks don't look stuck
|
|
14
|
+
- **Full Programmatic API**: Use as a library in your own tools
|
|
15
|
+
- **Zero Runtime Dependencies**: Lightweight and fast
|
|
16
|
+
- **ESM-Only**: Modern Node.js (>=18)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -D ralph-gate
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
1. Create a `gate.config.json` in your project root:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"gates": [
|
|
31
|
+
{ "name": "lint", "command": "npm run lint", "order": 10 },
|
|
32
|
+
{ "name": "typecheck", "command": "npm run typecheck", "order": 20 },
|
|
33
|
+
{ "name": "test", "command": "npm test", "order": 30 },
|
|
34
|
+
{ "name": "build", "command": "npm run build", "order": 40 }
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. Add to your `.claude/settings.local.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"hooks": {
|
|
44
|
+
"Stop": [
|
|
45
|
+
{
|
|
46
|
+
"type": "command",
|
|
47
|
+
"command": "npx ralph-gate --hook"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
3. Now when Claude Code tries to stop, your gates will run first!
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
### Gate Fields
|
|
59
|
+
|
|
60
|
+
| Field | Type | Default | Description |
|
|
61
|
+
| ------------- | ------- | -------- | --------------------------------------- |
|
|
62
|
+
| `name` | string | required | Unique identifier for the gate |
|
|
63
|
+
| `command` | string | required | Shell command to execute |
|
|
64
|
+
| `description` | string | - | Human-readable description |
|
|
65
|
+
| `order` | number | 100 | Execution order (lower = earlier) |
|
|
66
|
+
| `enabled` | boolean | true | Whether to run this gate |
|
|
67
|
+
| `blocking` | boolean | true | If false, failures warn but don't block |
|
|
68
|
+
|
|
69
|
+
### Config Fields
|
|
70
|
+
|
|
71
|
+
| Field | Type | Default | Description |
|
|
72
|
+
| ------------ | ------- | ------------------------- | --------------------------------- |
|
|
73
|
+
| `gates` | Gate[] | required | Array of gate definitions |
|
|
74
|
+
| `failFast` | boolean | true | Stop after first blocking failure |
|
|
75
|
+
| `outputPath` | string | "gate-results-<pid>.json" | Path for result file |
|
|
76
|
+
|
|
77
|
+
### Example Configuration
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"gates": [
|
|
82
|
+
{
|
|
83
|
+
"name": "lint",
|
|
84
|
+
"command": "npm run lint",
|
|
85
|
+
"description": "Run ESLint",
|
|
86
|
+
"order": 10
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "typecheck",
|
|
90
|
+
"command": "tsc --noEmit",
|
|
91
|
+
"order": 20
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "test",
|
|
95
|
+
"command": "npm test",
|
|
96
|
+
"order": 30
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "audit",
|
|
100
|
+
"command": "npm audit",
|
|
101
|
+
"order": 50,
|
|
102
|
+
"blocking": false
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"failFast": true
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## CLI Reference
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Run all gates with console output
|
|
113
|
+
npx ralph-gate
|
|
114
|
+
|
|
115
|
+
# Run in hook mode (JSON output, always exits 0)
|
|
116
|
+
npx ralph-gate --hook
|
|
117
|
+
|
|
118
|
+
# Preview which gates would run
|
|
119
|
+
npx ralph-gate --dry-run
|
|
120
|
+
|
|
121
|
+
# Run a single gate
|
|
122
|
+
npx ralph-gate --only typecheck
|
|
123
|
+
|
|
124
|
+
# Verbose mode with real-time output
|
|
125
|
+
npx ralph-gate --verbose
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Programmatic API
|
|
129
|
+
|
|
130
|
+
Ralph Gate can be used as a library in your own tools:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { runGates, loadConfig, generateHookResponse } from 'ralph-gate';
|
|
134
|
+
|
|
135
|
+
// Load and run gates
|
|
136
|
+
const config = await loadConfig();
|
|
137
|
+
const summary = await runGates(config);
|
|
138
|
+
|
|
139
|
+
// Generate hook response
|
|
140
|
+
const hookResponse = generateHookResponse(summary);
|
|
141
|
+
console.log(hookResponse);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Available Exports
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
export { runGates } from './runner';
|
|
148
|
+
export { loadConfig } from './config';
|
|
149
|
+
export { generateHookResponse } from './hook';
|
|
150
|
+
export { formatConsoleOutput, formatFailureContext } from './output';
|
|
151
|
+
export type {
|
|
152
|
+
Gate,
|
|
153
|
+
GateResult,
|
|
154
|
+
GateRunSummary,
|
|
155
|
+
GateConfig,
|
|
156
|
+
HookOutput,
|
|
157
|
+
} from './types';
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## How It Works
|
|
161
|
+
|
|
162
|
+
1. **Stop Event**: Claude Code triggers the stop hook
|
|
163
|
+
2. **Gate Runner**: Executes gates in order (cheap → expensive)
|
|
164
|
+
3. **Fail-Fast**: Stops at first blocking failure
|
|
165
|
+
4. **Result File**: Writes `gate-results-<pid>.json`
|
|
166
|
+
5. **Hook Response**: Returns JSON to Claude Code
|
|
167
|
+
- Pass: `{}` (allow completion)
|
|
168
|
+
- Fail: `{"decision": "block", "reason": "<context>", "warnings": [...]}`
|
|
169
|
+
|
|
170
|
+
## Non-Blocking Gates
|
|
171
|
+
|
|
172
|
+
Gates with `blocking: false` will collect failures as warnings but won't prevent completion:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"gates": [
|
|
177
|
+
{
|
|
178
|
+
"name": "audit",
|
|
179
|
+
"command": "npm audit",
|
|
180
|
+
"blocking": false
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Design Principles
|
|
187
|
+
|
|
188
|
+
- **Exit 0 in hook mode**: Control via JSON `decision` field
|
|
189
|
+
- **Fail-fast default**: Skip expensive gates if cheap ones fail
|
|
190
|
+
- **Truncated failure context**: Stdout + stderr with head/tail truncation (max 4000 chars)
|
|
191
|
+
- **Zero runtime dependencies**: Only dev deps for build/test
|
|
192
|
+
- **ESM-only**: Modern Node.js (>=18)
|
|
193
|
+
- **Trust exit codes**: Exit 0 = pass regardless of stderr
|
|
194
|
+
|
|
195
|
+
## Contributing
|
|
196
|
+
|
|
197
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT © Uzair Akram
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|