Skip to content

Conversation

@prosdev
Copy link
Collaborator

@prosdev prosdev commented Dec 12, 2025

Overview

This PR lays the foundation for the Dashboard & Visualization epic by implementing comprehensive stats validation, change frequency tracking, and CLI utilities for comparison and export.

What Changed

1. Change Frequency Integration

  • ✅ Integrated git history analysis into getStats()
  • ✅ Enriched language stats with avgCommitsPerFile and lastModified
  • ✅ Enriched package stats with totalCommits and lastModified
  • ✅ Graceful degradation with warning when git unavailable
  • ✅ Created compareStats() utility for trend analysis
  • ✅ Created export utilities: JSON, CSV, Markdown
  • ✅ Relaxed metadata validation for non-URL git remotes
  • ✅ Mocked console errors in tests to prevent CI pollution

2. Kero Logger Integration

  • ✅ Added optional logger parameter to AsyncEventBus
  • ✅ Replaced console.* calls with structured kero logging
  • ✅ Graceful fallback when no logger provided
  • ✅ Added 3 comprehensive integration tests
  • ✅ Aligns with scanner/observability logging patterns

3. CLI Stats Subcommands

  • ✅ Restructured stats command with subcommands:
    • dev stats or dev stats show - Show current stats (default)
    • dev stats compare <before> <after> - Compare two snapshots
    • dev stats export --format json|csv|markdown - Export stats
  • ✅ Rich visual comparison with color-coded changes (↑ ↓ •)
  • ✅ Percentage changes and before/after values
  • ✅ Trend analysis (growing/shrinking/stable)
  • ✅ Human-readable duration formatting
  • ✅ Maintains backward compatibility

Example Usage

# View current stats
dev stats

# Export snapshot for comparison
dev stats export --format json --output stats-before.json

# After making changes...
dev stats export --format json --output stats-after.json

# Compare snapshots
dev stats compare stats-before.json stats-after.json

Comparison Output:

📊 Stats Comparison

Summary:
  Trend: Growing
  Languages added: rust

Overall Changes:
  Files:     ↑ +15 (+12.5%) [120 → 135]
  Documents: ↑ +42 (+10.2%) [412 → 454]
  Vectors:   ↑ +42 (+10.2%) [412 → 454]
  Time between snapshots: 2.3h

By Language (top changes):
  typescript: ↑ +12 files (+15.0%) [80 → 92]
  go: ↑ +3 files (+10.0%) [30 → 33]

Testing

  • 736 tests passing (including 3 new logger tests)
  • Core tests: 601 passing
  • CLI tests: 726 passing
  • ✅ All quality checks passing (lint, typecheck, build)

Files Changed

Core:

  • packages/core/src/indexer/index.ts - Change frequency integration
  • packages/core/src/indexer/utils/comparison.ts - Stats comparison logic (NEW)
  • packages/core/src/indexer/utils/export.ts - Export utilities (NEW)
  • packages/core/src/events/event-bus.ts - Kero logger integration
  • packages/core/src/events/__tests__/event-bus.test.ts - Logger tests

CLI:

  • packages/cli/src/commands/stats.ts - Restructured with subcommands
  • packages/cli/src/cli.test.ts - Updated structure tests

Breaking Changes

None - all changes are backward compatible. dev stats still works as before.

Next Steps

This PR sets the foundation for:

  1. SQLite Metrics Store (feat/sqlite-metrics-store) - Persistent time-series data
  2. Web Dashboard - Visualization of trends and insights
  3. Metrics API - RESTful access to historical data

Checklist

  • Follows TypeScript Standards (TYPESCRIPT_STANDARDS.md)
  • Follows Workflow (WORKFLOW.md)
  • All tests passing (736 tests)
  • Lint and typecheck passing
  • Backward compatible
  • Documentation updated
  • Commit messages follow conventional commits

Related

Part of the Dashboard & Visualization epic (see temp/dashboard-epic.md)

…cking

- Create comprehensive Zod schemas for all indexer stats types
- Add runtime validation for state loading/saving
- Implement change frequency tracking for dashboard
- Add avgCommitsPerFile and lastModified to LanguageStats
- Add totalCommits and lastModified to PackageStats
- 52 new tests (schemas + change frequency)
- All 577 core tests passing

Follows TYPESCRIPT_STANDARDS.md - eliminates type assertions with
runtime validation at external boundaries (state files).

Aligns with Dashboard & Visualization epic.
…ities

- Integrate change frequency into getStats() for enriched metrics
  - Language stats now include avgCommitsPerFile and lastModified
  - Package stats now include totalCommits and lastModified
  - Graceful degradation with console.warn when git unavailable
- Add compareStats() for trend analysis between snapshots
- Add export utilities (JSON, CSV, Markdown table)
- Relax RepositoryMetadata.remote validation (allow non-URL values)
- Mock console.error in event-bus test to prevent CI pollution

All 598 core tests passing with clean output.

Sets foundation for metrics store by:
- Enabling actual use of change frequency data
- Providing comparison capabilities for trends
- Supporting data export for dashboards
- Add optional logger parameter to AsyncEventBusOptions
- Use kero logger for all debug/error logging when provided
- Graceful fallback to console.* when no logger provided
- Add comprehensive logger integration tests

Benefits:
- Consistent structured logging across core components
- Proper log levels and error context
- Better test isolation with logger mocking
- Aligns with scanner/observability logging patterns

All 601 core tests passing (added 3 new tests).
- Restructure stats command to support subcommands:
  - 'dev stats' or 'dev stats show' - Show current stats (default)
  - 'dev stats compare <before> <after>' - Compare two stat snapshots
  - 'dev stats export [--format json|csv|markdown]' - Export stats

Features:
- Compare shows overall changes, trend analysis, and per-language/component diffs
- Export supports JSON, CSV, and Markdown table formats
- Rich visual comparison with color-coded changes and percentages
- Helper function for human-readable duration formatting

Benefits:
- Users can track codebase evolution over time
- Dashboard-ready data export for visualization
- Clean CLI UX with consistent formatting
- Maintains backward compatibility (stats show is default)

All 736 tests passing (including updated CLI structure tests).
@prosdev prosdev merged commit 1122431 into main Dec 12, 2025
1 check 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