One list, merged from both READMEs and security-model.md "Known limits", each entry with its test. Entries fixed on this branch are gone. Both READMEs keep the warning and point at the page. tests/docs_known_failures.rs keeps the page and known_limits.rs in step, and test_crate_export.py checks that the public README's links resolve in the exported tree.
212 lines
8.0 KiB
Markdown
212 lines
8.0 KiB
Markdown
# CLI Command Reference
|
|
|
|
> **Do not use this software.** fermata is an experiment. It does not protect your secrets, and secrets can and do reach the model while it is installed. This document describes what fermata tries to do. See [Known failures](known-failures.md) for where it fails.
|
|
|
|
Fermata is an experiment in stopping tool calls by rule and masking secret values in tool output. It ships two subcommands: `check` for interactive path validation and `hook` for integration with AI harness hook systems.
|
|
|
|
---
|
|
|
|
## fermata check
|
|
|
|
Check whether one or more paths are allowed for a given operation. Fermata locates the nearest project root (a directory containing `.botsecrets`, `.botignore`, or `.git`) and evaluates the policy defined there.
|
|
|
|
**Usage**
|
|
|
|
```
|
|
fermata check [OPTIONS] <PATHS>...
|
|
```
|
|
|
|
**Options**
|
|
|
|
| Option | Description | Default |
|
|
|--------|-------------|---------|
|
|
| `--op <OP>` | Operation to check: `read`, `write`, or `execute` | `read` |
|
|
| `--json` | Print the full decision as JSON instead of a human message | off |
|
|
|
|
**Exit codes**
|
|
|
|
| Code | Meaning |
|
|
|------|---------|
|
|
| 0 | Allowed (or Ask -- the agent may prompt the user) |
|
|
| 1 | Denied -- the policy blocks this operation |
|
|
| 2 | Internal error (could not load policy, bad arguments, a config layer that does not load, or a `[files]` or `[policy]` pattern that does not compile, etc.) The message names the file and line. |
|
|
|
|
When multiple paths are provided, fermata evaluates each one independently and returns the **worst** result. If any path is denied, the exit code is 1.
|
|
|
|
**Examples**
|
|
|
|
A relative path is taken against the project root and checked like the absolute one.
|
|
|
|
```bash
|
|
# Check if the agent can read .env
|
|
fermata check --op read .env
|
|
|
|
# Check if the agent can write to a source file
|
|
fermata check --op write src/main.rs
|
|
|
|
# Check multiple paths at once; exits 1 if any are denied
|
|
fermata check --op read .env src/main.rs config/secrets.yaml
|
|
|
|
# Get a machine-readable JSON decision
|
|
fermata check --op read .env --json
|
|
```
|
|
|
|
---
|
|
|
|
## fermata hook
|
|
|
|
Read a harness hook payload from stdin, evaluate the policy (PreToolUse) or redact secrets from tool output (PostToolUse), and write the response to stdout. This is the command you wire into your AI agent's hook configuration.
|
|
|
|
**Usage**
|
|
|
|
```
|
|
fermata hook [OPTIONS]
|
|
```
|
|
|
|
The hook payload is always read from **stdin** as JSON. The response is written to **stdout** as JSON.
|
|
|
|
**Options**
|
|
|
|
| Option | Description | Default |
|
|
|--------|-------------|---------|
|
|
| `--event <EVENT>` | Hook event type. Accepted values: `pre-tool-use`, `PreToolUse`, `post-tool-use`, `PostToolUse` | `pre-tool-use` |
|
|
| `--harness <HARNESS>` | Harness adapter name. Currently supported: `claude` | `claude` |
|
|
|
|
**Exit codes**
|
|
|
|
| Code | Meaning |
|
|
|------|---------|
|
|
| 0 | Success. The JSON response on stdout tells the harness what to do. |
|
|
| 2 | Internal error (unknown harness, unknown event type, stdin read failure) |
|
|
|
|
Fermata follows a **fail-open** policy for hooks: if the payload cannot be parsed, it writes `{}` to stdout and exits 0 so the agent can continue. If a config layer cannot be loaded (including a field fermata does not know), only that layer's rules are off, and PostToolUse adds a note beside text output naming the file and line. A glob that does not compile costs only that pattern, with a note naming it, its section and its layer. A tool PreToolUse has no rules for answers `{}` without a message. Errors are reported on stderr and never quote a file.
|
|
|
|
The exception is `on_parse_error = "deny"` (the default is `allow`). If the config or a secret file cannot be loaded, `post-tool-use` answers with a refusal naming the file, in a form the tool's output schema accepts; if the config or the rules cannot be loaded or applied, `pre-tool-use` answers deny. See [`on_parse_error`](configuration.md) for what happens when the config itself is the broken file. Claude Code drops a replacement that its schema rejects and uses the original: see [Known failures](known-failures.md).
|
|
|
|
**Event types**
|
|
|
|
- **pre-tool-use** -- Runs before the tool executes. Fermata checks the requested path against `.botsecrets [policy]` / `.botignore`, and the files a command names (by the verb of each segment), and returns a deny or ask decision, or nothing. It also stops a Read of a listed secret file it cannot mask (`on_unparsed_read`) and a Write or Edit that adds a mask to a file (`on_mask_write`).
|
|
- **post-tool-use** -- Runs after the tool executes. Fermata loads `.botsecrets`, builds a manifest of known secret values, and masks any matches in every string of the tool output, returning it in the same shape (`updatedToolOutput`), or `{}` if nothing changed. Each masking adds the note "Values in this output are masked. Do not write them back into a file." A secret where a built-in tool's schema cannot take a mask (an object key, a fixed field) refuses the whole output under every setting. A heuristic scanner (regex patterns derived from gitleaks) adds a warning beside the output (`additionalContext`) for undeclared secrets; it does not mask them.
|
|
|
|
**Examples**
|
|
|
|
```bash
|
|
# PreToolUse: pipe a Claude Code hook payload through fermata
|
|
echo '{"tool_name":"Read","tool_input":{"file_path":"/project/.env"}}' \
|
|
| fermata hook --harness claude
|
|
|
|
# PostToolUse: redact secrets from tool output
|
|
echo '{"tool_name":"Bash","tool_input":{"command":"cat .env"},"tool_output":"API_KEY=sk-live-abc123"}' \
|
|
| fermata hook --harness claude --event post-tool-use
|
|
```
|
|
|
|
---
|
|
|
|
## Configuration Files
|
|
|
|
Fermata does not have its own global config file. All configuration lives in your project directory alongside the code:
|
|
|
|
| File | Purpose |
|
|
|------|---------|
|
|
| `.botsecrets` | TOML file for secret redaction (`[files]`, `[heuristic]`, `[keys]`) **and** access-control policy (`[policy]` section with `[policy.read]`, `[policy.write]`, `[policy.bash]`). Unified config for most projects. `fermata.toml` is accepted as an alias (same format, `.botsecrets` takes priority). |
|
|
| `.botignore` | Gitignore-syntax patterns. Blocks both reads and writes to matched paths, and commands that name a matched file. |
|
|
|
|
Fermata discovers these files by walking up from the target path (or the current working directory for `hook`) until it finds a project root.
|
|
|
|
---
|
|
|
|
## Common Patterns
|
|
|
|
### Trying both files
|
|
|
|
Drop two files in your project root:
|
|
|
|
```gitignore
|
|
# .botignore
|
|
.env
|
|
.env.*
|
|
secrets/**
|
|
credentials/**
|
|
```
|
|
|
|
```toml
|
|
# .botsecrets
|
|
[files]
|
|
patterns = [".env", ".env.*"]
|
|
|
|
[heuristic]
|
|
enabled = true
|
|
```
|
|
|
|
The `.botignore` stops the Read, Write and Edit tools on those paths, and a command such as `cat .env` or `cp a.txt .env` that names one of them. It does not see a command that hides the name (`cat $(...)`, a script). The `.botsecrets` tries to mask the values of the files it can parse in the output of tools that succeed.
|
|
|
|
### Single-file setup with .botsecrets
|
|
|
|
You can consolidate both secret redaction and access policy into `.botsecrets` alone, replacing the need for a separate `.botignore`:
|
|
|
|
```toml
|
|
# .botsecrets
|
|
[files]
|
|
patterns = [".env", ".env.*"]
|
|
|
|
[heuristic]
|
|
enabled = true
|
|
|
|
[policy.read]
|
|
patterns = [".env", ".env.*", "secrets/**", "credentials/**"]
|
|
|
|
[policy.bash]
|
|
deny = ["rm -rf /", "curl * | sh"]
|
|
```
|
|
|
|
### Wire fermata into Claude Code
|
|
|
|
Add both hook events to `.claude/settings.json`:
|
|
|
|
```json
|
|
{
|
|
"hooks": {
|
|
"PreToolUse": [
|
|
{
|
|
"hooks": [
|
|
{ "type": "command", "command": "fermata hook --harness claude", "onFailure": "block" }
|
|
]
|
|
}
|
|
],
|
|
"PostToolUse": [
|
|
{
|
|
"hooks": [
|
|
{ "type": "command", "command": "fermata hook --harness claude --event post-tool-use" }
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
```
|
|
|
|
### Block dangerous shell commands
|
|
|
|
Use `.botsecrets [policy.bash]` to deny specific command patterns:
|
|
|
|
```toml
|
|
[policy.bash]
|
|
deny = ["rm -rf /", "curl * | sh", "wget * | bash"]
|
|
```
|
|
|
|
### Quick smoke test
|
|
|
|
After installing fermata, try it in a throwaway project:
|
|
|
|
```bash
|
|
# Should exit 0 (allowed)
|
|
fermata check --op read "$PWD/src/main.rs"
|
|
echo $?
|
|
|
|
# Should exit 1 (denied) if .botignore blocks .env.
|
|
fermata check --op read "$PWD/.env"
|
|
echo $?
|
|
|
|
# JSON output for scripting
|
|
fermata check --op read "$PWD/.env" --json
|
|
```
|