Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:40:52 +08:00
commit fedac466b2
14 changed files with 1133 additions and 0 deletions

42
commands/config.md Normal file
View File

@@ -0,0 +1,42 @@
---
description: View and configure code quality thresholds
---
# config
View and customize file size thresholds for different file types.
## Usage
```bash
# View current configuration
/guard:config
# Show available options
/guard:config help
```
## Configuration
Edit `.claude/quality_config.json` in your project root to customize thresholds.
## Example Configuration
```json
{
"default": 1000,
"extensions": {
".dart": 800,
".py": 800,
".ts": 800,
".tsx": 600,
".jsx": 600
}
}
```
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/show_config.py
```

42
commands/disable.md Normal file
View File

@@ -0,0 +1,42 @@
---
description: Temporarily disable a guardian
---
# disable
Temporarily disable specific guardians or all guardians. Changes persist until explicitly re-enabled.
## Usage
```bash
/guard:disable <guardian-name>
/guard:disable all
```
## Available Guardians
- `file-protection` - File blacklist protection
- `markdown-control` - Unsolicited markdown blocking
- `code-quality` - File size and TODO enforcement
- `generated-files` - Generated file protection
- `tool-guardian` - Package manager enforcement
- `package-guardian` - Package manifest warnings
## Examples
```bash
# Disable package manifest warnings
/guard:disable package-guardian
# Disable all guardians
/guard:disable all
# Disable file protection temporarily
/guard:disable file-protection
```
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/manage_overrides.py disable {{guardian-name}}
```

42
commands/enable.md Normal file
View File

@@ -0,0 +1,42 @@
---
description: Re-enable a disabled guardian
---
# enable
Re-enable specific guardians or all guardians that were previously disabled.
## Usage
```bash
/guard:enable <guardian-name>
/guard:enable all
```
## Available Guardians
- `file-protection` - File blacklist protection
- `markdown-control` - Unsolicited markdown blocking
- `code-quality` - File size and TODO enforcement
- `generated-files` - Generated file protection
- `tool-guardian` - Package manager enforcement
- `package-guardian` - Package manifest warnings
## Examples
```bash
# Re-enable package manifest warnings
/guard:enable package-guardian
# Re-enable all guardians
/guard:enable all
# Re-enable file protection
/guard:enable file-protection
```
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/manage_overrides.py enable {{guardian-name}}
```

64
commands/init.md Normal file
View File

@@ -0,0 +1,64 @@
---
description: Initialize Guard plugin with file protection and code quality features
---
# init
Initialize the Guard plugin by:
- Creating `.claude/forbidden_paths.txt` with default protected patterns
- Creating `.claude/file_guardian_config.json` with markdown blocking settings
- Creating `.claude/quality_config.json` with code quality thresholds
- Setting up hooks in `.claude/hooks.json`
- Making scripts executable
## Usage
```bash
/guard:init
```
## What Gets Created
1. **Blacklist File** (`.claude/forbidden_paths.txt`)
- Default patterns for sensitive files (.env, secrets/, *.key, etc.)
- Lock files (package-lock.json, yarn.lock, etc.)
- Git internals and build artifacts
2. **File Guardian Configuration** (`.claude/file_guardian_config.json`)
- Markdown blocking settings
- Allowed patterns for documentation
3. **Quality Configuration** (`.claude/quality_config.json`)
- Default file size thresholds for different extensions
- TODO/FIXME blocking settings
4. **Hooks** (`.claude/hooks.json`)
- PreToolUse hooks for Write/Edit/MultiEdit operations
- Merges with existing hooks from other plugins
5. **Script Permissions**
- Makes all hook scripts executable
## Default Protections
### File Protection
After initialization, Guard will automatically protect:
- Environment files (`.env`, `.env.*`)
- Secrets directory
- Credential files (`*.key`, `*.pem`, `*credentials*.json`)
- Lock files (`package-lock.json`, `pubspec.lock`, etc.)
- Git internals (`.git/`)
- Build artifacts (`build/`, `dist/`, `node_modules/`)
- Unsolicited markdown summaries (`SUMMARY.md`, `RECAP.md`)
### Code Quality
Guard will enforce:
- File size limits (800 lines for code, 600 for components, 5000 for docs)
- TODO/FIXME/HACK comment blocking
- Architectural best practices
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/init_plugin.py
```

36
commands/protect.md Normal file
View File

