Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Extract Magic Constants to Centralized Constants Package

This PR extracts hardcoded magic values from compiler code to the centralized constants package, improving maintainability and consistency.

Implementation Plan

  • Identify all magic constants in scope

    • Prompt file path: /tmp/gh-aw/aw-prompts/prompt.txt (compiler_yaml.go lines 281, 287)
    • Max patch size: 1024 (compiler_safe_outputs_config.go lines 298, 322; create_pull_request.go line 90)
    • YAML builder size: 256 * 1024 (compiler_yaml.go line 179)
    • Chunk size constants: 20900 and 21000 (compiler_yaml.go line 201)
  • Add new constants to pkg/constants/constants.go

    • Add FilePath semantic type alias
    • Add ByteSize semantic type alias
    • Add PromptFilePath constant
    • Add DefaultMaxPatchSize constant
    • Add DefaultYAMLBuilderSize constant
    • Add MaxChunkSize and ChunkSizeBuffer constants
  • Update compiler_yaml.go to use new constants

    • Replace hardcoded prompt file paths
    • Replace YAML builder size
    • Replace chunk size constants
  • Update compiler_safe_outputs_config.go to use new constants

    • Replace maxPatchSize default value (2 occurrences)
  • Update create_pull_request.go to use new constants

    • Replace maxPatchSize default value
  • Run tests and validation

    • Run make fmt
    • Run make test-unit
    • Run make lint
    • Run make agent-finish
  • Request code review

Original prompt

This section details on the original issue you should resolve

<issue_title>[Code Quality] Extract magic constants from compiler_yaml.go to centralized constants package</issue_title>
<issue_description>### Description

The compiler_yaml.go file contains hardcoded magic values (file paths, size limits, constants) that should be extracted to a centralized constants package. This makes the code harder to maintain and creates inconsistencies when the same values are used across multiple files.

Problems Identified

Hardcoded Values Found:

  1. File Paths:

    • /tmp/gh-aw/aw-prompts/prompt.txt (line 257) - appears multiple times
    • Should be in PathConstants
  2. Size Limits:

    • maxPatchSize := 1024 // default 1024 KB (line 298) - should be constant
    • Should be DefaultMaxPatchSize = 1024
  3. Other Magic Values:

    • Step IDs and output names scattered throughout
    • Should be defined as constants for easy reference

Impact

  • Maintainability: Must search for all occurrences to change values
  • Consistency: Risk of different values in different locations
  • Documentation: Hard to find canonical values
  • Type Safety: Strings/ints don't convey semantic meaning

Suggested Changes

1. Create centralized constants in pkg/constants/paths.go:

const (
    PromptFilePath = "/tmp/gh-aw/aw-prompts/prompt.txt"
    DefaultMaxPatchSize = 1024  // KB
)

2. Replace hardcoded values in compiler_yaml.go:

// Before:
maxPatchSize := 1024

// After:
maxPatchSize := constants.DefaultMaxPatchSize

3. Extract step IDs and output names (if applicable):

const (
    SetupStepID = "setup"
    AgentStepID = "agent"
    // ... etc
)

Files Affected

  • pkg/workflow/compiler_yaml.go - Replace hardcoded values
  • pkg/constants/paths.go (new) - Or add to existing constants file
  • Other files using same constants - Update imports

Success Criteria

  • All magic values in compiler_yaml.go extracted to constants
  • Constants defined with semantic type aliases where appropriate
  • All references updated to use constants
  • No hardcoded file paths or size limits remaining
  • All tests pass without modification
  • Documentation updated if constants are user-configurable

Source

Extracted from Daily Compiler Code Quality Report - 2026-01-30

Finding: Issue #2 - Hardcoded Magic Values (Low Priority)

Priority

Low-Medium - Improves code maintainability and reduces technical debt, but not blocking functionality.

Estimated Effort

1-2 hours (extraction + testing)

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 13, 2026, 5:22 AM UTC

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add FilePath semantic type for file paths
- Add ByteSize semantic type for byte sizes
- Add PromptFilePath constant for workflow prompt file path
- Add DefaultMaxPatchSize constant for max patch size (1024 KB)
- Add DefaultYAMLBuilderSize constant (256 KB)
- Add MaxChunkSize and ChunkSizeBuffer constants
- Add comprehensive tests for new semantic types

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Quality] Extract magic constants from compiler_yaml.go to centralized constants package

2 participants