cc-safety-net 0.8.2 → 0.9.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 +69 -16
- package/dist/bin/cc-safety-net.js +1775 -260
- package/dist/bin/doctor/hooks.d.ts +2 -0
- package/dist/bin/doctor/types.d.ts +5 -1
- package/dist/core/analyze/analyze-command.d.ts +10 -0
- package/dist/core/analyze/parallel.d.ts +4 -1
- package/dist/core/analyze/segment.d.ts +2 -2
- package/dist/core/analyze/xargs.d.ts +2 -0
- package/dist/core/path.d.ts +1 -0
- package/dist/core/rules-git.d.ts +14 -2
- package/dist/core/shell.d.ts +8 -2
- package/dist/core/worktree.d.ts +15 -0
- package/dist/index.js +1435 -107
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
[](#opencode-installation)
|
|
8
8
|
[](#gemini-cli-installation)
|
|
9
9
|
[](#github-copilot-cli-installation)
|
|
10
|
+
[](#codex-installation)
|
|
10
11
|
[](https://opensource.org/licenses/MIT)
|
|
11
12
|
|
|
12
13
|
<div align="center">
|
|
@@ -28,6 +29,7 @@ A Claude Code plugin that acts as a safety net, catching destructive git and fil
|
|
|
28
29
|
- [OpenCode Installation](#opencode-installation)
|
|
29
30
|
- [Gemini CLI Installation](#gemini-cli-installation)
|
|
30
31
|
- [GitHub Copilot CLI Installation](#github-copilot-cli-installation)
|
|
32
|
+
- [Codex Installation](#codex-installation)
|
|
31
33
|
- [Status Line Integration](#status-line-integration)
|
|
32
34
|
- [Setup via Slash Command](#setup-via-slash-command)
|
|
33
35
|
- [Manual Setup](#manual-setup)
|
|
@@ -48,6 +50,7 @@ A Claude Code plugin that acts as a safety net, catching destructive git and fil
|
|
|
48
50
|
- [Advanced Features](#advanced-features)
|
|
49
51
|
- [Strict Mode](#strict-mode)
|
|
50
52
|
- [Paranoid Mode](#paranoid-mode)
|
|
53
|
+
- [Worktree Mode](#worktree-mode)
|
|
51
54
|
- [Shell Wrapper Detection](#shell-wrapper-detection)
|
|
52
55
|
- [Interpreter One-Liner Detection](#interpreter-one-liner-detection)
|
|
53
56
|
- [Secret Redaction](#secret-redaction)
|
|
@@ -214,25 +217,31 @@ gemini extensions install https://github.com/kenryu42/gemini-safety-net
|
|
|
214
217
|
|
|
215
218
|
---
|
|
216
219
|
|
|
217
|
-
|
|
220
|
+
### Codex Installation
|
|
218
221
|
|
|
219
|
-
|
|
222
|
+
1. Enable Codex plugin hooks in `~/.codex/config.toml`:
|
|
220
223
|
|
|
221
|
-
|
|
224
|
+
```toml
|
|
225
|
+
[features]
|
|
226
|
+
plugin_hooks = true
|
|
227
|
+
```
|
|
222
228
|
|
|
223
|
-
|
|
229
|
+
2. Add the marketplace:
|
|
224
230
|
|
|
225
|
-
```
|
|
226
|
-
/
|
|
227
|
-
```
|
|
231
|
+
```bash
|
|
232
|
+
codex plugin marketplace add kenryu42/cc-marketplace
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
3. Start Codex.
|
|
236
|
+
4. In the TUI, run `/plugins`.
|
|
237
|
+
5. Use arrow keys to select `[cc-marketplace]`.
|
|
238
|
+
6. Press Enter to install the plugin.
|
|
228
239
|
|
|
229
|
-
|
|
230
|
-
1. Ask whether you prefer `bunx` or `npx`
|
|
231
|
-
2. Check for existing status line configuration
|
|
232
|
-
3. Offer to replace or pipe with existing commands
|
|
233
|
-
4. Write the configuration to `~/.claude/settings.json`
|
|
240
|
+
---
|
|
234
241
|
|
|
235
|
-
|
|
242
|
+
## Status Line Integration
|
|
243
|
+
|
|
244
|
+
Safety Net can display its status in Claude Code's status line, showing whether protection is active and which modes are enabled.
|
|
236
245
|
|
|
237
246
|
Add the following to your `~/.claude/settings.json`:
|
|
238
247
|
|
|
@@ -300,6 +309,7 @@ The status line displays different emojis based on the current configuration:
|
|
|
300
309
|
| Paranoid mode | `🛡️ Safety Net 👁️` | `SAFETY_NET_PARANOID=1` — all paranoid checks enabled |
|
|
301
310
|
| Paranoid RM only | `🛡️ Safety Net 🗑️` | `SAFETY_NET_PARANOID_RM=1` — blocks `rm -rf` even within cwd |
|
|
302
311
|
| Paranoid interpreters only | `🛡️ Safety Net 🐚` | `SAFETY_NET_PARANOID_INTERPRETERS=1` — blocks interpreter one-liners |
|
|
312
|
+
| Worktree mode | `🛡️ Safety Net 🌳` | `SAFETY_NET_WORKTREE=1` — relax local git discards inside linked worktrees |
|
|
303
313
|
| Strict + Paranoid | `🛡️ Safety Net 🔒👁️` | Both strict and paranoid modes enabled |
|
|
304
314
|
|
|
305
315
|
Multiple mode emojis are combined when multiple environment variables are set.
|
|
@@ -398,6 +408,7 @@ npx cc-safety-net explain --cwd /tmp "git status"
|
|
|
398
408
|
| rm -rf /var/tmp/... | System temp directory |
|
|
399
409
|
| rm -rf $TMPDIR/... | User's temp directory |
|
|
400
410
|
| rm -rf ./... (within cwd) | Limited to current working directory |
|
|
411
|
+
| git restore / checkout -- / reset --hard / clean -f (in linked worktree) | Relaxed only when `SAFETY_NET_WORKTREE=1` and cwd is a linked worktree |
|
|
401
412
|
|
|
402
413
|
## What Happens When Blocked
|
|
403
414
|
|
|
@@ -435,9 +446,9 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this
|
|
|
435
446
|
Beyond the built-in protections, you can define your own blocking rules to enforce team conventions or project-specific safety policies.
|
|
436
447
|
|
|
437
448
|
> [!TIP]
|
|
438
|
-
> Use
|
|
449
|
+
> Use the `set-custom-rules` skill to create custom rules interactively with natural language.
|
|
439
450
|
>
|
|
440
|
-
>
|
|
451
|
+
> If your agent does not support skills, prompt it with:
|
|
441
452
|
> ```text
|
|
442
453
|
> run npx cc-safety-net --custom-rules-doc and help me set up custom rules
|
|
443
454
|
> ```
|
|
@@ -585,7 +596,7 @@ Custom rules use **silent fallback** error handling. If your config file is inva
|
|
|
585
596
|
|
|
586
597
|
|
|
587
598
|
> [!IMPORTANT]
|
|
588
|
-
> If you add or modify custom rules manually, always validate them with `npx -y cc-safety-net --verify-config` or
|
|
599
|
+
> If you add or modify custom rules manually, always validate them with `npx -y cc-safety-net --verify-config` or the `verify-custom-rules` skill in your coding agent.
|
|
589
600
|
|
|
590
601
|
### Block Output Format
|
|
591
602
|
|
|
@@ -631,6 +642,48 @@ Paranoid behavior:
|
|
|
631
642
|
- **interpreters**: blocks interpreter one-liners like `python -c`, `node -e`, `ruby -e`,
|
|
632
643
|
and `perl -e` (these can hide destructive commands).
|
|
633
644
|
|
|
645
|
+
### Worktree Mode
|
|
646
|
+
|
|
647
|
+
Linked git worktrees are designed as disposable, isolated workspaces — discarding
|
|
648
|
+
changes inside one doesn't risk the main working tree. Worktree mode relaxes
|
|
649
|
+
local-discard rules when (and only when) the command is proven to run inside a
|
|
650
|
+
linked worktree:
|
|
651
|
+
|
|
652
|
+
```bash
|
|
653
|
+
export SAFETY_NET_WORKTREE=1
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
When enabled, these commands are allowed inside a linked worktree:
|
|
657
|
+
|
|
658
|
+
- `git restore <file>` and `git restore --worktree <file>`
|
|
659
|
+
- `git checkout -- <file>`, `git checkout <ref> -- <file>`, `git checkout --force`,
|
|
660
|
+
and ambiguous multi-positional checkout forms
|
|
661
|
+
- `git switch --discard-changes` and `git switch -f / --force`
|
|
662
|
+
- `git reset --hard` and `git reset --merge`
|
|
663
|
+
- `git clean -f` (and combined short flags like `-fd`)
|
|
664
|
+
|
|
665
|
+
These remain blocked even in linked worktrees because they reach beyond the
|
|
666
|
+
local working tree:
|
|
667
|
+
|
|
668
|
+
- `git push --force` (affects remote)
|
|
669
|
+
- `git branch -D` (affects shared refs)
|
|
670
|
+
- `git stash drop` / `git stash clear` (stash is shared across worktrees)
|
|
671
|
+
- `git worktree remove --force` (could delete another worktree)
|
|
672
|
+
|
|
673
|
+
Detection is fail-closed and mostly filesystem-based:
|
|
674
|
+
|
|
675
|
+
- A linked worktree is identified by a `.git` *file* containing `gitdir:` whose
|
|
676
|
+
resolved git directory contains a `commondir` file. Main worktrees and
|
|
677
|
+
submodules don't satisfy this and are not relaxed.
|
|
678
|
+
- The cwd walk uses `realpath` so symlinked paths resolve correctly.
|
|
679
|
+
- `git -C <path>` (including chained `-C` and attached `-Cpath`) is honored;
|
|
680
|
+
unresolved targets keep the command blocked.
|
|
681
|
+
- Relaxation is disabled if cwd becomes unknown (e.g., after `cd`/`pushd`),
|
|
682
|
+
if `--git-dir` / `--work-tree` is passed, or if `GIT_DIR` / `GIT_WORK_TREE`
|
|
683
|
+
/ `GIT_COMMON_DIR` is set in the environment.
|
|
684
|
+
- Git may be invoked from a trusted system path to inspect effective config that
|
|
685
|
+
could make submodule operations recursive.
|
|
686
|
+
|
|
634
687
|
### Shell Wrapper Detection
|
|
635
688
|
|
|
636
689
|
The guard recursively analyzes commands wrapped in shells:
|