feat: add DRC recommendation contract + de-dup ledger#180
feat: add DRC recommendation contract + de-dup ledger#180labgadget015-dotcom wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
📊 Code Complexity AnalysisSummary:
|
| File | Function | Complexity | Line |
|---|---|---|---|
core/risk_scorer.py |
score_pull_request |
35 | 141 |
autopilot/autopilot.py |
generate_summary |
24 | 195 |
autopilot/staleness_engine.py |
process_stale_prs |
16 | 281 |
autopilot/ai_optimization/performance_monitor.py |
get_benchmark_stats |
15 | 184 |
.github/scripts/weekly_digest.py |
build_blocks |
15 | 38 |
autopilot/recommendation_contract.py |
validate |
14 | 48 |
.github/scripts/metrics_collector.py |
parse_workflow_metrics |
14 | 148 |
.github/scripts/setup_branch_protection.py |
main |
14 | 240 |
.github/scripts/self_healing_system.py |
analyze_failure_patterns |
14 | 256 |
.github/scripts/ai_code_suggestor.py |
_check_import_organization |
14 | 113 |
... and 17 more
Recommendations:
- Break down large functions into smaller, focused units
- Extract complex conditional logic into separate functions
- Use early returns to reduce nesting
🔧 Low Maintainability Files
These files have low maintainability scores and may need refactoring:
| File | Score | Status |
|---|---|---|
.github/scripts/health_dashboard_generator.py |
28.14 | 🔴 |
.github/scripts/workflow_monitor.py |
33.73 | 🔴 |
.github/scripts/ai_code_suggestor.py |
33.76 | 🔴 |
.github/scripts/ai_workflow_optimizer.py |
35.51 | 🔴 |
.github/scripts/performance_benchmark.py |
39.46 | 🔴 |
.github/scripts/self_healing_system.py |
40.27 | 🔴 |
.github/scripts/threshold_monitor.py |
41.13 | 🔴 |
.github/scripts/parallel_code_analyzer_optimized.py |
41.16 | 🔴 |
autopilot/autopilot.py |
42.45 | 🔴 |
autopilot/ai_optimization/anomaly_detector.py |
42.56 | 🔴 |
agents/triage_agent.py |
42.79 | 🔴 |
.github/scripts/refactoring_assistant.py |
43.03 | 🔴 |
autopilot/ai_optimization/intelligent_cache.py |
43.28 | 🔴 |
autopilot/ai_optimization/commit_summarizer.py |
44.05 | 🔴 |
.github/scripts/async_parallel_analyzer.py |
44.47 | 🔴 |
autopilot/ai_optimization/performance_monitor.py |
44.69 | 🔴 |
.github/scripts/badge_generator.py |
45.28 | 🔴 |
.github/scripts/copilot_integration.py |
45.37 | 🔴 |
.github/scripts/distributed_monitoring.py |
45.53 | 🔴 |
.github/scripts/elite_copilot.py |
45.69 | 🔴 |
agents/dependency_agent.py |
45.76 | 🔴 |
.github/scripts/cost_calculator.py |
46.4 | 🔴 |
.github/scripts/inline_pr_commenter.py |
46.63 | 🔴 |
.github/scripts/complexity_reporter.py |
46.78 | 🔴 |
.github/scripts/pr_triage.py |
47.13 | 🔴 |
core/risk_scorer.py |
48.15 | 🔴 |
autopilot/ai_optimization/nlp_relevance_filter.py |
48.43 | 🔴 |
.github/scripts/pr_inline_commenter.py |
48.47 | 🔴 |
autopilot/staleness_engine.py |
48.73 | 🔴 |
.github/scripts/metrics_collector.py |
48.91 | 🔴 |
.github/scripts/dependency_updater.py |
48.91 | 🔴 |
autopilot/ai_optimization/ml_priority_scorer.py |
49.53 | 🔴 |
.github/scripts/changelog_generator.py |
49.75 | 🔴 |
.github/scripts/parallel_code_analyzer.py |
49.96 | 🔴 |
autopilot/ai_optimization/api_optimizer.py |
50.46 | 🟡 |
.github/scripts/issue_auto_creator.py |
50.89 | 🟡 |
agents/security_scan_agent.py |
51.04 | 🟡 |
autopilot/tests/test_recommendation_contract.py |
51.18 | 🟡 |
.github/scripts/workflow_optimizer.py |
51.67 | 🟡 |
.github/scripts/cot_selector.py |
51.73 | 🟡 |
.github/scripts/release_manager.py |
51.92 | 🟡 |
.github/scripts/llm_router.py |
52.35 | 🟡 |
.github/scripts/auto_pr.py |
52.72 | 🟡 |
.github/scripts/notification_manager.py |
53.58 | 🟡 |
.github/scripts/prometheus_exporter.py |
54.96 | 🟡 |
.github/scripts/weekly_digest.py |
55.02 | 🟡 |
core/audit_logger.py |
55.6 | 🟡 |
.github/scripts/gather_context.py |
56.0 | 🟡 |
core/llm_provider.py |
56.32 | 🟡 |
.github/scripts/streaming_results.py |
56.64 | 🟡 |
.github/scripts/setup_branch_protection.py |
57.0 | 🟡 |
.github/scripts/optimized_github_client.py |
58.27 | 🟡 |
agents/orchestrator_agent.py |
59.02 | 🟡 |
agents/code_review_agent.py |
60.45 | 🟡 |
core/github_client.py |
61.96 | 🟡 |
core/message_queue.py |
63.22 | 🟡 |
core/agent_config.py |
63.86 | 🟡 |
core/idempotency.py |
64.45 | 🟡 |
Maintainability Index Guide:
- 🟢 85-100: Excellent maintainability
- 🟡 65-84: Good maintainability
- 🟠 50-64: Moderate maintainability (consider refactoring)
- 🔴 0-49: Poor maintainability (needs refactoring)
There was a problem hiding this comment.
Bandit found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
🟢 Risk Assessment: LOW (2.0/10)Analysed 8 files, 547+ / 0− lines. Test coverage unchanged or improved. Scoring breakdown
|
🔍 Pre-commit Checks🔧 Pre-commit issues were automatically fixed and committed. Please pull the latest changes before pushing again: git pull origin feat/recommendation-contractPre-commit hooks help maintain code quality and consistency. |
Code Quality Analysis ❌ FAILEDDuration: 0.02s Tool Results
View detailed results{
"timestamp": "2026-07-02 05:16:37",
"elapsed_seconds": 0.02,
"summary": {
"total_issues": 10,
"critical": 0,
"high": 0,
"medium": 0,
"low": 0
},
"tools": {
"pylint": {
"status": "failed",
"output": "",
"errors": "Pylint error: [Errno 2] No such file or directory: 'pylint'"
},
"flake8": {
"status": "failed",
"output": "",
"errors": "Flake8 error: [Errno 2] No such file or directory: 'flake8'"
},
"bandit": {
"status": "failed",
"output": "",
"errors": "Bandit error: [Errno 2] No such file or directory: 'bandit'"
},
"radon_cc": {
"status": "failed",
"output": "",
"errors": "Radon error: [Errno 2] No such file or directory: 'radon'"
},
"radon_mi": {
"status": "failed",
"output": "",
"errors": "Radon MI error: [Errno 2] No such file or directory: 'radon'"
}
},
"passed": false
} |
🤖 Elite AI Copilot AnalysisElite AI Copilot Analysis ReportGenerated: 2026-07-02 05:16:39 🎯 Health Score: 100.0/100🚀 Top Recommendations
📊 Detailed InsightsCode Quality Baseline Established
Security Scan Initiated
Repository Structure Analyzed
Performance Baseline Captured
Documentation Structure Good
Powered by Elite AI Copilot v1.0 |
🔒 Security Scan Results🛡️ Bandit Security Scan
📦 Dependency Vulnerabilities
Vulnerable Dependencies:
Security scans run automatically on every PR. View detailed reports in the Actions tab. |
There was a problem hiding this comment.
Pull request overview
Adds a recommendation “contract” + Slack message formatter + append-only decision ledger to reduce duplicate DRC recommendations and enforce basic triage metadata (owner/due/impact), alongside config/doc/test scaffolding for future wiring into the live loop.
Changes:
- Introduces
Recommendation+validate()contract enforcement for severity-dependent required fields and step constraints. - Adds a JSONL-based ledger with signature-based de-dup and status transitions, plus a Slack-oriented message formatter.
- Appends recommendation-related config blocks and adds a small test suite + README wiring notes.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| autopilot/recommendation_contract.py | Defines the recommendation dataclass and validation rules for the message contract. |
| autopilot/message_formatter.py | Renders validated recommendations into a consistent Slack-friendly template (or a reject block). |
| autopilot/decisions/ledger.py | Implements JSONL append-only ledger, de-dup decisioning (should_post) and lifecycle transitions. |
| autopilot/config.yaml | Appends config blocks intended to control debounce/status tags/contract settings. |
| autopilot/README.md | Documents the problem, contract, and intended integration sequence/snippets. |
| autopilot/tests/test_recommendation_contract.py | Adds smoke tests covering validation, ledger debounce, and formatting behavior. |
| autopilot/tests/init.py | Marks the new tests package. |
| autopilot/decisions/init.py | Marks the new decisions package. |
| if window is None: | ||
| return False, f"existing entry is {status} — never repost" | ||
|
|
||
| elapsed_h = (time.time() - existing.get("first_raised_ts", 0)) / 3600.0 |
| "due": r.due_date, | ||
| "severity": r.severity, | ||
| "headline": r.headline, | ||
| "first_raised": r.due_date, |
| # Headline must not be a raw run_id | ||
| if r.headline.strip().startswith(RUN_ID_TOKEN) or len(r.headline) < 8: | ||
| errs.append("headline must be an outcome, not a run_id") | ||
|
|
| from dataclasses import dataclass, field | ||
| from typing import Literal, Optional |
| } | ||
|
|
||
|
|
||
| def format(r: Recommendation) -> str: |
| # Drives the recommendation de-dup + closure loop. The DRC recommender | ||
| # reads these values before deciding whether to post to Slack. |
| """Smoke tests for recommendation_contract + ledger + formatter. | ||
|
|
||
| Run: python -m pytest autopilot/tests/test_recommendation_contract.py -q | ||
| or: python autopilot/tests/test_recommendation_contract.py |
Problem
The DRC bot in
#drc-recommendationsre-raised the same work items (e.g. "Smoke Test Harness") 5+ times in a week as brand-new P0s — each without an owner or a due date. Critical items (n8n key expiry) slipped for 8 days because nothing was ever named or dated. The channel behaved like a firehose instead of a triage queue.The contract enforced
This module adds an executive-grade message contract plus a de-dup ledger:
run_id (run_id lives in theRef:footer only).impact_if_ignoredfor P0/P1.due_datefor P0/P1.#morning-digestrather than posted to#drc-recommendations.action_verb|target_repo|file_or_workflow_path. Before posting,should_post()checks the append-only ledger and suppresses reposts inside a status-aware debounce window (open 72h, assigned/inflight 168h, done/dropped never).Files added
Note:
autopilot/config.yamlalready existed — the three new blocks (recommendation_debounce:,status_tags:,message_contract:) were appended to the existing file; the priorstaleness:config and repo list are untouched.Test status
9/9 passing locally and in-repo (stdlib only, no deps, Python 3.11+):
PYTHONPATH=autopilot python3 autopilot/tests/test_recommendation_contract.py # 9/9 passedCovers: valid recommendation, P0-without-owner rejection, missing impact, run_id-in-headline, oversize step, ledger debounce suppression, done-status blocks repost, formatter template render, formatter reject block.
Wiring notes
Integration is not wired into the live DRC loop in this PR — see
autopilot/README.mdfor the drop-in snippet: validate → escalate/withhold on failure →should_post()debounce →record()→slack_post(format(r)), with executor agents callingtransition()for lifecycle state.🤖 Generated with Claude Code