@ccdevkit/ccaudit 0.1.0 → 0.2.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 +205 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# ccaudit
|
|
2
|
+
|
|
3
|
+
Audit tool for Claude Code projects. Runs compliance checks on code and agent actions from `.ccaudit/audits/` directories.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Via npm (recommended)
|
|
9
|
+
npm install -g @ccdevkit/ccaudit
|
|
10
|
+
|
|
11
|
+
# Via Go
|
|
12
|
+
go install github.com/ccdevkit/ccaudit/cmd/ccaudit@latest
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# List available audits
|
|
19
|
+
ccaudit list
|
|
20
|
+
|
|
21
|
+
# Run an audit
|
|
22
|
+
ccaudit run security
|
|
23
|
+
|
|
24
|
+
# Run with verbose output
|
|
25
|
+
ccaudit run security -v
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Concepts
|
|
29
|
+
|
|
30
|
+
### Audit
|
|
31
|
+
|
|
32
|
+
An audit is a named collection of checks. An audit is defined by a directory in `.ccaudit/audits/{name}/` containing an `audit.yaml` file. The directory name becomes the audit name.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
.ccaudit/audits/
|
|
36
|
+
├── security/
|
|
37
|
+
│ ├── audit.yaml # Required - defines the audit
|
|
38
|
+
│ ├── check-secrets.sh # Shell check
|
|
39
|
+
│ └── check-xss.md # Agent check
|
|
40
|
+
└── quality/
|
|
41
|
+
└── audit.yaml
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Check
|
|
45
|
+
|
|
46
|
+
A check is an individual verification test. Two types exist:
|
|
47
|
+
|
|
48
|
+
**Shell checks** (`.sh` files): Execute shell scripts. Exit code 0 = pass, 1 = fail. Stdout on failure becomes the failure reason.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
#!/bin/bash
|
|
52
|
+
# ---
|
|
53
|
+
# name: check-secrets
|
|
54
|
+
# ---
|
|
55
|
+
if grep -r "API_KEY=" .; then
|
|
56
|
+
echo "Hardcoded API key found"
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
exit 0
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Agent checks** (`.md` files): Use Claude to analyze code or agent actions. The markdown content is the audit prompt.
|
|
63
|
+
|
|
64
|
+
```markdown
|
|
65
|
+
---
|
|
66
|
+
name: check-code-quality
|
|
67
|
+
model: sonnet # Optional: haiku (default), sonnet, opus
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
Review the code for:
|
|
71
|
+
1. Complex functions that should be refactored
|
|
72
|
+
2. Inconsistent error handling
|
|
73
|
+
3. Missing input validation
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Check vs Audit
|
|
77
|
+
|
|
78
|
+
- **Check**: Single verification (one `.sh` or `.md` file)
|
|
79
|
+
- **Audit**: Collection of checks (directory with `audit.yaml`)
|
|
80
|
+
|
|
81
|
+
Checks run sequentially and stop at first failure.
|
|
82
|
+
|
|
83
|
+
## audit.yaml
|
|
84
|
+
|
|
85
|
+
The `audit.yaml` file defines which checks an audit includes:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
includes:
|
|
89
|
+
- ../shared/* # All checks from shared/ directory
|
|
90
|
+
- ../other-audit # All checks from another audit (recursively)
|
|
91
|
+
- ./check-custom.sh # Specific check file
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Paths are relative to the audit directory. Wildcards (`*`, `?`, `[...]`) are supported.
|
|
95
|
+
|
|
96
|
+
An audit with no `includes` runs all `.sh` and `.md` files in its own directory.
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
Settings file: `.ccaudit/settings.json` (project) or `~/.ccaudit/settings.json` (global)
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"claude_command": "claude"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Setting | Default | Description |
|
|
109
|
+
|---------|---------|-------------|
|
|
110
|
+
| `claude_command` | `claude` | Command to invoke Claude CLI |
|
|
111
|
+
|
|
112
|
+
## CLI Reference
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
ccaudit run <audit-name> Execute an audit
|
|
116
|
+
-v, --verbose Enable debug output
|
|
117
|
+
--output <mode> Force output mode: interactive, plain, or hook
|
|
118
|
+
|
|
119
|
+
ccaudit list List available audits
|
|
120
|
+
-v, --verbose Enable debug output
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Output Modes
|
|
124
|
+
|
|
125
|
+
- **Interactive**: TUI with spinner and progress (default in terminal)
|
|
126
|
+
- **Plain**: Text output (default when piped)
|
|
127
|
+
- **Hook**: JSON output for Claude Code hook integration (auto-detected from stdin)
|
|
128
|
+
|
|
129
|
+
## Claude Code Hook Integration
|
|
130
|
+
|
|
131
|
+
Run ccaudit as a Claude Code hook to audit agent actions in real-time:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"hooks": {
|
|
136
|
+
"Stop": [
|
|
137
|
+
{
|
|
138
|
+
"command": "ccaudit run security"
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Supported hook events: `PreToolUse`, `PostToolUse`, `Stop`, `UserPromptSubmit`
|
|
146
|
+
|
|
147
|
+
When running as a hook:
|
|
148
|
+
- Hook context is read from stdin (JSON with `hook_event_name`, `cwd`, `transcript_path`, etc.)
|
|
149
|
+
- Agent checks gain access to MCP tools (`get_history`, `get_instructions`) for inspecting the audited session
|
|
150
|
+
- Output is JSON on failure only
|
|
151
|
+
|
|
152
|
+
## Check Frontmatter
|
|
153
|
+
|
|
154
|
+
All checks require a `name` field in YAML frontmatter:
|
|
155
|
+
|
|
156
|
+
Shell:
|
|
157
|
+
```bash
|
|
158
|
+
#!/bin/bash
|
|
159
|
+
# ---
|
|
160
|
+
# name: check-name
|
|
161
|
+
# ---
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Markdown:
|
|
165
|
+
```markdown
|
|
166
|
+
---
|
|
167
|
+
name: check-name
|
|
168
|
+
model: haiku # Optional
|
|
169
|
+
---
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Agent Check Behavior
|
|
173
|
+
|
|
174
|
+
Agent checks run in read-only mode. They can use `Read`, `Glob`, `Grep`, and `Bash` (for read operations only).
|
|
175
|
+
|
|
176
|
+
When running as a hook with transcript access, agent checks also have MCP tools to inspect the audited session's history and actions.
|
|
177
|
+
|
|
178
|
+
Agent checks return structured JSON:
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"passed": false,
|
|
182
|
+
"reason": "Single failure explanation",
|
|
183
|
+
"failures": ["Issue 1", "Issue 2"],
|
|
184
|
+
"hint": "How to fix"
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Project Structure
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
.ccaudit/
|
|
192
|
+
├── settings.json # Optional configuration
|
|
193
|
+
└── audits/
|
|
194
|
+
├── my-audit/
|
|
195
|
+
│ ├── audit.yaml # Required
|
|
196
|
+
│ ├── check-foo.sh
|
|
197
|
+
│ └── check-bar.md
|
|
198
|
+
└── shared/
|
|
199
|
+
└── check-common.sh
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Exit Codes
|
|
203
|
+
|
|
204
|
+
- `0`: All checks passed
|
|
205
|
+
- `1`: At least one check failed or error occurred
|