Skip to content

feat: deep runtime optimization — parser, gates, Layer 3, reflective log#13

Merged
VictorVVedtion merged 5 commits intomasterfrom
feat/deep-optimization
Mar 15, 2026
Merged

feat: deep runtime optimization — parser, gates, Layer 3, reflective log#13
VictorVVedtion merged 5 commits intomasterfrom
feat/deep-optimization

Conversation

@VictorVVedtion
Copy link
Owner

Summary

  • CLAUDE.md parser — structured extraction (standard headers) + fallback (prose-style), with parse_source field for consumer trust decisions
  • 5th gate (RECALL) — verifies BOUND constraints are accessible and parseable, not just present
  • Layer 3 verification — triggers human review on DANGER ZONE contact, 3+ consecutive RETRYs, architectural complexity, gate failures
  • Three-layer reflective log — WHAT/WHY/PATTERN structured JSONL entries, behavioral pattern detection (stuck loops, velocity trends, hot files), actionable alerts
  • 4 edge case fixes — DZ path-segment matching (no more auth matching unauthorized.py), velocity sensitivity (6+ entries required), overall WARN for unconfigured projects, bound_defined auto-refresh
  • Hooks — new momentum-gate.sh, recursive CLAUDE.md search in bound-guard/recall-gate, registered in settings.json.template
  • CI — ruff lint + format, bandit security scan, pytest-cov with 70% threshold
  • Tests — 247 → 415 (168 new tests across 4 files + 2 updated)

Dogfood validation

Ran Ouro Loop on itself (scan → init → verify → log → reflect). Found:

  1. Parser returned empty on own CLAUDE.md (prose format) → fixed with fallback
  2. Plan item P5 #24 was based on incorrect references → MAP stage caught it
  3. Fallback has noise (example dirs as DANGER ZONES) → parse_source field lets consumers decide trust level
  4. Layer 3 REVIEW correctly triggered when hook files were modified

Test plan

  • python -m pytest tests/ -v — 415 passed
  • ruff check framework.py prepare.py — all checks passed
  • ruff format --check framework.py prepare.py — formatted
  • Dogfood: framework.py verify . on own project — Layer 3, RECALL, fallback parser all functional
  • E2E behavioral testing — 4 edge cases found and fixed with regression tests
  • CI pipeline (ruff + bandit + coverage) — will validate on this PR

🤖 Generated with Claude Code

VictorVVedtion and others added 5 commits March 15, 2026 00:00
- Add parse_claude_md() with structured extraction + fallback for prose-style CLAUDE.md
- Add RECALL gate (5th gate, was missing from program.md spec)
- Add Layer 3 verification triggers (DANGER ZONE, consecutive RETRY, architectural complexity)
- Add detect_complexity() routing (trivial/simple/complex/architectural)
- Add three-layer reflective logging (WHAT/WHY/PATTERN) with JSONL persistence
- Add detect_patterns() for behavioral pattern detection (stuck loop, velocity trend)
- Fix DZ substring matching — now uses path-segment-aware matching
- Fix velocity trend sensitivity — requires 6+ entries and 0.3 threshold
- Fix overall=PASS when all gates WARN/SKIP — now correctly returns WARN
- Add bound_defined refresh in run_verification() — init snapshot no longer stale
- Extract shared BOUND constants (DRY), magic values, _get_claude_md_path() helper
- Move Counter import to top, add try-except for TSV writes
- Refactor prepare.py scan_project() into sub-functions (SRP)
- prepare.py now imports shared constants from framework.py
- danger_zones field in scan results now populated via parse_claude_md()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add momentum-gate.sh — tracks read/write ratio, warns on analysis paralysis
- Register momentum-gate.sh in settings.json.template (PostToolUse)
- Improve bound-guard.sh — recursive upward CLAUDE.md search (up to 5 levels)
- Improve recall-gate.sh — recursive search + remove head -50 limit
- Add ruff lint, ruff format, bandit security scan to CI
- Add pytest-cov with --cov-fail-under=70 to CI
- Add testpaths = ["tests"] to pyproject.toml

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- test_new_features.py (49): parse_claude_md, detect_complexity, Layer 3, RECALL gate, prepare integration
- test_reflective_log.py (45): three-layer log, pattern detection, JSONL persistence, print summary
- test_coverage_gaps.py (54): all previously untested code paths from gap analysis
- test_edge_case_fixes.py (19): DZ path-segment matching, velocity sensitivity, overall WARN, bound refresh
- Update test_framework.py + test_framework_extra.py for bound_defined refresh behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HIGH:
- bound-guard.sh: replace substring matching with path-segment-aware matching,
  consistent with Python-side _file_in_danger_zone() behavior
- Rename misleading test_contains_match → test_file_zone_segment_match_in_nested_path

MEDIUM:
- CI: --cov=framework --cov=prepare instead of --cov=. (exclude test files from coverage)
- Fix pseudo-assertion test_mild_variation_is_stable (was accepting two mutually exclusive results)
- Cache parse_claude_md() result in run_verification() and pass to sub-functions
  (eliminates 3 redundant file I/O + regex parses per verify call)
- Add shutil.move fallback for os.replace in write_reflective_log
  (handles cross-device mounts: Docker volumes, NFS)

LOW:
- Pin ruff version range in CI (>=0.8,<1.0) for reproducible builds

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HIGH:
- save_state() now uses atomic write (tmp + os.replace + shutil.move fallback),
  matching write_reflective_log() pattern — prevents state corruption on crash

MEDIUM:
- Surface parse_source field in check_bound() output — no longer dead data
- momentum-gate.sh: replace integer division with multiplication
  (READS >= WRITES*3 instead of READS/WRITES >= 3) to avoid truncation
- Replace conditional assertion in test_fail_takes_priority_over_review
  with deterministic mock — test now reliably catches regressions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@VictorVVedtion VictorVVedtion merged commit 139cb57 into master Mar 15, 2026
6 checks passed
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