Skip to content

Logging enhancements: rotation, stats, and documentation #28

Closed

Description

@admarble

Summary

Follow-up from #13. The core JSON logging is implemented, but some enhancements remain.

Remaining Work

Log Rotation

  • Implement log rotation when .sequant/logs/ grows large (> 10MB or > 100 files)
  • Add --rotate flag or automatic rotation
  • Consider compression of old logs

Stats Command

  • Add sequant stats command for aggregate analysis
    • Success/failure rates
    • Average phase duration
    • Most common failure points
  • Export to CSV option

Documentation

  • Document logging system in README or dedicated doc
  • Document log schema for external tooling
  • Add examples of parsing logs with jq

Current State

  • ✅ Per-run JSON files in .sequant/logs/<run-id>.json
  • ✅ sequant logs command to list and view runs
  • ✅ Logging enabled by default (autoDetectPhases: true in settings)
  • ✅ --no-log flag to disable for single run

Priority

Low - nice to have for power users

Activity

  1. admarble commented on Jan 9, 2026

    @admarble
    ContributorAuthor

    Implementation Plan for #28

    Acceptance Criteria

    AC Description Verification
    AC-1 Log rotation when .sequant/logs/ exceeds 10MB Unit Test
    AC-2 Log rotation when file count exceeds 100 Unit Test
    AC-3 --rotate CLI flag for manual rotation Integration Test
    AC-4 sequant stats command with aggregate analysis Unit Test + Manual
    AC-5 CSV export option for stats Unit Test
    AC-6 Document logging system in docs/logging.md Manual Review
    AC-7 Document JSON log schema for external tooling Manual Review
    AC-8 Provide working jq examples Manual Test

    Verification Criteria

    AC-1/AC-2 - Log Rotation:

    • Given: Log directory exceeds size/count threshold
    • When: New run completes OR --rotate is called
    • Then: Oldest logs deleted until under threshold

    AC-4 - Stats Command:

    • Given: Multiple run logs exist
    • When: sequant stats is run
    • Then: Shows success/failure rates, average phase durations, common failure points

    AC-5 - CSV Export:

    • Given: sequant stats --csv
    • Then: Valid CSV output with: runId, startTime, duration, issues, passed, failed, phases

    AC-8 - jq Examples:

    # List failed runs
    jq 'select(.summary.failed > 0)' .sequant/logs/*.json
    
    # Average duration
    jq -s 'map(.summary.totalDurationSeconds) | add / length' .sequant/logs/*.json
    
    # Common errors
    jq '.issues[].phases[] | select(.error) | .error' .sequant/logs/*.json | sort | uniq -c

    Implementation Phases

    Phase 1: Log Rotation

    1. Create src/lib/workflow/log-rotation.ts with rotation logic
    2. Add rotation settings to src/lib/settings.ts
    3. Integrate rotation into LogWriter.finalize()
    4. Add --rotate flag to sequant logs command
    5. Unit tests for rotation functions

    Phase 2: Stats Command

    1. Create src/commands/stats.ts with aggregate calculations
    2. Register sequant stats in bin/cli.ts
    3. Implement CSV export with --csv flag
    4. Unit tests for stats calculation

    Phase 3: Documentation

    1. Create docs/logging.md with system overview
    2. Add JSON schema reference
    3. Include jq examples section

    Settings Schema Addition

    {
      "run": {
        "rotation": {
          "enabled": true,
          "maxSizeMB": 10,
          "maxFiles": 100
        }
      }
    }

    Design Decisions

    Decision Choice Rationale
    Rotation strategy Delete (not compress) Simpler; compression can be added later
    Stats location New sequant stats command Clearer UX than logs --stats
    Auto-rotation Enabled by default Prevents unbounded log growth

    Effort Breakdown

    • Log Rotation: ~40% (new module + integration + tests)
    • Stats Command: ~35% (new command + CSV + tests)
    • Documentation: ~25% (new docs file + examples)

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: CLI feature with clear AC. No browser testing needed.

  2. admarble commented on Jan 9, 2026

    @admarble
    ContributorAuthor

    Spec Review: Verification Criteria & Implementation Plan

    Acceptance Criteria with Verification

    AC Description Verification Test Type
    AC-1 Log rotation when .sequant/logs/ exceeds 10MB Size threshold triggers deletion of oldest files Unit Test
    AC-2 Log rotation when file count exceeds 100 Count threshold triggers deletion of oldest files Unit Test
    AC-3 --rotate CLI flag for manual rotation Manual trigger with dry-run support Integration Test
    AC-4 sequant stats command with aggregate analysis Success/failure rates, phase durations, failure points Unit Test + Manual
    AC-5 CSV export option for stats Valid CSV with runId, startTime, duration, issues, passed, failed Unit Test
    AC-6 Document logging system in docs/logging.md Complete usage guide with examples Manual Review
    AC-7 Document JSON log schema for external tooling Schema reference matching implementation Manual Review
    AC-8 Provide working jq examples Commands execute successfully on real logs Manual Test

    Verification Criteria Details

    AC-1/AC-2 - Log Rotation:

    Given: Log directory exceeds size (>10MB) OR count (>100 files) threshold
    When: New run completes OR `sequant logs --rotate` is called
    Then: Oldest logs deleted until under threshold (with 10% buffer)
    

    AC-3 - Manual Rotation:

    Given: Log directory exists
    When: `sequant logs --rotate [--dry-run]`
    Then: Reports files deleted and space reclaimed (or would-be deleted in dry-run)
    

    AC-4 - Stats Command:

    Given: Multiple run logs exist in .sequant/logs/
    When: `sequant stats` is run
    Then: Shows:
      - Total runs analyzed
      - Success/failure rate (%)
      - Average phase durations
      - Most common failure points (phase + error pattern)
    

    AC-5 - CSV Export:

    Given: Run logs exist
    When: `sequant stats --csv`
    Then: Valid CSV output: runId,startTime,duration,issues,passed,failed,phases
    

    AC-8 - jq Examples:

    # List failed runs
    jq 'select(.summary.failed > 0)' .sequant/logs/*.json
    
    # Average duration
    jq -s 'map(.summary.totalDurationSeconds) | add / length' .sequant/logs/*.json
    
    # Common errors by phase
    jq '.issues[].phases[] | select(.error) | {phase, error}' .sequant/logs/*.json | sort | uniq -c

    Implementation Plan

    Phase 1: Log Rotation (AC-1, AC-2, AC-3)

    1. Add RotationSettings to src/lib/settings.ts:

      rotation: { enabled: true, maxSizeMB: 10, maxFiles: 100 }
    2. Create src/lib/workflow/log-rotation.ts:

      • getLogStats() - size/count analysis
      • rotateIfNeeded() - threshold check + rotation
      • Returns deleted files + space reclaimed
    3. Integrate into LogWriter.finalize() - auto-rotate after write

    4. Add --rotate flag to sequant logs command with --dry-run support

    5. Unit tests: src/lib/workflow/log-rotation.test.ts

    Phase 2: Stats Command (AC-4, AC-5)

    1. Create src/commands/stats.ts:

      • Aggregate analysis: success rates, phase durations, failure patterns
      • CSV export with --csv flag
    2. Register in bin/cli.ts with options: --csv, --path, --json

    3. Unit tests: src/commands/stats.test.ts

    Phase 3: Documentation (AC-6, AC-7, AC-8)

    1. Create docs/logging.md:
      • System overview + configuration
      • Stats command usage
      • JSON schema reference
      • jq examples section

    Design Decisions

    Decision Choice Rationale
    Rotation strategy Delete oldest (not compress) Simpler; compression deferred per issue
    Rotation buffer Stop at 90% of threshold Prevents immediate re-rotation
    Stats location Separate sequant stats command Cleaner UX vs logs --stats
    Auto-rotation Enabled by default Prevents unbounded log growth

    Open Questions

    1. Time filtering for stats - Defer --since/--last-n-days to future?

      • Recommendation: Yes, keep v1 simple
    2. Compression - Implement as alternative to deletion?

      • Recommendation: Defer per issue description

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: CLI feature with clear AC. Unit tests provide primary verification. No browser testing needed.


    Effort Breakdown

    • Log Rotation: ~40% (new module + integration + tests)
    • Stats Command: ~35% (new command + CSV + tests)
    • Documentation: ~25% (new docs file + examples)
  3. added
    documentation
    on Jan 9, 2026
  4. admarble commented on Jan 10, 2026

    @admarble
    ContributorAuthor

    Spec Review: Enhanced Verification Criteria & Implementation Plan

    Acceptance Criteria with Verification

    AC Description Verification Method Test Type
    AC-1 Log rotation when .sequant/logs/ exceeds 10MB Size threshold triggers deletion of oldest files until ≤9MB Unit Test
    AC-2 Log rotation when file count exceeds 100 Count threshold triggers deletion until ≤90 files Unit Test
    AC-3 --rotate CLI flag for manual rotation Manual trigger with --dry-run support Integration Test
    AC-4 sequant stats command with aggregate analysis Success/failure rates, phase durations, failure points Unit Test + Manual
    AC-5 CSV export option for stats Valid CSV: runId,startTime,duration,issues,passed,failed,phases Unit Test
    AC-6 Document logging system in docs/logging.md Complete usage guide with examples Manual Review
    AC-7 Document JSON log schema for external tooling Schema reference matching implementation Manual Review
    AC-8 Provide working jq examples Commands execute successfully on real logs Manual Test

    Verification Criteria Details

    AC-1/AC-2 - Log Rotation:

    Given: Log directory exceeds size (>10MB) OR count (>100 files) threshold
    When: LogWriter.finalize() completes OR `sequant logs --rotate` is called
    Then: Oldest logs deleted until under threshold (with 10% buffer)
    

    AC-3 - Manual Rotation:

    Given: Log directory exists
    When: `sequant logs --rotate [--dry-run]`
    Then: Reports files deleted and space reclaimed (or would-be in dry-run)
    

    AC-4 - Stats Command:

    Given: Multiple run logs exist in .sequant/logs/
    When: `sequant stats` is run
    Then: Shows:
      - Total runs analyzed
      - Success/failure rate (%)
      - Average phase durations (by phase type)
      - Most common failure points (phase + error pattern)
    

    AC-5 - CSV Export:

    Given: Run logs exist
    When: `sequant stats --csv`
    Then: Valid CSV with headers: runId,startTime,duration,issues,passed,failed,phases
    

    AC-8 - jq Examples:

    # List failed runs
    jq 'select(.summary.failed > 0)' .sequant/logs/*.json
    
    # Average duration
    jq -s 'map(.summary.totalDurationSeconds) | add / length' .sequant/logs/*.json
    
    # Common errors by phase
    jq '.issues[].phases[] | select(.error) | {phase, error}' .sequant/logs/*.json

    Implementation Plan

    Phase 1: Log Rotation (AC-1, AC-2, AC-3)

    Step File Description
    1A src/lib/settings.ts Add rotation: { enabled, maxSizeMB, maxFiles } to RunSettings
    1B src/lib/workflow/log-rotation.ts Create rotation module with getLogStats(), rotateIfNeeded()
    1C src/lib/workflow/log-writer.ts Integrate rotateIfNeeded() into finalize()
    1D src/commands/logs.ts Add --rotate and --dry-run flags
    1E src/lib/workflow/log-rotation.test.ts Unit tests for rotation logic

    Phase 2: Stats Command (AC-4, AC-5)

    Step File Description
    2A src/commands/stats.ts Create stats command with aggregate calculations
    2B bin/cli.ts Register sequant stats command
    2C src/commands/stats.test.ts Unit tests for stats calculations

    Phase 3: Documentation (AC-6, AC-7, AC-8)

    Step File Description
    3A docs/logging.md System overview, configuration, rotation policy
    3B docs/logging.md JSON schema reference
    3C docs/logging.md jq examples section

    Design Decisions

    Decision Choice Rationale
    Rotation strategy Delete oldest (not compress) Simpler; compression deferred per issue
    Rotation buffer Stop at 90% of threshold Prevents immediate re-rotation
    Stats location Separate sequant stats command Cleaner UX vs logs --stats
    Auto-rotation Enabled by default Prevents unbounded log growth
    File age determination File mtime (not filename parsing) More reliable

    Assumptions to Validate

    • Total size calculated from file stats (not directory size)
    • Only run-*.json files counted for rotation
    • CSV properly escapes special characters
    • Schema version documented (currently version: 1)

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: CLI feature with clear AC. Unit tests provide primary verification. No browser testing needed.


    Effort Breakdown

    • Log Rotation: ~40% (new module + integration + tests)
    • Stats Command: ~35% (new command + CSV + tests)
    • Documentation: ~25% (new docs file + examples)

    🤖 Generated with Claude Code via /spec 28

  5. added a commit that references this issue on Jan 10, 2026
  6. admarble commented on Jan 10, 2026

    @admarble
    ContributorAuthor

    Implementation Progress Update

    AC Coverage

    AC Description Status
    AC-1 Log rotation when .sequant/logs/ exceeds 10MB ✅ Complete
    AC-2 Log rotation when file count exceeds 100 ✅ Complete
    AC-3 --rotate CLI flag for manual rotation ✅ Complete
    AC-4 sequant stats command with aggregate analysis ✅ Complete
    AC-5 CSV export option for stats ✅ Complete
    AC-6 Document logging system in docs/logging.md ✅ Complete
    AC-7 Document JSON log schema for external tooling ✅ Complete
    AC-8 Provide working jq examples ✅ Complete

    Key Files Changed

    New Files:

    • src/lib/workflow/log-rotation.ts - Log rotation logic with size/count thresholds
    • src/lib/workflow/log-rotation.test.ts - 16 unit tests for rotation
    • src/commands/stats.ts - Stats command with aggregate analysis
    • src/commands/stats.test.ts - 9 unit tests for stats
    • docs/logging.md - Comprehensive documentation

    Modified Files:

    • bin/cli.ts - Register stats command
    • src/commands/logs.ts - Add --rotate and --dry-run flags
    • src/lib/settings.ts - Add RotationSettings interface
    • src/lib/workflow/log-writer.ts - Integrate auto-rotation

    Test Results

    ✓ 213 tests pass (9 test files)
    ✓ Build succeeds
    

    PR Status

    Created: #53

    Implementation Notes

    1. Rotation Buffer: Rotation stops at 90% of threshold to prevent immediate re-rotation on next run
    2. Auto-rotation: Enabled by default after LogWriter.finalize()
    3. File Age: Uses file mtime for determining oldest files (not filename parsing)
    4. Stats Output: Supports human-readable, JSON (--json), and CSV (--csv) formats

    🤖 Generated with Claude Code via /exec 28

  7. admarble commented on Jan 10, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #28

    AC Coverage

    AC Description Status Notes
    AC-1 Log rotation when .sequant/logs/ exceeds 10MB MET getFilesToDelete() checks exceedsSizeThreshold and deletes oldest files until ≤9MB (90% buffer).
    AC-2 Log rotation when file count exceeds 100 MET exceedsCountThreshold triggers rotation to 90 files. Unit tests verify behavior.
    AC-3 --rotate CLI flag for manual rotation MET logs.ts implements handleRotation() with --rotate and --dry-run flags.
    AC-4 sequant stats command with aggregate analysis MET Stats shows success/failure rates, phase durations, and common failure points.
    AC-5 CSV export option for stats MET --csv outputs valid CSV with required headers.
    AC-6 Document logging system in docs/logging.md MET 253-line doc covers configuration, rotation, stats, and schema.
    AC-7 Document JSON log schema for external tooling MET Complete TypeScript interfaces in documentation.
    AC-8 Provide working jq examples MET 8 practical jq examples included.

    Coverage: 8/8 AC items fully met


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 ✅ OK
    Deleted tests 0 ✅ OK
    Files changed 10 ✅ OK
    Lines added +1678 -
    Tests 213 pass ✅ OK
    Build Success ✅ OK

    Code Review Summary

    Strengths:

    • Clean separation: log-rotation.ts for rotation, stats.ts for statistics
    • 25 new tests (16 rotation + 9 stats)
    • 10% threshold buffer prevents re-rotation cycles
    • Thorough documentation with practical examples

    Issues: None identified


    Verdict: READY_FOR_MERGE ✅

    All 8 AC fully met with comprehensive test coverage. Implementation is clean, well-documented, and follows project patterns.


    🤖 Generated with Claude Code via /qa 28

  8. added
    ready-for-review
    on Jan 10, 2026
  9. added 2 commits that reference this issue on Jan 10, 2026
  10. added a commit that references this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions