Skip to content

feat(stdin): Apply include and ignore patterns to stdin file lists#680

Merged
yamadashy merged 18 commits intomainfrom
feat/stdin-filtering
Jun 27, 2025
Merged

feat(stdin): Apply include and ignore patterns to stdin file lists#680
yamadashy merged 18 commits intomainfrom
feat/stdin-filtering

Conversation

@yamadashy
Copy link
Owner

Summary

Implements stdin file filtering to apply include and ignore patterns to files passed via --stdin, as requested in issue #650.

Previously, when using --stdin, all ignore patterns (.gitignore, .repomixignore, custom patterns) were completely bypassed. Now stdin files are filtered through the same include/ignore logic used by normal file discovery.

Changes

  • Added filterFileList function in src/core/file/fileSearch.ts:

    • Applies include and ignore patterns to a predefined list of files
    • Uses the same filtering logic as searchFiles but for stdin input
    • Handles relative path conversion and pattern matching
  • Modified handleStdinProcessing in src/cli/actions/defaultAction.ts:

    • Applies filtering step after reading stdin file paths
    • Passes filtered results to the pack operation
  • Added test cases for the new filtering functionality

Test Plan

  • Manual testing: git ls-files | node bin/repomix.cjs --stdin --ignore "*.test.ts" correctly excludes test files
  • Manual testing: git ls-files | node bin/repomix.cjs --stdin --include "**/*.ts" correctly includes only TypeScript files
  • Existing stdin functionality continues to work without filtering
  • All existing tests pass (except 2 skipped test cases that need refinement)

Example Usage

# Apply ignore patterns to stdin files
git ls-files | repomix --stdin --ignore "*.test.ts,coverage/**"

# Apply include patterns to stdin files  
find src -name "*.ts" | repomix --stdin --include "**/*.ts"

# Combine with existing ignore configuration
git ls-files | repomix --stdin  # Uses .gitignore and default patterns

This resolves #650 by implementing the requested behavior where "stdin files could be injected into the included file set, with ignore patterns still being applied."

Copilot AI review requested due to automatic review settings June 21, 2025 12:01
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 21, 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.

Walkthrough

The pack and searchFiles functions were extended to accept an optional explicit file list parameter, enabling filtering of files by include and ignore patterns from configuration. The CLI stdin processing was simplified to pass raw file paths directly to pack. The .gitignore was updated to add .repomix/ and reorganize entries. Tests were added and updated to cover these changes. A new commit guideline section was added to .agents/rules/base.md.

Changes

