Skip to content

chore: prune dead ledger functions + pre-commit import hygiene#203

Merged
labgadget015-dotcom merged 1 commit into
mainfrom
chore/ledger-cleanup-prec-imports
Jul 17, 2026
Merged

chore: prune dead ledger functions + pre-commit import hygiene#203
labgadget015-dotcom merged 1 commit into
mainfrom
chore/ledger-cleanup-prec-imports

Conversation

@labgadget015-dotcom

Copy link
Copy Markdown
Owner

Small, verified cleanup on top of #202.

Changes

  • autopilot/decisions/ledger.py: remove dead _append() and _next_seq() (both unused — record/transition go through _append_with_seq). Cuts 25 lines, removes a latent divergence risk.
  • autopilot/config_loader.py: pre-commit pyupgrade (Optional[X] -> X | None, drop redundant open mode).
  • autopilot/tests/test_recommendation_contract.py: blank-line import hygiene.

Verification

  • PYTHONPATH=autopilot python3 autopilot/tests/test_recommendation_contract.py -> 14/14 passed
  • pytest tests/unit -> 1001 passed, 0 failed
  • ruff check autopilot/decisions/ledger.py -> all checks passed

- Remove unused `_append()` and `_next_seq()` from decisions/ledger.py
  (record/transition both go through `_append_with_seq`; no live callers).
- config_loader.py: pyupgrade Optional[X] -> X | None, drop redundant
  open() mode arg (pre-commit auto-fix).
- test_recommendation_contract.py: blank-line import hygiene.

1001 unit tests pass; ruff clean on ledger.py.

Co-Authored-By: Hermes Agent <noreply@nous.sh>
Copilot AI review requested due to automatic review settings July 17, 2026 07:48
@labgadget015-dotcom
labgadget015-dotcom merged commit ff8e4f6 into main Jul 17, 2026
21 of 23 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📊 Code Complexity Analysis

Summary:

  • Total Functions Analyzed: 786
  • Average Complexity: 3.52
  • High Complexity Functions: 26
  • Low Maintainability Files: 55

⚠️ High Complexity Functions

These functions exceed the complexity threshold and should be refactored:

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 54
.github/scripts/workflow_monitor.py get_workflow_statistics 14 216
.github/scripts/ai_code_suggestor.py _check_import_organization 14 113
.github/scripts/prometheus_exporter.py collect_metrics 14 99
.github/scripts/metrics_collector.py parse_workflow_metrics 14 148

... and 16 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/tests/test_recommendation_contract.py 41.91 🔴
autopilot/autopilot.py 42.45 🔴
autopilot/ai_optimization/anomaly_detector.py 42.56 🔴
.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 🔴
.github/scripts/issue_auto_creator.py 46.39 🔴
.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/dependency_updater.py 48.91 🔴
.github/scripts/metrics_collector.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/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.33 🟡
.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 🟡
core/github_client.py 61.96 🟡
core/message_queue.py 63.22 🟡
core/agent_config.py 63.86 🟡
autopilot/decisions/ledger.py 63.92 🟡
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)

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Pre-commit Checks

🔧 Pre-commit issues were automatically fixed and committed.

Please pull the latest changes before pushing again:

git pull origin chore/ledger-cleanup-prec-imports

Pre-commit hooks help maintain code quality and consistency.

@github-actions

Copy link
Copy Markdown
Contributor

Code Quality Analysis ❌ FAILED

Duration: 0.01s
Total Issues: 10

Tool Results

  • pylint: ❌
  • flake8: ❌
  • bandit: ❌
  • radon_cc: ❌
  • radon_mi: ❌
View detailed results
{
  "timestamp": "2026-07-17 07:49:31",
  "elapsed_seconds": 0.01,
  "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
}

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Elite AI Copilot Analysis

Elite AI Copilot Analysis Report

Generated: 2026-07-17 07:49:31
Session ID: copilot_1784274571
Repository: .

🎯 Health Score: 100.0/100

🚀 Top Recommendations

  1. ✅ Repository is in excellent shape - continue current practices

📊 Detailed Insights

Code Quality Baseline Established

  • Category: code_quality
  • Severity: info
  • Description: Repository code quality metrics captured
  • Suggested Action: Continue monitoring for regressions
  • Confidence: 90%

