Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/colorwriter/colorprofile_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"strings"

"github.com/charmbracelet/colorprofile"
"github.com/github/gh-aw/pkg/logger"
)

var colorwriterLog = logger.New("colorwriter:colorprofile_writer")

// New returns an io.Writer that adapts color output based on the provided
// environment variables (e.g. NO_COLOR, COLORTERM, TERM).
func New(w io.Writer, environ []string) io.Writer {
colorwriterLog.Printf("New: creating color-profile writer, environ_len=%d", len(environ))
return colorprofile.NewWriter(w, environ)
}

Expand All @@ -31,6 +35,7 @@ func Degrade(s string, environ []string) string {
var buf strings.Builder
profile := colorprofile.Env(environ)
if noColorEnabled(environ) {
colorwriterLog.Print("Degrade: NO_COLOR enabled, forcing NoTTY profile")
profile = colorprofile.NoTTY
}
w := &colorprofile.Writer{
Expand All @@ -41,6 +46,7 @@ func Degrade(s string, environ []string) string {
// and strings.Builder writes cannot fail, so a write error would indicate an
// unexpected future behavior change; fall back to the original string then.
if _, err := io.WriteString(w, s); err != nil {
colorwriterLog.Printf("Degrade: color profile write failed, returning original string: %v", err)
return s
}
return buf.String()
Expand Down
8 changes: 8 additions & 0 deletions pkg/console/console_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import (
"os"
"strconv"
"strings"

"github.com/github/gh-aw/pkg/logger"
)

var consoleWasmLog = logger.New("console:console_wasm")

func isTTY() bool {
return false
}

func FormatError(err CompilerError) string {
consoleWasmLog.Printf("FormatError: type=%s, file=%s, line=%d", err.Type, err.Position.File, err.Position.Line)

var output strings.Builder

var prefix string
Expand All @@ -38,6 +44,7 @@ func FormatError(err CompilerError) string {
output.WriteString("\n")

if len(err.Context) > 0 && err.Position.Line > 0 {
consoleWasmLog.Printf("FormatError: rendering %d lines of source context", len(err.Context))
maxLineNum := err.Position.Line + len(err.Context)/2
lineNumWidth := len(strconv.Itoa(maxLineNum))
for i, line := range err.Context {
Expand Down Expand Up @@ -152,6 +159,7 @@ func RenderComposedSections(sections []string) {
}

func RenderTree(root TreeNode) string {
consoleWasmLog.Printf("RenderTree: rendering tree rooted at %q with %d children", root.Value, len(root.Children))
var render func(node TreeNode, prefix string, isLast bool) string
render = func(node TreeNode, prefix string, isLast bool) string {
var output strings.Builder
Expand Down
5 changes: 5 additions & 0 deletions pkg/parser/remote_fetch_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func isRepositoryImport(importPath string) bool {
}

func ResolveIncludePath(filePath, baseDir string, cache *ImportCache) (string, error) {
parserLog.Printf("ResolveIncludePath: filePath=%s, baseDir=%s", filePath, baseDir)

// Handle builtin paths - these are embedded files that bypass filesystem resolution.
if strings.HasPrefix(filePath, BuiltinPathPrefix) {
if !BuiltinVirtualFileExists(filePath) {
Expand All @@ -65,6 +67,7 @@ func ResolveIncludePath(filePath, baseDir string, cache *ImportCache) (string, e
}

if isWorkflowSpec(filePath) {
parserLog.Printf("ResolveIncludePath: rejecting remote workflowspec in Wasm build: %s", filePath)
return "", fmt.Errorf("remote imports not available in Wasm: %s", filePath)
}

Expand Down Expand Up @@ -109,6 +112,7 @@ func ResolveIncludePath(filePath, baseDir string, cache *ImportCache) (string, e
relativePath, err := filepath.Rel(normalizedSecurityBase, normalizedFullPath)
if err != nil || relativePath == ".." || strings.HasPrefix(relativePath, ".."+string(filepath.Separator)) || filepath.IsAbs(relativePath) {
allowedFolder := filepath.Base(normalizedSecurityBase)
parserLog.Printf("ResolveIncludePath: security boundary violation: path=%s, allowedFolder=%s", filePath, allowedFolder)
return "", fmt.Errorf("security: path %s must be within %s folder (resolves to: %s)", filePath, allowedFolder, relativePath)
}

Expand All @@ -117,6 +121,7 @@ func ResolveIncludePath(filePath, baseDir string, cache *ImportCache) (string, e
return fullPath, nil
}

parserLog.Printf("ResolveIncludePath: file not found in virtual filesystem: %s", fullPath)
return "", fmt.Errorf("file not found: %s", fullPath)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/parser/virtual_fs_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ var virtualFiles map[string][]byte
// The keys should be file paths relative to the workflow directory
// (e.g. "shared/elastic-tools.md").
func SetVirtualFiles(files map[string][]byte) {
parserLog.Printf("SetVirtualFiles: registering %d virtual files", len(files))
virtualFiles = files
}

// ClearVirtualFiles removes all virtual files.
func ClearVirtualFiles() {
parserLog.Print("ClearVirtualFiles: clearing virtual filesystem")
virtualFiles = nil
}

Expand All @@ -38,13 +40,16 @@ func init() {
defer builtinVirtualFilesMu.RUnlock()
builtinContent, builtinOK := builtinVirtualFiles[path]
if builtinOK {
parserLog.Printf("readFileFunc: resolved builtin virtual file: %s", path)
return builtinContent, nil
}
if virtualFiles != nil {
if content, ok := virtualFiles[path]; ok {
parserLog.Printf("readFileFunc: resolved user virtual file: %s", path)
return content, nil
}
}
parserLog.Printf("readFileFunc: file not found in virtual filesystem: %s", path)
return nil, fmt.Errorf("file not found in virtual filesystem: %s", path)
}
}
7 changes: 6 additions & 1 deletion pkg/workflow/awf_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,26 @@ type AWFCommandConfig struct {
}

func shouldUseWorkflowCallNetworkAllowedInput(data *WorkflowData) bool {
return data != nil &&
result := data != nil &&
data.NetworkPermissions != nil &&
data.NetworkPermissions.AllowedInput &&
hasWorkflowCallTrigger(data.On)
awfHelpersLog.Printf("shouldUseWorkflowCallNetworkAllowedInput: result=%v", result)
return result
}

func buildModelsJSONPathExportScript(isArcDind bool) string {
modelsJSONPathExpr := awfModelsJSONPathExpr
if isArcDind {
modelsJSONPathExpr = awfArcDindRootPathExpr + "/models.json"
}
awfHelpersLog.Printf("buildModelsJSONPathExportScript: isArcDind=%v, path=%s", isArcDind, modelsJSONPathExpr)
return fmt.Sprintf(`export GH_AW_MODELS_JSON_PATH="%s"`, modelsJSONPathExpr)
}

func buildWorkflowCallNetworkAllowedUpdateScript() (string, error) {
ecosystemDomains := getLoadedEcosystemDomains()
awfHelpersLog.Printf("buildWorkflowCallNetworkAllowedUpdateScript: ecosystems=%d, compoundEcosystems=%d", len(ecosystemDomains), len(compoundEcosystems))
ecosystemMap := make(map[string][]string, safeAllocationCapacity(len(ecosystemDomains), len(compoundEcosystems)))
for ecosystem := range ecosystemDomains {
ecosystemMap[ecosystem] = getEcosystemDomains(ecosystem)
Expand All @@ -126,6 +130,7 @@ func buildWorkflowCallNetworkAllowedUpdateScript() (string, error) {

ecosystemJSON, err := json.Marshal(ecosystemMap)
if err != nil {
awfHelpersLog.Printf("buildWorkflowCallNetworkAllowedUpdateScript: failed to marshal ecosystem map: %v", err)
return "", fmt.Errorf("marshal network allowed ecosystem map: %w", err)
}

Expand Down
Loading