Skip to content

feat(cast): skip writing files with empty template output #100

@kriscoleman

Description

@kriscoleman

Problem

When a template file's content is entirely wrapped in a conditional that evaluates to false, the template produces an empty string. Currently, ailloy cast still writes this empty string to disk, creating empty files in the target project.

This is common with multi-agent molds where files are conditional on agent.targets:

{{- if has "claude" .agent.targets -}}
[file content]
{{- end -}}

When casting with --set agent.targets="[copilot]", the above produces an empty CLAUDE.md file — polluting the target project.

Proposed Solution

After ProcessTemplate() returns the rendered content, check if strings.TrimSpace(processed) == "". If so, skip os.WriteFile and optionally log a debug message.

Suggested location: internal/commands/cast.go in the file-writing loop, after template processing and before os.WriteFile.

Use Case

This is needed for the nimble-mold multi-agent output architecture (nimble-giant/nimble-mold#3). Molds that target multiple agents (Claude, Copilot, Cursor) use content-level conditionals to include/exclude files based on agent.targets. Without this fix, non-targeted agent files are written as empty files.

Acceptance Criteria

  • Files whose template output is empty (whitespace-only after trimming) are not written to disk
  • A debug/verbose log message indicates the file was skipped
  • Files with actual content continue to be written normally

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions