Rules Module
Discovery, validation, scope, and sidecar symlink sync for the rules/
workspace — soft guidelines (markdown, prompt-style) and strong formal
constraints (yaml/json), distinct from projects/ (executable code) and
fonds/ (data resource pools).
Modules
| File |
Exports |
__init__.py |
RuleInfo, build_rule_info, discover_rules, resolve_rule_root, validate_rule_structure |
discovery.py |
discover_rules, resolve_rule_root, NON_RENDERED_RULE_SUBDIRS, RENDERED_RULE_SUBDIRS |
rules_info.py |
RuleInfo, build_rule_info |
validation.py |
validate_rule_structure |
public_scope.py |
PUBLIC_RULE_NAMES, public_rule_infos, public_rule_names |
linking.py |
sync_private_rule_links, private_rules_root, is_managed_symlink, LIFECYCLE_LINK_DIRS, LinkSyncResult |
Discovery and validation
from pathlib import Path
from infrastructure.rules import discover_rules, resolve_rule_root, validate_rule_structure, RuleInfo
# Discover all valid rules (skips working/, archive/)
rules: list[RuleInfo] = discover_rules(Path("."))
for r in rules:
print(r.qualified_name, r.rule_type, r.is_valid)
# Resolve by name
path = resolve_rule_root(Path("."), "templates/template_project_rules")
path = resolve_rule_root(Path("."), "template_project_rules") # bare name
# Validate structure (requires rules.yaml + soft/ or strong/)
is_valid, message = validate_rule_structure(Path("rules/templates/template_project_rules"))
RuleInfo dataclass
from infrastructure.rules import RuleInfo, build_rule_info
info = build_rule_info(Path("rules/templates/template_project_rules"))
info.name # "template_project_rules"
info.rule_type # "type" from rules.yaml, or "project"
info.has_soft # True iff soft/ exists
info.has_strong # True iff strong/ exists
info.is_valid # True iff has_soft or has_strong
info.qualified_name # "template_project_rules" or "program/name"
Public scope
from infrastructure.rules.public_scope import (
PUBLIC_RULE_NAMES, # ('templates/template_project_rules', 'templates/template_manuscript_rules')
public_rule_infos, # list[RuleInfo] present in checkout
public_rule_names, # list[str] sorted
)
Sidecar sync
from pathlib import Path
from infrastructure.rules.linking import (
sync_private_rule_links,
private_rules_root,
is_managed_symlink,
LinkSyncResult,
)
root = private_rules_root(Path(".")) # Path | None
result: LinkSyncResult = sync_private_rule_links(Path("."), dry_run=True)
print(result.summary())
# result.created / .updated / .removed / .skipped / .changed
CLI
uv run python -m infrastructure.rules.linking --dry-run
uv run python -m infrastructure.rules.linking
uv run python -m infrastructure.rules.linking --no-prune
uv run python -m infrastructure.rules.linking --private-root /path/to/rules
Rule structure contract
| Path |
Required? |
rules.yaml |
✅ manifest |
soft/ |
✅ or strong/ |
strong/ |
✅ or soft/ |
scripts/ |
optional |
tests/ |
optional |
examples/ |
optional |
Discovery scope constants
from infrastructure.rules.discovery import NON_RENDERED_RULE_SUBDIRS, RENDERED_RULE_SUBDIRS
# NON_RENDERED_RULE_SUBDIRS = frozenset({"working", "archive"})
# RENDERED_RULE_SUBDIRS = frozenset({"templates"})
Rule types
rule_type |
Domain |
project |
Entire project governance (default) |
manuscript |
Manuscript style, structure, content |
code |
Code quality, formatting, architecture |
data |
Data schema, validation, quality |
Environment variables
| Variable |
Purpose |
TEMPLATE_RULES_ROOT |
Override private rules root (highest precedence) |
TEMPLATE_SKIP_RULE_LINK_SYNC |
Set to skip auto-sync in orchestration CLI |
Safety invariants (linking.py)
- Real directories and unmanaged symlinks are never touched.
PROTECTED_NAMES (public exemplars from PUBLIC_RULE_NAMES) are always skipped.
- No-op and no error when the private sidecar is absent.
See also
AGENTS.md — full operating contract, boundaries, lifecycle layout
../fonds/SKILL.md — fonds module (same pattern, resource pools)
../project/SKILL.md — canonical project-layer skill
1---2name: infrastructure-rules3description: "Skill for the rules module — discovery, validation, scope, and private-sidecar symlink sync for the top-level rules/ directory (specifications include soft markdown guidelines and strong yaml/json formal constraints). Use when discovering rules (discover_rules), resolving a rule path (resolve_rule_root), validating rule structure (validate_rule_structure), building RuleInfo dataclasses (build_rule_info), checking PUBLIC_RULE_NAMES for CI-safe scope (public_scope.py), syncing private lifecycle rules into the template checkout (sync_private_rule_links / linking.py), checking whether a path is a managed rule symlink (is_managed_symlink), or adding new public rule exemplars. Distinct from projects/ (executable research code) and fonds/ (data resource pools); rules are passive specifications requiring rules.yaml + at least one of soft/ or strong/."4metadata:5 source: https://skillmd.com/skills/docxology/infrastructure-rules6---78# Rules Module910Discovery, validation, scope, and sidecar symlink sync for the `rules/`11workspace — soft guidelines (markdown, prompt-style) and strong formal12constraints (yaml/json), distinct from `projects/` (executable code) and13`fonds/` (data resource pools).1415## Modules1617| File | Exports |18|------|---------|19| `__init__.py` | `RuleInfo`, `build_rule_info`, `discover_rules`, `resolve_rule_root`, `validate_rule_structure` |20| `discovery.py` | `discover_rules`, `resolve_rule_root`, `NON_RENDERED_RULE_SUBDIRS`, `RENDERED_RULE_SUBDIRS` |21| `rules_info.py` | `RuleInfo`, `build_rule_info` |22| `validation.py` | `validate_rule_structure` |23| `public_scope.py` | `PUBLIC_RULE_NAMES`, `public_rule_infos`, `public_rule_names` |24| `linking.py` | `sync_private_rule_links`, `private_rules_root`, `is_managed_symlink`, `LIFECYCLE_LINK_DIRS`, `LinkSyncResult` |2526## Discovery and validation2728```python29from pathlib import Path30from infrastructure.rules import discover_rules, resolve_rule_root, validate_rule_structure, RuleInfo3132# Discover all valid rules (skips working/, archive/)33rules: list[RuleInfo] = discover_rules(Path("."))34for r in rules:35 print(r.qualified_name, r.rule_type, r.is_valid)3637# Resolve by name38path = resolve_rule_root(Path("."), "templates/template_project_rules")39path = resolve_rule_root(Path("."), "template_project_rules") # bare name4041# Validate structure (requires rules.yaml + soft/ or strong/)42is_valid, message = validate_rule_structure(Path("rules/templates/template_project_rules"))43```4445## RuleInfo dataclass4647```python48from infrastructure.rules import RuleInfo, build_rule_info4950info = build_rule_info(Path("rules/templates/template_project_rules"))51info.name # "template_project_rules"52info.rule_type # "type" from rules.yaml, or "project"53info.has_soft # True iff soft/ exists54info.has_strong # True iff strong/ exists55info.is_valid # True iff has_soft or has_strong56info.qualified_name # "template_project_rules" or "program/name"57```5859## Public scope6061```python62from infrastructure.rules.public_scope import (63 PUBLIC_RULE_NAMES, # ('templates/template_project_rules', 'templates/template_manuscript_rules')64 public_rule_infos, # list[RuleInfo] present in checkout65 public_rule_names, # list[str] sorted66)67```6869## Sidecar sync7071```python72from pathlib import Path73from infrastructure.rules.linking import (74 sync_private_rule_links,75 private_rules_root,76 is_managed_symlink,77 LinkSyncResult,78)7980root = private_rules_root(Path(".")) # Path | None81result: LinkSyncResult = sync_private_rule_links(Path("."), dry_run=True)82print(result.summary())83# result.created / .updated / .removed / .skipped / .changed84```8586## CLI8788```bash89uv run python -m infrastructure.rules.linking --dry-run90uv run python -m infrastructure.rules.linking91uv run python -m infrastructure.rules.linking --no-prune92uv run python -m infrastructure.rules.linking --private-root /path/to/rules93```9495## Rule structure contract9697| Path | Required? |98|------|-----------|99| `rules.yaml` | ✅ manifest |100| `soft/` | ✅ or `strong/` |101| `strong/` | ✅ or `soft/` |102| `scripts/` | optional |103| `tests/` | optional |104| `examples/` | optional |105106## Discovery scope constants107108```python109from infrastructure.rules.discovery import NON_RENDERED_RULE_SUBDIRS, RENDERED_RULE_SUBDIRS110# NON_RENDERED_RULE_SUBDIRS = frozenset({"working", "archive"})111# RENDERED_RULE_SUBDIRS = frozenset({"templates"})112```113114## Rule types115116| `rule_type` | Domain |117|-------------|--------|118| `project` | Entire project governance (default) |119| `manuscript` | Manuscript style, structure, content |120| `code` | Code quality, formatting, architecture |121| `data` | Data schema, validation, quality |122123## Environment variables124125| Variable | Purpose |126|----------|---------|127| `TEMPLATE_RULES_ROOT` | Override private rules root (highest precedence) |128| `TEMPLATE_SKIP_RULE_LINK_SYNC` | Set to skip auto-sync in orchestration CLI |129130## Safety invariants (linking.py)131132- Real directories and unmanaged symlinks are **never** touched.133- `PROTECTED_NAMES` (public exemplars from `PUBLIC_RULE_NAMES`) are always skipped.134- No-op and no error when the private sidecar is absent.135136## See also137138- [`AGENTS.md`](AGENTS.md) — full operating contract, boundaries, lifecycle layout139- [`../fonds/SKILL.md`](../fonds/SKILL.md) — fonds module (same pattern, resource pools)140- [`../project/SKILL.md`](../project/SKILL.md) — canonical project-layer skill