Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

ensure dir exists before applying

Dane Schneidera33049b2dafc
diff --git a/cli/lib/apply.go b/cli/lib/apply.go
index 3a40e034..1f016a5c 100644
--- a/cli/lib/apply.go
+++ b/cli/lib/apply.go
@@ -307,6 +307,13 @@ func ApplyPlanWithOutput(name string, autoConfirm bool) error {
for path, content := range toApply {
// Compute destination path
dstPath := filepath.Join(ProjectRoot, path)
+ // Create the directory if it doesn't exist
+ err := os.MkdirAll(filepath.Dir(dstPath), 0755)
+ if err != nil {
+ aborted = true
+ return fmt.Errorf("failed to create directory %s: %w", filepath.Dir(dstPath), err)
+ }
+
// Write the file
err = os.WriteFile(dstPath, []byte(content), 0644)
if err != nil {