feat(cli,core,config): Add --include-full-directory-structure and full repository tree#896
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a new output option includeFullDirectoryStructure at CLI, types, and config schema levels; implements directory listing via listDirectories with updated ignore handling; integrates full-tree inclusion into output generation with dependency injection; adds a Secretlint ambient module type; updates and adds tests for the new flag and behavior. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CLI as CLI
participant Config as Config Schema
participant Output as Output Generator
participant FS as File Search
participant Render as Renderers
User->>CLI: Run with --include-full-directory-structure
CLI->>Config: Build merged config (output.includeFullDirectoryStructure)
CLI->>Output: generateOutput(rootDirs, config, deps)
alt includeFullDirectoryStructure = true
Output->>FS: listDirectories(rootDir, config)
FS-->>Output: [sorted dir paths]
Output->>Render: generate output with full dir tree
else includeFullDirectoryStructure = false
Output->>FS: searchFiles(...) for includeEmptyDirectories
FS-->>Output: [empty dir paths]
Output->>Render: generate output (files + optional empty dirs)
end
Render-->>User: Final output
note over FS: getIgnorePatterns may read .git/info/exclude<br/>and adjust for worktrees
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @slavakurilyak, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the CLI by adding an Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new --include-full-directory-structure flag, which allows displaying the complete repository directory tree even when using --include to filter files. The implementation is solid, adding the new flag to the CLI, configuration schemas, and core logic. A new listDirectories helper is introduced to fetch all directories, and the output generation is updated to use this data when the flag is active. The changes are well-tested with a new focused unit test and updates to existing mocks.
My review includes a few suggestions to improve maintainability and clarity:
- Refactoring duplicated code for handling ignore patterns into a shared helper.
- Renaming a variable for better clarity in its new context.
- Improving error handling to be more robust and consistent.
Overall, this is a great addition that enhances the flexibility of the tool's output.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/core/security/workers/secretlint.d.ts (1)
1-3: Consider usingunknowninstead ofanyfor better type safety.While
anyis acceptable for ambient module declarations of external packages,unknownprovides slightly better type safety by requiring type assertions before use.Apply this diff:
declare module '@secretlint/secretlint-rule-preset-recommend' { - export const creator: any; + export const creator: unknown; }tests/core/output/flagFullDirectoryStructure.test.ts (1)
51-80: Good focused test for full-tree mode. Consider adding a negative-path test.Add a test where includeFullDirectoryStructure=true but include=[], to assert full-tree is not used (docs should not appear).
src/core/output/outputGenerate.ts (1)
287-318: Avoid unnecessary directory scans when directoryStructure is disabled; ensure deterministic order.
- Currently, listDirectories/searchFiles can run even if directoryStructure=false (tree not rendered). Add a guard to skip scanning in that case.
- After dedup with Set, sort for stable output.
Apply this diff:
- // Determine if full-tree mode applies - const shouldUseFullTree = !!config.output.includeFullDirectoryStructure && (config.include?.length ?? 0) > 0; + // Determine if full-tree mode applies (only when directory structure is actually rendered) + const shouldUseFullTree = + config.output.directoryStructure === true && + !!config.output.includeFullDirectoryStructure && + (config.include?.length ?? 0) > 0; @@ - if (shouldUseFullTree) { + if (shouldUseFullTree) { @@ - // Merge and deduplicate directory lists - emptyDirPaths = Array.from(new Set(allDirectories.flat())); + // Merge, deduplicate, and sort directory lists for determinism + emptyDirPaths = Array.from(new Set(allDirectories.flat())).sort(); } catch (error) { @@ - } else if (config.output.includeEmptyDirectories) { + } else if (config.output.directoryStructure && config.output.includeEmptyDirectories) { @@ - ).emptyDirPaths; + ).emptyDirPaths.sort();
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/cli/actions/defaultAction.ts(1 hunks)src/cli/cliRun.ts(1 hunks)src/cli/types.ts(1 hunks)src/config/configSchema.ts(2 hunks)src/core/file/fileSearch.ts(2 hunks)src/core/output/outputGenerate.ts(3 hunks)src/core/security/workers/secretlint.d.ts(1 hunks)tests/cli/actions/workers/defaultActionWorker.test.ts(1 hunks)tests/config/configSchema.test.ts(2 hunks)tests/core/metrics/calculateGitDiffMetrics.test.ts(1 hunks)tests/core/metrics/calculateGitLogMetrics.test.ts(1 hunks)tests/core/output/flagFullDirectoryStructure.test.ts(1 hunks)tests/core/output/outputStyles/jsonStyle.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/core/file/fileSearch.ts (2)
src/config/configSchema.ts (1)
RepomixConfigMerged(167-167)src/index.ts (1)
sortPaths(9-9)
tests/core/output/flagFullDirectoryStructure.test.ts (3)
tests/testing/testUtils.ts (1)
createMockConfig(15-45)src/config/configSchema.ts (1)
RepomixConfigMerged(167-167)src/core/output/outputGenerate.ts (1)
buildOutputGeneratorContext(264-329)
src/core/output/outputGenerate.ts (1)
src/shared/errorHandle.ts (1)
RepomixError(6-11)
🔇 Additional comments (12)
tests/core/metrics/calculateGitLogMetrics.test.ts (1)
44-44: LGTM!Test mock config correctly updated to include the new
includeFullDirectoryStructurefield with the default value.tests/core/metrics/calculateGitDiffMetrics.test.ts (1)
44-44: LGTM!Test configuration properly updated with the new field.
tests/core/output/outputStyles/jsonStyle.test.ts (1)
26-26: LGTM!Mock configuration correctly includes the new optional field.
tests/cli/actions/workers/defaultActionWorker.test.ts (1)
54-54: LGTM!Test mock properly updated with the new configuration field.
tests/config/configSchema.test.ts (1)
116-116: LGTM!Schema validation tests properly updated to include the new
includeFullDirectoryStructurefield in both default and merged configuration test cases.Also applies to: 215-215
src/cli/types.ts (1)
25-25: LGTM!The new optional boolean field is correctly positioned in the Output Options section of the
CliOptionsinterface and follows the existing naming conventions.src/cli/cliRun.ts (1)
120-123: LGTM!The new CLI option is well-documented, properly placed in the "Repomix Output Options" group, and the description clearly explains its purpose—showing the entire repository tree even when using
--includepatterns.src/config/configSchema.ts (1)
42-42: Schema addition and default look correct.includeFullDirectoryStructure is optional in base and defaults to false in defaults. LGTM. Please ensure config docs/README mention the new option.
Also applies to: 104-104
src/core/file/fileSearch.ts (2)
307-320: Reading .git/info/exclude when useGitignore is enabled — looks good.Graceful fallback + trace logging is appropriate. No change requested.
333-368: Directory listing honors ignore rules; implementation is sound.
- Globby config (onlyDirectories, dot, ignore/ignoreFiles) is correct.
- Worktree adjustment for .git/** is a nice touch.
src/core/output/outputGenerate.ts (1)
271-275: Nice DI surface for output generation internals.Defaulted deps and testability improvements are welcome.
src/cli/actions/defaultAction.ts (1)
237-242: includeFullDirectoryStructure flag wiring verified end-to-end Defined in commander, typed in CliOptions, mapped in defaultAction, consumed in outputGenerate, and covered by tests; CLI help description present.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #896 +/- ##
==========================================
- Coverage 74.66% 74.28% -0.38%
==========================================
Files 109 110 +1
Lines 7653 7750 +97
Branches 1433 1446 +13
==========================================
+ Hits 5714 5757 +43
- Misses 1939 1993 +54 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi, @slavakurilyak ! Both the implementation and behavior look great. I'll do a bit more review and then merge it soon! |
|
Quick question: I noticed But the issue example (#895) seems to expect those files to be shown. Was this intentional, or should we also include files not matched by |
…l repository tree
…e flag Add CLI option documentation for the --include-full-directory-structure flag in the README. This flag allows users to display the complete directory tree in output, including files not matched by --include patterns, providing full project context while maintaining focused file selection.
When --include-full-directory-structure flag is enabled, the tree now displays all files in the repository (subject to ignore patterns), not just files matching include patterns. This provides a more complete view of the repository structure. Changes: - Add listFiles() function to scan all repository files - Merge additional files into tree visualization - Update tests to verify root-level files appear in tree - Bump Biome schema to 2.2.6 - Improve Secretlint TypeScript type declarations
e2eb36c to
532c38f
Compare
|
@yamadashy good catch! I made the necessary changes to account for this. |
|
@slavakurilyak The implementation looks perfect now, and everything is working as expected. I'll merge this PR! Thanks again for the great contribution, and looking forward to collaborating with you again! 🚀 |
…re flag Add comprehensive documentation for the new --include-full-directory-structure CLI flag across all language versions of the website documentation. This flag allows users to display the complete repository directory tree in the output when using --include patterns, providing full project context while maintaining focused file selection. Updated files: - usage.md: Added new section explaining the feature with examples - configuration.md: Added output.includeFullDirectoryStructure option to config table - command-line-options.md: Added CLI flag description Languages updated: en, ja, de, fr, es, pt-br, id, vi, hi, ko, zh-cn, zh-tw Related to PR #896
Clarify the default behavior of --include option in usage.md across all language versions. Changes: - Modify example to show only files matching the glob pattern when --include is used without --include-full-directory-structure - Update note to explain default --include pattern behavior - Maintain consistent translation across all languages Addresses Gemini Code Assistant's review comment about potentially misleading directory structure example. Related to PR #896
Clarify the default behavior of --include option in usage.md across all language versions. Changes: - Modify example to show only files matching the glob pattern when --include is used without --include-full-directory-structure - Update note to explain default --include pattern behavior - Maintain consistent translation across all 12 languages Addresses Gemini Code Assistant's review comment about potentially misleading directory structure example that could confuse users about the base behavior of --include patterns. Languages updated: de, en, es, fr, hi, id, ja, ko, pt-br, vi, zh-cn, zh-tw Related to PR #896
Summary
Adds
--include-full-directory-structureto display the full repository directory tree (subject to ignore rules) in the Directory Structure section when--includeis used. File processing remains scoped to the--includepatterns. The flag is opt‑in and defaults tofalse(non‑breaking).Motivation
Tracked in #895. When using
--includepatterns, Repomix only shows directories that contain included files, which hides top‑level context.Current output:
Expected:
This change adds a flag to render the full tree while leaving file selection unchanged.
Behavior
.gitignore(viaglobbyignoreFiles),.repomixignore, custom--ignore, default ignore patterns, and.git/info/exclude.--no-gitignore(shows directories without.gitignorefiltering).output.directoryStructureis disabled, the section is omitted regardless of this flag.includepatterns are present; otherwise behavior is unchanged.Usage
repomix --include "cli/**/*.go" --include-full-directory-structureImplementation
--include-full-directory-structureandoutput.includeFullDirectoryStructure(defaultfalse).listDirectories()(respects ignore logic) and switches the directory tree source inbuildOutputGeneratorContextwhen appropriate..gitignoreentries directly into theignorelist to preserve negation semantics; instead relies onignoreFilesfor.gitignoreand reads.git/info/excludeexplicitly.Tests
Verification
Benefits
--no-directory-structureas an opt‑in visualization feature.Checklist
npm run testnpm run lintCloses #895.