Add reference implementations for Steps 13-15#2
Conversation
12 new files providing runnable reference implementations for the defense-in-depth, testing, and procedure-encoding patterns documented in Steps 13-15: Layer 1 — PreToolUse hooks: - destructive-gate.py: blocks dangerous file/git/database operations - credential-scan.py: blocks hardcoded secrets (Azure/AWS/GCP patterns) Layer 2 — Pre-commit guardrails: - pre-commit: orchestrator script (chains all checks) - check_test_deletion.py: blocks test file deletion - check_assertion_ratchet.py: rejects assertion count decreases - generate_assertion_baseline.py: scans test files, builds JSON baseline Session scheduler: - scheduler.py: cross-platform (Windows + Unix) FIFO prompt scheduler - SCHEDULE.md: example schedule format Custom agents: - code-reviewer.md: confidence-filtered reviewer (>80% threshold) - security-analyzer.md: OWASP Top 10 scanner with customizable sections Skills: - session-wrap/SKILL.md: 5-phase session wrap-up template Configuration: - settings.local.json: full hook registration (all 5 hooks) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the reference implementations for the three-layer defense model, testing strategy, and procedure encoding, addressing a previous gap in practical examples for Steps 13-15. It provides a comprehensive set of new hooks, guardrails, agents, and skills, enabling more robust real-time enforcement, commit-time checks, and structured session management within the system. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive set of new guardrails, hooks, and agent definitions for the Claude Code project. Key additions include code-reviewer and security-analyzer agent definitions, pre-commit hooks for assertion count ratcheting and test file deletion prevention, and PreToolUse hooks for credential scanning and destructive command gating. A new scheduler.py hook manages scheduled tasks based on SCHEDULE.md, and a kb-session-wrap skill defines a structured session wrap-up procedure. The settings.local.json file has been updated to integrate these new hooks and ensure consistent python3 usage. Review comments point out inconsistencies in how test files are identified within check_assertion_ratchet.py and check_test_deletion.py, suggesting alignment with generate_assertion_baseline.py's logic. A minor consistency improvement is also suggested for the kb-session-wrap skill to use python3 for executing the assertion check script.
| normalized = line.strip().replace("\\", "/") | ||
| if normalized.endswith(".py"): | ||
| parts = normalized.split("/") | ||
| if any(p.startswith("test_") for p in parts): | ||
| files.append(normalized) |
There was a problem hiding this comment.
The logic for identifying test files in get_staged_test_files should align with how generate_assertion_baseline.py identifies them. Currently, any(p.startswith("test_") for p in parts) is too broad and might include non-test files or miss actual test files that are not directly under a tests/ directory but whose filename starts with test_.
generate_assertion_baseline.py explicitly scans PROJECT_ROOT / "tests" for files whose filename starts with test_ and ends with .py. This function should apply similar filtering to ensure consistency.
This inconsistency can lead to the assertion ratchet being applied to unintended files or failing to track legitimate test files.
| normalized = line.strip().replace("\\", "/") | |
| if normalized.endswith(".py"): | |
| parts = normalized.split("/") | |
| if any(p.startswith("test_") for p in parts): | |
| files.append(normalized) | |
| if normalized.startswith("tests/") and normalized.endswith(".py"): | |
| filename = Path(normalized).name | |
| if filename.startswith("test_"): | |
| files.append(normalized) |
| if any(p.startswith("test_") and p.endswith(".py") for p in parts): | ||
| deleted.append(normalized) |
There was a problem hiding this comment.
The logic for identifying test files in get_deleted_test_files should align with how generate_assertion_baseline.py identifies them. Currently, any(p.startswith("test_") and p.endswith(".py") for p in parts) is too broad and might include non-test files or miss actual test files.
generate_assertion_baseline.py explicitly scans PROJECT_ROOT / "tests" for files whose filename starts with test_ and ends with .py. This function should apply similar filtering to ensure consistency.
This inconsistency can lead to legitimate test files being deleted without being caught, or non-test files being incorrectly flagged.
| if any(p.startswith("test_") and p.endswith(".py") for p in parts): | |
| deleted.append(normalized) | |
| if normalized.startswith("tests/") and normalized.endswith(".py"): | |
| filename = Path(normalized).name | |
| if filename.startswith("test_"): | |
| deleted.append(normalized) |
|
|
||
| ### 1.2 Run Assertions | ||
| ```bash | ||
| python .claude/hooks/assertion-check.py |
There was a problem hiding this comment.
Summary
12 new runnable reference files that back the documentation added in PR #1. Previously, Steps 13-15 described the three-layer defense model, testing strategy, and procedure encoding — but the
reference/directory only shipped Layer 3 (SessionStart hook). This PR closes that gap.New files
Layer 1 — PreToolUse hooks (real-time enforcement):
reference/hooks/destructive-gate.py— blocks dangerous file, git, and database operations. Fail-closed design.reference/hooks/credential-scan.py— blocks hardcoded secrets. Configurable patterns for Azure, AWS, GCP (commented examples). Fail-open design.Layer 2 — Pre-commit guardrails (commit-time enforcement):
reference/guardrails/pre-commit— orchestrator bash script that chains all checksreference/guardrails/check_test_deletion.py— 100% generic, blocks test file deletionreference/guardrails/check_assertion_ratchet.py— rejects commits that decrease assertion countsreference/guardrails/generate_assertion_baseline.py— scans tests/, builds JSON baseline for the ratchetSession scheduler (deferred automation):
reference/hooks/scheduler.py— cross-platform (Windows msvcrt + Unix fcntl), FIFO prompt queuereference/hooks/SCHEDULE.md— example schedule with trigger typesCustom agents (on-demand review):
reference/agents/code-reviewer.md— confidence-filtered (>80%), severity-rated output formatreference/agents/security-analyzer.md— OWASP Top 10 table with[CUSTOMIZE]sectionsSkills (encoded procedures):
reference/skills/session-wrap/SKILL.md— 5-phase session wrap-up templateConfiguration:
reference/hooks/settings.local.json— updated from 2 hooks to all 5 (PreToolUse + SessionStart + UserPromptSubmit)Test plan
[CUSTOMIZE]markers for project-specific sections🤖 Generated with Claude Code