Overview
The file pkg/cli/logs.go has grown to 1,354 lines, significantly exceeding the healthy 800-line threshold. This makes it difficult to navigate, maintain, and test effectively. The file contains the core gh aw logs command implementation with multiple distinct functional areas that should be split into focused modules.
Current State
- File:
pkg/cli/logs.go
- Size: 1,354 lines (69% over threshold)
- Test Coverage: 1,646 lines of tests (1.22 ratio - excellent coverage to preserve!)
- Complexity: High - handles CLI command setup, GitHub API interactions, concurrent downloads, metrics extraction, output rendering, and workflow discovery
Functional Analysis
The file contains these distinct functional areas:
- CLI Command Setup (lines 121-282): Cobra command definition with extensive flags
- Core Download Orchestration (lines 283-689): Main
DownloadWorkflowLogs function with pagination logic
- Concurrent Download Operations (lines 690-948): Artifact downloading with progress tracking
- GitHub API Integration (lines 949-1089): Workflow run listing and job status fetching
- Output & Display (lines 1090-1272): Table rendering and metrics formatting
- Utility Functions (lines 1273-1354): Workflow name discovery and helper functions
Refactoring Strategy
Proposed File Splits
1. logs_command.go (CLI Command Definition)
Responsibility: Cobra command setup, flag definitions, and command entry point
Functions to move:
NewLogsCommand() (lines 121-282)
Estimated LOC: ~200 lines
Rationale: Separates the CLI interface layer from business logic
2. logs_orchestrator.go (Download Orchestration)
Responsibility: Main download workflow coordination, pagination, iteration logic
Functions to move:
DownloadWorkflowLogs() (lines 283-689)
Estimated LOC: ~450 lines
Rationale: Core orchestration logic is complex enough to warrant its own file
3. logs_download.go (Concurrent Download Operations)
Responsibility: Artifact downloading, concurrent processing, cache management
Functions to move:
downloadRunArtifactsConcurrent() (lines 690-948)
- Related download helper functions
Estimated LOC: ~300 lines
Rationale: Isolates concurrent operations and artifact handling logic
4. logs_github_api.go (GitHub API Integration)
Responsibility: GitHub API calls for workflow runs, jobs, and statuses
Functions to move:
listWorkflowRunsWithPagination() (lines 949-1089)
fetchJobStatuses() (lines 26-71)
fetchJobDetails() (lines 74-119)
Estimated LOC: ~250 lines
Rationale: Encapsulates all GitHub API interactions in one place
5. logs_display.go (Output & Rendering)
Responsibility: Table formatting, metrics display, console output
Functions to move:
displayLogsOverview() (lines 1090-1272)
Estimated LOC: ~200 lines
Rationale: Separates presentation logic from data operations
6. logs_utils.go (Utility Functions)
Responsibility: Helper functions for workflow discovery and common operations
Functions to move:
getAgenticWorkflowNames() (lines 1273-1332)
contains() (lines 1335-1342)
- Other utility functions
Estimated LOC: ~100 lines
Rationale: Keeps utilities separate and easily reusable
Shared Types & Constants
Create logs_types.go to hold:
- All struct definitions (WorkflowRun, ProcessedRun, DownloadResult, LogMetrics, etc.)
- Constants (BatchSize, MaxConcurrentDownloads, MaxIterations)
- The logger:
var logsLog = logger.New("cli:logs")
Estimated LOC: ~100 lines
Test Coverage Plan
The existing test file logs_test.go (1,646 lines) already provides excellent coverage. When splitting the file:
Testing Strategy
- Preserve Existing Tests: All 1,646 lines of existing tests remain valid
- Run Tests Frequently: After each file split, verify
make test-unit passes
- No Test Rewrite Needed: Since we're preserving public APIs, existing tests continue to work
Optional Test Organization
Consider splitting logs_test.go to match the new structure (optional, not required):
logs_command_test.go - Command flag parsing tests
logs_orchestrator_test.go - Main workflow tests
logs_download_test.go - Concurrent download tests
logs_github_api_test.go - API integration tests
logs_display_test.go - Output formatting tests
Target Coverage: Maintain current >80% coverage for all new files
Implementation Guidelines
Phase 1: Create Shared Types File
- Create
pkg/cli/logs_types.go
- Move all struct definitions, constants, and the logger
- Update imports in
logs.go
- Verify
make test-unit passes
Phase 2: Extract Utility Functions (Smallest Impact)
- Create
pkg/cli/logs_utils.go
- Move
getAgenticWorkflowNames(), contains() and other helpers
- Update imports
- Verify tests pass
Phase 3: Extract Display Logic
- Create
pkg/cli/logs_display.go
- Move
displayLogsOverview() and related rendering functions
- Verify tests pass
Phase 4: Extract GitHub API Layer
- Create
pkg/cli/logs_github_api.go
- Move all GitHub API interaction functions
- Verify tests pass
Phase 5: Extract Download Operations
- Create
pkg/cli/logs_download.go
- Move
downloadRunArtifactsConcurrent() and related functions
- Verify tests pass
Phase 6: Extract Orchestrator
- Create
pkg/cli/logs_orchestrator.go
- Move
DownloadWorkflowLogs() function
- Verify tests pass
Phase 7: Simplify Command File
- Verify
logs_command.go only contains NewLogsCommand()
- Rename
logs.go to logs_command.go (or keep as is)
- Final verification of all tests
Critical Rules
- Preserve Behavior: Ensure all existing functionality works identically
- Maintain Exports: Keep public API unchanged (
NewLogsCommand() and DownloadWorkflowLogs())
- Add Comments: Document module boundaries at the top of each new file
- Run Tests After Each Split: Verify
make test-unit passes after each phase
- Update Imports: Ensure all internal function calls work across new file boundaries
- Keep Logger Shared: Use the same
logsLog logger across all files via logs_types.go
Acceptance Criteria
Additional Context
- Repository Guidelines: Follow patterns in
AGENTS.md - prefer many smaller files grouped by functionality
- Code Organization: Review existing multi-file patterns in
pkg/workflow/ for consistency
- Testing: Match existing test patterns in
pkg/cli/*_test.go
- Console Output: All user-facing messages already use
console.Format*Message() helpers
Campaign Context
This refactoring is part of the go-file-size-reduction-20330678188 campaign to maintain a healthy, modular codebase.
Current Status:
- Date: 2025-12-18
- Largest File:
pkg/cli/logs.go (1,354 lines)
- Files Over Threshold: 21 files in the codebase exceed 800 lines
Priority: Medium
Effort: Large (7 files to create, extensive function moves, careful testing required)
Expected Impact: Significantly improved maintainability, easier navigation, clearer module boundaries, better testability
AI generated by Daily File Diet
Overview
The file
pkg/cli/logs.gohas grown to 1,354 lines, significantly exceeding the healthy 800-line threshold. This makes it difficult to navigate, maintain, and test effectively. The file contains the coregh aw logscommand implementation with multiple distinct functional areas that should be split into focused modules.Current State
pkg/cli/logs.goFunctional Analysis
The file contains these distinct functional areas:
DownloadWorkflowLogsfunction with pagination logicRefactoring Strategy
Proposed File Splits
1.
logs_command.go(CLI Command Definition)Responsibility: Cobra command setup, flag definitions, and command entry point
Functions to move:
NewLogsCommand()(lines 121-282)Estimated LOC: ~200 lines
Rationale: Separates the CLI interface layer from business logic
2.
logs_orchestrator.go(Download Orchestration)Responsibility: Main download workflow coordination, pagination, iteration logic
Functions to move:
DownloadWorkflowLogs()(lines 283-689)Estimated LOC: ~450 lines
Rationale: Core orchestration logic is complex enough to warrant its own file
3.
logs_download.go(Concurrent Download Operations)Responsibility: Artifact downloading, concurrent processing, cache management
Functions to move:
downloadRunArtifactsConcurrent()(lines 690-948)Estimated LOC: ~300 lines
Rationale: Isolates concurrent operations and artifact handling logic
4.
logs_github_api.go(GitHub API Integration)Responsibility: GitHub API calls for workflow runs, jobs, and statuses
Functions to move:
listWorkflowRunsWithPagination()(lines 949-1089)fetchJobStatuses()(lines 26-71)fetchJobDetails()(lines 74-119)Estimated LOC: ~250 lines
Rationale: Encapsulates all GitHub API interactions in one place
5.
logs_display.go(Output & Rendering)Responsibility: Table formatting, metrics display, console output
Functions to move:
displayLogsOverview()(lines 1090-1272)Estimated LOC: ~200 lines
Rationale: Separates presentation logic from data operations
6.
logs_utils.go(Utility Functions)Responsibility: Helper functions for workflow discovery and common operations
Functions to move:
getAgenticWorkflowNames()(lines 1273-1332)contains()(lines 1335-1342)Estimated LOC: ~100 lines
Rationale: Keeps utilities separate and easily reusable
Shared Types & Constants
Create
logs_types.goto hold:var logsLog = logger.New("cli:logs")Estimated LOC: ~100 lines
Test Coverage Plan
The existing test file
logs_test.go(1,646 lines) already provides excellent coverage. When splitting the file:Testing Strategy
make test-unitpassesOptional Test Organization
Consider splitting
logs_test.goto match the new structure (optional, not required):logs_command_test.go- Command flag parsing testslogs_orchestrator_test.go- Main workflow testslogs_download_test.go- Concurrent download testslogs_github_api_test.go- API integration testslogs_display_test.go- Output formatting testsTarget Coverage: Maintain current >80% coverage for all new files
Implementation Guidelines
Phase 1: Create Shared Types File
pkg/cli/logs_types.gologs.gomake test-unitpassesPhase 2: Extract Utility Functions (Smallest Impact)
pkg/cli/logs_utils.gogetAgenticWorkflowNames(),contains()and other helpersPhase 3: Extract Display Logic
pkg/cli/logs_display.godisplayLogsOverview()and related rendering functionsPhase 4: Extract GitHub API Layer
pkg/cli/logs_github_api.goPhase 5: Extract Download Operations
pkg/cli/logs_download.godownloadRunArtifactsConcurrent()and related functionsPhase 6: Extract Orchestrator
pkg/cli/logs_orchestrator.goDownloadWorkflowLogs()functionPhase 7: Simplify Command File
logs_command.goonly containsNewLogsCommand()logs.gotologs_command.go(or keep as is)Critical Rules
NewLogsCommand()andDownloadWorkflowLogs())make test-unitpasses after each phaselogsLoglogger across all files vialogs_types.goAcceptance Criteria
make test-unit)NewLogsCommand(),DownloadWorkflowLogs())make lint)make build)Additional Context
AGENTS.md- prefer many smaller files grouped by functionalitypkg/workflow/for consistencypkg/cli/*_test.goconsole.Format*Message()helpersCampaign Context
This refactoring is part of the go-file-size-reduction-20330678188 campaign to maintain a healthy, modular codebase.
Current Status:
pkg/cli/logs.go(1,354 lines)Priority: Medium
Effort: Large (7 files to create, extensive function moves, careful testing required)
Expected Impact: Significantly improved maintainability, easier navigation, clearer module boundaries, better testability