Skip to content

[file-diet] Refactor pkg/workflow/compiler_yaml.go (1262 lines) into focused modules #45478

Description

@github-actions

Overview

The file pkg/workflow/compiler_yaml.go has grown to 1262 lines, significantly exceeding the healthy threshold of 800 lines. It contains distinct functional domains tightly packed into a single file, making it harder to navigate, maintain, and test.

Current State

  • File: pkg/workflow/compiler_yaml.go
  • Size: 1262 lines
  • Test file: pkg/workflow/compiler_yaml_test.go (1860 lines)
  • Test-to-source ratio: 1.47× (good coverage exists)
  • Complexity: High — the file covers YAML generation, prompt assembly, output collection, header construction, and text-normalization utilities
Full File Analysis

Function Distribution

Function Lines Domain
generateWorkflowHeader ~177 Header/metadata generation
generatePrompt ~290 Prompt assembly
generateYAML ~131 Top-level YAML orchestration
normalizeBlankLines ~105 YAML text normalization
generateCreateAwInfo ~181 AW info step generation
generateOutputCollectionStep ~88 Output collection
blockScalarHeaderIndentForLine ~32 YAML indent utility
splitContentIntoChunks ~30 Prompt chunking
Small helpers ~80 Various

Complexity Hotspots

  • generatePrompt (lines 633–922, ~290 lines): Largest function — handles ordered/legacy imports, runtime-import macros, expression mappings, chunking, and YAML emission. High cyclomatic complexity.
  • generateWorkflowHeader (lines 84–260, ~177 lines): Embeds metadata, permissions, secrets, on-triggers, and concurrency config.
  • generateCreateAwInfo (lines 965–1145, ~181 lines): Serialises engine info, environment variables, and run metadata into YAML steps.

Refactoring Strategy

Proposed File Splits

  1. compiler_yaml_header.go

    • Functions: generateWorkflowHeader, effectiveStrictMode, effectiveSafeUpdate
    • Responsibility: YAML header/metadata/frontmatter emission
    • Estimated LOC: ~230
  2. compiler_yaml_prompt.go

    • Functions: generatePrompt, splitContentIntoChunks, extractPromptChunksFromMarkdown, writePromptBashStep
    • Responsibility: Prompt assembly, chunking, import resolution, expression mapping
    • Estimated LOC: ~340
  3. compiler_yaml_steps.go

    • Functions: generatePreSteps, generatePostSteps, generatePreAgentSteps, writeStepsSection, generateCreateAwInfo, generateOutputCollectionStep
    • Responsibility: Individual step generation (pre/post steps, aw-info, output collection)
    • Estimated LOC: ~320
  4. compiler_yaml_normalize.go

    • Functions: normalizeBlankLines, countLeadingSpaces, blockScalarHeaderIndentForLine
    • Responsibility: YAML text normalization and indentation utilities
    • Estimated LOC: ~110
  5. compiler_yaml.go (trimmed)

    • Functions: buildJobsAndValidate, generateYAML, generateWorkflowBody, resolveWorkspaceRoot
    • Responsibility: Top-level orchestration — entry point for YAML generation
    • Estimated LOC: ~280

Shared Utilities

normalizeBlankLines, countLeadingSpaces, and blockScalarHeaderIndentForLine are pure text utilities with no Compiler receiver — natural candidates for compiler_yaml_normalize.go with zero coupling change.

Interface Abstractions

No new interfaces required for this split; all functions share the same *Compiler receiver. The split is purely by domain/file boundary.

Test Coverage Plan

Existing tests in compiler_yaml_test.go cover the public surface well (ratio 1.47×). After the split:

  1. compiler_yaml_header_test.go: TestEffectiveStrictMode, TestGenerateWorkflowHeader
  2. compiler_yaml_prompt_test.go: TestSplitContentIntoChunks, TestGeneratePrompt, TestExtractPromptChunksFromMarkdown
  3. compiler_yaml_steps_test.go: TestWriteStepsSection, TestGenerateCreateAwInfo, TestGenerateOutputCollectionStep
  4. compiler_yaml_normalize_test.go: TestNormalizeBlankLines, TestBlockScalarHeaderIndentForLine

Existing tests can be redistributed to match the new file structure or kept in the single test file — both are valid per existing repository patterns.

Implementation Guidelines

  1. Preserve Behavior: Ensure all existing functionality works identically
  2. Maintain Exports: Keep public API unchanged (exported functions/types)
  3. Incremental Changes: Split one module at a time, verify make test-unit after each
  4. Update Imports: Ensure all import paths are correct after each split
  5. Document Changes: Add comments explaining module boundaries

Acceptance Criteria

  • compiler_yaml.go is split into 5 focused files
  • Each new file is under 500 lines
  • All tests pass (make test-unit)
  • Test coverage is ≥80% for new files
  • No breaking changes to public API
  • Code passes linting (make lint)
  • Build succeeds (make build)
Additional Context
  • Repository Guidelines: Follow patterns in .github/agents/developer.instructions.agent.md
  • Code Organization: Prefer many small files grouped by functionality (see create_*.go pattern)
  • Testing: Match existing test patterns in pkg/workflow/*_test.go

Priority: Medium
Effort: Medium (well-tested file, clear domain boundaries, no interface changes needed)
Expected Impact: Improved maintainability, easier navigation, reduced per-file complexity

Generated by 🧹 Daily File Diet · 43.6 AIC · ⌖ 8.41 AIC · ⊞ 6.8K ·

  • expires on Jul 16, 2026, 5:04 AM UTC-08:00

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions