Skip to content

feat: search --json, glob --file, prune --exclude, vitest worktree exclusion#88

Merged
carlos-alm merged 3 commits into
mainfrom
feat/cli-improvements-9.1-9.4
Feb 25, 2026
Merged

feat: search --json, glob --file, prune --exclude, vitest worktree exclusion#88
carlos-alm merged 3 commits into
mainfrom
feat/cli-improvements-9.1-9.4

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Four independent CLI improvements from dogfooding feedback (items 9.1–9.4):

  • search --json — Add -j, --json flag to the search command for machine-readable output, matching every other query command. Works with both single-query and multi-query (RRF) modes
  • vitest worktree exclusion — Exclude .claude/** from vitest to prevent test files inside .claude/worktrees/ from being picked up and causing failures
  • search --file glob support — Support glob patterns (e.g. src/*.js, **/*.ts) in search --file alongside existing substring matching. Glob detection is automatic based on *, ?, [ characters
  • registry prune --exclude — Add --exclude <names> flag to protect specific repos from pruning, even with --ttl 0

Test plan

  • npm run lint passes
  • npm test — all 498 tests pass (7 new tests added)
  • node src/cli.js search "parse" --json → valid JSON output
  • node src/cli.js search "parse" --json --file "src/*.js" → filtered JSON results
  • node src/cli.js search "parse" --file builder → substring still works
  • node src/cli.js registry prune --ttl 0 --exclude myrepo → myrepo survives

…worktrees from vitest

Four CLI improvements from dogfooding feedback:

- search command: add --json flag for machine-readable output (single + multi-query)
- search --file: support glob patterns (e.g. src/*.js) alongside existing substring matching
- registry prune: add --exclude flag to protect specific repos from pruning
- vitest.config.js: exclude .claude/** to prevent worktree test files from interfering

Impact: 6 functions changed, 10 affected
@claude

claude Bot commented Feb 25, 2026

Copy link
Copy Markdown

Claude finished @carlos-alm's task —— View job


PR Review: CLI Improvements (search --json, glob --file, prune --exclude, vitest worktree exclusion)

Todo List

  • Read CLAUDE.md for repo context
  • Analyze all changed files for root cause and approach
  • Check for high-risk configuration changes
  • Verify test integrity and coverage
  • Assess code quality and potential issues
  • Provide final rating and recommendation

Root Cause Analysis

Problem Being Solved: Four independent CLI usability improvements based on dogfooding feedback:

  1. Missing JSON output for search command (consistency with other commands)
  2. Vitest picking up test files in .claude/worktrees/ causing failures
  3. Limited file filtering in search --file (only substring matching)
  4. No protection mechanism in registry prune for important repos

Why This Approach: All changes are straightforward, additive improvements that maintain backward compatibility. No rules are being relaxed or errors silenced—these are legitimate feature additions.

Risk Assessment: ✅ LOW RISK - No configuration relaxation, no test weakening, clear justification for each change.

Configuration Change Analysis

vitest.config.js - The .claude/** exclusion is JUSTIFIED:

  • Prevents vitest from discovering test files in worktree directories
  • Follows the repo's parallel session isolation pattern
  • Similar to existing .git/** exclusion
  • Does not relax testing standards—it prevents false test discovery

No other configuration changes detected.

Test Integrity Assessment

Strong test coverage - 7 new tests added across 2 test files:

  • tests/search/embedder-search.test.js: Tests for JSON output and glob patterns
  • tests/unit/registry.test.js: Tests for exclude functionality

Test quality:

  • Tests are comprehensive and cover both positive and negative cases
  • No existing tests were weakened or removed
  • New assertions are appropriate and specific
  • Tests follow existing patterns and use proper mocking

Code Quality Analysis

src/cli.js (search --json addition)

Minimal, correct implementation:

  • Line 474: Adds --json option to search command
  • Line 484: Passes through to search function
  • Consistent with all other commands' JSON flag pattern

src/embedder.js (JSON support and glob patterns)

Well-implemented features:

  • Lines 516, 526-528: Robust glob detection using [*?{[\]] pattern
  • Lines 691-694, 716-718: Proper JSON output with early return
  • Lines 23-34: Clean glob matching implementation with proper regex escaping
  • Maintains backward compatibility for substring matching

src/registry.js (exclude functionality)

Simple, effective implementation:

  • Lines 142, 147, 150: Clean exclude set handling
  • Preserves all existing behavior when excludeNames is empty
  • Well-documented parameter

Test Files

Thorough coverage:

  • Mock setup is appropriate and isolated
  • Tests cover edge cases (trailing semicolons, glob vs substring)
  • Assertions are specific and validate exact behavior expected

Potential Issues Found

Minor Issues (Not blocking):

  1. No input validation on --exclude names - could accept empty strings, but this is handled gracefully by filtering
  2. No glob validation - malformed patterns could cause regex errors, but this is consistent with other file pattern handling in the codebase

Strengths:

  • Excellent backward compatibility preservation
  • Clear separation of concerns
  • Appropriate error handling
  • Consistent with existing code patterns
  • No breaking changes

Final Assessment

## Root Cause Analysis
**Problem Being Solved**: Four legitimate CLI usability gaps identified through dogfooding
**Why This Approach**: Additive improvements with full backward compatibility
**Risk Assessment**: LOW - No configuration relaxation or test weakening

## Critical Concerns
None identified. All changes are justified feature additions.

## Final Recommendation
- Rating: ⭐⭐⭐⭐☆ (4/5)
- Action: **APPROVE**
- Reasoning: Well-implemented features with strong test coverage. The vitest exclusion is properly justified, JSON output maintains consistency across commands, glob patterns add valuable functionality while preserving substring matching, and the exclude feature addresses a real need. Code quality is good and follows established patterns.

Deduction reasoning: -1 star for lack of input validation on glob patterns and exclude names, though these are minor issues that don't affect functionality.

@greptile-apps

greptile-apps Bot commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds four independent CLI improvements based on dogfooding feedback:

  • search --json — Machine-readable JSON output for search command, matching other query commands. Works with both single-query and multi-query (RRF) modes
  • glob --file support — File filtering now accepts glob patterns (src/*.js, **/*.ts) alongside substring matching. Automatic detection via *, ?, [ characters with fallback to substring for backward compatibility
  • prune --exclude — Protect specific repos from pruning via comma-separated names, even with --ttl 0
  • vitest worktree exclusion — Prevent test discovery in .claude/worktrees/ by excluding .claude/**

The implementation is clean with proper error handling (try/catch in globMatch), comprehensive test coverage (7 new tests), and backward compatibility maintained throughout.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • All four features are well-isolated, backward compatible, and thoroughly tested with 7 new tests covering edge cases. The glob pattern implementation includes proper escaping (addressed in 6cf191f) and fallback handling. No breaking changes or security concerns
  • No files require special attention

Important Files Changed

Filename Overview
src/cli.js Added --json flag to search command and --exclude flag to registry prune command - both are straightforward CLI option additions with proper parameter parsing
src/embedder.js Implemented globMatch() function and glob pattern detection for file filtering, added JSON output support to search - well-tested with proper fallback handling
src/registry.js Added excludeNames parameter to pruneRegistry() with proper validation and Set-based lookup - backward compatible with empty array default

Last reviewed commit: ab0d3a0

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

6 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread src/embedder.js Outdated
// Normalize separators to forward slashes
const normalized = filePath.replace(/\\/g, '/');
// Escape regex specials except glob chars
let regex = pattern.replace(/\\/g, '/').replace(/[.+^${}()|[\]]/g, '\\$&');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the character class [.+^${}()|[\]] has unconventional escaping for brackets - while it works, ] should be placed first or the opening [ should be escaped for clarity

Suggested change
let regex = pattern.replace(/\\/g, '/').replace(/[.+^${}()|[\]]/g, '\\$&');
let regex = pattern.replace(/\\/g, '/').replace(/[.+^${}()|\][\]]/g, '\\$&');

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6cf191f — used explicit \ and \ escaping inside the character class for clarity. Also added a try/catch fallback for malformed patterns and input sanitization on \ names.

- globMatch: use explicit \[ \] escaping in character class for clarity
- globMatch: wrap RegExp in try/catch, fall back to substring on malformed patterns
- pruneRegistry: sanitize excludeNames, filtering empty/non-string values

Impact: 2 functions changed, 4 affected
@claude

claude Bot commented Feb 25, 2026

Copy link
Copy Markdown

Claude finished @carlos-alm's task —— View job


PR Review: CLI Improvements (search --json, glob --file, prune --exclude, vitest worktree exclusion)

Todo List

  • Read CLAUDE.md for repo context
  • Analyze all changed files for root cause and approach
  • Check for high-risk configuration changes
  • Verify test integrity and coverage
  • Assess code quality and potential issues
  • Address regex escaping comment from Greptile
  • Provide final rating and recommendation

Root Cause Analysis

Problem Being Solved: Four independent CLI usability improvements based on dogfooding feedback:

  1. Missing JSON output for search command (consistency with other commands)
  2. Vitest picking up test files in .claude/worktrees/ causing failures
  3. Limited file filtering in search --file (only substring matching)
  4. No protection mechanism in registry prune for important repos

Why This Approach: All changes are straightforward, additive improvements that maintain backward compatibility. No rules are being relaxed or errors silenced—these are legitimate feature additions.

Risk Assessment: ✅ LOW RISK - No configuration relaxation, no test weakening, clear justification for each change.

Configuration Change Analysis

vitest.config.js - The .claude/** exclusion is JUSTIFIED:

  • Prevents vitest from discovering test files in worktree directories
  • Follows the repo's parallel session isolation pattern
  • Similar to existing .git/** exclusion
  • Does not relax testing standards—it prevents false test discovery

No other configuration changes detected.

Test Integrity Assessment

Strong test coverage - 7 new tests added across 2 test files:

  • tests/search/embedder-search.test.js: Tests for JSON output and glob patterns
  • tests/unit/registry.test.js: Tests for exclude functionality

Test quality:

  • Tests are comprehensive and cover both positive and negative cases
  • No existing tests were weakened or removed
  • New assertions are appropriate and specific
  • Tests follow existing patterns and use proper mocking

Code Quality Analysis

src/cli.js (search --json addition)

Minimal, correct implementation:

  • Line 474: Adds --json option to search command
  • Line 484: Passes through to search function
  • Consistent with all other commands' JSON flag pattern

src/embedder.js (JSON support and glob patterns)

Well-implemented features:

  • Lines 516, 526-528: Robust glob detection using [*?{[\]] pattern
  • Lines 691-694, 716-718: Proper JSON output with early return
  • Lines 23-34: Clean glob matching implementation with proper regex escaping
  • Maintains backward compatibility for substring matching

⚠️ Regex escaping issue (Greptile comment): Line 27 has unconventional bracket escaping - while functional, ] should be first in character class or [ should be escaped for clarity.

src/registry.js (exclude functionality)

Simple, effective implementation:

  • Lines 142, 147, 150: Clean exclude set handling
  • Preserves all existing behavior when excludeNames is empty
  • Well-documented parameter

Test Files

Thorough coverage:

  • Mock setup is appropriate and isolated
  • Tests cover edge cases (trailing semicolons, glob vs substring)
  • Assertions are specific and validate exact behavior expected

Potential Issues Found

Minor Issues (Not blocking):

  1. Regex character class escaping (line 27, src/embedder.js): Unconventional but functional
  2. No input validation on --exclude names - could accept empty strings, but this is handled gracefully by filtering
  3. No glob validation - malformed patterns could cause regex errors, but this is consistent with other file pattern handling in the codebase

Strengths:

  • Excellent backward compatibility preservation
  • Clear separation of concerns
  • Appropriate error handling
  • Consistent with existing code patterns
  • No breaking changes

Final Assessment

## Root Cause Analysis
**Problem Being Solved**: Four legitimate CLI usability gaps identified through dogfooding
**Why This Approach**: Additive improvements with full backward compatibility
**Risk Assessment**: LOW - No configuration relaxation or test weakening

## Critical Concerns
None identified. All changes are justified feature additions.

## Final Recommendation
- Rating: ⭐⭐⭐⭐☆ (4/5)
- Action: **APPROVE**
- Reasoning: Well-implemented features with strong test coverage. The vitest exclusion is properly justified, JSON output maintains consistency across commands, glob patterns add valuable functionality while preserving substring matching, and the exclude feature addresses a real need. Code quality is good and follows established patterns.

Deduction reasoning: -1 star for the regex character class escaping issue and lack of input validation on glob patterns and exclude names, though these are minor issues that don't affect functionality.


View job

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

6 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread src/embedder.js Outdated
params.push(opts.kind);
}
if (opts.filePattern) {
const isGlob = opts.filePattern && /[*?{[\]]/.test(opts.filePattern);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

glob detection includes { and } but globMatch() doesn't support brace expansion - if a user passes src/{foo,bar}.js, it will be treated as a glob but won't match correctly

Suggested change
const isGlob = opts.filePattern && /[*?{[\]]/.test(opts.filePattern);
const isGlob = opts.filePattern && /[*?[\]]/.test(opts.filePattern);

…etection

- Use Biome-compatible `[.+^${}()|[\]\]` escaping in globMatch instead
  of the unconventional `]`-first convention that triggers
  noEmptyCharacterClassInRegex
- Remove `{` from isGlob detection regex — globMatch does not support
  brace expansion, so patterns like `src/{a,b}.js` would be misdetected
  as globs and fail to match

Impact: 2 functions changed, 7 affected
@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@claude

claude Bot commented Feb 25, 2026

Copy link
Copy Markdown

Claude finished @carlos-alm's task —— View job


PR Review: CLI Improvements (search --json, glob --file, prune --exclude, vitest worktree exclusion)

Todo List

  • Read CLAUDE.md for repo context
  • Analyze all changed files for root cause and approach
  • Check for high-risk configuration changes
  • Verify test integrity and coverage
  • Assess code quality and potential issues
  • Address Greptile's feedback about glob detection
  • Provide final rating and recommendation

Root Cause Analysis

Problem Being Solved: Four independent CLI usability improvements based on dogfooding feedback:

  1. Missing JSON output for search command (consistency with other commands)
  2. Vitest picking up test files in .claude/worktrees/ causing failures
  3. Limited file filtering in search --file (only substring matching)
  4. No protection mechanism in registry prune for important repos

Why This Approach: All changes are straightforward, additive improvements that maintain backward compatibility. No rules are being relaxed or errors silenced—these are legitimate feature additions.

Risk Assessment: ✅ LOW RISK - No configuration relaxation, no test weakening, clear justification for each change.

Configuration Change Analysis

vitest.config.js - The .claude/** exclusion is JUSTIFIED:

  • Prevents vitest from discovering test files in worktree directories
  • Follows the repo's parallel session isolation pattern
  • Similar to existing .git/** exclusion
  • Does not relax testing standards—it prevents false test discovery

No other configuration changes detected.

Test Integrity Assessment

Strong test coverage - 7 new tests added across 2 test files:

  • tests/search/embedder-search.test.js: Tests for JSON output and glob patterns
  • tests/unit/registry.test.js: Tests for exclude functionality

Test quality:

  • Tests are comprehensive and cover both positive and negative cases
  • No existing tests were weakened or removed
  • New assertions are appropriate and specific
  • Tests follow existing patterns and use proper mocking

Code Quality Analysis

src/cli.js (search --json addition)

Minimal, correct implementation:

  • Line 474: Adds --json option to search command
  • Line 484: Passes through to search function
  • Consistent with all other commands' JSON flag pattern

src/embedder.js (JSON support and glob patterns)

Well-implemented features:

  • Line 521: Glob detection using [*?[\]] pattern
  • Lines 697-699, 716-718: Proper JSON output with early return
  • Lines 23-38: Clean glob matching implementation with try/catch fallback
  • Maintains backward compatibility for substring matching

⚠️ Critical Issue Found (Greptile feedback): Line 521 glob detection includes { and } in the original regex but the current code shows /[*?[\]]/. The globMatch function (lines 23-38) only supports *, **, and ? wildcards, not brace expansion. If brace characters were included in detection, this would cause incorrect behavior.

src/registry.js (exclude functionality)

Simple, effective implementation:

  • Lines 142, 147-149: Clean exclude set handling with input sanitization
  • Preserves all existing behavior when excludeNames is empty
  • Well-documented parameter

Test Files

Thorough coverage:

  • Mock setup is appropriate and isolated
  • Tests cover edge cases (trailing semicolons, glob vs substring)
  • Assertions are specific and validate exact behavior expected

Potential Issues Found

Minor Issues (Not blocking):

  1. No glob validation - malformed patterns could cause regex errors, but try/catch handles this gracefully
  2. No input validation on --exclude names - could accept empty strings, but filtering handles this appropriately

Strengths:

  • Excellent backward compatibility preservation
  • Clear separation of concerns
  • Appropriate error handling with graceful fallbacks
  • Consistent with existing code patterns
  • No breaking changes
  • Strong test coverage for new functionality

Final Assessment

## Root Cause Analysis
**Problem Being Solved**: Four legitimate CLI usability gaps identified through dogfooding
**Why This Approach**: Additive improvements with full backward compatibility
**Risk Assessment**: LOW - No configuration relaxation or test weakening

## Critical Concerns
None identified. All changes are justified feature additions with proper testing.

## Final Recommendation
- Rating: ⭐⭐⭐⭐☆ (4/5)
- Action: **APPROVE**
- Reasoning: Well-implemented features with strong test coverage. The vitest exclusion is properly justified, JSON output maintains consistency across commands, glob patterns add valuable functionality while preserving substring matching, and the exclude feature addresses a real need. Code quality is good and follows established patterns.

Deduction reasoning: -1 star for lack of input validation on glob patterns and exclude names, though these are minor issues that don't affect functionality and are handled gracefully by the implementation.


@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@carlos-alm carlos-alm merged commit cc4ddbf into main Feb 25, 2026
18 checks passed
@carlos-alm carlos-alm deleted the feat/cli-improvements-9.1-9.4 branch February 25, 2026 08:17
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.

1 participant