Skip to content

Commit 132f269

Browse files
Add debug logging to core compilation and CLI files (#3860)
1 parent d0bad47 commit 132f269

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

pkg/cli/compile_command.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,13 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
265265

266266
// Set validation based on the validate flag (false by default for compatibility)
267267
compiler.SetSkipValidation(!validate)
268+
compileLog.Printf("Validation enabled: %v", validate)
268269

269270
// Set noEmit flag to validate without generating lock files
270271
compiler.SetNoEmit(noEmit)
272+
if noEmit {
273+
compileLog.Print("No-emit mode enabled: validating without generating lock files")
274+
}
271275

272276
// Set strict mode if specified
273277
compiler.SetStrictMode(strict)
@@ -302,6 +306,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
302306
var workflowDataList []*workflow.WorkflowData
303307

304308
if len(markdownFiles) > 0 {
309+
compileLog.Printf("Compiling %d specific workflow files", len(markdownFiles))
305310
// Compile specific workflow files
306311
var compiledCount int
307312
var errorCount int
@@ -855,6 +860,7 @@ func watchAndCompileWorkflows(markdownFile string, compiler *workflow.Compiler,
855860

856861
// compileAllWorkflowFiles compiles all markdown files in the workflows directory
857862
func compileAllWorkflowFiles(compiler *workflow.Compiler, workflowsDir string, verbose bool) (*CompilationStats, error) {
863+
compileLog.Printf("Compiling all workflow files in directory: %s", workflowsDir)
858864
// Reset warning count before compilation
859865
compiler.ResetWarningCount()
860866

@@ -868,12 +874,15 @@ func compileAllWorkflowFiles(compiler *workflow.Compiler, workflowsDir string, v
868874
}
869875

870876
if len(mdFiles) == 0 {
877+
compileLog.Printf("No markdown files found in %s", workflowsDir)
871878
if verbose {
872879
fmt.Printf("No markdown files found in %s\n", workflowsDir)
873880
}
874881
return stats, nil
875882
}
876883

884+
compileLog.Printf("Found %d markdown files to compile", len(mdFiles))
885+
877886
// Compile each file
878887
for _, file := range mdFiles {
879888
stats.Total++

pkg/workflow/compiler_yaml.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ func (c *Compiler) generateYAML(data *WorkflowData, markdownPath string) (string
162162
}
163163

164164
func (c *Compiler) generateMainJobSteps(yaml *strings.Builder, data *WorkflowData) {
165+
compilerYamlLog.Printf("Generating main job steps for workflow: %s", data.Name)
166+
165167
// Determine if we need to add a checkout step
166168
needsCheckout := c.shouldAddCheckoutStep(data)
169+
compilerYamlLog.Printf("Checkout step needed: %t", needsCheckout)
167170

168171
// Add checkout step first if needed
169172
if needsCheckout {
@@ -192,6 +195,7 @@ func (c *Compiler) generateMainJobSteps(yaml *strings.Builder, data *WorkflowDat
192195
// Runtime detection now smartly filters out runtimes that already have setup actions
193196
runtimeRequirements := DetectRuntimeRequirements(data)
194197
runtimeSetupSteps := GenerateRuntimeSetupSteps(runtimeRequirements)
198+
compilerYamlLog.Printf("Detected runtime requirements: %d runtimes, %d setup steps", len(runtimeRequirements), len(runtimeSetupSteps))
195199
for _, step := range runtimeSetupSteps {
196200
for _, line := range step {
197201
yaml.WriteString(line + "\n")
@@ -245,6 +249,7 @@ func (c *Compiler) generateMainJobSteps(yaml *strings.Builder, data *WorkflowDat
245249

246250
// Add engine-specific installation steps (includes Node.js setup for npm-based engines)
247251
installSteps := engine.GetInstallationSteps(data)
252+
compilerYamlLog.Printf("Adding %d engine installation steps for %s", len(installSteps), engine.GetID())
248253
for _, step := range installSteps {
249254
for _, line := range step {
250255
yaml.WriteString(line + "\n")
@@ -565,6 +570,8 @@ func splitContentIntoChunks(content string) []string {
565570
}
566571

567572
func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData) {
573+
compilerYamlLog.Printf("Generating prompt for workflow: %s (markdown size: %d bytes)", data.Name, len(data.MarkdownContent))
574+
568575
// Clean the markdown content
569576
cleanedMarkdownContent := removeXMLComments(data.MarkdownContent)
570577

@@ -587,6 +594,7 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData) {
587594

588595
// Split content into manageable chunks
589596
chunks := splitContentIntoChunks(cleanedMarkdownContent)
597+
compilerYamlLog.Printf("Split prompt into %d chunks", len(chunks))
590598

591599
// Create the initial prompt file step
592600
yaml.WriteString(" - name: Create prompt\n")

pkg/workflow/expressions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,15 @@ func (c *ContainsNode) Render() string {
212212

213213
// buildConditionTree creates a condition tree from existing if condition and new draft condition
214214
func buildConditionTree(existingCondition string, draftCondition string) ConditionNode {
215+
expressionsLog.Printf("Building condition tree: existing=%q, draft=%q", existingCondition, draftCondition)
215216
draftNode := &ExpressionNode{Expression: draftCondition}
216217

217218
if existingCondition == "" {
219+
expressionsLog.Print("No existing condition, using draft only")
218220
return draftNode
219221
}
220222

223+
expressionsLog.Print("Combining existing and draft conditions with AND")
221224
existingNode := &ExpressionNode{Expression: existingCondition}
222225
return &AndNode{Left: existingNode, Right: draftNode}
223226
}
@@ -232,6 +235,7 @@ func buildAnd(left ConditionNode, right ConditionNode) ConditionNode {
232235

233236
// buildReactionCondition creates a condition tree for the add_reaction job
234237
func buildReactionCondition() ConditionNode {
238+
expressionsLog.Print("Building reaction condition for multiple event types")
235239
// Build a list of event types that should trigger reactions using the new expression nodes
236240
var terms []ConditionNode
237241

@@ -563,6 +567,7 @@ func ParseExpression(expression string) (ConditionNode, error) {
563567

564568
// tokenize breaks the expression string into tokens
565569
func (p *ExpressionParser) tokenize(expression string) ([]token, error) {
570+
expressionsLog.Printf("Tokenizing expression of length %d", len(expression))
566571
var tokens []token
567572
i := 0
568573

@@ -717,6 +722,9 @@ func (p *ExpressionParser) parseUnaryExpression() (ConditionNode, error) {
717722

718723
// parsePrimaryExpression parses literals and parenthesized expressions
719724
func (p *ExpressionParser) parsePrimaryExpression() (ConditionNode, error) {
725+
if expressionsLog.Enabled() {
726+
expressionsLog.Printf("Parsing primary expression at token: %s", p.current().value)
727+
}
720728
switch p.current().kind {
721729
case tokenLeftParen:
722730
p.advance() // consume (

pkg/workflow/mcp-config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func renderAgenticWorkflowsMCPConfigTOML(yaml *strings.Builder) {
253253
// renderCustomMCPConfigWrapper generates custom MCP server configuration wrapper
254254
// This is a shared function used by both Claude and Custom engines
255255
func renderCustomMCPConfigWrapper(yaml *strings.Builder, toolName string, toolConfig map[string]any, isLast bool) error {
256+
mcpLog.Printf("Rendering custom MCP config wrapper for tool: %s", toolName)
256257
fmt.Fprintf(yaml, " \"%s\": {\n", toolName)
257258

258259
// Use the shared MCP config renderer with JSON format
@@ -708,20 +709,25 @@ func getMCPConfig(toolConfig map[string]any, toolName string) (*parser.MCPServer
708709

709710
// Infer type from fields if not explicitly provided
710711
if typeStr, hasType := config.GetString("type"); hasType {
712+
mcpLog.Printf("MCP type explicitly set to: %s", typeStr)
711713
// Normalize "local" to "stdio"
712714
if typeStr == "local" {
713715
result.Type = "stdio"
714716
} else {
715717
result.Type = typeStr
716718
}
717719
} else {
720+
mcpLog.Print("No explicit MCP type, inferring from fields")
718721
// Infer type from presence of fields
719722
if _, hasURL := config.GetString("url"); hasURL {
720723
result.Type = "http"
724+
mcpLog.Printf("Inferred MCP type as http (has url field)")
721725
} else if _, hasCommand := config.GetString("command"); hasCommand {
722726
result.Type = "stdio"
727+
mcpLog.Printf("Inferred MCP type as stdio (has command field)")
723728
} else if _, hasContainer := config.GetString("container"); hasContainer {
724729
result.Type = "stdio"
730+
mcpLog.Printf("Inferred MCP type as stdio (has container field)")
725731
} else {
726732
return nil, fmt.Errorf("unable to determine MCP type for tool '%s': missing type, url, command, or container", toolName)
727733
}
@@ -733,6 +739,7 @@ func getMCPConfig(toolConfig map[string]any, toolName string) (*parser.MCPServer
733739
}
734740

735741
// Extract fields based on type
742+
mcpLog.Printf("Extracting fields for MCP type: %s", result.Type)
736743
switch result.Type {
737744
case "stdio":
738745
if command, hasCommand := config.GetString("command"); hasCommand {

pkg/workflow/safe_outputs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func generateSafeOutputsPromptSection(yaml *strings.Builder, safeOutputs *SafeOu
6161
return
6262
}
6363

64+
safeOutputsLog.Print("Generating safe outputs prompt section")
65+
6466
// Add output instructions for all engines (GH_AW_SAFE_OUTPUTS functionality)
6567
yaml.WriteString(" \n")
6668
yaml.WriteString(" ---\n")
@@ -624,10 +626,12 @@ type SafeOutputJobConfig struct {
624626
// 3. Invoke buildGitHubScriptStep
625627
// 4. Create Job with standard metadata
626628
func (c *Compiler) buildSafeOutputJob(data *WorkflowData, config SafeOutputJobConfig) (*Job, error) {
629+
safeOutputsLog.Printf("Building safe output job: %s", config.JobName)
627630
var steps []string
628631

629632
// Add pre-steps if provided (e.g., checkout, git config for create-pull-request)
630633
if len(config.PreSteps) > 0 {
634+
safeOutputsLog.Printf("Adding %d pre-steps to job", len(config.PreSteps))
631635
steps = append(steps, config.PreSteps...)
632636
}
633637

@@ -651,6 +655,7 @@ func (c *Compiler) buildSafeOutputJob(data *WorkflowData, config SafeOutputJobCo
651655
// Determine job condition
652656
jobCondition := config.Condition
653657
if jobCondition == nil {
658+
safeOutputsLog.Printf("No custom condition provided, using default for job: %s", config.JobName)
654659
jobCondition = BuildSafeOutputType(config.JobName)
655660
}
656661

@@ -659,6 +664,7 @@ func (c *Compiler) buildSafeOutputJob(data *WorkflowData, config SafeOutputJobCo
659664
if len(needs) == 0 {
660665
needs = []string{config.MainJobName}
661666
}
667+
safeOutputsLog.Printf("Job %s needs: %v", config.JobName, needs)
662668

663669
// Create the job with standard configuration
664670
job := &Job{
@@ -680,6 +686,7 @@ func generateSafeOutputsConfig(data *WorkflowData) string {
680686
if data.SafeOutputs == nil {
681687
return ""
682688
}
689+
safeOutputsLog.Print("Generating safe outputs configuration for workflow")
683690
// Create a simplified config object for validation
684691
safeOutputsConfig := make(map[string]any)
685692

0 commit comments

Comments
 (0)