@premierstudio/ai-hooks 1.0.6 → 1.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/README.md +190 -0
- package/dist/adapters/all.d.ts +2 -0
- package/dist/adapters/all.js +2058 -0
- package/dist/adapters/all.js.map +1 -0
- package/dist/cli/bin.js +2588 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +2584 -0
- package/dist/cli/index.js.map +1 -0
- package/package.json +12 -1
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# ai-hooks
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
**Universal hook engine for AI coding tools. Write policy once — enforce it everywhere, or let external systems drive it.**
|
|
9
|
+
|
|
10
|
+
`ai-hooks` is an open-source framework for portable guardrails, audit trails, and runtime control across AI coding tools. Define hooks in one config and they work everywhere — Claude Code, Codex, Gemini CLI, Cursor, Kiro, Cline, and more. Or use it as a library to let external platforms programmatically steer the AI client a developer is using.
|
|
11
|
+
|
|
12
|
+
## The problem
|
|
13
|
+
|
|
14
|
+
AI coding tools are proliferating, and every team hits the same wall:
|
|
15
|
+
|
|
16
|
+
- **No unified policy layer.** Each tool has its own hook format, so guardrails get duplicated, drift, and break silently.
|
|
17
|
+
- **No external control plane.** If you need to programmatically steer the client a developer is using — set boundaries, collect signals, enforce workflow rules — there's no standard way to do it. You're locked into one vendor's API.
|
|
18
|
+
- **Fragmented audit trails.** Shell commands, file writes, and tool calls are logged in different formats per tool, making compliance and debugging painful.
|
|
19
|
+
- **Inconsistent enforcement.** Some tools can block dangerous actions before they happen; others can only observe after the fact. You need a framework that normalizes this.
|
|
20
|
+
|
|
21
|
+
## How ai-hooks solves it
|
|
22
|
+
|
|
23
|
+
ai-hooks gives you a single policy engine that can steer any AI coding client with native hook support. Write rules once, and adapters translate them into the exact config format each tool understands. Block, observe, or redirect actions across every tool from one place.
|
|
24
|
+
|
|
25
|
+
```mermaid
|
|
26
|
+
graph TD
|
|
27
|
+
Config["<b>ai-hooks.config.ts</b><br/>Define once"]
|
|
28
|
+
Engine["Hook Engine<br/><i>middleware chain, priority, filters</i>"]
|
|
29
|
+
Platform["External Platform<br/><i>orchestrator, PM tool, CI system</i>"]
|
|
30
|
+
|
|
31
|
+
Config --> Engine
|
|
32
|
+
Platform -->|"library API"| Engine
|
|
33
|
+
|
|
34
|
+
Engine -->|"adapters generate<br/>native configs"| native
|
|
35
|
+
|
|
36
|
+
subgraph native ["Hook-compatible clients — blocking + observation"]
|
|
37
|
+
CC["Claude Code"]
|
|
38
|
+
Codex["Codex CLI"]
|
|
39
|
+
Gemini["Gemini CLI"]
|
|
40
|
+
Cursor["Cursor"]
|
|
41
|
+
Kiro["Kiro"]
|
|
42
|
+
OC["OpenCode"]
|
|
43
|
+
Droid["Factory Droid"]
|
|
44
|
+
Amp["Amp"]
|
|
45
|
+
Cline["Cline"]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
style Config fill:#7c3aed,color:#fff,stroke:none
|
|
49
|
+
style Engine fill:#2563eb,color:#fff,stroke:none
|
|
50
|
+
style Platform fill:#059669,color:#fff,stroke:none
|
|
51
|
+
style native fill:#f0fdf4,stroke:#16a34a
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Two ways to use it:**
|
|
55
|
+
|
|
56
|
+
1. **Config-driven** — Write an `ai-hooks.config.ts`, run `ai-hooks generate`, and adapters produce native hook configs for every detected tool. When the agent tries to run a shell command, write a file, or call a tool, your hooks fire natively inside the client — blocking dangerous actions, scanning for secrets, and logging everything before it happens.
|
|
57
|
+
|
|
58
|
+
2. **Library / control plane** — Import the engine into your platform. Programmatically steer the AI client a developer is using — set boundaries, collect signals, and enforce workflow rules — all through a standard API that works regardless of which tool they're running.
|
|
59
|
+
|
|
60
|
+
## Supported tools
|
|
61
|
+
|
|
62
|
+
| Tool | Blocking | Observation | Events |
|
|
63
|
+
| ------------------------------------------------------------- | -------- | ----------- | ------ |
|
|
64
|
+
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | Yes | Yes | 13 |
|
|
65
|
+
| [Codex CLI](https://github.com/openai/codex) | Yes | Yes | 13 |
|
|
66
|
+
| [Gemini CLI](https://github.com/google-gemini/gemini-cli) | Yes | Yes | 13 |
|
|
67
|
+
| [Cursor](https://cursor.com) | Yes | Yes | 9 |
|
|
68
|
+
| [Kiro](https://kiro.dev) | Yes | Yes | 14 |
|
|
69
|
+
| [OpenCode](https://opencode.ai) | Yes | Yes | 13 |
|
|
70
|
+
| [Factory Droid](https://factory.ai) | Yes | Yes | 9 |
|
|
71
|
+
| [Amp](https://ampcode.com) | Yes | Yes | 2 |
|
|
72
|
+
| [Cline](https://cline.bot) | Yes | Yes | 7 |
|
|
73
|
+
|
|
74
|
+
### Compatible tools (no separate adapter needed)
|
|
75
|
+
|
|
76
|
+
| Tool | Notes |
|
|
77
|
+
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
78
|
+
| [VS Code / Copilot](https://code.visualstudio.com) | VS Code 1.109+ agent hooks use the same format as Claude Code. The Claude Code adapter output works directly in VS Code via `.claude/settings.json` or `.github/hooks/*.json`. |
|
|
79
|
+
|
|
80
|
+
## Quick start
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Install
|
|
84
|
+
npm i -D @premierstudio/ai-hooks
|
|
85
|
+
|
|
86
|
+
# Initialize config
|
|
87
|
+
npx ai-hooks init
|
|
88
|
+
|
|
89
|
+
# Detect installed tools and generate hooks
|
|
90
|
+
npx ai-hooks detect --verbose
|
|
91
|
+
npx ai-hooks generate
|
|
92
|
+
npx ai-hooks install
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Config example
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
// ai-hooks.config.ts
|
|
99
|
+
import { defineConfig, hook, builtinHooks } from "@premierstudio/ai-hooks";
|
|
100
|
+
|
|
101
|
+
export default defineConfig({
|
|
102
|
+
extends: [{ hooks: builtinHooks }],
|
|
103
|
+
hooks: [
|
|
104
|
+
hook("before", ["shell:before"], async (ctx, next) => {
|
|
105
|
+
if (ctx.event.command.includes("npm publish")) {
|
|
106
|
+
ctx.results.push({ blocked: true, reason: "Publishing is restricted" });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
await next();
|
|
110
|
+
})
|
|
111
|
+
.id("org:block-publish")
|
|
112
|
+
.name("Block npm publish")
|
|
113
|
+
.priority(10)
|
|
114
|
+
.build(),
|
|
115
|
+
],
|
|
116
|
+
settings: {
|
|
117
|
+
hookTimeout: 5000,
|
|
118
|
+
failMode: "open",
|
|
119
|
+
logLevel: "warn",
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Built-in safety hooks
|
|
125
|
+
|
|
126
|
+
ai-hooks ships with 4 hooks you can use immediately:
|
|
127
|
+
|
|
128
|
+
| Hook | Phase | What it does |
|
|
129
|
+
| -------------------------- | ------ | ------------------------------------------------------- |
|
|
130
|
+
| `block-dangerous-commands` | before | Blocks `rm -rf /`, `DROP DATABASE`, fork bombs |
|
|
131
|
+
| `scan-secrets` | before | Detects API keys, tokens, private keys in file writes |
|
|
132
|
+
| `protect-sensitive-files` | before | Prevents writes to `.env`, `credentials.json`, SSH keys |
|
|
133
|
+
| `audit-shell` | after | Records command, exit code, duration, tool name |
|
|
134
|
+
|
|
135
|
+
## Universal event model
|
|
136
|
+
|
|
137
|
+
15 event types across the full AI tool lifecycle:
|
|
138
|
+
|
|
139
|
+
| Category | Before (blockable) | After (observe-only) |
|
|
140
|
+
| -------- | ---------------------------------------- | -------------------- |
|
|
141
|
+
| Session | `session:start` | `session:end` |
|
|
142
|
+
| Prompt | `prompt:submit` | `prompt:response` |
|
|
143
|
+
| Tool | `tool:before` | `tool:after` |
|
|
144
|
+
| File | `file:write`, `file:edit`, `file:delete` | `file:read` |
|
|
145
|
+
| Shell | `shell:before` | `shell:after` |
|
|
146
|
+
| MCP | `mcp:before` | `mcp:after` |
|
|
147
|
+
| System | — | `notification` |
|
|
148
|
+
|
|
149
|
+
## Using as a library
|
|
150
|
+
|
|
151
|
+
If you're building a platform that orchestrates AI agents — a PM tool, CI system, or custom control plane — import the engine directly:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { HookEngine, builtinHooks } from "@premierstudio/ai-hooks";
|
|
155
|
+
|
|
156
|
+
const engine = new HookEngine({
|
|
157
|
+
hooks: builtinHooks,
|
|
158
|
+
settings: { failMode: "closed" },
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Check if an action should be blocked
|
|
162
|
+
const result = await engine.isBlocked(event, { name: "my-platform", version: "1.0" });
|
|
163
|
+
if (result.blocked) {
|
|
164
|
+
console.log(`Blocked: ${result.reason}`);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
This gives your platform a standard interface for controlling what AI agents can do, regardless of which tool (Claude Code, Codex, Cursor, etc.) the developer is running.
|
|
169
|
+
|
|
170
|
+
## Packages
|
|
171
|
+
|
|
172
|
+
| Package | Description |
|
|
173
|
+
| -------------------------- | ------------------------------------------------------------------------- |
|
|
174
|
+
| `@premierstudio/ai-hooks` | Core engine, 9 built-in adapters, CLI, types, config loader |
|
|
175
|
+
| `@premierstudio/plannable` | CLI + preset for connecting AI tools to [Plannable](https://plannable.ai) |
|
|
176
|
+
|
|
177
|
+
## Development
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
git clone https://github.com/PremierStudio/ai-hooks.git
|
|
181
|
+
cd ai-hooks
|
|
182
|
+
npm install
|
|
183
|
+
npm run check # lint + format + typecheck + test
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for adding adapters and submitting PRs.
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|