chore: fix 67 ruff violations across SDK (unblock CI)#103
Conversation
…ompts
Two measured waste eliminations:
1. inject_brain_rules: mandatory_reminder block restated every mandatory
rule verbatim in a recency tag. mandatory_block already places them in
primacy position — the reminder was defensive redundancy costing
~50-200 tok/session per mandatory rule.
2. context_inject: MIN_MESSAGE_LEN raised 10 → 60 to skip brain FTS
search on trivial follow-ups ("ok", "yes", "continue"). Previous
threshold only filtered 1-9 char messages, causing ~400 tok of
wasted context per ack-style reply.
Council audit (adversarial, synthesized from Skeptic + Architect +
Pragmatist) found my earlier measurement methodology used synthetic
inputs that masked real per-operation costs. Real heavy session
(10 prompts, 30 edits, 5 agents) accumulates ~9.6K gradata tokens;
context_inject alone can contribute 3.5K when prompts are substantive.
Tests: 2884 passed, 1 preexisting cp1252 Windows unicode failure
in test_rule_to_hook (unrelated to injection).
Co-Authored-By: Gradata <noreply@gradata.ai>
…imits Rule_enforcement was re-injecting SessionStart rules on every Write/Edit, costing ~165 tok/edit for zero added primacy value. Default it off behind GRADATA_RULE_ENFORCEMENT=1 opt-in for ablation. Also add env knobs for tuning injection volume without redeploying: - context_inject: GRADATA_CONTEXT_INJECT kill switch + MIN_MESSAGE_LEN raised 60 -> 100 so ack-style replies skip FTS cost - inject_brain_rules: GRADATA_MAX_RULES, GRADATA_MIN_CONFIDENCE, GRADATA_MAX_META_RULES for tuning SessionStart payload Tests updated to opt into rule_enforcement where they exercise the hook and to use a >=100 char message for context_inject. Co-Authored-By: Gradata <noreply@gradata.ai>
Telemetry showed 10 SessionStart events in a long session re-injected 1.9KB each (~3.7k tokens total) — duplicative because the compact summary already carries rules from the prior session, and the new session's primacy slot is consumed by that summary. Skip inject_brain_rules when source is 'compact' or 'resume'. Opt back in with GRADATA_INJECT_ON_COMPACT=1 for ablation. Co-Authored-By: Gradata <noreply@gradata.ai>
…d metas
When a meta-rule is injected, its source_lesson_ids are added to a mutex
set; individual RULE/PATTERN leaves whose _lesson_id() is in that set are
skipped so the principle isn't double-injected as both the meta and its
concrete leaves.
Freed slots get refilled: rank_rules is now called with a 3x overshoot
so the render loop has candidates beyond the MAX_RULES cap; the cap is
enforced at render time (cluster_lines + individual_lines <= MAX_RULES)
rather than at rank time.
On current brain: 1822B -> 1319B per SessionStart (27% smaller), and
leaf categories diversify from {LEADS, DEMO_PREP, DRAFTING} to
{DRAFTING, TONE, DATA_INTEGRITY, ARCHITECTURE, CODE} while the LEADS +
DEMO_PREP principles still land via metas.
Opt-out: GRADATA_META_RULE_MUTEX=0 for ablation. Mirrors the existing
cluster-vs-meta mutex pattern (meta_covered_categories).
Co-Authored-By: Gradata <noreply@gradata.ai>
Fixes all ruff lint errors on main that were blocking CI: - F401 unused imports: add __all__ to self_improvement/__init__.py re-export hub - SIM105 try/except/pass -> contextlib.suppress in _file_lock.py - SIM102 collapse nested if in _graduation domain-filter path - SIM103 simplify boolean return in rule_enforcement.py - SIM117 combine nested `with` in _events._locked_append_many - RUF022 sort __all__ in rules/rule_engine/__init__.py (unsafe-fix) - TC001 move Lesson import into TYPE_CHECKING in rule_engine/_models.py - UP037 remove quotes from type annotations No behavior changes. 3670 tests pass; the flaky Windows cp1252 test_cli_export_writes_cursorrules remains pre-existing and unrelated. Co-Authored-By: Gradata <noreply@gradata.ai>
There was a problem hiding this comment.
Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (15)
💤 Files with no reviewable changes (8)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (2)src/gradata/**/*.py⚙️ CodeRabbit configuration file
Files:
src/gradata/hooks/**⚙️ CodeRabbit configuration file
Files:
🔇 Additional comments (10)
📝 WalkthroughRuff Lint Cleanup
WalkthroughThis PR performs code quality improvements across the gradata codebase: removing unused imports, refactoring context managers and exception handling, converting a runtime import to TYPE_CHECKING guards, adding explicit Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
* docs: v0.6.1 changelog entry covering post-v0.6.0 work through PR #114 Covers: gradata.patterns deprecation (remove in v0.8.0), Alert dedup (#109), Meta-Harness A-D, multi-tenant SDK (#102), BM25 JIT ranking (#101), gradata seed/mine CLI, rule_verifier wiring, security hardening, and 67+66 ruff-violation fixes (#100, #103). Co-Authored-By: Gradata <noreply@gradata.ai> * docs(changelog): qualify env-centralization claim CodeRabbit flagged that GRADATA_RULE_VERIFIER is still read directly in rule_pipeline.py. Weaken the claim rather than block on the migration. Co-Authored-By: Gradata <noreply@gradata.ai> --------- Co-authored-by: Gradata <noreply@gradata.ai>
Summary
Key changes
enhancements/self_improvement/__init__.py— add__all__to re-export hub (silences 45 F401)_file_lock.py—contextlib.suppress(OSError)replaces 2 try/except/pass_events.py— collapse nestedwith open / with platform_lockinto single-linerule_enforcement.py— simplify boolean return_graduation.py— combine nested if in domain filterrule_engine/_models.py— moveLessonimport intoTYPE_CHECKINGrule_engine/__init__.py— sort__all__Test plan
Generated with Gradata