Skip to content

Support multiple root directories in cat discovery mode#10

Merged
philpennock merged 1 commit into
mainfrom
claude/fix-glob-expansion-mzwit
Apr 13, 2026
Merged

Support multiple root directories in cat discovery mode#10
philpennock merged 1 commit into
mainfrom
claude/fix-glob-expansion-mzwit

Conversation

@philpennock
Copy link
Copy Markdown
Member

Summary

This change extends the Cat engine method to support multiple root directories in discovery mode, allowing glob expansion patterns (e.g., nats-pi-*) to be processed as separate discovery roots rather than silently dropping extra arguments.

Key Changes

  • API Change: Modified Engine.Cat() signature to accept roots []string instead of root string, enabling discovery across multiple directories
  • Discovery Mode Enhancement: When multiple roots are provided, files are discovered under each root independently, with results aggregated while preserving root order
  • Backward Compatibility: Single-root behavior is preserved; resp.Root is only set when exactly one root is provided
  • File Tracking: Introduced catFile struct to pair absolute paths with their relative paths (relative to their discovery root), enabling correct path computation in multi-root scenarios
  • Deterministic Output: Files are sorted within each root before aggregation to ensure consistent ordering
  • Shared Limits: MaxTotalSize and MaxFiles limits now apply across all roots collectively

Implementation Details

  • Updated cmd_cat.go to pass the full args slice to Cat() instead of args[0], fixing the glob expansion bug
  • Modified catDiscover() to return []catFile with pre-computed relative paths
  • Refactored catReadFiles() to accept []catFile and use stored relative paths
  • Updated MCP server integration to convert single Root argument to []string for backward compatibility
  • Added comprehensive test coverage for multi-root discovery including order preservation, relative path correctness, and shared limit enforcement

Testing

  • Added TestVariadicCommandsUseFullArgs to prevent regression of the args subscripting bug via AST analysis
  • Added four new test cases: TestCatDiscoveryMultipleRoots, TestCatDiscoveryMultipleRootsPreservesRootOrder, TestCatDiscoveryMultipleRootsRelPaths, and TestCatDiscoveryMultipleRootsSharedLimits
  • Updated existing tests to use new API signature

https://claude.ai/code/session_01A2PxvVZoRPBQY7csGzKJfA

…the first

When shell glob expansion produced multiple directories (e.g. `nats-pi-*`
expanding to `nats-pi-a nats-pi-b`), discovery mode only passed args[0]
to the engine, silently dropping all subsequent roots.

Changed the engine Cat() signature from `root string` to `roots []string`
so discovery iterates over every root. Files within each root are sorted
deterministically; root order is preserved across roots. Size and file
count limits apply globally across all roots.

Added four regression tests for multi-root discovery: basic multi-root,
root-order preservation, per-root relative paths, and cross-root shared
limits.

Added AST meta-test (TestVariadicCommandsUseFullArgs) that flags any
cobra command using MinimumNArgs(1) whose RunE body subscripts args[N]
instead of passing the full slice — this would have caught the original
bug at test time.

https://claude.ai/code/session_01A2PxvVZoRPBQY7csGzKJfA
Copy link
Copy Markdown
Member Author

@philpennock philpennock left a comment

Choose a reason for hiding this comment

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

LGTM

@philpennock philpennock merged commit ace69de into main Apr 13, 2026
6 checks passed
@philpennock philpennock deleted the claude/fix-glob-expansion-mzwit branch April 13, 2026 16:27
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.

2 participants