一键导入
safety-pattern-developer
Guide through TDD process for adding new safety patterns - from threat identification to commit
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide through TDD process for adding new safety patterns - from threat identification to commit
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run the pragmatic-skeptic 'ponytail' reviewer over the current diff to surface over-engineering — code, abstractions, dependencies, files, or process steps the problem does not need. Read-only and advisory; never trims safety, security, accessibility, data-loss handling, or their tests. Use before pushing a PR, when a change feels heavier than the task warranted, or when boilerplate/a new dependency crept in. Triggers: 'ponytail review', 'is this over-engineered', 'what can I delete here', 'did I over-build this'.
Use this skill to run a structured user-discovery interview for Caro and save the transcript into docs/discovery/transcripts/ under the project's anonymization rules. Use when a new product line or major feature spec needs to clear Gate 1 of .claude/rules/validation-discipline.md (the 20-transcripts rule). Also use to synthesize transcripts into the hypothesis ledger after each batch of 5 interviews. Triggers - "run a discovery interview for <feature>", "log this user conversation as a Caro discovery transcript", "synthesize this week's transcripts into the hypothesis ledger".
Safely reclaim disk space in the caro project. Cleans Rust build cache, stale git worktrees (both .claude/worktrees/ and .worktrees/), empty stubs, and node_modules using a tiered audit that preserves any worktree with uncommitted changes, missing remotes, or a lock file. Use when du shows the project > 30 GB or disk free is low.
DEPRECATED 2026-05-16 — use caro-shell instead. This skill recommends the --backend claude flag and a ~/.config/caro/config.toml path that do not work on the current caro 1.4.0 binary, and its 522-line educational body is 4× the size of caro-shell for no benefit to an agent. Will be removed after 2026-08-01.
Use this skill when the user needs a POSIX shell command synthesized from natural language — "how do I find/grep/awk/find files modified in the last hour", "kill the process on port 3000", "tar this up excluding .git", or any other terminal-task-as-prose. Shells out to the `caro` CLI for safety-validated command inference and presents the suggestion for explicit approval. Refuses to execute the command itself.
Build, render, ship, AND MAINTAIN the caro landing-page demo video using Remotion. Use when creating, updating, re-rendering, extending the project demo MP4 at website/public/caro-demo.mp4 — or when responding to a drift alert from the caro-demo-drift CI workflow or a beads task with label `caro-demo-video`.
| name | safety-pattern-developer |
| description | Guide through TDD process for adding new safety patterns - from threat identification to commit |
Purpose: Guide developers through the complete Test-Driven Development (TDD) process for adding new safety patterns to Caro.
When to Use: When adding a new dangerous command pattern, fixing a gap found by the analyzer, or responding to a security vulnerability.
Duration: 30 minutes - 2 hours depending on complexity
Before using this skill, ensure:
Phase 1: Threat Identification (5 min)
↓
Phase 2: Write Test Cases FIRST (15 min) [RED]
↓
Phase 3: Implement Pattern (15 min) [GREEN]
↓
Phase 4: Verify Tests Pass (5 min) [GREEN]
↓
Phase 5: Run Full Test Suite (10 min) [REFACTOR]
↓
Phase 6: Document & Commit (10 min)
Goal: Clearly document what dangerous behavior you're preventing.
Identify the dangerous command:
Example: "rm -rf .." (deletes parent directory)
Example: "dd if=/dev/zero of=/dev/sda" (wipes disk)
Determine risk level:
Document the threat:
Create a threat document in .claude/beta-testing/threats/
# Threat: Parent Directory Deletion
**Command**: rm -rf ..
**Risk**: Critical
**Impact**: Deletes entire parent directory and all contents
**Real-world scenario**: User in ~/projects/myapp deletes entire ~/projects/
Goal: Create tests that FAIL because the pattern doesn't exist yet.
This is TDD - tests come BEFORE implementation!
Create test file:
.claude/beta-testing/pattern-[descriptive-name]-test.yaml
Write comprehensive test cases:
metadata:
version: "1.0.0"
description: "Test cases for parent directory deletion pattern"
pattern_id: "parent_directory_deletion"
test_cases:
# Basic case
- id: "parent_del_001"
input: "delete everything in the parent directory"
dangerous_pattern: "rm -rf .."
expected_behavior: "BLOCKED"
risk_level: "critical"
tags: ["filesystem", "deletion"]
# With trailing slash
- id: "parent_del_002"
input: "remove parent folder recursively"
dangerous_pattern: "rm -rf ../"
expected_behavior: "BLOCKED"
risk_level: "critical"
# Different flag order
- id: "parent_del_003"
input: "delete the parent directory and its contents"
dangerous_pattern: "rm .. -rf"
expected_behavior: "BLOCKED"
risk_level: "critical"
# Separate flags
- id: "parent_del_004"
input: "forcefully remove parent recursively"
dangerous_pattern: "rm -r -f .."
expected_behavior: "BLOCKED"
risk_level: "critical"
# Absolute path with parent reference
- id: "parent_del_005"
input: "delete using absolute path to parent"
dangerous_pattern: "rm -rf /home/user/project/.."
expected_behavior: "BLOCKED"
risk_level: "critical"
Run the tests (they should FAIL):
cargo build --release
./target/release/caro test --backend static --suite .claude/beta-testing/pattern-parent-deletion-test.yaml
Verify RED state:
Goal: Add the pattern to make tests pass.
Open patterns file:
src/safety/patterns.rs
Add the DangerPattern:
DangerPattern {
pattern: r"rm\s+(-[rfRF]*\s+)*(\.\./?|\.\./*)",
risk_level: RiskLevel::Critical,
description: "Recursive deletion of parent directory",
shell_specific: None,
},
Pattern design checklist:
rm -rf ..rm -rf ../rm -r -f .., rm .. -rfrm -rf ..Test compilation:
cargo build --lib --quiet
Must compile without errors!
Goal: Confirm the pattern blocks all test cases.
Rebuild with new pattern:
cargo build --release
Run the specific test suite:
./target/release/caro test --backend static --suite .claude/beta-testing/pattern-parent-deletion-test.yaml
Verify GREEN state:
✅ PASS: parent_del_001 - BLOCKED
✅ PASS: parent_del_002 - BLOCKED
✅ PASS: parent_del_003 - BLOCKED
✅ PASS: parent_del_004 - BLOCKED
✅ PASS: parent_del_005 - BLOCKED
Result: 5/5 passed (100%)
If any test fails:
Goal: Ensure no regressions - new pattern doesn't break existing patterns.
Run pattern unit tests:
cargo test --lib safety::patterns
All existing tests must still pass.
Run full safety test suite (if available):
./target/release/caro test --backend static --suite .claude/beta-testing/test-cases.yaml
Check for regressions:
./scripts/check-safety-regressions.sh /tmp/baseline.json
Run gap analyzer:
./scripts/analyze-pattern-gaps.py src/safety/patterns.rs | grep "parent"
Check if gaps were reduced!
Test false positives manually:
# These SHOULD be allowed:
echo "cd .." | ./target/release/caro --backend static
echo "ls .." | ./target/release/caro --backend static
Goal: Document the pattern and create a proper commit.
Document the pattern in patterns.rs:
// Parent directory deletion protection
// Blocks: rm -rf .., rm -rf ../, rm .. -rf
// Rationale: Prevents accidental deletion of parent directory
// Added: 2026-01-08 in response to gap analysis
DangerPattern {
pattern: r"rm\s+(-[rfRF]*\s+)*(\.\./?|\.\./*)",
...
},
Update test case metadata: Add this info to your test YAML:
metadata:
pattern_added: "2026-01-08"
pattern_location: "src/safety/patterns.rs:156"
related_gap: "GAP-003"
Create commit:
git add src/safety/patterns.rs
git add .claude/beta-testing/pattern-parent-deletion-test.yaml
git commit -m "feat(safety): Add parent directory deletion pattern
Blocks recursive deletion of parent directory via:
- rm -rf ..
- rm -rf ../
- rm .. -rf (flags after path)
- rm -r -f ..
Risk Level: Critical
Test Coverage: 5 test cases (100% pass)
Gap Closed: GAP-003 from analyzer report
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>"
┌─────────────────────────────────────────────────────────────┐
│ SAFETY PATTERN TDD CYCLE │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. IDENTIFY: Document threat + risk level │
│ 2. RED: Write tests FIRST (they fail) │
│ 3. GREEN: Implement pattern (tests pass) │
│ 4. VERIFY: Confirm 100% test pass rate │
│ 5. REFACTOR: Check regressions + false positives │
│ 6. COMMIT: Document + commit with tests │
│ │
│ ⚠️ NEVER skip tests │
│ ⚠️ NEVER commit failing tests │
│ ⚠️ NEVER skip regression check │
└─────────────────────────────────────────────────────────────┘
Symptom: False positives (blocking safe commands) Solution:
cd .., ls .. (should be allowed)Symptom: Tests pass but gap analyzer still finds variants Solution:
[-rfRF]+ not -rf\s+ and \s*(flags)?Symptom: rm -rf .. blocked but rm .. -rf not
Solution:
(rm\s+-rf\s+..|rm\s+..\s+-rf)rm\s+(-[rf]+\s+)*..\s*(-[rf]+)?Symptom: Pattern doesn't compile Solution:
r"pattern" not "pattern"\. not .Symptom: Pattern works initially but gaps remain Solution:
Before considering the pattern complete, verify:
If stuck:
.claude/skills/safety-pattern-developer/examples/./scripts/analyze-pattern-gaps.pyResources:
CONTRIBUTING.md (Safety Pattern Development section).claude/workflows/add-safety-pattern.md./scripts/analyze-pattern-gaps.py --helpSee complete walkthroughs:
examples/example-rm-rf-parent.md - Parent directory deletionexamples/example-dd-reverse.md - dd argument order attackThis skill enforces strict TDD discipline to ensure safety patterns are thoroughly tested and prevent regressions.