Skip to content

Commit 15b3746

Browse files
Add debug logging to five pkg/ files (#30266)
1 parent 31153dc commit 15b3746

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

pkg/fileutil/fileutil.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var log = logger.New("fileutil:fileutil")
3737
func ValidateAbsolutePath(path string) (string, error) {
3838
// Check for empty path
3939
if path == "" {
40+
log.Print("ValidateAbsolutePath: rejected empty path")
4041
return "", errors.New("path cannot be empty")
4142
}
4243

@@ -45,9 +46,11 @@ func ValidateAbsolutePath(path string) (string, error) {
4546

4647
// Verify the path is absolute to prevent relative path traversal
4748
if !filepath.IsAbs(cleanPath) {
49+
log.Printf("ValidateAbsolutePath: rejected relative path: %s", path)
4850
return "", fmt.Errorf("path must be absolute, got: %s", path)
4951
}
5052

53+
log.Printf("ValidateAbsolutePath: validated path: %s", cleanPath)
5154
return cleanPath, nil
5255
}
5356

@@ -60,6 +63,7 @@ func ValidateAbsolutePath(path string) (string, error) {
6063
// - Either path cannot be resolved to an absolute form.
6164
// - The resolved candidate path starts outside the resolved base directory.
6265
func MustBeWithin(base, candidate string) error {
66+
log.Printf("MustBeWithin: checking candidate=%q within base=%q", candidate, base)
6367
// EvalSymlinks resolves both symlinks and ".." components.
6468
// Fall back to Abs when a path does not exist on disk yet.
6569
absBase, err := filepath.EvalSymlinks(base)
@@ -78,8 +82,10 @@ func MustBeWithin(base, candidate string) error {
7882
}
7983
rel, err := filepath.Rel(absBase, absCand)
8084
if err != nil || !filepath.IsLocal(rel) {
85+
log.Printf("MustBeWithin: path escape detected: candidate=%q base=%q", candidate, base)
8186
return fmt.Errorf("path %q escapes base directory %q", candidate, base)
8287
}
88+
log.Printf("MustBeWithin: path is safe: candidate=%q (rel=%s) within base=%q", candidate, rel, base)
8389
return nil
8490
}
8591

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
package workflow
22

3+
import "github.com/github/gh-aw/pkg/logger"
4+
5+
var repoConfigLog = logger.New("workflow:compiler_repo_config")
6+
37
// loadRepoConfig loads and caches repository-level configuration from aw.json.
48
func (c *Compiler) loadRepoConfig() (*RepoConfig, error) {
59
if c.repoConfigLoaded {
10+
repoConfigLog.Print("loadRepoConfig: returning cached repo config")
611
return c.repoConfig, c.repoConfigErr
712
}
813

14+
repoConfigLog.Printf("loadRepoConfig: loading repo config from git root: %s", c.gitRoot)
915
c.repoConfig, c.repoConfigErr = LoadRepoConfig(c.gitRoot)
1016
c.repoConfigLoaded = true
17+
if c.repoConfigErr != nil {
18+
repoConfigLog.Printf("loadRepoConfig: failed to load repo config: %v", c.repoConfigErr)
19+
} else {
20+
repoConfigLog.Print("loadRepoConfig: repo config loaded successfully")
21+
}
1122
return c.repoConfig, c.repoConfigErr
1223
}

pkg/workflow/compiler_yaml_audit_step.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package workflow
22

33
import (
44
"strings"
5+
6+
"github.com/github/gh-aw/pkg/logger"
57
)
68

9+
var auditStepLog = logger.New("workflow:compiler_yaml_audit_step")
10+
711
// generatePreAgentAuditStep emits a step that lists files in agent-related directories
812
// for all known agentic engines (Copilot, Claude, Codex, Gemini, Crush, OpenCode, Pi)
913
// under the workspace and the agent user's home folder.
@@ -18,6 +22,7 @@ import (
1822
// continue-on-error so a missing directory or permission error does not block agent
1923
// execution.
2024
func (c *Compiler) generatePreAgentAuditStep(yaml *strings.Builder) {
25+
auditStepLog.Print("Generating pre-agent workspace audit step")
2126
yaml.WriteString(" - name: Audit pre-agent workspace\n")
2227
yaml.WriteString(" id: pre_agent_audit\n")
2328
yaml.WriteString(" continue-on-error: true\n")

pkg/workflow/map_helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ package workflow
3636
import (
3737
"maps"
3838
"slices"
39+
40+
"github.com/github/gh-aw/pkg/logger"
3941
)
4042

43+
var mapHelpersLog = logger.New("workflow:map_helpers")
44+
4145
// excludeMapKeys creates a new map excluding the specified keys
4246
func excludeMapKeys(original map[string]any, excludeKeys ...string) map[string]any {
47+
if mapHelpersLog.Enabled() {
48+
mapHelpersLog.Printf("excludeMapKeys: input=%d keys, excluding=%v", len(original), excludeKeys)
49+
}
4350
excludeSet := make(map[string]bool)
4451
for _, key := range excludeKeys {
4552
excludeSet[key] = true
@@ -51,6 +58,9 @@ func excludeMapKeys(original map[string]any, excludeKeys ...string) map[string]a
5158
result[key] = value
5259
}
5360
}
61+
if mapHelpersLog.Enabled() {
62+
mapHelpersLog.Printf("excludeMapKeys: output=%d keys", len(result))
63+
}
5464
return result
5565
}
5666

pkg/workflow/sub_agent_step.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/github/gh-aw/pkg/logger"
78
"github.com/github/gh-aw/pkg/parser"
89
)
910

11+
var subAgentStepLog = logger.New("workflow:sub_agent_step")
12+
1013
// generateRestoreInlineSubAgentsStep emits a step that copies inline sub-agent files
1114
// from the activation artifact into the workspace after the base-branch restore.
1215
//
@@ -24,6 +27,7 @@ func generateRestoreInlineSubAgentsStep(yaml *strings.Builder, data *WorkflowDat
2427
}
2528
subAgentDir := parser.GetEngineSubAgentDir(engineID)
2629
subAgentExt := parser.GetEngineSubAgentExt(engineID)
30+
subAgentStepLog.Printf("Generating restore inline sub-agents step: engine=%s, dir=%s, ext=%s", engineID, subAgentDir, subAgentExt)
2731

2832
yaml.WriteString(" - name: Restore inline sub-agents from activation artifact\n")
2933
yaml.WriteString(" env:\n")

0 commit comments

Comments
 (0)