ai/opencode/tech-team/skills/rule-enforcement/SKILL.md
Programmatic rule enforcement with glob patterns, priority resolution, and pre/post validation. Use when checking compliance before or after agent actions.
npx skillsauth add akshay-na/dotfiles rule-enforcementInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill defines how agents programmatically discover, evaluate, and enforce rules. It provides a consistent mechanism for pre-action validation (before writes) and post-action validation (after writes), with priority resolution when rules conflict.
Rules use YAML frontmatter with these fields:
---
description: string # Required. What the rule does.
globs: string # File patterns (e.g., "**/*.sh", "**/*.ts,**/*.tsx")
alwaysApply: boolean # If true, applies regardless of globs (default false)
priority: number # 0-1000, higher wins on conflict (default 500)
enforcement: strict | advisory | informational # Default advisory
pre_action: boolean # Validate before agent writes (default false)
post_action: boolean # Validate after agent writes (default true)
override_by: string[] # Rules that can override this one
tags: string[] # For categorization and filtering
---
| Field | Required | Default | Description |
| ------------- | -------- | ---------- | -------------------------------------------------------- |
| description | yes | — | Clear explanation of rule purpose |
| globs | no | — | Comma-separated glob patterns for file matching |
| alwaysApply | no | false | If true, rule applies to all files regardless of globs |
| priority | no | 500 | Conflict resolution priority (0-1000) |
| enforcement | no | advisory | How strictly to enforce violations |
| pre_action | no | false | Run validation before file modifications |
| post_action | no | true | Run validation after file modifications |
| override_by | no | [] | List of rule names that can override this rule |
| tags | no | [] | Tags for filtering and categorization |
Rules are loaded from two locations, in order:
~/.config/opencode/rules/*.md (global defaults).opencode/rules/*.md (project overrides)For each .md file in rule directories:
1. Extract YAML frontmatter
2. Parse: description, globs, alwaysApply, priority, enforcement, pre_action, post_action, override_by, tags
3. Apply defaults from configurations/rule-priorities.yml where fields are missing
4. Add to rule index with source (org or project)
For each target file being modified or checked:
applicable_rules = []
for rule in all_rules:
if rule.alwaysApply:
applicable_rules.append(rule)
elif rule.globs:
for glob_pattern in rule.globs.split(','):
if file matches glob_pattern.trim():
applicable_rules.append(rule)
break
return applicable_rules
When the same rule name exists at both levels:
| Band | Range | Description | | ----------------- | -------- | ------------------------------------------------- | | Critical | 900-1000 | Security, error handling — must never be violated | | Standard | 400-600 | Conventions, style — should be followed | | Informational | 0-200 | Suggestions, best practices — nice to have |
When two rules conflict on the same aspect:
priority value takes precedenceoverride_by, rule A can override rule B regardless of prioritystrict enforcement wins over advisoryThe override_by field creates explicit override permissions:
# In shell-conventions.md
override_by: [local-overrides]
# This means local-overrides can override shell-conventions
# even if shell-conventions has higher priority
Run before any file modifications:
1. Identify all files that will be modified
2. Load all rules with pre_action: true
3. Match rules to target files by glob patterns
4. For each matched rule with enforcement: strict:
a. Evaluate rule against planned changes
b. If violation detected:
- Report violation with details
- STOP — do not proceed with writes
- Suggest fix or ask for guidance
5. For advisory/informational rules:
- Log potential violations
- Continue with writes
6. Return validation result
pre_action_result:
status: passed | violations_found | error
violations:
- rule: rule-name
files_affected: [file1.ts, file2.ts]
severity: strict
message: What would violate the rule
suggested_fix: How to modify the planned change
proceed: boolean # false if any strict violations
Run after file modifications:
1. Identify all files that were modified
2. Load all rules with post_action: true (default)
3. Match rules to modified files by glob patterns
4. For each matched rule:
a. Evaluate rule against file contents
b. Record any violations with severity
5. For strict violations:
- Attempt auto-fix if auto_fixable
- If not auto-fixable, report and request human intervention
6. For advisory violations:
- Log warning with context
- Document in response to user
7. Return validation result
post_action_result:
status: passed | violations_found | error
violations:
- rule: rule-name
file: path/to/file
line: 42
severity: strict | advisory | informational
message: What violated the rule
suggested_fix: How to fix it
auto_fixable: boolean
fixed: boolean # true if auto-fixed
rules_checked: [rule1, rule2, rule3]
files_validated: [file1.ts, file2.ts]
Each violation includes:
violations:
- rule: rule-name # Name of the violated rule
file: path/to/file # Full path to the file
line: number # Line number if applicable, null otherwise
severity: strict # strict | advisory | informational
message: "what violated" # Clear description of the violation
suggested_fix: "how to fix" # Actionable fix instruction
auto_fixable: boolean # true if agent can fix automatically
code_context: | # Optional: surrounding code for context
relevant code snippet
# Strict violation - security
- rule: error-handling-and-security
file: src/api/auth.ts
line: 45
severity: strict
message: Hardcoded secret detected in source code
suggested_fix: Move secret to environment variable and reference via process.env
auto_fixable: false
# Advisory violation - convention
- rule: shell-conventions
file: scripts/deploy.sh
line: 1
severity: advisory
message: Missing file header documentation block
suggested_fix: Add header block with Purpose and Usage sections
auto_fixable: true
# Informational violation - suggestion
- rule: stow-structure
file: newpkg/.config/tool/config.toml
line: null
severity: informational
message: Consider adding package to Makefile stow target list
suggested_fix: Update Makefile CONFIGS variable to include newpkg
auto_fixable: false
For violations marked auto_fixable: true:
| Fix Type | Description | Example |
| --------------------- | ----------------------------- | ------------------------ |
| format | Code formatting | Indentation, line length |
| import_order | Import statement ordering | Alphabetize imports |
| header | Add/update header comments | Shell file headers |
| trailing_whitespace | Remove trailing whitespace | Line cleanup |
| newline_eof | Ensure newline at end of file | File endings |
1. Read current file content
2. Determine fix type and location
3. Apply transformation:
- format: Run formatter if available, else skip
- import_order: Sort import blocks
- header: Insert standard header template
- trailing_whitespace: Strip trailing spaces
- newline_eof: Append newline if missing
4. Write updated content
5. Re-validate to confirm fix
6. Update violation record: fixed: true
Shell Header Template:
# ---------------------------------------------------------------
# [File Name]
# ---------------------------------------------------------------
# Purpose:
# - [Description]
#
# Usage:
# - [How to use]
# ---------------------------------------------------------------
Common Auto-Fixes:
set -eagent.validate_pre_action(target_files) ->
if violations.any?(strict):
report_violations()
fix_or_abort()
else:
proceed_with_writes()
agent.validate_post_action(modified_files) ->
for violation in violations:
if violation.auto_fixable:
apply_auto_fix(violation)
elif violation.severity == 'strict':
request_human_intervention(violation)
else:
log_violation(violation)
When proceeding despite advisory violations:
justification:
rule: shell-conventions
reason: "Legacy script maintained for compatibility; header format intentionally omitted"
approved_by: user | tech-lead | explicit-override
timestamp: 2026-04-04T10:00:00Z
Rules load configuration defaults from ~/.config/opencode/configurations/rule-priorities.yml:
1. Load configurations/rule-priorities.yml
2. Apply defaults.* to rules missing those fields
3. Apply rule_defaults.<rule-name>.* to specific rules
4. Apply overrides.* for explicit priority/enforcement changes
tags: [security, auth])development
Discovery + naming convention reference for typed dev/SME/QA/devops team members in any workspace folder. Primary consumer: `tech-lead` (org-tier).
devops
Automated task classification, agent selection, and state tracking. Use when routing tasks to agents, selecting pipelines, or managing task state.
testing
Use when designing scalable systems, evaluating consistency models, planning state management, making architectural decisions, or when trade-offs around coupling, failure isolation, and reversibility need explicit reasoning before implementation.
tools
CTO/tech-lead helper — split work into disjoint shard briefs with caps (instance_cap, partition_basis, determinism keys).