Skip to content

Commit c27e53c

Browse files
authored
Add comprehensive documentation for validation and parsing organization (#7065)
1 parent cdf3b72 commit c27e53c

10 files changed

Lines changed: 271 additions & 3 deletions

pkg/cli/actions_build_command.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,19 @@ func getActionDirectories(actionsDir string) ([]string, error) {
141141
return dirs, nil
142142
}
143143

144-
// validateActionYml validates an action.yml file
144+
// validateActionYml validates that an action.yml file exists and contains required fields.
145+
//
146+
// This validation function is co-located with the actions build command because:
147+
// - It's specific to GitHub Actions custom action structure
148+
// - It's only called during the actions build process
149+
// - It validates action metadata before bundling JavaScript
150+
//
151+
// The function validates:
152+
// - action.yml file exists in the action directory
153+
// - Required fields are present (name, description, runs)
154+
// - Basic action metadata structure is valid
155+
//
156+
// This follows the principle that domain-specific validation belongs in domain files.
145157
func validateActionYml(actionPath string) error {
146158
ymlPath := filepath.Join(actionPath, "action.yml")
147159

pkg/cli/compile_campaign.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
// Package cli provides campaign workflow compilation and validation.
2+
//
3+
// This file handles validation of campaign spec files and their referenced workflows.
4+
// Campaign workflows are special workflows that orchestrate multiple sub-workflows
5+
// across a set of target repositories.
6+
//
7+
// # Organization Rationale
8+
//
9+
// The validateCampaigns function is co-located with campaign compilation logic because:
10+
// - It's domain-specific to campaign workflows
11+
// - It's only called during compile operations
12+
// - It's tightly coupled to the campaign compilation process
13+
// - The file is small (98 lines) and focused
14+
//
15+
// This follows the principle that domain-specific validation belongs in domain files.
16+
// See skills/developer/SKILL.md for validation architecture patterns.
17+
//
18+
// # Validation Functions
19+
//
20+
// Campaign Validation:
21+
// - validateCampaigns() - Validates campaign specs and referenced workflows
22+
//
23+
// This validation ensures that:
24+
// - Campaign spec files are syntactically valid
25+
// - Referenced workflow files exist in the workflows directory
26+
// - Campaign configuration is complete and correct
127
package cli
228

329
import (

pkg/cli/compile_helpers.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
// Package cli provides helper functions for workflow compilation.
2+
//
3+
// This file contains shared utilities used by the compile command to process workflow
4+
// files, manage compilation statistics, and handle campaign workflows. These helpers
5+
// support both single-file and batch compilation operations.
6+
//
7+
// # Organization Rationale
8+
//
9+
// These helper functions are grouped here because they:
10+
// - Are used by multiple compile command variants (compile, watch, campaign)
11+
// - Provide common compilation patterns and error handling
12+
// - Have a clear domain focus (compilation operations)
13+
// - Keep the main compile_command.go file focused on CLI interaction
14+
//
15+
// This follows the helper file conventions documented in skills/developer/SKILL.md.
16+
//
17+
// # Key Functions
18+
//
19+
// Single File Compilation:
20+
// - compileSingleFile() - Compile a single markdown workflow with stats tracking
21+
//
22+
// Batch Compilation:
23+
// - compileBatchWorkflows() - Compile multiple workflows in parallel
24+
// - scanAllWorkflows() - Scan directories for workflow files
25+
//
26+
// Campaign Compilation:
27+
// - compileAllCampaignOrchestrators() - Generate and compile campaign orchestrators
28+
//
29+
// Statistics:
30+
// - CompilationStats - Track compilation success/failure/skip counts
31+
//
32+
// These functions abstract common compilation patterns, allowing the main compile
33+
// command to focus on CLI interaction while these helpers handle the mechanics.
134
package cli
235

336
import (

pkg/cli/run_command.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,19 @@ func getWorkflowInputs(markdownPath string) (map[string]*workflow.InputDefinitio
616616
return workflow.ParseInputDefinitions(inputsMap), nil
617617
}
618618

619-
// validateWorkflowInputs validates that required inputs are provided and checks for typos
619+
// validateWorkflowInputs validates that required inputs are provided and checks for typos.
620+
//
621+
// This validation function is co-located with the run command implementation because:
622+
// - It's specific to the workflow run operation
623+
// - It's only called during workflow dispatch
624+
// - It provides immediate feedback before triggering the workflow
625+
//
626+
// The function validates:
627+
// - All required inputs are provided
628+
// - Provided input names match defined inputs (typo detection)
629+
// - Suggestions for misspelled input names
630+
//
631+
// This follows the principle that domain-specific validation belongs in domain files.
620632
func validateWorkflowInputs(markdownPath string, providedInputs []string) error {
621633
// Extract workflow inputs
622634
workflowInputs, err := getWorkflowInputs(markdownPath)
@@ -888,7 +900,19 @@ func getLatestWorkflowRunWithRetry(lockFileName string, repo string, verbose boo
888900
return nil, fmt.Errorf("no workflow run found after %d attempts", maxRetries)
889901
}
890902

891-
// validateRemoteWorkflow checks if a workflow exists in a remote repository and can be triggered
903+
// validateRemoteWorkflow checks if a workflow exists in a remote repository and can be triggered.
904+
//
905+
// This validation function is co-located with the run command implementation because:
906+
// - It's specific to remote workflow execution
907+
// - It's only called when running workflows in remote repositories
908+
// - It provides early validation before attempting workflow dispatch
909+
//
910+
// The function validates:
911+
// - The specified repository exists and is accessible
912+
// - The workflow file exists in the repository
913+
// - The workflow can be triggered via GitHub Actions API
914+
//
915+
// This follows the principle that domain-specific validation belongs in domain files.
892916
func validateRemoteWorkflow(workflowName string, repoOverride string, verbose bool) error {
893917
if repoOverride == "" {
894918
return fmt.Errorf("repository must be specified for remote workflow validation")

pkg/workflow/config_helpers.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
// Package workflow provides helper functions for parsing safe output configurations.
2+
//
3+
// This file contains parsing utilities for extracting and validating configuration
4+
// values from safe output config maps. These helpers are used across safe output
5+
// processors to parse common configuration patterns.
6+
//
7+
// # Organization Rationale
8+
//
9+
// These parse functions are grouped in a helper file because they:
10+
// - Share a common purpose (safe output config parsing)
11+
// - Are used by multiple safe output modules (3+ callers)
12+
// - Provide stable, reusable parsing patterns
13+
// - Have clear domain focus (configuration extraction)
14+
//
15+
// This follows the helper file conventions documented in the developer instructions.
16+
// See skills/developer/SKILL.md#helper-file-conventions for details.
17+
//
18+
// # Key Functions
19+
//
20+
// Configuration Array Parsing:
21+
// - ParseStringArrayFromConfig() - Generic string array extraction
22+
// - parseLabelsFromConfig() - Extract labels array
23+
// - parseParticipantsFromConfig() - Extract participants array
24+
// - parseAllowedReposFromConfig() - Extract allowed repos array
25+
// - parseAllowedLabelsFromConfig() - Extract allowed labels array
26+
//
27+
// Configuration String Parsing:
28+
// - extractStringFromMap() - Generic string extraction
29+
// - parseTitlePrefixFromConfig() - Extract title prefix
30+
// - parseTargetRepoFromConfig() - Extract target repository
31+
// - parseTargetRepoWithValidation() - Extract and validate target repo
32+
//
33+
// Configuration Integer Parsing:
34+
// - parseExpiresFromConfig() - Extract expiration time
35+
// - parseRelativeTimeSpec() - Parse relative time specifications
136
package workflow
237

338
import (

pkg/workflow/engine_helpers.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
// Package workflow provides shared helper functions for AI engine implementations.
2+
//
3+
// This file contains utilities used across multiple AI engine files (copilot_engine.go,
4+
// claude_engine.go, codex_engine.go, custom_engine.go) to generate common workflow
5+
// steps and configurations.
6+
//
7+
// # Organization Rationale
8+
//
9+
// These helper functions are grouped here because they:
10+
// - Are used by 3+ engine implementations (shared utilities)
11+
// - Provide common patterns for agent installation and npm setup
12+
// - Have a clear domain focus (engine workflow generation)
13+
// - Are stable and change infrequently
14+
//
15+
// This follows the helper file conventions documented in skills/developer/SKILL.md.
16+
//
17+
// # Key Functions
18+
//
19+
// Agent Installation:
20+
// - GenerateAgentInstallSteps() - Generate agent installation workflow steps
21+
//
22+
// NPM Installation:
23+
// - GenerateNpmInstallStep() - Generate npm package installation step
24+
// - GenerateEngineDependenciesInstallStep() - Generate engine dependencies install step
25+
//
26+
// Configuration:
27+
// - GetClaudeSystemPrompt() - Get system prompt for Claude engine
28+
//
29+
// These functions encapsulate shared logic that would otherwise be duplicated across
30+
// engine files, maintaining DRY principles while keeping engine-specific code separate.
131
package workflow
232

333
import (

pkg/workflow/map_helpers.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
// Package workflow provides generic map and type conversion utilities.
2+
//
3+
// This file contains low-level helper functions for working with map[string]any
4+
// structures and type conversions. These utilities are used throughout the workflow
5+
// compilation process to safely parse and manipulate configuration data.
6+
//
7+
// # Organization Rationale
8+
//
9+
// These functions are grouped in a helper file because they:
10+
// - Provide generic, reusable utilities (used by 10+ files)
11+
// - Have no specific domain focus (work with any map/type data)
12+
// - Are small, stable functions (< 50 lines each)
13+
// - Follow clear, single-purpose patterns
14+
//
15+
// This follows the helper file conventions documented in skills/developer/SKILL.md.
16+
//
17+
// # Key Functions
18+
//
19+
// Type Conversion:
20+
// - parseIntValue() - Safely parse numeric types to int with truncation warnings
21+
//
22+
// Map Operations:
23+
// - filterMapKeys() - Create new map excluding specified keys
24+
//
25+
// These utilities handle common type conversion and map manipulation patterns that
26+
// occur frequently during YAML-to-struct parsing and configuration processing.
127
package workflow
228

329
import "github.com/githubnext/gh-aw/pkg/logger"

pkg/workflow/repo_memory.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// Package workflow provides repository memory configuration and validation.
2+
//
3+
// This file handles:
4+
// - Repo-memory configuration structures and defaults
5+
// - Repo-memory tool configuration extraction and parsing
6+
// - Generation of per-memory GitHub token secrets
7+
// - Domain-specific validation for repo-memory configurations
8+
//
9+
// # Validation Functions
10+
//
11+
// This file contains domain-specific validation functions for repo-memory:
12+
// - validateNoDuplicateMemoryIDs() - Ensures unique memory identifiers
13+
//
14+
// These validation functions are co-located with repo-memory logic following the
15+
// principle that domain-specific validation belongs in domain files. See validation.go
16+
// for the validation architecture documentation.
117
package workflow
218

319
import (

pkg/workflow/sandbox.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
// Package workflow provides sandbox configuration and validation for agentic workflows.
2+
//
3+
// This file handles:
4+
// - Sandbox type definitions (AWF, SRT)
5+
// - Sandbox configuration structures and parsing
6+
// - Sandbox runtime config generation
7+
// - Domain-specific validation for sandbox configurations
8+
//
9+
// # Validation Functions
10+
//
11+
// This file contains domain-specific validation functions for sandbox configuration:
12+
// - validateMountsSyntax() - Validates container mount syntax
13+
// - validateSandboxConfig() - Validates complete sandbox configuration
14+
//
15+
// These validation functions are co-located with sandbox logic following the principle
16+
// that domain-specific validation belongs in domain files. See validation.go for the
17+
// validation architecture documentation.
118
package workflow
219

320
import (

pkg/workflow/tools_parser.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
// Package workflow provides tool configuration parsing for agentic workflows.
2+
//
3+
// This file handles parsing of tool configurations from the frontmatter tools section.
4+
// It extracts and validates tool configurations for all supported tools, converting
5+
// YAML-parsed maps into strongly-typed Go structs.
6+
//
7+
// # Organization Rationale
8+
//
9+
// All tool parsing functions are grouped in this file because they:
10+
// - Share a common purpose (tool configuration parsing)
11+
// - Follow similar parsing patterns (map[string]any -> struct)
12+
// - Are called together during workflow compilation
13+
// - Provide a single source of truth for tool configuration
14+
//
15+
// This follows established patterns where domain-specific parsing is grouped by
16+
// functionality rather than scattered across files. See skills/developer/SKILL.md
17+
// for code organization principles.
18+
//
19+
// # Supported Tools
20+
//
21+
// Built-in Tools:
22+
// - github: GitHub API and repository operations
23+
// - bash: Shell command execution
24+
// - web-fetch: HTTP content fetching
25+
// - web-search: Web search capabilities
26+
// - edit: File editing operations
27+
// - playwright: Browser automation
28+
// - serena: Serena integration
29+
// - agentic-workflows: Nested workflow execution
30+
// - cache-memory: In-workflow memory caching
31+
// - repo-memory: Repository-backed persistent memory
32+
//
33+
// Configuration Tools:
34+
// - safety-prompt: Safety prompt injection
35+
// - timeout: Agent timeout configuration
36+
// - startup-timeout: Agent startup timeout
37+
//
38+
// Custom Tools:
39+
// - MCP servers and other custom tool configurations
40+
//
41+
// # Parse Function Pattern
42+
//
43+
// Each parse function follows the pattern:
44+
// 1. Accept any type to handle various YAML representations
45+
// 2. Type-assert to expected structure (bool, string, map, array)
46+
// 3. Extract and validate configuration values
47+
// 4. Return strongly-typed configuration struct
48+
//
49+
// This provides type safety while accommodating flexible YAML syntax.
150
package workflow
251

352
import (

0 commit comments

Comments
 (0)