The hook matcher goes: Grep, Glob, WebFetch, Agent and MCP output needs the hook too. onFailure: block on PreToolUse (v2.1.295+) stops a tool when fermata cannot run. A new Known limits section lists what is not covered, including failed tools, whose text no hook can rewrite.
53 lines
6.0 KiB
Markdown
53 lines
6.0 KiB
Markdown
# Package: dirigent_fermata
|
|
|
|
Harness-agnostic secret redaction engine and policy gate for AI coding agents.
|
|
|
|
## Quick Facts
|
|
- **Type**: Library + binary (`fermata`)
|
|
- **Main Entry**: `src/lib.rs`, `src/bin/fermata.rs`
|
|
- **Dependencies**: `ignore`, `toml`, `regex`, `globset`, `serde`, `clap` (cli feature), `aho-corasick`, `serde_yaml`
|
|
- **Status**: v0.2 — secret redaction + policy gate (`.botsecrets` now includes `[policy]` section)
|
|
|
|
## Layering
|
|
|
|
Three concentric layers; nothing inner imports from anything outer.
|
|
|
|
- **`core/`** — harness-unaware, transport-unaware, sync. Types (`Op`, `Decision`), `.botignore` walker, `Policy::check` / `check_command`, path extraction. `.botsecrets` contains a `[policy]` section for access control rules (`fermata.toml` is accepted as an alias for `.botsecrets`). Sync, no tokio.
|
|
- **`core/secrets/`** — the secret filtering engine:
|
|
- `config.rs` — `.botsecrets` TOML parser (`SecretsConfig`, `PolicyConfig`) and hierarchical resolution (user, project, local override).
|
|
- `manifest.rs` — discovers secret-containing files from `.botsecrets` patterns and loads their content for redaction.
|
|
- `parser.rs` — multi-format secret file parser (`.env`, TOML, YAML, JSON). Extracts key-value pairs where the value is a secret.
|
|
- `patterns.rs` — built-in key name patterns (~30 universal patterns like `*_KEY`, `*_SECRET`, `*_PASSWORD`) and gitleaks-derived regex patterns for heuristic scanning.
|
|
- `redactor.rs` — `Redactor` builds an Aho-Corasick automaton from known secret values and replaces them in arbitrary text. Sub-millisecond performance.
|
|
- `scanner.rs` — `Scanner` applies heuristic regex patterns to detect secrets not covered by the known-value manifest (entropy-based and format-based detection).
|
|
- **`harness/`** — `HarnessAdapter` trait over a normalized `ToolCall` (PreToolUse) and `PostToolUsePayload` (PostToolUse). Each adapter (Claude, future Codex, etc.) lives in its own submodule, feature-gated. PostToolUse enables output redaction via `updatedToolOutput` before content enters the LLM context.
|
|
- **`bin/fermata.rs`** — only place where `clap`, stdio, and exit codes appear.
|
|
|
|
## Release Model
|
|
|
|
Developed in this monorepo; planned to be exported as a standalone repo in the future for advertising / external distribution. Development stays here. See `docs/tools/fermata.md`.
|
|
|
|
## Dependency Direction
|
|
|
|
`dirigent_tools` depends on `dirigent_fermata`, never the reverse. Fermata must remain usable as a standalone hook/MCP without dragging in the in-process ACP tool runtime.
|
|
|
|
## Failure behaviour and known limits
|
|
|
|
- **Hooks fail open, except under `on_parse_error = "deny"`.** With `deny` in effect, PostToolUse answers with a refusal naming the file when the config or a secret file cannot be loaded, and PreToolUse answers `deny` when the config or the rules cannot be loaded or applied. A malformed hook payload and a missing working directory stay open: no payload means nothing to render, no directory means no setting to read. `fermata check` does not refuse on a broken config.
|
|
- **A config that cannot be read: the setting is unknown.** `SecretsConfig::denies_on_failure` reads the raw bytes of every layer: an uncommented line setting `deny` counts, broken layer or not; without one the hook stays open as for any default root; a layer whose bytes cannot be read says nothing and does not count, so an unreadable global config cannot stop every project on the machine.
|
|
- **Replacing output depends on the harness.** Claude Code ignores an `updatedToolOutput` that does not match a built-in tool's output schema and then uses the original. `harness/claude.rs` therefore walks `tool_response` in any shape and masks strings in place. `SCHEMA_VALUES` lists the enum and literal values of every built-in output schema in Claude Code v2.1.314 (re-read it when a release adds tools): those exact values stay. A secret elsewhere under those names or in a built-in's object key cannot take a mask, so `OutputEdit::Unmaskable` refuses the output under every setting. Refusals: Bash and Read answer a minimal schema-valid output, other built-ins keep their shape, MCP gets the plain text. `tests/cli_hook_redaction.rs` checks shapes against a copy of those schemas; nothing here runs Claude Code.
|
|
- **Redaction limits.** A failed tool (`PostToolUseFailure`, including a Bash non-zero exit per the docs) cannot be rewritten by any hook and is not hooked. Values split across strings, encoded values, numbers and binary fields are not masked. Heuristics warn in `additionalContext` and do not mask. Full list: `docs/security-model.md`, "Known limits".
|
|
- **Errors never quote a file.** `ParseError::Format` and `SecretsConfigError::Parse` keep the format and line number and drop the parser's text, because it can quote the failing line. Patterns (`.botignore`, `[policy]`, `[files]`) can appear in messages: they are not values, and a deny reason names them too.
|
|
- **Editor files never refuse.** A discovered vim swap file (`*.sw[a-p]`, `*.swx`), Kate's `*.kate-swp` or a `*~` that cannot be read or parsed is passed over silently under every `on_parse_error`, in the hooks and in Dirigent's channel filter (which forces `deny`). If it can be parsed its values stay known and are redacted, as before. `.bak`, `.orig` and `.env.gpg` keep today's rule, since a hand-made copy can hold live values. A `[[file]]` override is meant, whatever its name, and keeps the rule too. Files with no parser format (`secrets.toml~`, `#secrets.toml#`, `secrets.toml.bak`) were and are opaque: not read, no refusal, not redacted.
|
|
|
|
## Out of scope (v0.2)
|
|
|
|
Codex / Gemini hook adapters, MCP server mode, `readonly_only` Bash mode, audit log, filesystem watcher, context taint tracking. Each is a future task with its own plan.
|
|
|
|
## See also
|
|
|
|
- `docs/tools/fermata.md` — Dirigent integration plan
|
|
- `docs/workpad/brainstorm/fermata.md` — canonical product spec
|
|
- `docs/architecture/fermata-security-philosophy.md` — security philosophy and the reveal triangle
|
|
- `.botsecrets` format: `core/secrets/config.rs` — unified config for secret redaction and policy (`fermata.toml` accepted as alias)
|