fix(glob): default hidden=true and follow=true to align with OpenCode (#720)

- Add follow?: boolean option to GlobOptions interface
- Change buildRgArgs to use !== false pattern for hidden and follow flags
- Change buildFindArgs to use === false pattern, add -L for symlinks
- Change buildPowerShellCommand to use !== false pattern for hidden
- Remove -FollowSymlink from PowerShell (unsupported in PS 5.1)
- Export build functions for testing
- Add comprehensive BDD-style tests (18 tests, 21 assertions)

Note: Symlink following via -FollowSymlink is not supported in Windows
PowerShell 5.1. OpenCode auto-downloads ripgrep which handles symlinks
via --follow flag. PowerShell fallback is a safety net that rarely triggers.

Fixes #631
This commit is contained in:
Kenny
2026-01-12 19:24:07 -05:00
committed by GitHub
parent 405c81d8ae
commit d0a34d68ca
3 changed files with 177 additions and 4 deletions
+18 -4
View File
@@ -22,7 +22,8 @@ function buildRgArgs(options: GlobOptions): string[] {
`--max-depth=${Math.min(options.maxDepth ?? DEFAULT_MAX_DEPTH, DEFAULT_MAX_DEPTH)}`,
]
if (options.hidden) args.push("--hidden")
if (options.hidden !== false) args.push("--hidden")
if (options.follow !== false) args.push("--follow")
if (options.noIgnore) args.push("--no-ignore")
args.push(`--glob=${options.pattern}`)
@@ -31,7 +32,13 @@ function buildRgArgs(options: GlobOptions): string[] {
}
function buildFindArgs(options: GlobOptions): string[] {
const args: string[] = ["."]
const args: string[] = []
if (options.follow !== false) {
args.push("-L")
}
args.push(".")
const maxDepth = Math.min(options.maxDepth ?? DEFAULT_MAX_DEPTH, DEFAULT_MAX_DEPTH)
args.push("-maxdepth", String(maxDepth))
@@ -39,7 +46,7 @@ function buildFindArgs(options: GlobOptions): string[] {
args.push("-type", "f")
args.push("-name", options.pattern)
if (!options.hidden) {
if (options.hidden === false) {
args.push("-not", "-path", "*/.*")
}
@@ -56,10 +63,15 @@ function buildPowerShellCommand(options: GlobOptions): string[] {
let psCommand = `Get-ChildItem -Path '${escapedPath}' -File -Recurse -Depth ${maxDepth - 1} -Filter '${escapedPattern}'`
if (options.hidden) {
if (options.hidden !== false) {
psCommand += " -Force"
}
// NOTE: Symlink following (-FollowSymlink) is NOT supported in PowerShell backend.
// -FollowSymlink was introduced in PowerShell Core 6.0+ and is unavailable in
// Windows PowerShell 5.1 (default on Windows). OpenCode auto-downloads ripgrep
// which handles symlinks via --follow. This fallback rarely triggers in practice.
psCommand += " -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName"
return ["powershell", "-NoProfile", "-Command", psCommand]
@@ -74,6 +86,8 @@ async function getFileMtime(filePath: string): Promise<number> {
}
}
export { buildRgArgs, buildFindArgs, buildPowerShellCommand }
export async function runRgFiles(
options: GlobOptions,
resolvedCli?: ResolvedCli