feat: Add configurable stats mode with Git integration#17
feat: Add configurable stats mode with Git integration#17
Conversation
Add --mode flag with tree (default) and stats options: - Stats mode shows flat summary of change counts by type - Example: "Tracks: 2 Added, 1 Removed, 5 Modified" - Validates incompatibility with tree-specific flags Create lib/output/stats_renderer.ml module: - collect_view: recursively counts changes by domain_type - render: formats statistics as multi-line summary - display_name: provides plural labels (Tracks, Devices, etc.) Add test/test_stats_renderer.ml with 8 tests: - Empty/unchanged handling - Single/multiple change types - Non-reportable types excluded - Fixed ordering per reportable_types list - Deep nesting and zero count omissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…mit messages Add an interactive option to setup-git.sh that installs a prepare-commit-msg git hook using 'alsdiff --mode stats' to auto-generate commit message summaries from staged .als file changes. Co-Authored-By: Claude <noreply@anthropic.com>
…tering Refactor stats_renderer from hardcoded reportable_types list to config-driven type filtering via get_effective_detail. Stats mode now supports --config and --preset flags for customizing which types appear in statistics. Changes: - bin/alsdiff.ml: Extract build_base_renderer_config helper to eliminate duplicate config building logic between Stats and Tree modes - lib/output/config.ml: Add stats_default preset (7 historically tracked types) - lib/output/stats_renderer.ml: Replace reportable_types with stats_from_config, making render/collect/collect_view functions accept detail_config parameter - test/test_stats_renderer.ml: Update tests to pass stats_default config 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65c0cf5e73
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if config.output_mode = Stats && stats_incompatible_flags_provided config then begin | ||
| Fmt.epr "Error: --mode stats is incompatible with --prefix-*, \ | ||
| --note-name-style, and --max-collection-items@."; | ||
| 1 |
There was a problem hiding this comment.
Return git-mode argument errors with exit code 2
This branch returns 1 for a stats-mode argument error even when --git is active, which makes Git (trustExitCode) interpret the failure as "differences found" instead of an invalid invocation. In practice, alsdiff --git --mode stats --prefix-added ... will look like a real diff result rather than a configuration error, despite the command documentation in this file defining exit code 2 for invalid arguments. Return 2 in git mode for this path so misconfiguration is surfaced correctly.
Useful? React with 👍 / 👎.
|
|
||
| while IFS=$'"'"'\t'"'"' read -r status filepath; do | ||
| filename=$(basename "$filepath") | ||
| case "$status" in |
There was a problem hiding this comment.
Handle renamed .als files in commit-message hook
The generated hook only branches on M, A, and D, but git diff --cached --name-status can emit rename/copy statuses (for example R100\told.als\tnew.als). Those entries currently fall through and produce no summary text, so commits that rename .als files silently miss stats output for those changes. Add handling for R* (and ideally C*) statuses so commit summaries cover all staged .als changes.
Useful? React with 👍 / 👎.
Summary
Introduces a new stats mode output option that provides concise change statistics instead of full tree diffs, along with automated Git integration for
.alsfiles.Motivation
Current limitations:
.alsfiles requires manual configuration of.gitattributes.alschanges must be manually written or copy-pasted from diff outputWhat this PR solves:
.alschangesChanges Overview
🆕 New Stats Mode
lib/output/stats_renderer.ml(84 lines)--mode statstest/test_stats_renderer.ml(165 lines, 8 tests)Example output:
⚙️ Configurable Type Filtering
Refactored from hardcoded
reportable_typeslist to config-driven filtering viaget_effective_detail()Added
stats_defaultpreset inlib/output/config.mlwith 7 historically tracked types:🐙 Automated Git Integration
New script:
scripts/setup-git.sh(111 lines)Features:
.gitattributesconfiguration for.alsfiles📝 Prepare-commit-msg Hook
Auto-generates commit message summaries using
alsdiff --mode statson staged.alsfiles🔧 Code Refactoring
render_viewsfrombin/alsdiff.ml→lib/output/text_renderer.mlbuild_base_renderer_config()helper to eliminate duplicate config building logicFiles Changed
bin/alsdiff.mllib/output/config.mlstats_defaultpresetlib/output/stats_renderer.mllib/output/text_renderer.mlrender_viewsfunctionscripts/setup-git.shtest/test_stats_renderer.mlTotal: 8 files changed, 527 insertions(+), 80 deletions(-)
Usage Examples
Testing
✅ All tests pass: 8 new tests + existing tests unaffected
Backwards Compatibility
✅ No breaking changes: Tree mode remains default, new
--modeflag is optional