Repository Quality: File Size Discipline — 2026-04-01 #23903
Closed
Replies: 2 comments 1 reply
-
|
/plan |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
This discussion has been marked as outdated by Repository Quality Improvement Agent. A newer discussion is available at Discussion #24117. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🎯 Repository Quality Improvement Report — File Size Discipline
Analysis Date: 2026-04-01
Focus Area: File Size Discipline (Custom)
Strategy Type: Custom
Custom Area: Yes — this repository has a documented hard limit of 300 lines per file (in AGENTS.md), yet several production files significantly exceed this boundary. This focus area examines those violations and provides concrete decomposition tasks.
Executive Summary
The codebase has an explicit "hard limit" of 300 lines per Go source file, with a stated guideline to refactor files exceeding this size. An analysis of 629 non-test source files reveals 6 files exceeding 1,000 lines and 74 files between 500–1,000 lines — representing systematic drift from the documented standard.
The worst offenders are concentrated in
pkg/cli/andpkg/workflow/, the two highest-activity packages. The pattern is consistent: files that mix multiple concerns (parsing, processing, rendering, or configuration) tend to grow organically past the limit. Each of the top offenders has clear, natural seams where it can be split into smaller, single-responsibility files without changing public APIs.Test coverage is excellent (219% test-to-source LOC ratio), so there is good test infrastructure to validate refactoring. TODO/FIXME debt is low (7 items), suggesting this is a quality codebase with focused technical debt.
Full Analysis Report
Focus Area: File Size Discipline
Current State Assessment
Metrics Collected:
.gofilesFiles exceeding 1,000 lines (all violate hard limit):
pkg/cli/gateway_logs.gopkg/constants/constants.gopkg/cli/audit_report_render.gopkg/cli/logs_report.gopkg/cli/trial_command.gopkg/workflow/checkout_manager.goFindings
Strengths
Areas for Improvement
pkg/cli/gateway_logs.go(1,332 lines) mixes 4+ concerns: type definitions, RPC parsing, log processing, and metrics rendering — HIGH severitypkg/constants/constants.go(1,083 lines) bundles all constants regardless of domain — MEDIUM severitypkg/cli/audit_report_render.go(1,045 lines) has 25+ render functions that could be grouped into sub-files by domain — HIGH severitypkg/cli/trial_command.go(1,007 lines) mixes Cobra command setup with substantial business logic — HIGH severitypkg/workflow/checkout_manager.go(1,005 lines) conflates state management with step generation — MEDIUM severityDetailed Analysis
gateway_logs.gois the most egregious violation at 1,332 lines. It contains: type definitions (GatewayLogEntry,GatewayMetrics,RPCMessageEntry, etc.), RPC message parsing (parseRPCMessages), gateway log processing (parseGatewayLogs,processGatewayLogEntry), and metrics rendering (renderGatewayMetricsTable). Natural split points are clearly visible from the function list.constants.goat 1,083 lines contains all constants in a single file. The type system is well-designed (semantic types withString()/IsValid()methods), but grouping all constants together regardless of domain makes it hard to navigate. Splitting by domain (engine constants, job constants, URL constants, etc.) would improve discoverability.audit_report_render.gohas 25+ render functions. The file renders: overview, metrics, tool usage, MCP tools, guard policies, firewall analysis, recommendations, performance metrics, policy analysis, and engine config. Each cluster could be its own file.trial_command.goat 1,007 lines is a command file that significantly exceeds the typical command file size. It likely contains business logic that should live in separate helper files.checkout_manager.goat 1,005 lines mixesCheckoutManagerstate management with GitHub Actions YAML step generation. The step generation functions (GenerateCheckoutAppTokenSteps,GenerateAdditionalCheckoutSteps, etc.) could be a separatecheckout_step_generator.go.🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: The following tasks are designed for GitHub Copilot coding agent execution. Please split these into individual work items for the agent to process. Each task is self-contained with clear acceptance criteria and a specific code region.
Improvement Tasks
Task 1: Split
gateway_logs.gointo focused filesPriority: High
Estimated Effort: Medium
Focus Area: File Size Discipline
Description:
pkg/cli/gateway_logs.gois 1,332 lines and mixes four distinct concerns. Split it into focused files without changing any public APIs or function signatures.Acceptance Criteria:
pkg/cli/gateway_log_types.go— all type definitions (structs, consts) currently in gateway_logs.gopkg/cli/gateway_log_parser.go—parseRPCMessages,parseGatewayLogs,findRPCMessagesPathpkg/cli/gateway_log_processor.go—processGatewayLogEntry,getOrCreateServer,getOrCreateTool,calculateGatewayAggregates,buildGuardPolicySummarypkg/cli/gateway_log_renderer.go—renderGatewayMetricsTable,getSortedServerNames, and any other render functionsgateway_logs.goeither removed or reduced to a thin orchestrating filego test ./pkg/cli/ -run ".*Gateway.*")Code Region:
pkg/cli/gateway_logs.goTask 2: Split
audit_report_render.gointo domain-focused render filesPriority: High
Estimated Effort: Medium
Focus Area: File Size Discipline
Description:
pkg/cli/audit_report_render.go(1,045 lines) contains 25+ render functions spanning many distinct report domains. Split into domain-focused files.Acceptance Criteria:
pkg/cli/audit_render_overview.go— renderConsole, renderOverview, renderMetrics, renderJobsTable, renderAuditComparisonpkg/cli/audit_render_tools.go— renderToolUsageTable, renderMCPToolUsageTablepkg/cli/audit_render_security.go— renderGuardPolicySummary, renderFirewallAnalysis, renderRedactedDomainsAnalysis, renderPolicyAnalysispkg/cli/audit_render_insights.go— renderKeyFindings, renderRecommendations, renderAgenticAssessments, renderBehaviorFingerprint, renderTaskDomainpkg/cli/audit_render_metrics.go— renderPerformanceMetrics, renderEngineConfig, renderPromptAnalysis, renderSessionAnalysis, renderCreatedItemsTable, formatUnixTimestamprenderJSONcan stay in the originalaudit_report_render.goor move to overviewCode Region:
pkg/cli/audit_report_render.goTask 3: Split
trial_command.goby separating business logic from command setupPriority: High
Estimated Effort: Medium
Focus Area: File Size Discipline
Description:
pkg/cli/trial_command.go(1,007 lines) exceeds the hard limit significantly. Command files should be thin wrappers; business logic should move to separate helper files.Acceptance Criteria:
pkg/cli/trial_command.goreduced to Cobra command setup, flag definitions, and delegation — ideally under 200 linespkg/cli/trial_runner.goor appropriate named filesCode Region:
pkg/cli/trial_command.goTask 4: Split
checkout_manager.gointo state management and step generationPriority: Medium
Estimated Effort: Small
Focus Area: File Size Discipline
Description:
pkg/workflow/checkout_manager.go(1,005 lines) mixesCheckoutManagerstate management with GitHub Actions YAML step generation. The step generation functions are independently testable and should be in their own file.Acceptance Criteria:
pkg/workflow/checkout_manager.goreduced to: type definitions,NewCheckoutManager, getters/setters,add, and any resolver logic — under 400 linespkg/workflow/checkout_step_generator.gocontains allGenerate*functions (GenerateCheckoutAppTokenSteps,GenerateCheckoutAppTokenInvalidationSteps,GenerateAdditionalCheckoutSteps,GenerateGitHubFolderCheckoutStep,GenerateDefaultCheckoutStep,generateCheckoutStepLines)Code Region:
pkg/workflow/checkout_manager.goTask 5: Split
constants.gointo domain-grouped filesPriority: Medium
Estimated Effort: Small
Focus Area: File Size Discipline
Description:
pkg/constants/constants.go(1,083 lines) has all constants, types, and values in one file. Splitting by domain improves discoverability and adheres to the size guideline.Acceptance Criteria:
pkg/constants/engine_constants.go—EngineNametype + engine constants (CopilotEngine,ClaudeEngine, etc.)pkg/constants/job_constants.go—JobName,StepIDtypes + all job/step name constantspkg/constants/url_constants.go—URL,DocURLtypes + URL constantspkg/constants/version_constants.go—Version,ModelNametypes + version/model constantspkg/constants/constants.go— remaining general constants (CommandPrefix,LineLength,FeatureFlag,WorkflowID)go test ./pkg/constants/...)Code Region:
pkg/constants/constants.go📊 Historical Context
Previous Focus Areas
🎯 Recommendations
Immediate Actions (This Week)
gateway_logs.go(1,332 lines) — most impactful, clear seams — Priority: Highaudit_report_render.go(1,045 lines) — 25+ functions, easy grouping — Priority: HighShort-term Actions (This Month)
trial_command.go(1,007 lines) — improves testability of business logic — Priority: Highcheckout_manager.go(1,005 lines) — natural seam already identified — Priority: MediumLong-term Actions (This Quarter)
constants.gointo domain files — lower urgency, no behavior change — Priority: Mediummake check-file-sizestarget that reports files over the 300-line guideline📈 Success Metrics
Track these metrics to measure improvement in File Size Discipline:
Next Steps
References:
Beta Was this translation helpful? Give feedback.
All reactions