@@ -0,0 +1,36 @@
---
description: Add files or patterns to the protection blacklist
---
# protect
Protect files from accidental edits by adding them to the blacklist.
## Usage
```bash
/protect <pattern>
/protect list
```
## Examples
```bash
# Protect environment files
/protect .env
# Protect entire directory
/protect secrets/
# Protect by extension
/protect *.key
# Show current protections
/protect list
```
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/manage_blacklist.py add {{pattern}}
```

275
commands/split-markdown.md Normal file
View File

@@ -0,0 +1,275 @@
---
description: Split large markdown files into manageable sections with automatic navigation
---
# split-markdown
Intelligently split a large markdown file into context-friendly sections with automatic table of contents and navigation.
## Usage
```bash
# Split a specific markdown file
/guard:split-markdown <file-path>
# Examples
/guard:split-markdown task.md
/guard:split-markdown docs/PRD.md
/guard:split-markdown ./planning/requirements.md
```
## What It Does
When you split a markdown file, the Guard plugin will:
1. **Analyze Structure** - Parse the document to identify logical sections based on headers
2. **Propose Split** - Show you how the file will be divided before making changes
3. **Create Index** - Generate `00-<basename>.md` with table of contents and navigation
4. **Create Sections** - Generate numbered files (`01-`, `02-`, etc.) for each section
5. **Add Navigation** - Include bidirectional links between index and sections
6. **Backup Original** - Save the original file as `<filename>.backup`
## Output Structure
For a file named `task.md`, you'll get:
```
task.md.backup # Original file (backup)
00-task.md # Index with TOC
01-task.md # First section
02-task.md # Second section
03-task.md # Third section
...
```
### Index File (00-task.md)
Contains:
- Document title
- Table of contents with links to all sections
- Quick navigation statistics (total sections, line counts)
- Overview explaining why the split was done
- Metadata (split date, strategy used)
### Section Files (01-task.md, 02-task.md, etc.)
Each section includes:
- Section title
- Navigation header (links to index, previous, next)
- Full section content (preserved formatting)
- Navigation footer (same links as header)
## Configuration
The splitting behavior is controlled by `.claude/quality_config.json`:
```json
{
"markdown_splitter": {
"enabled": true,
"auto_suggest_threshold": 2000,
"target_chunk_size": 800,
"split_strategy": "headers",
"preserve_original": true,
"create_index": true
}
}
```
### Configuration Options
- **`auto_suggest_threshold`** (default: 2000)
- Line count threshold for automatic split suggestions
- When a markdown file exceeds this, Guard will offer to split it
- **`target_chunk_size`** (default: 800)
- Target lines per section (used with "smart" strategy)
- Helps keep sections at manageable sizes
- **`split_strategy`** (default: "headers")
- `"headers"` - Split at each top-level header (# title)
- `"smart"` - Group sections to target chunk size while respecting boundaries
- **`preserve_original`** (default: true)
- Keep backup of original file as `<filename>.backup`
- Set to false to remove original after split
- **`create_index`** (default: true)
- Generate `00-<basename>.md` index file
- Set to false to only create section files
## Split Strategies
### Headers Strategy (Default)
Splits at every top-level header (`# Title`):
**Pros:**
- Preserves logical document structure
- Sections are semantically meaningful
- Easy to understand split points
**Cons:**
- May create uneven section sizes
**Best for:**
- Well-structured documents with clear top-level sections
- PRDs, design docs, technical specifications
### Smart Strategy
Groups sections to target chunk size while respecting header boundaries:
**Pros:**
- More consistent section sizes
- Still respects logical boundaries
- Better for documents with many small sections
**Cons:**
- May group unrelated content together
**Best for:**
- Documents with many small sections
- Task lists with many items
- API documentation with many endpoints
## Examples
### Example 1: Large PRD Document
```bash
/guard:split-markdown requirements.md
```
**Before:**
```
requirements.md (3500 lines)
# Overview
# User Stories
# Technical Requirements
# Architecture
# Testing Strategy
```
**After:**
```
requirements.md.backup
00-requirements.md (index)
01-requirements.md (Overview - 400 lines)
02-requirements.md (User Stories - 900 lines)
03-requirements.md (Technical Requirements - 1100 lines)
04-requirements.md (Architecture - 700 lines)
05-requirements.md (Testing Strategy - 400 lines)
```
### Example 2: Implementation Task List
```bash
/guard:split-markdown tasks.md
```
**Before:**
```
tasks.md (4200 lines)
# Backend Tasks
## API Endpoints (many subtasks)
## Database Schema (many subtasks)
# Frontend Tasks
## Components (many subtasks)
## Pages (many subtasks)
```
**After:**
```
tasks.md.backup
00-tasks.md (index)
01-tasks.md (Backend Tasks - 2100 lines)
02-tasks.md (Frontend Tasks - 2100 lines)
```
### Example 3: API Documentation
```bash
/guard:split-markdown api-docs.md
```
With `"split_strategy": "smart"` in config:
**Before:**
```
api-docs.md (5000 lines)
# Authentication
# User Endpoints (50+ endpoints)
# Data Endpoints (40+ endpoints)
# Admin Endpoints (30+ endpoints)
```
**After:**
```
api-docs.backup
00-api-docs.md (index)
01-api-docs.md (Authentication - 600 lines)
02-api-docs.md (User Endpoints Part 1 - 800 lines)
03-api-docs.md (User Endpoints Part 2 - 850 lines)
04-api-docs.md (Data Endpoints Part 1 - 800 lines)
05-api-docs.md (Data Endpoints Part 2 - 750 lines)
06-api-docs.md (Admin Endpoints - 700 lines)
```
## When to Use
Split a markdown file when:
- 📄 **File exceeds 2000 lines** - May hit LLM context limits
- 🔍 **Hard to navigate** - Takes too long to find sections
-**Performance issues** - Editor or tools slow down with large file
- 👥 **Team collaboration** - Easier to work on separate sections
- 📝 **Documentation** - Better organization for large docs
## Integration with Guard
The markdown splitter integrates with Guard's file size checking:
1. When you try to write a large markdown file (>2000 lines)
2. Guard detects it exceeds the threshold
3. Guard offers: "This file is large. Would you like to split it?"
4. If you say "yes", the markdown-splitter agent is automatically launched
5. The agent analyzes, proposes a split, and executes with your approval
This provides **proactive** splitting suggestions without manual command invocation.
## Implementation
This command launches the **markdown-splitter agent** with the specified file:
```bash
# The agent will:
# 1. Read and analyze the file structure
# 2. Present a proposed split plan
# 3. Ask for confirmation
# 4. Execute the split using split_markdown.py
# 5. Verify results and report success
```
## Tips
1. **Review before splitting** - Always check the proposed split plan
2. **Adjust strategy** - Switch between "headers" and "smart" for different results
3. **Update references** - If other files link to the original, update them
4. **Commit original first** - Use git to track changes before splitting
5. **Test navigation** - After splitting, click through a few section links
## Related Commands
- `/guard:config` - View and configure splitting thresholds
- `/guard:init` - Initialize Guard with default configuration
## See Also
- **markdown-splitter agent** - The AI agent that performs the analysis and splitting
- **split_markdown.py** - The underlying Python script
- `.claude/quality_config.json` - Configuration file
---
**Need help?** The markdown-splitter agent will guide you through the process and explain each step.

43
commands/status.md Normal file
View File

@@ -0,0 +1,43 @@
---
description: View guardian status
---
# status
Display the current enabled/disabled state of all guardians.
## Usage
```bash
/guard:status
```
## What It Shows
For each guardian:
- Current status (enabled/disabled)
- Guardian name and description
- Configuration file location
## Example Output
```
🛡️ Guard Plugin - Guardian Status
🛡️ File Protection ✅ enabled
Prevents editing forbidden files (blacklist)
📄 Markdown Control ❌ disabled
Blocks unsolicited markdown summaries
📏 Code Quality ✅ enabled
Enforces file size limits and TODO blocking
...
```
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/show_status.py
```

33
commands/unprotect.md Normal file
View File

@@ -0,0 +1,33 @@
---
description: Remove files or patterns from the protection blacklist
---
# unprotect
Remove protection from files, allowing them to be edited.
## Usage
```bash
/unprotect <pattern>
/unprotect list
```
## Examples
```bash
# Unprotect a file
/unprotect .env.example
# Unprotect directory
/unprotect build/
# Show all protections
/unprotect list
```
## Implementation
```bash
${CLAUDE_PLUGIN_ROOT}/scripts/manage_blacklist.py remove {{pattern}}
```