Skip to content
Back to skills

Custom Blocking Rules Compiler

ASecurity

Use when compiling custom blocking rules.

  • 2 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 10, 2026
ai-agentspythonperformance

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill custom-blocking-rules-compiler --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Custom Blocking Rules Compiler?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Custom Blocking Rules Compiler
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-custom-blocking-rules-compiler/badge)](https://www.skillsdirectory.com/skills/loopyluci-custom-blocking-rules-compiler)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: custom-blocking-rules-compiler
description: "Use when compiling custom blocking rules."
version: 1.0.0
author: Hermes Agent
license: MIT
metadata:
  hermes:
    tags: [blocking-rules, adblock, firewall-rules, ABP-format, rule-compiler]
    related_skills: [adblock-engine-core-patterns, firewall-rules-engine, url-content-filter, waf-web-application-firewall]
---

# Custom Blocking Rules Compiler

Compiling custom blocking rules for adblocking, firewall, and content filtering — from rule parsing and optimization through compiled rule formats and performance tuning.

## When to Use

- Building custom adblock or content filter rule sets
- Converting rules between formats (ABP → uBlock, Surge, Pi-hole)
- Optimizing rule matching performance with data structures
- Compiling human-readable rules into efficient matching formats

## Rule Compilation

```python
import re
from typing import List, Dict

class BlockingRule:
    """A single blocking rule in ABP/adblock format."""
    def __init__(self, pattern: str, options: Dict = None):
        self.pattern = pattern  # e.g., ||example.com/ads/*
        self.options = options or {}
        self.type = self._detect_type()
    
    def _detect_type(self) -> str:
        if self.pattern.startswith('||'): return 'domain'
        if self.pattern.startswith('|'): return 'exact_prefix'
        if self.pattern.endswith('|'): return 'exact_suffix'
        if '*' in self.pattern: return 'wildcard'
        if self.pattern.startswith('/') and self.pattern.endswith('/'): return 'regex'
        return 'substring'

class RuleCompiler:
    """Compile blocking rules into optimized matching structures."""
    def __init__(self):
        self.rules = []
    
    def add_rules(self, rules_text: str):
        for line in rules_text.strip().split('\n'):
            line = line.strip()
            if line and not line.startswith('!'):
                self.rules.append(BlockingRule(line))
    
    def compile_to_bloom(self) -> Dict:
        """Convert rules to bloom filter for fast pre-filtering."""
        domains = [r.pattern[2:] for r in self.rules if r.type == 'domain']
        return {'domains': domains, 'count': len(domains)}
    
    def optimize(self) -> int:
        """Merge and deduplicate rules."""
        patterns = set(r.pattern for r in self.rules)
        self.rules = [BlockingRule(p) for p in patterns]
        return len(self.rules)
```

## Verification Checklist

- [ ] Rules parsed from ABP-compatible format
- [ ] Rule types detected correctly (domain, wildcard, regex, exact)
- [ ] Rules compiled into optimized matching structure
- [ ] Deduplication and merging applied
- [ ] Performance benchmarked (rules/sec matching)
- [ ] False positive rate measured
- [ ] Export format supports target platform (Pi-hole, uBlock, AdGuard)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.