cc-safety-net 2.0.10 → 2.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 CHANGED
@@ -19,32 +19,32 @@
19
19
 
20
20
  </div>
21
21
 
22
- CC Safety Net — short for **Coding CLI** Safety Net — is a PreToolUse hook that blocks destructive commands and access to secrets like SSH keys and `.env` files, before AI coding agents run them. It parses command **semantics**, so flag reordering, shell wrappers, and interpreter one-liners can't bypass it.
22
+ CC Safety Net is short for Coding CLI Safety Net. It is a PreToolUse hook that blocks destructive commands and access to secrets such as SSH keys and `.env` files before the tool call runs. It parses what a command does, so flag reordering, shell wrappers, and interpreter one-liners cannot bypass it.
23
23
 
24
24
  > [!NOTE]
25
- > **[Full documentation →](https://ccsafetynet.com/docs)** — installation, configuration, reference, guides, and the security model live on the docs site. This README is the short version.
25
+ > **[Full documentation →](https://ccsafetynet.com/docs)** covers installation, configuration, reference material, guides, and the security model. This README is the short version.
26
26
 
27
27
  ## Why this exists
28
28
 
29
- We learned the [hard way](https://www.reddit.com/r/ClaudeAI/comments/1pgxckk/claude_cli_deleted_my_entire_home_directory_wiped/) that instructions aren't enough to keep AI agents in check. After an agent silently wiped hours of progress with a single `rm -rf ~/` or `git checkout --`, it became clear that **soft** rules in a `CLAUDE.md` or `AGENTS.md` file cannot replace **hard** technical constraints. CC Safety Net is that constraint: it observes relevant tool calls and blocks destructive commands and secret access before they reach the shell. See [What Is CC Safety Net](https://ccsafetynet.com/docs/introduction) for the full background.
29
+ We built CC Safety Net after an agent [wiped hours of work](https://www.reddit.com/r/ClaudeAI/comments/1pgxckk/claude_cli_deleted_my_entire_home_directory_wiped/) with one `rm -rf ~/` or `git checkout --`. Instructions did not stop it. Rules in `CLAUDE.md` or `AGENTS.md` can guide an agent, but they cannot enforce a technical limit. CC Safety Net watches relevant tool calls and blocks destructive commands and secret access before they reach the shell. See [What is CC Safety Net](https://ccsafetynet.com/docs/introduction) for the full background.
30
30
 
31
31
  ## What's new in v2.0.0
32
32
 
33
33
  > [!TIP]
34
- > **Already running v1?** One command upgrades every installed integration to v2: `npx -y cc-safety-net@latest update`. If you defined custom rules under v1, also read [Upgrading from an older version](#upgrading-from-an-older-version).
34
+ > **Already running v1?** Run `npx -y cc-safety-net@latest update` to upgrade every installed integration to v2. If you defined custom rules under v1, also read [Upgrading from an older version](#upgrading-from-an-older-version).
35
35
 
36
- - **Rebuilt evaluation engine** — canonical command IR, deeply immutable policy snapshots, and an ordered guard pipeline with intrinsic decision tracing behind `explain`.
37
- - **Secret protection** — built-in rules block content access to SSH keys, `.env` files, cloud credentials, and coding-CLI credential stores, across shell commands and file tools alike.
38
- - **Always-on catastrophic protections** — recursive deletion of root or home, Git metadata mutation (`.git` control plane, hooks, worktrees, submodules), and mutation of the user policy file are blocked in every mode, regardless of overrides.
39
- - **Safety presets** — `standard`/`strict`/`paranoid` levels with per-rule overrides, trusted delete allow-paths, and safety-level and capability env vars that can only raise protection — the one deliberate exception is `CC_SAFETY_NET_WORKTREE`, which allows local git discards in linked worktrees.
40
- - **Policy GUI** — `cc-safety-net gui` serves a local, token-authenticated editor with live preset preview.
41
- - **Universal installer** — interactive `install`/`uninstall` across all twelve supported agent CLIs, with an `update` command for installed integrations.
42
- - **Command-decision audit trail** — allowed and blocked command decisions recorded by default to local per-project JSONL with secret redaction, retained for 30 days by default, browsable via `cc-safety-net logs`.
43
- - **Documented threat model** — the [SECURITY.md](SECURITY.md) mode contract, explicit resource limits, and a residual-risk registry of adjudicated bypass families.
36
+ - **Evaluation engine.** A canonical command IR, policy snapshots that remain immutable at every nested level, and an ordered guard pipeline now support decision tracing through `explain`.
37
+ - **Secret protection.** Built-in rules block content access to SSH keys, `.env` files, cloud credentials, and coding-CLI credential stores through shell commands and file tools.
38
+ - **Always-on protections.** Every mode blocks recursive deletion of root or home, Git metadata changes to the `.git` control plane, hooks, worktrees, or submodules, and changes to the user policy file. Overrides do not disable these rules.
39
+ - **Safety presets.** The `standard`, `strict`, and `paranoid` levels support per-rule overrides and trusted delete allow-paths. Safety-level and capability environment variables can only raise protection. `CC_SAFETY_NET_WORKTREE` is the one exception. It allows local Git discards in linked worktrees.
40
+ - **Policy GUI.** `cc-safety-net gui` runs a local, token-authenticated editor with a live preset preview.
41
+ - **Universal installer.** Interactive `install` and `uninstall` commands support all twelve coding CLIs. The `update` command updates installed integrations.
42
+ - **Command-decision audit trail.** CC Safety Net records allowed and blocked decisions in local per-project JSONL. It redacts secrets, keeps records for 30 days by default, and shows them through `cc-safety-net logs`.
43
+ - **Threat model.** [SECURITY.md](SECURITY.md) defines the mode contract and resource limits. Its residual-risk registry records decisions for bypass families.
44
44
 
45
45
  ## Quick start
46
46
 
47
- **Prerequisite:** Node.js 18 or higher.
47
+ You need Node.js 18 or higher.
48
48
 
49
49
  Run the interactive selector to install CC Safety Net into one or more installed coding CLIs:
50
50
 
@@ -58,8 +58,8 @@ To update every installed integration:
58
58
  npx -y cc-safety-net@latest update
59
59
  ```
60
60
 
61
- The `@latest` qualifier matters: a bare `cc-safety-net` spec can re-run an older
62
- cached copy from the npx cache instead of the current release.
61
+ Keep the `@latest` qualifier. A bare `cc-safety-net` spec can run an older cached
62
+ copy from the npx cache instead of the current release.
63
63
 
64
64
  To remove integrations interactively:
65
65
 
@@ -76,7 +76,7 @@ ccsn doctor
76
76
 
77
77
  ## Supported coding CLIs
78
78
 
79
- CC Safety Net works across all coding agent CLIs on **Windows, macOS, and Linux**. Windows is covered by automated tests for the analyzer and a subset of integrations; for the remaining hosts it is best-effort and untested, and Amp's own manual documents macOS, Linux, and WSL rather than native Windows.
79
+ CC Safety Net supports the coding agent CLIs below on Windows, macOS, and Linux. Automated tests cover the analyzer and some Windows integrations. Other hosts have best-effort Windows support that has not been tested. Amp documents macOS, Linux, and WSL, but not native Windows.
80
80
 
81
81
  <table align="center">
82
82
  <tr>
@@ -103,23 +103,23 @@ CC Safety Net works across all coding agent CLIs on **Windows, macOS, and Linux*
103
103
 
104
104
  | Capability | What it catches |
105
105
  |---|---|
106
- | **Semantic command analysis** | `rm -rf` on destructive targets, `git reset --hard`, `git checkout --`, `git push --force`, `git stash clear`, `git clean -f`, unsafe `find -delete`, `dd`/`mkfs`/`shred` — by intent, not string pattern. `git checkout -b feature` (safe) is allowed while `git checkout -- file` (destructive) is blocked. |
107
- | **Shell wrapper detection** | Destructive commands hidden in `bash -c`, `sh -c`, and similar wrappers, recursively analyzed up to 10 levels deep. |
108
- | **Interpreter one-liners** | Destructive code in `python -c`, `node -e`, `ruby -e`, `perl -e` one-liners (e.g. `os.system("rm -rf /")`). |
109
- | **Fail-closed by default** | Malformed hook input and unparseable commands (in strict mode) block rather than allow. Invalid config never blocks: an unverifiable rule source is dropped and an unreadable `policy.json` falls back to protective defaults, both with a warning on every reporting surface. |
110
- | **Secret protection** | Content access to SSH keys, `.env` files, `~/.aws`, kube/docker/gcloud configs, and coding-CLI credential stores — enforced on shell commands and file tools (read/edit/write/search) alike. |
111
- | **Custom rules via rulebooks** | Add your own blocking rules at user or project scope, pinned by SHA-256 digest when fetched from GitHub. |
112
- | **Audit logging** | Allowed and blocked command decisions written to local per-project JSONL with secrets auto-redacted, retained for 30 days by default. Browse them with `npx cc-safety-net logs`, or triage them in the **Activity** view of `npx cc-safety-net gui`. |
106
+ | **Semantic command analysis** | Detects the intent of `rm -rf` on destructive targets, `git reset --hard`, `git checkout --`, `git push --force`, `git stash clear`, `git clean -f`, unsafe `find -delete`, `dd`, `mkfs`, and `shred`. It allows `git checkout -b feature` but blocks `git checkout -- file`. |
107
+ | **Shell wrapper detection** | Finds destructive commands inside `bash -c`, `sh -c`, and similar wrappers. It analyzes nested wrappers up to 10 levels deep. |
108
+ | **Interpreter one-liners** | Finds destructive code in `python -c`, `node -e`, `ruby -e`, and `perl -e` one-liners such as `os.system("rm -rf /")`. |
109
+ | **Fail-closed by default** | Blocks malformed hook input and, in strict mode, commands it cannot parse. Invalid configuration never blocks. CC Safety Net drops an unverifiable rule source and uses protective defaults when it cannot read `policy.json`. It reports these states in block messages, `doctor`, the status line, and the GUI. |
110
+ | **Secret protection** | Blocks content access to SSH keys, `.env` files, `~/.aws`, Kubernetes, Docker, and gcloud configuration, and coding-CLI credential stores. The rules apply to shell commands and read, edit, write, and search tools. |
111
+ | **Custom rules via rulebooks** | Lets you add blocking rules at user or project scope. CC Safety Net pins rulebooks fetched from GitHub by SHA-256 digest. |
112
+ | **Audit logging** | Writes allowed and blocked command decisions to local per-project JSONL, redacts secrets, and keeps records for 30 days by default. Browse them with `npx cc-safety-net logs`, or review them in the Activity view of `npx cc-safety-net gui`. |
113
113
 
114
114
  Full rule catalogs: [Blocked Commands](https://ccsafetynet.com/docs/reference/blocked-commands) · [Allowed Commands](https://ccsafetynet.com/docs/reference/allowed-commands) · [Secret Protection](https://ccsafetynet.com/docs/reference/secret-protection).
115
115
 
116
116
  ## Why not just use a sandbox?
117
117
 
118
- A workspace-writable sandbox still permits `git reset --hard`, `git push --force`, and `rm -rf .` *inside* the project directory, because the OS only sees writes to an allowed path. Sandboxing contains blast radius; CC Safety Net catches the destructive operations sandboxing permits — use both for defense-in-depth. See [vs Sandboxing](https://ccsafetynet.com/docs/guides/vs-sandboxing).
118
+ A workspace-writable sandbox still permits `git reset --hard`, `git push --force`, and `rm -rf .` inside the project directory. The operating system sees writes to an allowed path. A sandbox limits where a process can write. CC Safety Net blocks destructive operations inside that allowed area. Use both. See [vs Sandboxing](https://ccsafetynet.com/docs/guides/vs-sandboxing).
119
119
 
120
120
  ## Safety presets
121
121
 
122
- Set a session safety preset with `CC_SAFETY_NET_LEVEL=standard|strict|paranoid`:
122
+ Set a session safety preset with the GUI `npx cc-safety-net gui` then navigate to the policy tab:
123
123
 
124
124
  | Preset | Effect |
125
125
  |---|---|
@@ -127,8 +127,6 @@ Set a session safety preset with `CC_SAFETY_NET_LEVEL=standard|strict|paranoid`:
127
127
  | Strict | Standard, plus blocks dynamic or unparseable commands the analyzer cannot verify safely and metadata-only discovery of built-in sensitive paths. Occasional false positives on advanced shell. |
128
128
  | Paranoid | Strict, plus blocks `rm -rf` inside your project and interpreter one-liners. Expect friction; for untrusted agents or high-stakes repos. |
129
129
 
130
- Presets supply inherited defaults; `policy.json` stores only your explicit deviations — per-rule overrides, allow paths, deny paths, worktree mode, and audit retention. Safety-level and capability environment variables can only raise protection, never lower it; the one deliberate relaxation is `CC_SAFETY_NET_WORKTREE`, which enables worktree mode to allow local git discards in linked worktrees. The full contract is on [Modes](https://ccsafetynet.com/docs/configuration/modes), [Policy](https://ccsafetynet.com/docs/configuration/policy), and [Environment](https://ccsafetynet.com/docs/configuration/environment), or edit everything visually with the [local GUI](https://ccsafetynet.com/docs/guides/dashboard).
131
-
132
130
  ## Diagnostics and tracing
133
131
 
134
132
  ```bash
@@ -144,17 +142,61 @@ npx cc-safety-net logs
144
142
  npx cc-safety-net gui
145
143
  ```
146
144
 
147
- `doctor`, `explain`, and `logs` support `--json` for machine-readable output. The audit trail records command decisions only — never command output or prompts — and stays on your machine. Invalid configuration never blocks your agent: unverifiable rule sources are dropped and every degraded state is reported on the next block message, `doctor`, the status line, and the GUI banner.
145
+ `doctor`, `explain`, and `logs` support `--json` for machine-readable output. The audit trail stays on your machine. It records command decisions, but it does not record command output or prompts. Invalid configuration never blocks your agent. CC Safety Net drops unverifiable rule sources and reports each degraded state in the next block message, `doctor`, the status line, and the GUI banner.
148
146
 
149
147
  Details: [CLI Commands](https://ccsafetynet.com/docs/reference/cli-commands) · [Explain Trace](https://ccsafetynet.com/docs/reference/explain-trace) · [Audit Log](https://ccsafetynet.com/docs/reference/audit-log) · [Dashboard](https://ccsafetynet.com/docs/guides/dashboard) · [Configuration Recovery](https://ccsafetynet.com/docs/configuration/recovery).
150
148
 
149
+ ## Library API
150
+
151
+ Node.js hosts that need an in-process allow or deny decision can call the command-check
152
+ function directly instead of installing an agent integration:
153
+
154
+ ```bash
155
+ npm install cc-safety-net
156
+ ```
157
+
158
+ ```ts
159
+ import { checkCommand } from 'cc-safety-net/api';
160
+
161
+ function commandIsAllowed(command: string, cwd: string): boolean {
162
+ try {
163
+ const result = checkCommand({ command, cwd });
164
+ if (result.kind === 'allow') return true;
165
+ console.error(result.reason);
166
+ return false;
167
+ } catch (error) {
168
+ console.error('CC Safety Net could not check the command', error);
169
+ return false;
170
+ }
171
+ }
172
+
173
+ if (commandIsAllowed('git status', process.cwd())) {
174
+ // The host can now decide how to run the command.
175
+ }
176
+ ```
177
+
178
+ Usage rules:
179
+
180
+ - Requires Node.js 18 or later and ESM. There is no CommonJS build.
181
+ - `cwd` is required and must be an absolute directory path. It anchors relative command
182
+ targets and selects the project policy, so the API never defaults to hidden process state.
183
+ - The function reads local policy files, filesystem facts, and `CC_SAFETY_NET_*` environment
184
+ settings on each call. An invalid `CC_SAFETY_NET_LEVEL` is ignored and reported to stderr.
185
+ It does not run the command, write audit logs, change configuration, or make network requests.
186
+ - Commands are fully checked, including secret file access performed through commands. The
187
+ host's own non-shell file tools (read, write, edit, search) are not checked by this function.
188
+ - A `deny` result means the host must not execute the command. **If `checkCommand` throws,
189
+ do not execute the command either.**
190
+ - `reason` is display text; do not parse or compare it. Use the `kind` field for the
191
+ decision and treat the optional `ruleId` as diagnostic data only.
192
+
151
193
  ## Limitations
152
194
 
153
- CC Safety Net denies a tool call before it runs; it does not enforce filesystem permissions, inspect network egress, or contain a process. Two v2 bounds worth knowing up front: the policy and sensitive-path command extractors remain primarily POSIX-oriented, so native PowerShell path expressions such as `Get-Content $HOME\.ssh\id_rsa` can evade static path extraction; and policy-file protection is a best-effort exact-path guard, not command emulation. Use operating-system permissions, a sandbox, or equivalent runtime enforcement when complete protection is required.
195
+ CC Safety Net denies a tool call before it runs. It does not enforce filesystem permissions, inspect network egress, or contain a process. Two v2 limits matter. First, the policy and sensitive-path command extractors remain mainly POSIX-oriented. Native PowerShell path expressions such as `Get-Content $HOME\.ssh\id_rsa` can evade static path extraction. Second, policy-file protection is a best-effort exact-path guard. It does not emulate commands. Use operating-system permissions, a sandbox, or equivalent runtime controls when you need complete protection.
154
196
 
155
- One integration-specific bound: Codex's unified exec path, the default on macOS and Linux, sends a hook payload when a command starts a session but none for `write_stdin`. Text the model types into an already-running interactive session is therefore never inspected and never audited — only the command that opened the session is. The host emits no event for that call, so no adapter change can close it.
197
+ Codex has one integration-specific limit. Its unified exec path is the default on macOS and Linux. It sends a hook payload when a command starts a session, but it sends none for `write_stdin`. CC Safety Net can inspect and audit the command that opens the session. It cannot inspect or audit text that the model types into the running session. Codex emits no event for that call, so an adapter change cannot close this gap.
156
198
 
157
- The full residual-risk registry lives in [SECURITY.md](SECURITY.md); the practical consequences are on [Known Limitations](https://ccsafetynet.com/docs/guides/known-limitations).
199
+ [SECURITY.md](SECURITY.md) contains the full residual-risk registry. [Known Limitations](https://ccsafetynet.com/docs/guides/known-limitations) explains what those risks mean in practice.
158
200
 
159
201
  ## Upgrading from an older version
160
202
 
@@ -165,11 +207,11 @@ npx -y cc-safety-net@latest update
165
207
  ```
166
208
 
167
209
  > [!WARNING]
168
- > If you previously defined custom rules in a legacy inline config (`.safety-net.json` or `~/.cc-safety-net/config.json`), those files are **no longer loaded at runtime** and **their rules are not enforcing anything**. Nothing is blocked, so you will not notice this from normal use — the commands those rules used to block now run. Run `npx -y cc-safety-net rule migrate` to convert them to the rulebook layout, then `npx -y cc-safety-net doctor` to confirm the runtime is `ready`. See the [migration guide](https://ccsafetynet.com/docs/configuration/custom-rules#migrate-legacy-configuration).
210
+ > If you defined custom rules in a legacy inline config such as `.safety-net.json` or `~/.cc-safety-net/config.json`, CC Safety Net no longer loads those files at runtime. Their rules enforce nothing. Normal use does not show this failure because the commands now run. Run `npx -y cc-safety-net rule migrate` to convert the rules to the rulebook layout. Then run `npx -y cc-safety-net doctor` and confirm that the runtime is `ready`. See the [migration guide](https://ccsafetynet.com/docs/configuration/custom-rules#migrate-legacy-configuration).
169
211
 
170
212
  ## Full documentation
171
213
 
172
- All details live on the docs site at **[ccsafetynet.com/docs](https://ccsafetynet.com/docs)**:
214
+ The **[ccsafetynet.com/docs](https://ccsafetynet.com/docs)** site contains the full documentation:
173
215
 
174
216
  | Area | Pages |
175
217
  |---|---|
@@ -181,11 +223,12 @@ All details live on the docs site at **[ccsafetynet.com/docs](https://ccsafetyne
181
223
 
182
224
  ## Development
183
225
 
184
- See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this project.
226
+ See [CONTRIBUTING.md](CONTRIBUTING.md) to contribute to the project.
185
227
 
186
- The generated distribution is committed: all 11 files under `dist/` are tracked — the library
187
- bundle and its type declarations, the CLI entrypoint, the shared chunks, the vendored Zod copy,
188
- and the Pi, Amp and OpenClaw adapter files. Run `bun run verify:package` and
228
+ The repository tracks all 14 generated files under `dist/`. They include the library
229
+ bundle and its type declarations, the command-check API entry and its declaration, the CLI
230
+ entrypoint, the shared chunks, the vendored Zod copy,
231
+ and the Pi, Amp, and OpenClaw adapter files. Run `bun run verify:package` and
189
232
  `bun run verify:repository-plugin` when changing packaging, integrations, or release automation.
190
233
 
191
234
  ## License