Skip to content

fix(shell): add find name, path, and depth filters (OPE-99) - #242

Open
aakarim wants to merge 2 commits into
mainfrom
fix/ope-99-find-predicates
Open

aakarim wants to merge 2 commits into
mainfrom
fix/ope-99-find-predicates

Conversation

@aakarim

@aakarim aakarim commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Linear issue

Fixes OPE-99.

Diagnosis

The shell's find parser only accepted -L, -name, and -type. It explicitly rejected common case-insensitive, full-path, and depth filters. A caller that discarded stderr and piped to head could mistake the rejected search for no matching files. Repeated name/type predicates also overwrote earlier filters instead of combining them.

Fix

  • Support -iname, -path, -ipath, -maxdepth, and -mindepth, with AND semantics for combined/repeated match predicates.
  • Match full virtual paths, letting wildcards cross directory separators as standard find does. Preserve original characters and ranges: a separator-permissive wildcard matcher delegates syntax validation and unchanged character classes to path.Match.
  • Count the starting point as depth 0, prune traversal at maxdepth, and reject missing, negative, nonnumeric, empty, and overflowing depth arguments before producing output.
  • Preserve alias traversal defaults and -L behavior, unsupported-flag exit 1, and existing search metrics for name filters.
  • Expose the flags in find --help, help/list_commands, embedded command docs, and the command reference.
  • Cover mixed case, cross-directory globs, character classes, repeated and combined predicates, empty patterns, depth boundaries, and option errors through the shell's public execution interface.

Verification

All Go commands ran in the repository's Nix development shell.

  • Before fix: go test ./pkg/shell/cmds -run '^TestFind' -count=1 failed, reproducing unsupported filters and absent help.
  • After fix: go test -race ./pkg/shell/... ./pkg/openlore ./assets -count=1 passed (non-short affected suites, including alias behavior).
  • go test -race -short ./... passed repository-wide.
  • go vet ./... and go build ./... passed.
  • go generate ./docs/... produced no additional changes; gofmt and git diff --check passed.
  • Existing dashboard FuzzyFinder tests: 6 passed, used only to assess the older OPE-95 candidate; no dashboard code changed.
  • Docker/integration-tag suites and libghostty were not run locally; PR CI remains the delivery gate. No production writes or deployment changes.

Selection

Selected by Linear creation date, oldest first, among unresolved OpenLore bugs. Older issues skipped:

  • OPE-65: historical transport/write incident lacks server evidence to establish a safe fix.
  • OPE-74: issue comment confirms distinct on-disk case variants; remediation requires a case/content policy decision.
  • OPE-77 / OPE-88: already In Progress.
  • OPE-90: explicit literal-heredoc design, with a comment awaiting a maintainer decision.
  • OPE-91 / OPE-94: In Review with open PRs.
  • OPE-95: no reproduction details; Escape handling and its existing regression tests pass, so no remaining failing case could be identified safely.

Agent thread

Implemented in this scheduled Amp child thread. The thread was labeled linear-auto-fix and the issue moved to In Progress with a thread-link comment before implementation.

Do not merge automatically.

Review correction

Reproduced the separator-remapping defect identified in review: [.-0]Skills missed /Skills, while /Skills/[/-z] incorrectly matched /Skills/-, for both -path and -ipath. Replaced remapping with matching over unchanged characters. Regression coverage includes both examples, negated ranges, escaped brackets, Unicode, and wildcard backtracking. After this correction, go test -race ./pkg/shell/... -count=1, go test -race -short ./..., go vet ./..., go build ./..., gofmt, and diff checks passed. New-head CI is pending.

Add case-insensitive name and full-path predicates, AND combined filters, and bound traversal with validated depth limits. Expose the new options through find --help, the command catalogue, and reference docs.

Amp-Thread-ID: https://ampcode.com/threads/T-ab5c38fa-df4f-4ded-b295-40513d6586bb
Co-authored-by: Amp <amp@ampcode.com>
@linear-code

linear-code Bot commented Nov 7, 2026

Copy link
Copy Markdown

OPE-99

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The path matcher changes character-class range membership for both -path and -ipath, producing false positives and false negatives that need correction and regression tests.

1 open issue
What changed in this PR

Extends the shell’s find command with common name, path, and depth filters to address OPE-99 while preserving alias traversal behavior.

Changes:

  • Adds case-insensitive name and full-path matching, with AND semantics for repeated and combined predicates.
  • Adds validated depth limits and traversal pruning.
  • Updates help and documentation, with tests for filtering, depth boundaries, and option errors.
File Description
pkg/​shell/​cmds/​help.go Documents new filters and matching semantics in shell help.
pkg/​shell/​cmds/​find.go Implements predicates, depth limits, validation, and --help.
pkg/​shell/​cmds/​find_test.go Adds filtering, depth, validation, and help tests.
docs/​reference/​commands.md Explains supported options and path/depth behavior.
assets/​lore/​commands.md Updates the embedded command listing with new filters.

Review effort: Balanced

Comment thread pkg/shell/cmds/find.go Outdated
// find globs allow wildcards to match slashes. Map slashes
// to NUL (not a valid filename byte) on both sides so we can
// reuse path.Match without its separator restriction.
value = strings.ReplaceAll(value, "/", "\x00")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Confirmed and fixed in f174077. Added shell-level regressions for both reported cases under -path and -ipath; they failed with the original implementation. The replacement preserves all characters, handles separator-permissive * and ? directly, and delegates unchanged character classes and syntax validation to path.Match. Also covered negated ranges, Unicode, escaped brackets, and wildcard backtracking. Shell race tests, repository-wide short race tests, go vet, go build, formatting, and diff checks pass. New-head CI is subscribed.

Replace separator remapping with wildcard matching over unchanged characters. Reuse path.Match for syntax validation and character classes, and cover the review's false positive/negative cases for both path predicates.

Amp-Thread-ID: https://ampcode.com/threads/T-ab5c38fa-df4f-4ded-b295-40513d6586bb
Co-authored-by: Amp <amp@ampcode.com>
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