Security Scan Initiated

  • Category: security
  • Severity: info
  • Description: No critical vulnerabilities detected in initial scan
  • Suggested Action: Enable continuous security monitoring
  • Confidence: 85%

Repository Structure Analyzed

  • Category: architecture
  • Severity: info
  • Description: Well-organized modular structure detected
  • Suggested Action: Maintain separation of concerns
  • Confidence: 80%

Performance Baseline Captured

  • Category: performance
  • Severity: info
  • Description: Repository performance metrics recorded
  • Suggested Action: Monitor for performance regressions
  • Confidence: 75%

Documentation Structure Good

  • Category: documentation
  • Severity: info
  • Description: Comprehensive documentation files present
  • Suggested Action: Keep documentation in sync with code changes
  • Confidence: 90%

Powered by Elite AI Copilot v1.0

@github-actions

Copy link
Copy Markdown
Contributor

🟢 Risk Assessment: LOW (0.0/10)

Analysed 3 files, 6+ / 30− lines. Test coverage unchanged or improved.

Scoring breakdown

Factor Score

✅ Eligible for auto-merge (subject to CI passing).

@github-actions

Copy link
Copy Markdown
Contributor

🔒 Security Scan Results

🛡️ Bandit Security Scan

  • 🔴 HIGH: 0
  • 🟡 MEDIUM: 4
  • 🟢 LOW: 100

📦 Dependency Vulnerabilities

  • Total vulnerable dependencies: 61

Vulnerable Dependencies:

  • pygithub 2.9.1
  • aiohttp 3.14.1
  • multidict 6.7.1
  • yarl 1.24.2
  • pyyaml 6.0.3
  • ... and 56 more

Security scans run automatically on every PR. View detailed reports in the Actions tab.

@labgadget015-dotcom

Copy link
Copy Markdown
Owner Author

🤖 DRC Agent Analysis

Recommendation: 🟠 P1 IMPORTANT

Summary: Automated Dead-Code Guardian Pipeline (Dreamer ID 2) — merge PR #203 as clean baseline, then add vulture + ruff (with UP and I rules) as required CI status checks, backed by a whitelist.py for intentional symbol retention

Next steps:

  1. Step 1: Merge PR chore: prune dead ledger functions + pre-commit import hygiene #203 immediately — all 1001 tests green, this is the clean baseline everything else depends on
  2. Step 2: Create .github/workflows/lint-deadcode.yml triggered on pull_request, running 'ruff check --select E,F,I,UP autopilot/' and 'vulture autopilot/ whitelist.py --min-confidence 80'
  3. Step 3: Run both commands locally against the post-merge codebase to capture all existing violations; fix ruff issues in a single batch commit and populate whitelist.py with any legitimate vulture false positives
  4. Step 4: Push lint-deadcode workflow to a feature branch and validate it passes cleanly before adding as a required status check
  5. Step 5: In GitHub Settings > Branches > main protection, add lint-deadcode as a required status check

Strategic fit: Consulting: high · Product: high · Tech debt: reduces


Analysed by GadgetLab DRC Agent (Dreamer → Realist → Critic) · Run run_1784274534588

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Cleanup follow-up to the config-driven ledger work from #202: removes unused internal helpers in the decisions ledger and applies pre-commit/pyupgrade hygiene to keep types and imports modern for the repo’s Python 3.11+ baseline.

Changes:

  • Prune unused _append() and _next_seq() helpers from autopilot/decisions/ledger.py to reduce divergence risk.
  • Modernize typing in autopilot/config_loader.py (Optional[T]T | None) and simplify open() call.
  • Fix import-spacing hygiene in autopilot/tests/test_recommendation_contract.py.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
autopilot/decisions/ledger.py Removes dead ledger helper functions; keeps seq assignment centralized in _append_with_seq().
autopilot/config_loader.py Updates type hints to modern union syntax and minor file-open cleanup.
autopilot/tests/test_recommendation_contract.py Adds blank line for import hygiene in the concurrent writer test.

Comment on lines 72 to 73
def _append_with_seq(entry: dict, path: str = DEFAULT_LEDGER_PATH) -> dict:
"""Atomic: assign seq under lock, then append. Prevents _next_seq races."""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autopilot Changes to autopilot/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants