Agent Host worktree include copying misses collapsible nested ignored directories
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Type of issue
Performance / worktree creation
## Reproduction
1. Configure `git.worktreeIncludeFiles` with a glob such as `**/node_modules/**`.
2. Use a repository where a wholly ignored parent (for example `.build/`) contains both ignored files that do not match the configured glob and a large nested subtree that matches it completely, such as `.build/extensions/copilot/node_modules/**`.
3. Create an Agent Host worktree.
## Current behavior
`AgentHostGitService.copyWorktreeIncludeFiles` only collapses a directory when the entire wholly ignored root matches. If the root is only partially matched, every selected file in a fully matched nested subtree is copied as an individual entry.
In a real profile this produced 23,553 copy entries and took about 9.2 seconds.
## Expected behavior
Within a partially matched wholly ignored root, collapse the highest nested directories whose complete ignored contents match the configured globs, while preserving the existing collision checks and leaving selected files without such an ancestor as standalone entries.
A prototype reduced the same workload to 61 copy entries and about 6.0 seconds.
## Proposed fix
Extract a pure collapse helper used by `copyWorktreeIncludeFiles`, with:
- unit coverage for partially matched parents, sibling subtrees, fully matched roots, standalone files, and nested unmatched files;
- a real-Git integration test proving the copy result and progress counts;
- no protocol, configuration, or persistence changes.
I can submit the focused fix and tests.
Contributor guide
Assessment
This issue has not been assessed yet.