Skip to content

PR-03: Rules as data (scanner) - #26

Merged
emmanuelgjr merged 1 commit into
mainfrom
improve/pr-03-rules-as-data
Jul 18, 2026
Merged

PR-03: Rules as data (scanner)#26
emmanuelgjr merged 1 commit into
mainfrom
improve/pr-03-rules-as-data

Conversation

@emmanuelgjr

Copy link
Copy Markdown
Contributor

Phase 1 foundation. Extracts every detection pattern into reviewable, testable data. Depends on nothing; unblocks PR-04/05/11.

What's here

  • rules/dsgai-rules.yaml — all 106 patterns (P01.1–P21.4) extracted verbatim from dsgai_scanner_tool.md Step 2. v0.2 bugs are preserved on purpose so PR-11 fixes are clean diffs against a tested baseline.
  • rules/rules.schema.json — draft 2020-12 schema; the whole file validates.
  • rules/dsgai-rules.json — generated; the CLI loads it with stdlib only (no runtime PyYAML), preserving the one-file install story.
  • build/generate_rules.py — one-time extraction bootstrap (kept for audit/provenance).
  • build/build_rules_json.py — repeatable YAML→JSON build; --check gates CI so the JSON can't drift.
  • rules/README.md — field reference; CONTRIBUTING now links it; skill Step 2 carries a banner marking the YAML canonical.

Encoded compound logic (from the Step 2 prose)

  • subtract: P04.1 − P04.2 (torch.load( without weights_only=True).
  • requires_nearby: P11.1→P11.2 (±15), P18.4→P18.5 (±10), P20.5→P20.1/P20.2, P05.1→P05.2/P05.3 (module), P06.5→P06.2 (module, absent).
  • exclude_globs: P12.6 excludes migrations/fixtures/tests.
  • gated_on: P09.x multimodal, P10.x synthetic_data, P19.x labeling.
  • notes: absence-group rules (P07/P08/P16/P17) captured faithfully pending formalization.

Verification (all run locally)

  • Fidelity: all 106 PCREs appear byte-identical in the skill (0 drift).
  • Compilation: all 106 compile under rg --pcre2 (0 failures).
  • ID-set equality: rg -o 'P\d\d\.\d+' skill | sort -u == rule IDs in YAML (empty diff).
  • Schema: the plan's exact jsonschema.validate(...) acceptance command passes.
  • Classification: all DSGAI02/13/14/15 rules are value_bearing (21 total).
  • scanner-lint (yamllint + md-link-check) green locally.

Notes

  • remediation/references are left optional/unpopulated (Step 2 has no per-pattern remediation) — no fabrication; populated later.
  • Confidence/signal are seeded per Appendix B guidance; PR-11 refines them alongside the pattern fixes.

Extract all 106 patterns from dsgai_scanner_tool.md Step 2 into
rules/dsgai-rules.yaml as the source of truth. Patterns are copied VERBATIM
(v0.2 bugs preserved — fixes land in PR-11 as reviewable diffs); every PCRE
verified byte-identical to the skill and confirmed to compile under rg --pcre2.

- rules/rules.schema.json: draft 2020-12 schema; the full file validates.
- Encoded compound logic from the Step 2 prose: subtract (P04.1-P04.2),
  requires_nearby (P11.1/P18.4/P20.5/P05.1/P06.5), exclude_globs (P12.6),
  gated_on (multimodal/synthetic_data/labeling), plus notes for absence-group
  rules not yet fully formalized.
- Per-rule classification/signal/confidence seeded; all DSGAI02/13/14/15 rules
  are value_bearing (21 total).
- build/generate_rules.py: one-time extraction bootstrap (kept for audit).
- build/build_rules_json.py: repeatable YAML->JSON build (--check gates CI);
  the CLI loads the JSON with stdlib only, preserving the one-file install.
- rules/README.md documents the format; CONTRIBUTING now links it; skill Step 2
  banner marks the YAML canonical.

Acceptance: schema validation passes; rule-ID set == skill pattern-ID set
(diff empty); all four value-bearing controls carry classification:value_bearing.
@emmanuelgjr
emmanuelgjr merged commit ce6dbbb into main Jul 18, 2026
8 checks passed
@emmanuelgjr
emmanuelgjr deleted the improve/pr-03-rules-as-data branch July 18, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant