diff --git a/cmd/root.go b/cmd/root.go index 154c179..cf9112f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,7 +71,6 @@ Examples: tuiMode bool instructions bool pickPaths []string - smallTree bool ) func Execute() { @@ -99,7 +98,6 @@ func init() { rootCmd.Flags().BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md") rootCmd.Flags().BoolVar(&instructions, "instructions", false, "include .dirmd instructions file if present in root") rootCmd.Flags().StringArrayVar(&pickPaths, "pick", nil, "repeatable: relative path to file to include as pick (requires --vertical-slices)") - rootCmd.Flags().BoolVar(&smallTree, "small-tree", false, "use breadcrumb-only tree for picked files (default: full tree)") } func run(cmd *cobra.Command, args []string) error { @@ -153,7 +151,6 @@ func run(cmd *cobra.Command, args []string) error { OmitMd: omitMd, IncludeInstructions: instructions, PickPaths: pickPaths, - SmallTree: smallTree, } if singleFile != "" { diff --git a/internal/config/config.go b/internal/config/config.go index dda3337..e33e091 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -66,7 +66,6 @@ type Config struct { OmitMd bool IncludeInstructions bool PickPaths []string - SmallTree bool } func PrintUsage() { @@ -97,7 +96,6 @@ func Parse() (*Config, error) { omitMd bool includeInstructions bool pickPaths stringSlice - smallTree bool ) flag.StringVar(&input, "i", "", "single file input (append mode only)") @@ -118,7 +116,6 @@ func Parse() (*Config, error) { flag.BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md") flag.BoolVar(&includeInstructions, "instructions", false, "include .dirmd instructions file if present in root") flag.Var(&pickPaths, "pick", "repeatable: relative path to file to include as pick (requires --vertical-slices)") - flag.BoolVar(&smallTree, "small-tree", false, "use breadcrumb-only tree for picked files (default: full tree)") flag.Usage = PrintUsage flag.Parse() @@ -169,7 +166,6 @@ func Parse() (*Config, error) { OmitMd: omitMd, IncludeInstructions: includeInstructions, PickPaths: pickPaths, - SmallTree: smallTree, } if input != "" { diff --git a/internal/renderer/renderer.go b/internal/renderer/renderer.go index 27dfda2..99976be 100644 --- a/internal/renderer/renderer.go +++ b/internal/renderer/renderer.go @@ -154,7 +154,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e pickInfos := make([]PickInfo, 0) if len(result.Cfg.PickPaths) > 0 { - pickInfos, err = writePickFiles(absRoot, absRoot, outputDir, result.Cfg, result.OmitTest, result.Commit, treeRoot, result.Cfg.SmallTree) + pickInfos, err = writePickFiles(absRoot, outputDir, result.Cfg, result.OmitTest, result.Commit) if err != nil { return nil, fmt.Errorf("failed to write pick files: %w", err) } @@ -165,7 +165,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e return nil, fmt.Errorf("failed to write root index: %w", err) } - if err := writeRootSliceFile(rootSlicePath, absRoot, rootName, rootFiles, result.OmitTest, result.Commit, result.Cfg); err != nil { + if err := writeRootSliceFile(rootSlicePath, absRoot, rootFiles, result.OmitTest, result.Commit, result.Cfg); err != nil { return nil, fmt.Errorf("failed to write root slice: %w", err) } @@ -181,7 +181,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e absDir := filepath.Join(absRoot, dirName) dirEntries := topLevelDirs[dirName] - if err := writeDirSlice(slicePath, absDir, absRoot, dirName, dirEntries, indexBasename, result.OmitTest, result.Commit, treeRoot, result.Cfg); err != nil { + if err := writeDirSlice(slicePath, absDir, absRoot, dirName, dirEntries, indexBasename, result.OmitTest, result.Commit, result.Cfg); err != nil { return nil, fmt.Errorf("failed to write slice %s: %w", sliceName, err) } } @@ -203,7 +203,7 @@ func pickInfoPaths(picks []PickInfo) []string { return paths } -func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omitTest bool, commit *git.CommitInfo, treeRoot *tree.Node, smallTree bool) ([]PickInfo, error) { +func writePickFiles(absRoot, outputDir string, cfg *config.Config, omitTest bool, commit *git.CommitInfo) ([]PickInfo, error) { var pickInfos []PickInfo for _, pickPath := range cfg.PickPaths { @@ -218,9 +218,8 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi return nil, fmt.Errorf("pick path must be a file: %s", pickPath) } - // Validate file passes filters name := filepath.Base(pickPath) - filter := &filter.Filter{ + flt := &filter.Filter{ MaxSize: cfg.MaxSize, Extensions: cfg.Extensions, Ignores: cfg.Ignores, @@ -229,11 +228,10 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi OmitMd: cfg.OmitMd, } - if filter.ShouldSkipFile(fullPath, name, info) { + if flt.ShouldSkipFile(fullPath, name, info) { return nil, fmt.Errorf("pick path %s filtered by active rules", pickPath) } - // Determine slice dir from first path segment parts := strings.Split(pickPath, string(filepath.Separator)) sliceDir := outputDir if len(parts) > 1 { @@ -241,15 +239,12 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi if err := os.MkdirAll(sliceDir, 0755); err != nil { return nil, fmt.Errorf("cannot create pick slice directory %s: %w", sliceDir, err) } - } else { - // Root-level pick - sliceDir = outputDir } sliceName := filepath.Base(pickPath) + ".md" pickPathOut := filepath.Join(sliceDir, sliceName) - if err := writePickFile(pickPathOut, absRoot, pickPath, omitTest, commit, cfg, treeRoot, smallTree); err != nil { + if err := writePickFile(pickPathOut, absRoot, pickPath, omitTest, commit, cfg); err != nil { return nil, fmt.Errorf("failed to write pick %s: %w", pickPath, err) } @@ -263,7 +258,7 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi return pickInfos, nil } -func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.CommitInfo, cfg *config.Config, treeRoot *tree.Node, smallTree bool) error { +func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error { f, err := os.Create(path) if err != nil { return fmt.Errorf("cannot create pick file: %w", err) @@ -276,6 +271,7 @@ func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.Com fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339)) sb.WriteString(git.FormatCommitLine(commit)) sb.WriteString(FormatFlags(cfg)) + fmt.Fprintf(&sb, "Root document: index_%s.md\n\n", filepath.Base(absRoot)) fullPath := filepath.Join(absRoot, relPath) content, err := readFileForOutput(fullPath, omitTest) @@ -285,15 +281,7 @@ func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.Com language := extToLang(filepath.Ext(relPath)) lines := countLines(content) - if smallTree { - breadcrumb := tree.RenderBreadcrumb(absRoot, relPath) - fmt.Fprintf(&sb, "Tree: %s\n\n", breadcrumb) - } else { - sb.WriteString("## Directory Tree\n\n") - sb.WriteString(fenceChars + "\n") - sb.WriteString(renderTreeWithLegend(treeRoot, filepath.Base(absRoot))) - sb.WriteString(fenceChars + "\n\n") - } + fmt.Fprintf(&sb, "Tree: %s\n\n", tree.RenderBreadcrumb(absRoot, relPath)) fmt.Fprintf(&sb, "--- FILE: ./%s (%d bytes, %d lines) ---\n", relPath, infoSize(fullPath), lines) sb.WriteString(fenceChars) @@ -305,7 +293,7 @@ func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.Com if !strings.HasSuffix(content, "\n") { sb.WriteString("\n") } - sb.WriteString(fmt.Sprintf("%s\n--- END FILE ---\n\n", fenceChars)) + fmt.Fprintf(&sb, "%s\n--- END FILE ---\n\n", fenceChars) _, err = f.WriteString(sb.String()) return err @@ -378,7 +366,7 @@ func writeRootIndex(path, absRoot, rootName, repoName string, topLevelDirs map[s return err } -func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error { +func writeRootSliceFile(path, absRoot string, rootFiles []walker.Entry, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error { f, err := os.Create(path) if err != nil { return fmt.Errorf("cannot create root slice file: %w", err) @@ -391,7 +379,8 @@ func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry sb.WriteString(git.FormatCommitLine(commit)) sb.WriteString(FormatFlags(cfg)) - sb.WriteString("Root contents: all files at the repository root level.\n\n") + rootName := filepath.Base(absRoot) + fmt.Fprintf(&sb, "Tree: %s /\n\n", rootName) if len(rootFiles) == 0 { sb.WriteString("(none)\n") @@ -425,7 +414,7 @@ func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry return err } -func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.Entry, rootFileName string, omitTest bool, commit *git.CommitInfo, treeRoot *tree.Node, cfg *config.Config) error { +func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.Entry, rootFileName string, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error { f, err := os.Create(path) if err != nil { return fmt.Errorf("cannot create slice file: %w", err) @@ -439,10 +428,7 @@ func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.E sb.WriteString(FormatFlags(cfg)) fmt.Fprintf(&sb, "Root document: %s\n\n", rootFileName) - sb.WriteString("## Directory Tree\n\n") - sb.WriteString(fenceChars + "\n") - sb.WriteString(renderTreeWithLegend(treeRoot, filepath.Base(absDir))) - sb.WriteString(fenceChars + "\n\n") + fmt.Fprintf(&sb, "Tree: %s / %s\n\n", filepath.Base(absRoot), dirName) if len(fileEntries) > 0 { sb.WriteString("## Contents\n\n")