Skip to content

feat(cli,core,config): Add --include-full-directory-structure and full repository tree#896

Merged
yamadashy merged 7 commits intoyamadashy:mainfrom
slavakurilyak:feat/include-full-directory-structure
Oct 18, 2025
Merged

feat(cli,core,config): Add --include-full-directory-structure and full repository tree#896
yamadashy merged 7 commits intoyamadashy:mainfrom
slavakurilyak:feat/include-full-directory-structure

Conversation

@slavakurilyak
Copy link
Contributor

@slavakurilyak slavakurilyak commented Oct 15, 2025

Summary

Adds --include-full-directory-structure to display the full repository directory tree (subject to ignore rules) in the Directory Structure section when --include is used. File processing remains scoped to the --include patterns. The flag is opt‑in and defaults to false (non‑breaking).

Motivation

Tracked in #895. When using --include patterns, Repomix only shows directories that contain included files, which hides top‑level context.

Current output:

<directory_structure>
cli/
  go.mod
  main.go
  README.md
</directory_structure>

Expected:

<directory_structure>
README.md
LICENSE.md
cli/
  go.mod
  main.go
  README.md
</directory_structure>

This change adds a flag to render the full tree while leaving file selection unchanged.

Behavior

  • Affects tree rendering only; does not change file selection or metrics.
  • Honors ignore rules: .gitignore (via globby ignoreFiles), .repomixignore, custom --ignore, default ignore patterns, and .git/info/exclude.
  • Respects --no-gitignore (shows directories without .gitignore filtering).
  • Worktree handling stays consistent with existing logic.
  • If output.directoryStructure is disabled, the section is omitted regardless of this flag.
  • Applies when the flag is on and include patterns are present; otherwise behavior is unchanged.

Usage

repomix --include "cli/**/*.go" --include-full-directory-structure

Implementation

  • CLI/Config: adds --include-full-directory-structure and output.includeFullDirectoryStructure (default false).
  • Core: introduces listDirectories() (respects ignore logic) and switches the directory tree source in buildOutputGeneratorContext when appropriate.
  • Ignore handling: avoids merging .gitignore entries directly into the ignore list to preserve negation semantics; instead relies on ignoreFiles for .gitignore and reads .git/info/exclude explicitly.

Tests

  • Adds a focused unit test for the new flag behavior.
  • Updates existing tests to include the new default in config expectations.

Verification

  • Type-check passes.
  • Focused unit test for full-directory-structure passes.

Benefits

  • Provides full project context while still allowing focused file selection.
  • Complements --no-directory-structure as an opt‑in visualization feature.
  • Non‑breaking; default behavior unchanged.

Checklist

  • Run npm run test
  • Run npm run lint

Closes #895.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Adds 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

Cohort / File(s) Summary
CLI options handling
src/cli/actions/defaultAction.ts, src/cli/cliRun.ts, src/cli/types.ts
Adds --include-full-directory-structure flag; plumbs option into CliOptions; merges includeFullDirectoryStructure into cliConfig.output.
Config schema
src/config/configSchema.ts
Adds output.includeFullDirectoryStructure to base and default schemas (default false); inferred types updated.
File search enhancements
src/core/file/fileSearch.ts
Adds exported listDirectories(rootDir, config); extends ignore pattern resolution (supports .git/info/exclude; worktree adjustment); returns sorted relative dirs.
Output generation logic & DI
src/core/output/outputGenerate.ts
Adds deps parameter to buildOutputGeneratorContext and generateOutput; implements full-tree mode using deps.listDirectories; retains empty directory handling via deps.searchFiles; centralized error wrapping.
Security types
src/core/security/workers/secretlint.d.ts
Declares ambient module @secretlint/secretlint-rule-preset-recommend exporting creator: any.
Tests
tests/cli/actions/workers/defaultActionWorker.test.ts, tests/config/configSchema.test.ts, tests/core/metrics/calculateGitDiffMetrics.test.ts, tests/core/metrics/calculateGitLogMetrics.test.ts, tests/core/output/flagFullDirectoryStructure.test.ts, tests/core/output/outputStyles/jsonStyle.test.ts
Updates configs to include includeFullDirectoryStructure (false); adds new test validating full-tree behavior via buildOutputGeneratorContext with mocked deps.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • yamadashy

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary feature addition of the new CLI flag and full repository tree behavior, aligns with conventional commit format, and clearly summarizes the main change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed The PR description includes a clear summary of the changes and concludes with a ## Checklist section containing both required test and lint items, matching the repository’s template verbatim, and the additional sections (Motivation, Behavior, Usage, Implementation, Tests, Verification, Benefits) complement but do not conflict with the minimal template requirements.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 --include-full-directory-structure option. This new flag allows users to generate a comprehensive view of the entire repository's directory tree, even when specific file inclusion patterns are defined. It integrates seamlessly with existing ignore mechanisms, ensuring that .gitignore rules are respected, and provides a more complete contextual understanding of the project's layout.

Highlights

  • New CLI Option: Introduced --include-full-directory-structure to display the complete repository directory tree.
  • Full Tree Display: When enabled with --include patterns, this flag ensures the entire repository structure is shown, respecting ignore rules.
  • Ignore Logic Integration: The feature reuses existing ignore logic, honoring .gitignore and .git/info/exclude files.
  • New Helper Function: A listDirectories helper was added to efficiently retrieve all directories.
  • Test Coverage: Includes a focused unit test for the new functionality and updates to existing tests.
  • TypeScript Shim: A small TypeScript declaration file was added for the Secretlint preset.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/core/security/workers/secretlint.d.ts (1)

1-3: Consider using unknown instead of any for better type safety.

While any is acceptable for ambient module declarations of external packages, unknown provides 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c118c9 and 5ed4515.

📒 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 includeFullDirectoryStructure field 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 includeFullDirectoryStructure field 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 CliOptions interface 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 --include patterns.

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
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

❌ Patch coverage is 45.71429% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.28%. Comparing base (9211d4e) to head (532c38f).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/core/file/fileSearch.ts 42.59% 31 Missing ⚠️
src/core/output/outputGenerate.ts 39.47% 23 Missing ⚠️
src/cli/actions/defaultAction.ts 50.00% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yamadashy
Copy link
Owner

Hi, @slavakurilyak !
Thank you for the PR!

Both the implementation and behavior look great. I'll do a bit more review and then merge it soon!

@yamadashy
Copy link
Owner

yamadashy commented Oct 17, 2025

Quick question: I noticed listDirectories() uses onlyDirectories: true, which means files like README.md at the root won't appear in the tree structure.

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 --include patterns?

slavakurilyak and others added 7 commits October 17, 2025 17:50
…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
@slavakurilyak slavakurilyak force-pushed the feat/include-full-directory-structure branch from e2eb36c to 532c38f Compare October 18, 2025 00:50
@slavakurilyak
Copy link
Contributor Author

@yamadashy good catch! I made the necessary changes to account for this.

@yamadashy
Copy link
Owner

@slavakurilyak
Thank you for your quick response and the fix!

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! 🚀

@yamadashy yamadashy merged commit 4e45329 into yamadashy:main Oct 18, 2025
79 of 82 checks passed
yamadashy added a commit that referenced this pull request Oct 18, 2025
…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
yamadashy added a commit that referenced this pull request Oct 18, 2025
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
yamadashy added a commit that referenced this pull request Oct 18, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add --incude-full-directory-structure flag

2 participants