@red-codes/agentguard 1.1.1 → 1.1.3

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 ADDED
@@ -0,0 +1,190 @@
1
+ # @red-codes/agentguard
2
+
3
+ **Runtime governance for AI coding agents.** Intercepts tool calls, enforces policies and invariants, and produces a verifiable execution trail.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@red-codes/agentguard.svg)](https://www.npmjs.com/package/@red-codes/agentguard)
6
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/AgentGuardHQ/agentguard/blob/main/LICENSE)
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install -g @red-codes/agentguard
12
+ ```
13
+
14
+ ## What It Does
15
+
16
+ AgentGuard adds a deterministic decision layer between what an AI agent proposes and what actually runs. Every tool call passes through a governed action kernel:
17
+
18
+ ```
19
+ agent proposes action → policy evaluated → invariants checked → allow/deny → events emitted
20
+ ```
21
+
22
+ - **20 built-in invariants** — secret exposure, protected branches, blast radius, CI/CD config modification, permission escalation, and more
23
+ - **YAML policy format** — declare what agents can and can't do
24
+ - **Full audit trail** — every decision recorded to SQLite
25
+ - **Claude Code integration** — hooks fire on every tool call, zero config
26
+
27
+ ## Quick Start
28
+
29
+ ```bash
30
+ # Set up Claude Code hooks (one-time)
31
+ agentguard claude-init
32
+
33
+ # Check governance status
34
+ agentguard status
35
+
36
+ # Validate a policy file
37
+ agentguard policy validate agentguard.yaml
38
+
39
+ # Evaluate an action against policy (dry-run)
40
+ echo '{"tool":"Bash","command":"git push origin main"}' | agentguard guard --dry-run
41
+
42
+ # Inspect the most recent governance session
43
+ agentguard inspect --last
44
+ ```
45
+
46
+ ## Claude Code Integration
47
+
48
+ AgentGuard integrates via inline hooks — no daemon, no ports, no IPC:
49
+
50
+ ```bash
51
+ agentguard claude-init # Installs PreToolUse + PostToolUse + SessionStart hooks
52
+ ```
53
+
54
+ | Hook | Purpose |
55
+ |------|---------|
56
+ | **PreToolUse** | Evaluates every tool call against policies and invariants before execution |
57
+ | **PostToolUse** | Reports Bash stderr errors (informational) |
58
+ | **SessionStart** | Ensures build is ready, shows governance status |
59
+
60
+ Tool call mapping:
61
+
62
+ | Claude Code Tool | AgentGuard Action |
63
+ |-----------------|-------------------|
64
+ | Write / Edit | file.write |
65
+ | Read / Glob / Grep | file.read |
66
+ | Bash | shell.exec (or git.push, git.commit if git command detected) |
67
+
68
+ ## Policy Format
69
+
70
+ ```yaml
71
+ id: project-policy
72
+ name: Project Policy
73
+ severity: 4
74
+ rules:
75
+ - action: git.push
76
+ effect: deny
77
+ branches: [main, master]
78
+ reason: Protected branch
79
+
80
+ - action: file.write
81
+ effect: deny
82
+ target: .env
83
+ reason: No secrets modification
84
+ ```
85
+
86
+ Drop an `agentguard.yaml` in your repo root — the CLI picks it up automatically.
87
+
88
+ ## Built-in Invariants
89
+
90
+ 20 safety invariants run on every action:
91
+
92
+ | Invariant | Severity | What it does |
93
+ |-----------|----------|-------------|
94
+ | no-secret-exposure | Critical | Blocks .env, .pem, .key, credentials files |
95
+ | no-credential-file-creation | Critical | Blocks SSH keys, cloud configs, auth tokens |
96
+ | no-cicd-config-modification | Critical | Protects CI/CD pipeline configs |
97
+ | no-governance-self-modification | Critical | Prevents agents from modifying governance |
98
+ | protected-branch | High | Prevents push to main/master |
99
+ | no-force-push | High | Forbids force push |
100
+ | no-package-script-injection | High | Blocks lifecycle script tampering |
101
+ | no-permission-escalation | High | Catches chmod world-writable, setuid |
102
+ | no-network-egress | High | Denies HTTP to non-allowlisted domains |
103
+ | transitive-effect-analysis | High | Analyzes written files for downstream effects |
104
+ | blast-radius-limit | Medium | Enforces file modification limit |
105
+ | test-before-push | Medium | Requires tests pass before push |
106
+ | large-file-write | Medium | Per-file size limit |
107
+ | ...and 7 more | Low-Medium | Container config, env vars, migrations, lockfiles, recursive ops |
108
+
109
+ ## CLI Commands
110
+
111
+ ```bash
112
+ # Governance
113
+ agentguard guard [--policy <file>] [--dry-run] # Start governed runtime
114
+ agentguard inspect [--last] # Inspect action graph
115
+ agentguard events [--last] # Raw event stream
116
+ agentguard analytics # Violation patterns
117
+ agentguard traces [--last] # Policy evaluation traces
118
+
119
+ # Policy
120
+ agentguard policy validate <file> # Validate policy
121
+ agentguard policy suggest # Auto-suggest rules from violations
122
+ agentguard policy verify <file> # Verify against historical violations
123
+
124
+ # Simulation
125
+ agentguard simulate <action-json> # Predict impact without executing
126
+ agentguard simulate --plan <file> # Batch simulate an action plan
127
+
128
+ # Session tools
129
+ agentguard replay --last [--step] # Replay governance session
130
+ agentguard session-viewer --last # Interactive HTML timeline
131
+ agentguard diff <runA> <runB> # Compare two sessions
132
+ agentguard export/import # Portable JSONL sessions
133
+
134
+ # CI/CD
135
+ agentguard ci-check [--last] # Verify governance in CI
136
+ agentguard evidence-pr [--pr <num>] # Attach evidence to PR
137
+ agentguard audit-verify [--last] # Verify audit chain integrity
138
+
139
+ # Integration
140
+ agentguard claude-init # Set up Claude Code hooks
141
+ agentguard auto-setup # Auto-detect and configure
142
+ agentguard status # Check governance readiness
143
+ agentguard demo # Interactive showcase
144
+
145
+ # Configuration
146
+ agentguard config show|get|set # Manage config
147
+ agentguard init --extension <type> # Scaffold extensions
148
+ agentguard migrate # Import JSONL into SQLite
149
+ ```
150
+
151
+ ## Library Packages
152
+
153
+ For building integrations, the core types and event model are available as separate packages:
154
+
155
+ ```bash
156
+ npm install @red-codes/core # Types, actions, utilities
157
+ npm install @red-codes/events # Canonical event model
158
+ ```
159
+
160
+ ## RTK Token Optimization
161
+
162
+ AgentGuard integrates with [RTK](https://github.com/rtk-ai/rtk) to reduce token consumption by 60-90%. When RTK is installed, shell commands are automatically rewritten for compact output after governance approval.
163
+
164
+ ```bash
165
+ npm install -g @anthropic-ai/rtk # Install RTK (optional)
166
+ agentguard status # Confirms: ⚡ Token optimization active
167
+ ```
168
+
169
+ Works with git, npm, cargo, tsc, docker, kubectl, and more. No configuration needed — AgentGuard detects RTK automatically.
170
+
171
+ ## Agent Swarm
172
+
173
+ AgentGuard ships with a 26-agent autonomous development swarm:
174
+
175
+ ```bash
176
+ agentguard init swarm # Scaffolds agents, skills, and governance into your repo
177
+ ```
178
+
179
+ Agents handle implementation, code review, CI triage, security audits, planning, docs, and more — all under governance.
180
+
181
+ ## Links
182
+
183
+ - [GitHub](https://github.com/AgentGuardHQ/agentguard)
184
+ - [Documentation](https://agentguardhq.github.io/agentguard/)
185
+ - [Architecture](https://github.com/AgentGuardHQ/agentguard/blob/main/docs/unified-architecture.md)
186
+ - [Roadmap](https://github.com/AgentGuardHQ/agentguard/blob/main/ROADMAP.md)
187
+
188
+ ## License
189
+
190
+ [Apache 2.0](https://github.com/AgentGuardHQ/agentguard/blob/main/LICENSE)
package/dist/bin.js CHANGED
@@ -27540,7 +27540,8 @@ async function claudeHook(hookType, extraArgs = []) {
27540
27540
  if (isPreToolUse) {
27541
27541
  const sessionId = data.session_id || process.env.CLAUDE_SESSION_ID || void 0;
27542
27542
  const payload = { ...data, session_id: sessionId };
27543
- await handlePreToolUse(payload, extraArgs);
27543
+ const denied = await handlePreToolUse(payload, extraArgs);
27544
+ process.exit(denied ? 2 : 0);
27544
27545
  } else {
27545
27546
  handlePostToolUse(data, extraArgs);
27546
27547
  }
@@ -27607,7 +27608,9 @@ async function handlePreToolUse(payload, cliArgs) {
27607
27608
  if (response) {
27608
27609
  process.stdout.write(response);
27609
27610
  }
27611
+ return true;
27610
27612
  }
27613
+ return false;
27611
27614
  }
27612
27615
  function handlePostToolUse(data, cliArgs = []) {
27613
27616
  if (data.tool_name !== "Bash") return;
@@ -29045,12 +29048,7 @@ async function main() {
29045
29048
  }
29046
29049
  case "--version":
29047
29050
  case "-v": {
29048
- const { readFileSync: readFileSync32 } = await import("node:fs");
29049
- const { fileURLToPath: fileURLToPath6 } = await import("node:url");
29050
- const { dirname: dirname14, join: join32 } = await import("node:path");
29051
- const __dir = dirname14(fileURLToPath6(import.meta.url));
29052
- const pkg = JSON.parse(readFileSync32(join32(__dir, "..", "..", "package.json"), "utf8"));
29053
- console.log(`agentguard v${pkg.version}`);
29051
+ console.log(`agentguard v${"1.1.3"}`);
29054
29052
  break;
29055
29053
  }
29056
29054
  case "help":