Skip to content

Commit 66b5188

Browse files
fix: strip prompts/ prefix from config paths to avoid duplication (#200)
Previously, config paths like 'prompts/coder.md' resulted in destination .opencode/prompts/prompts/coder.md (duplicated prompts/). Now the CLI normalizes paths by stripping the leading 'prompts/' prefix before determining the destination, ensuring the output matches the config structure. Also adds validation to fail with a clear error if the normalized path would be empty (e.g., config just says 'prompts').
1 parent c70f7dd commit 66b5188

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cmd/bundle.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,33 @@ func installPromptFiles(bundleRoot, projectRoot string, promptFiles []string, fo
344344
}
345345

346346
for _, pf := range promptFiles {
347+
// Normalize path: strip leading "prompts/" prefix to avoid duplication
348+
normalizedPath := strings.TrimPrefix(pf, "prompts/")
349+
normalizedPath = strings.TrimPrefix(normalizedPath, "/")
350+
351+
// Validate normalized path isn't empty
352+
if normalizedPath == "" {
353+
return nil, fmt.Errorf("invalid prompt path in config: %q - path cannot be empty after normalization", pf)
354+
}
355+
347356
sourcePath := filepath.Join(bundleRoot, pf)
348357

349358
// Verify source file exists
350359
if _, err := os.Stat(sourcePath); err != nil {
351360
return nil, fmt.Errorf("prompt file not found in bundle: %s", pf)
352361
}
353362

354-
// Determine destination (preserve relative structure)
355-
destPath := filepath.Join(promptsDir, filepath.Base(pf))
363+
// Determine destination (preserve relative structure, but strip leading "prompts/" prefix)
364+
destPath := filepath.Join(promptsDir, filepath.Base(normalizedPath))
356365

357-
// Create subdirectory if needed (for paths like prompts/subdir/file.md)
358-
if strings.Contains(pf, string(filepath.Separator)) {
359-
subdir := filepath.Dir(pf)
366+
// Create subdirectory if needed (for paths like subdir/file.md)
367+
if strings.Contains(normalizedPath, string(filepath.Separator)) {
368+
subdir := filepath.Dir(normalizedPath)
360369
subdirPath := filepath.Join(promptsDir, subdir)
361370
if err := os.MkdirAll(subdirPath, 0755); err != nil {
362371
return nil, fmt.Errorf("failed to create subdirectory: %w", err)
363372
}
364-
destPath = filepath.Join(promptsDir, pf)
373+
destPath = filepath.Join(promptsDir, normalizedPath)
365374
}
366375

367376
// Check if destination exists (unless force)

0 commit comments

Comments
 (0)