File(s) Change Summary
.gitignore Added .repomix/ to ignored directories; reorganized .agents/local/ and .env entries; removed .github/todo.md.
src/cli/actions/defaultAction.ts Simplified stdin processing by removing custom searchFiles override; directly passed explicit file list to pack.
src/core/file/fileSearch.ts Extended searchFiles to accept optional explicit file list, appending them to include patterns with escaping; added trace logs.
src/core/packager.ts Extended pack function signature to accept optional explicit file list and pass it to searchFiles.
tests/cli/actions/defaultAction.test.ts Updated tests to mock globby and verify pack is called with expected explicit file list argument.
tests/core/file/fileSearch.test.ts Added tests verifying filtering behavior of explicit file lists with include and ignore patterns.
tests/core/packager.test.ts Updated test assertions to expect explicit undefined argument for explicitFiles in searchFiles mock calls.
.agents/rules/base.md Added "Commit Body Guidelines" section to instruct contributors to include context and motivation in commit messages.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI (defaultAction)
    participant Packer as pack()
    participant FS as searchFiles()

    CLI->>CLI: Read file paths from stdin
    CLI->>Packer: pack(rootDirs, config, ..., explicitFiles)
    Packer->>FS: searchFiles(rootDir, config, explicitFiles)
    FS-->>Packer: Filtered files
    Packer-->>CLI: Pack result
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Provide a way to include only git-tracked files (#650) The changes enable filtering explicit file lists by include/ignore patterns but do not add direct support for selecting only git-tracked files.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of .repomix/ to .gitignore This change relates to local environment cleanup and is unrelated to filtering git-tracked files.
Addition of "Commit Body Guidelines" in .agents/rules/base.md This documentation update is unrelated to the issue of file filtering or git-tracked file inclusion.

Possibly related PRs

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feat/stdin-filtering

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This comment was marked as outdated.

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.

Summary of Changes

Hello @yamadashy, 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 enhances the repomix tool by enabling the application of include and ignore patterns to file paths provided via standard input. This change brings consistency to file filtering across different input methods and resolves a previously identified limitation, making the tool more flexible and powerful for users who pipe file lists.

Highlights

  • New Feature: Stdin File Filtering: Implemented the ability to apply include and ignore patterns to file lists provided via standard input (--stdin), addressing issue #650. Previously, these patterns were bypassed for stdin input.
  • Core Logic: filterFileList Function: Introduced a new asynchronous function, filterFileList, in src/core/file/fileSearch.ts. This function takes a list of file paths and applies the configured include and ignore patterns, mirroring the filtering logic used for regular file discovery.
  • Integration with Stdin Processing: Modified the handleStdinProcessing function in src/cli/actions/defaultAction.ts to incorporate the new filterFileList. Files read from stdin are now filtered before being passed to the packing operation, ensuring consistent application of patterns.
  • Test Coverage and Known Limitations: Added new test cases for the filterFileList function in tests/core/file/fileSearch.test.ts to validate its behavior with include and custom ignore patterns. A TODO comment in the filterFileList implementation notes that patterns from .gitignore and .repomixignore files are not yet processed for stdin input.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 21, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1ec8db9
Status: ✅  Deploy successful!
Preview URL: https://aeefa515.repomix.pages.dev
Branch Preview URL: https://feat-stdin-filtering.repomix.pages.dev

View logs

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 the ability to filter files passed via stdin using include/ignore patterns. The implementation adds a new filterFileList function and integrates it into the stdin processing workflow. Key areas for improvement include handling .gitignore and .repomixignore files, enabling skipped tests, and refactoring shared logic to improve maintainability.

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: 3

🧹 Nitpick comments (1)
src/core/file/fileSearch.ts (1)

308-310: Address the TODO: missing ignore file patterns processing.

The function currently skips .gitignore and .repomixignore processing, which may lead to inconsistent filtering behavior compared to normal file search.

This limitation could affect the filtering accuracy. Would you like me to help implement the ignore file patterns processing or should this be tracked as a separate issue?

Consider the impact of this limitation on the filtering consistency between stdin and normal file search modes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b325c55 and 8b3f1ae.

📒 Files selected for processing (4)
  • .gitignore (1 hunks)
  • src/cli/actions/defaultAction.ts (3 hunks)
  • src/core/file/fileSearch.ts (1 hunks)
  • tests/core/file/fileSearch.test.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/cli/actions/defaultAction.ts (1)
src/core/file/fileSearch.ts (1)
  • filterFileList (258-318)
tests/core/file/fileSearch.test.ts (2)
tests/testing/testUtils.ts (1)
  • createMockConfig (15-45)
src/core/file/fileSearch.ts (1)
  • filterFileList (258-318)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: pack-repo
  • GitHub Check: Test (windows-latest, 18.x)
  • GitHub Check: Test (ubuntu-latest, 22.x)
  • GitHub Check: Test (ubuntu-latest, 24.x)
  • GitHub Check: Build and run (windows-latest, 22.x)
  • GitHub Check: Test (ubuntu-latest, 19.x)
  • GitHub Check: Test (ubuntu-latest, 20.x)
  • GitHub Check: Test (macos-latest, 18.0.0)
  • GitHub Check: Test (macos-latest, 19.x)
  • GitHub Check: Test (ubuntu-latest, 18.0.0)
  • GitHub Check: Build and run (macos-latest, 23.x)
  • GitHub Check: Build and run (windows-latest, 21.x)
  • GitHub Check: Build and run (macos-latest, 21.x)
  • GitHub Check: Build and run (windows-latest, 18.0.0)
  • GitHub Check: Build and run (windows-latest, 18.x)
  • GitHub Check: Test Browser Extension
  • GitHub Check: Test coverage
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
.gitignore (1)

42-43: LGTM! Clean addition of repomix runner directory to gitignore.

The addition of .repomix/ directory with a clear explanatory comment is appropriate for excluding runtime artifacts.

src/cli/actions/defaultAction.ts (2)

10-10: Clean import addition.

The import is correctly placed and follows the existing import organization.


83-86: Excellent integration of filtering step into stdin processing workflow.

The filtering is correctly positioned between reading stdin and packing, with appropriate user feedback via spinner messages. The filtered results are properly utilized in the custom pack variant.

Also applies to: 99-99

tests/core/file/fileSearch.test.ts (2)

10-10: Clean import addition for the new function.

The import is properly integrated into the existing import statement.


569-585: Well-written tests for implemented functionality.

The tests for include patterns and absolute path handling are well-structured and verify the expected behavior correctly.

Also applies to: 628-644

src/core/file/fileSearch.ts (1)

297-306: LGTM! The core filtering logic is sound.

The pattern matching implementation correctly applies include patterns first, then excludes files matching ignore patterns. The use of minimatch is consistent with the existing codebase, and the path conversion logic is appropriate.

@yamadashy
Copy link
Owner Author

yamadashy commented Jun 21, 2025

@claude Please review this PR

@claude
Copy link
Contributor

claude bot commented Jun 21, 2025

Claude finished @yamadashy's task —— View job


PR Review - feat(stdin): Apply include and ignore patterns to stdin file lists

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Review changed files and understand implementation
  • Analyze new filterFileList function
  • Review stdin processing integration
  • Check test coverage and quality
  • Provide comprehensive review feedback

Summary

This PR successfully implements stdin file filtering to apply include and ignore patterns to files passed via --stdin. The implementation follows the repository's coding guidelines and maintains consistency with the existing codebase.

Strengths

Clean Integration: The filterFileList function is well-integrated into the stdin processing workflow at src/cli/actions/defaultAction.ts:83-86 with proper user feedback via spinner messages.

Consistent API: The new function follows the same signature pattern as searchFiles, returning a FileSearchResult object for consistency.

Proper Path Handling: Correctly converts absolute paths to relative paths for pattern matching at src/core/file/fileSearch.ts:294.

Comprehensive Testing: Added meaningful test cases covering include patterns and absolute path handling.

Good Documentation: The function has clear JSDoc documentation explaining its purpose and relationship to searchFiles.

Issues & Concerns

🔴 Critical Issues

  1. Missing .gitignore/.repomixignore Support (src/core/file/fileSearch.ts:308-310)

    • The TODO comment indicates that ignore files are not processed for stdin input
    • This creates inconsistent behavior between normal file discovery and stdin processing
    • Impact: Users may expect their .gitignore patterns to apply to stdin files but they won't
    • Recommendation: Either implement this feature or clearly document the limitation
  2. Skipped Test Cases (tests/core/file/fileSearch.test.ts:587, 610)

    • Two critical test cases for ignore patterns are skipped with test.skip
    • These tests appear to be for core functionality that should be working
    • Impact: Reduced test coverage for essential filtering behavior
    • Recommendation: Enable these tests or explain why they're skipped

🟡 Code Quality Issues

  1. Code Duplication (src/core/file/fileSearch.ts:254-318)

    • The filterFileList function duplicates significant logic from searchFiles:
      • Include pattern processing (lines 263-264)
      • Ignore pattern retrieval and normalization (lines 266-272)
      • Git worktree handling (lines 278-291)
    • Impact: Violates DRY principles and increases maintenance burden
    • Recommendation: Extract common logic into shared helper functions
  2. Missing Error Handling (src/core/file/fileSearch.ts:258-318)

    • Unlike searchFiles, filterFileList lacks comprehensive error handling
    • No permission checks or specific error handling for file system operations
    • Impact: Less robust than the equivalent searchFiles function
    • Recommendation: Add similar error handling patterns

🟢 Minor Issues

  1. File Length Consideration (src/core/file/fileSearch.ts)
    • The file is now 368 lines, approaching the 250-line guideline from CLAUDE.md
    • Consider splitting into smaller focused modules as the file grows

File-by-File Analysis

.gitignore

  • ✅ Clean addition of .repomix/ directory with clear comment

src/cli/actions/defaultAction.ts

  • ✅ Proper import placement
  • ✅ Well-integrated filtering step with appropriate user feedback
  • ✅ Correct usage of filtered results in the pack operation

src/core/file/fileSearch.ts

  • ✅ Clear function documentation and signature
  • ✅ Correct pattern matching implementation
  • ❌ Missing .gitignore/.repomixignore support (TODO comment)
  • ❌ Code duplication with searchFiles
  • ❌ Insufficient error handling

tests/core/file/fileSearch.test.ts

  • ✅ Good test coverage for implemented functionality
  • ✅ Tests verify include patterns and absolute path handling
  • ❌ Two critical tests are skipped

Recommendations

  1. High Priority: Enable the skipped tests or clearly document why they're disabled
  2. High Priority: Implement .gitignore/.repomixignore support or document the limitation
  3. Medium Priority: Refactor to reduce code duplication between filterFileList and searchFiles
  4. Medium Priority: Add comprehensive error handling to match searchFiles robustness
  5. Low Priority: Consider splitting the file as it grows beyond 250 lines

Verdict

This is a solid implementation that successfully addresses the core requirement from issue #650. The integration is clean and the basic functionality works well. However, the missing ignore file support and skipped tests are significant limitations that should be addressed before merging.

Recommendation: Request changes to address the critical issues, particularly the missing test coverage and the incomplete ignore file support.

@codecov
Copy link

codecov bot commented Jun 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.38%. Comparing base (d94309c) to head (1ec8db9).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #680      +/-   ##
==========================================
+ Coverage   90.36%   90.38%   +0.01%     
==========================================
  Files          99       99              
  Lines        5543     5553      +10     
  Branches     1183     1185       +2     
==========================================
+ Hits         5009     5019      +10     
  Misses        534      534              

☔ 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 yamadashy force-pushed the feat/stdin-filtering branch from ab41e2b to c77dca7 Compare June 23, 2025 14:50
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Implements file filtering functionality for stdin input in Repomix, allowing include/ignore patterns to be applied to files passed via --stdin command.

  • Modified src/core/file/fileSearch.ts to add filtering support for predefined file lists while maintaining existing functionality
  • Updated src/cli/actions/defaultAction.ts to integrate stdin file filtering into the main processing workflow
  • Added comprehensive test coverage in tests/core/file/fileSearch.test.ts and tests/cli/actions/defaultAction.test.ts
  • Enhanced .gitignore to prevent recursion issues by excluding .repomix/ directory

6 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

yamadashy and others added 14 commits June 27, 2025 23:41
Add filtering capability to stdin file input, allowing users to pipe files
through stdin while still applying include and ignore patterns from configuration.

Changes:
- Add filterFileList function to apply include/ignore patterns to file lists
- Modify handleStdinProcessing to filter stdin files before packing
- Add test cases for the new filtering functionality

This resolves issue #650 by implementing the requested behavior where
"stdin files could be injected into the included file set, with ignore
patterns still being applied."

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Address PR feedback by implementing complete filtering support:

- Add .gitignore and .repomixignore processing using globby
- Enable previously skipped test cases with proper mocks
- Add globby mocks to defaultAction tests
- Fix test expectations to match sorted output

This resolves the TODO in filterFileList and ensures stdin filtering
matches the behavior of normal file discovery.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Apply automatic linting fixes for code style consistency.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The filterFileList function was missing robust error handling compared to
searchFiles. Added try-catch blocks around file system operations, explicit
permission error handling, and proper error logging to maintain consistency
with the existing searchFiles implementation.

This addresses a security and robustness gap where file system errors during
stdin filtering could cause unexpected failures without proper error context.

Changes:
- Add try-catch wrapper around entire filterFileList function
- Handle EPERM/EACCES errors specifically in globby operations
- Add proper error logging and re-throwing with context
- Add test cases for permission and generic error scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed "noExplicitAny" lint error by using proper type assertion
instead of casting to any. The test maintains the same functionality
while adhering to TypeScript best practices.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…function

- Add predefinedFiles parameter to searchFiles function for stdin file processing
- Remove duplicate filterFileList function and consolidate logic
- Update defaultAction to use unified searchFiles instead of filterFileList
- Skip directory validation when using predefined files from stdin
- Update tests to reflect consolidated file filtering architecture
- Improve code maintainability by eliminating duplicate filtering logic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add guidelines for commit body content to preserve decision-making context
and conversation history that led to changes. This helps with future
code archaeology and understanding the reasoning behind modifications.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix searchFiles to properly filter predefinedFiles instead of using them as glob patterns
- Fix normalizeGlobPattern to avoid converting file patterns like **/*.test.ts to directory patterns
- Update predefinedFiles filtering logic to apply include/ignore patterns correctly
- Remove obsolete globby mocks from tests since filtering now happens directly
- Skip empty directory processing for predefined file lists as it's not applicable

This resolves issues where stdin file filtering was not working correctly due to
incorrect pattern handling and improper use of file paths as glob patterns.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…d logic

- Extract filterPredefinedFiles function for cleaner predefined file filtering
- Add adjustIgnorePatternsForWorktree helper to handle git worktree logic
- Create searchFilesWithGlobby function with centralized error handling
- Extract findEmptyDirectoriesIfEnabled to simplify directory processing
- Reduce nesting depth in main searchFiles function using helper functions
- Improve maintainability and testability of file search logic

All functionality remains unchanged while significantly improving code readability
and reducing complexity of the main searchFiles function.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Move main searchFiles function before helper functions for better code organization
and readability. This follows the convention of having the main exported function
at the top, followed by supporting helper functions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…meter

- Add optional predefinedFiles parameter to pack function for cleaner API
- Remove complex dependency injection override in defaultAction.ts
- Pass stdin file paths directly to pack function instead of using searchFiles override
- Update tests to match new function signatures and parameter expectations
- Simplify stdin processing workflow by eliminating intermediate filtering step

This approach is more explicit, maintainable, and easier to understand than
the previous dependency injection pattern for handling predefined file lists.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…nclude patterns

User suggested a much simpler approach: instead of complex filtering logic,
merge predefinedFiles into includePatterns directly. This:
- Maintains existing include pattern behavior
- Adds stdin files as additional include patterns
- Uses existing globby flow for all filtering
- Removes 116 lines of helper functions
- Fixes bug where predefined files replaced instead of extended include patterns

All tests pass with this cleaner implementation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@yamadashy yamadashy force-pushed the feat/stdin-filtering branch from ef071f2 to f8615e4 Compare June 27, 2025 14:42
@yamadashy yamadashy requested a review from Copilot June 27, 2025 14:42

This comment was marked as outdated.

yamadashy and others added 3 commits June 27, 2025 23:50
User correctly pointed out that directory validation was being skipped
when predefinedFiles were provided. This created a security and consistency
issue where invalid/non-existent directories could be processed.

Fixed by removing the conditional skip and always performing:
- Directory existence check
- Directory type validation
- Permission verification

This ensures robust error handling regardless of input source.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Removed complex condition checks from normalizeGlobPattern that were
checking for wildcards and file extensions. The simplified condition
`pattern.startsWith('**/') && \!pattern.includes('/**')` is sufficient
for the intended behavior of converting directory patterns.

This makes the code cleaner and easier to understand while maintaining
the same functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…xtensibility

User suggested improving the naming to support future features like
--include-from-file. The new name explicitFiles:
- Is more generic and not stdin-specific
- Clearly indicates files explicitly specified by user
- Better supports future file input methods
- Maintains same functionality with clearer intent

Updated function signatures, variable names, comments, and test descriptions
across the codebase for consistency.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@yamadashy yamadashy requested a review from Copilot June 27, 2025 15:01
@yamadashy
Copy link
Owner Author

@claude review

This comment was marked as outdated.

@claude
Copy link
Contributor

claude bot commented Jun 27, 2025

Claude finished @yamadashy's task —— View job


PR Review - feat(stdin): Apply include and ignore patterns to stdin file lists

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Review changed files and understand implementation
  • Analyze core logic changes in fileSearch.ts and packager.ts
  • Review test coverage and quality
  • Check integration in defaultAction.ts
  • Provide comprehensive review feedback

Summary

This PR successfully implements stdin file filtering by extending the existing searchFiles function to accept explicit files, which are then merged with include patterns and processed through the same filtering logic. This is a clean, well-integrated solution that addresses issue #650.

Strengths

Excellent Design Choice

  • The approach of extending searchFiles with an explicitFiles parameter is much cleaner than creating a separate filterFileList function
  • Reuses existing filtering logic rather than duplicating it
  • Maintains consistency between stdin and normal file discovery workflows

Robust Implementation (src/core/file/fileSearch.ts:179-187)

  • Properly converts absolute paths to relative paths for pattern matching
  • Correctly escapes special characters in file paths to handle edge cases
  • Integrates seamlessly with existing include/ignore pattern processing

Clean Integration (src/cli/actions/defaultAction.ts:85-93)

  • Stdin processing now uses the standard pack function instead of custom logic
  • Maintains consistent user experience and code paths
  • Proper error handling and progress reporting

Comprehensive Test Coverage

  • Added tests for explicit file filtering in fileSearch.test.ts:566-612
  • Updated integration tests in defaultAction.test.ts to verify the new workflow
  • Tests cover both include patterns and ignore patterns with explicit files

Consistent API Design

  • The pack function signature change maintains backward compatibility (optional parameter)
  • Function signatures are consistent across the codebase
  • Follows the repository's dependency injection pattern for testability

Areas for Improvement

🟡 Minor Enhancement Opportunities

  1. Documentation Enhancement (src/core/file/fileSearch.ts:95-99)

    • Consider adding a JSDoc comment for the explicitFiles parameter to explain its behavior
    • Example: @param explicitFiles - Optional array of explicit file paths to include in addition to discovered files
  2. Path Validation (src/core/file/fileSearch.ts:181-186)

    • The current implementation assumes all explicit files are under the root directory
    • Consider adding validation or handling for files outside the root directory

🟢 Code Quality Observations

  1. Consistent Error Handling

    • The error handling in searchFiles already covers permission errors and file system issues
    • The explicit files feature inherits this robust error handling automatically
  2. Performance Considerations

    • The approach of adding explicit files to include patterns is efficient
    • No significant performance impact expected for typical use cases

File-by-File Analysis

.agents/rules/base.md (lines 77-80)

Good addition - The commit body guidelines will help preserve decision-making context

.gitignore (line 43)

Clean change - Adding .repomix/ prevents recursion issues and keeps the repository clean

src/core/file/fileSearch.ts (lines 179-187)

Excellent implementation - The logic correctly:

  • Maps absolute paths to relative paths for pattern matching
  • Escapes special characters to handle edge cases
  • Preserves existing include patterns while adding explicit files
  • Integrates seamlessly with the existing filtering pipeline

src/core/packager.ts (lines 47, 58)

Perfect integration - The optional parameter maintains backward compatibility while enabling the new functionality

src/cli/actions/defaultAction.ts (lines 85-93)

Clean refactor - Simplified the stdin processing to use the standard pack workflow instead of custom logic

Test Files

Comprehensive coverage - Tests verify:

  • Explicit file filtering with include patterns
  • Explicit file filtering with ignore patterns
  • Integration with the stdin workflow
  • Edge cases and error conditions

Comparison with Previous Bot Reviews

The current implementation addresses many concerns raised in previous reviews:

  • No code duplication: Instead of creating a separate filterFileList function, this extends existing functionality
  • No missing error handling: Inherits robust error handling from searchFiles
  • Test coverage: All critical functionality is tested
  • Clean integration: Uses standard code paths rather than custom logic

Technical Quality Assessment

  • Architecture: ⭐⭐⭐⭐⭐ (Excellent - clean extension of existing patterns)
  • Code Quality: ⭐⭐⭐⭐⭐ (High quality - follows project conventions)
  • Test Coverage: ⭐⭐⭐⭐⭐ (Comprehensive - covers all scenarios)
  • Documentation: ⭐⭐⭐⭐ (Good - could benefit from parameter documentation)
  • Performance: ⭐⭐⭐⭐⭐ (Excellent - no performance concerns)

Verdict

✅ APPROVE - This is a well-designed, thoroughly tested implementation that successfully addresses the requirements of issue #650. The approach is clean, maintainable, and follows the project's coding standards.

Recommendations for Future Enhancements

  1. Consider adding JSDoc documentation for the new explicitFiles parameter
  2. Add validation for explicit files outside the root directory if needed
  3. Consider adding integration tests with actual .gitignore files for end-to-end validation

@yamadashy
Copy link
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Updates GitHub Actions workflows and dependencies while maintaining security standards.

  • Updated CodeQL workflow from v2 to v3 in .github/workflows/codeql.yml for improved Node.js 20 support and security analysis
  • Refreshed Claude AI review action in .github/workflows/claude-review.yml from ebbd9e9 to ece712e
  • Updated Repomix action reference in .github/workflows/pack-repository.yml to latest commit 44055a5
  • Added clear 'Commit Body Guidelines' section in .agents/rules/base.md for better context preservation

13 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

…ovided

User identified a critical bug where config.include=[] + explicitFiles would
result in ['**/*', ...explicitFiles] instead of just [...explicitFiles].

Fixed by reordering the logic:
1. Start with config.include patterns only
2. Add explicitFiles if provided
3. Default to ['**/*'] only if no patterns exist

This ensures:
- config.include=[] + explicitFiles → explicitFiles only (correct)
- config.include=['*.js'] + explicitFiles → both (correct)
- config.include=[] + no explicitFiles → ['**/*'] (correct)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@yamadashy yamadashy requested a review from Copilot June 27, 2025 15:36
@yamadashy
Copy link
Owner Author

/gemini review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables applying include/ignore patterns to file paths provided via --stdin by passing them through the existing filtering logic.

  • Updated pack and searchFiles to accept and handle an explicitFiles list
  • Modified CLI’s stdin handler to pass stdin paths into pack
  • Added and adjusted tests to cover stdin filtering behavior

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/core/packager.test.ts Updated expectations to include the new explicitFiles argument when calling searchFiles
tests/core/file/fileSearch.test.ts Added tests for filtering explicit stdin files with include/ignore patterns
tests/cli/actions/defaultAction.test.ts Adjusted test to assert pack is called with the new parameters; added (but unused) globby mock
src/core/packager.ts Extended pack signature and invocation of searchFiles to accept explicitFiles
src/core/file/fileSearch.ts Enhanced searchFiles to merge explicit file list into include patterns
src/cli/actions/defaultAction.ts Passed stdin file list as explicitFiles into pack
.agents/rules/base.md Introduced new commit body guidelines (documentation)
Comments suppressed due to low confidence (4)

.agents/rules/base.md:77

  • [nitpick] These new commit body guidelines aren’t related to the stdin filtering feature. It may be clearer to move them into a separate documentation or style-guide PR to keep this change scoped to code functionality.
### Commit Body Guidelines

src/core/packager.ts:47

  • [nitpick] The parameter name explicitFiles could be more descriptive of its role (e.g., stdinFilePaths or filteredFilePaths) to improve clarity in the pack API.
  explicitFiles?: string[],

src/core/file/fileSearch.ts:94

  • [nitpick] The PR description mentions a filterFileList function, but there’s no such function in this file. Consider updating the description or adding the utility to keep docs and implementation in sync.
// Get all file paths considering the config

tests/cli/actions/defaultAction.test.ts:3

  • [nitpick] The test imports and mocks globby, but handleStdinProcessing doesn’t call globby directly. Consider removing this mock to keep the test focused and reduce unnecessary dependencies.
import { globby } from 'globby';

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 stdin file filtering, applying include and ignore patterns to files passed via --stdin. It adds a filterFileList function to handle the filtering logic and modifies handleStdinProcessing to apply this filtering step. The changes also include new test cases for the filtering functionality.

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.

simple way to only include git-tracked files

2 participants