Skip to content

feat(cli): expose RecordQuery negation as exclude filters - #1987

Merged
akijakya merged 2 commits into
mainfrom
feat/exclude-filter-dirctl
Aug 7, 2026
Merged

akijakya merged 2 commits into
mainfrom
feat/exclude-filter-dirctl

Conversation

@akijakya

@akijakya akijakya commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

Closes #1986.

What

RecordQuery.negate landed in #1983 and the server compiles exclusion for every filter type — 17 Without* options in server/types/search.go, with the correct NOT EXISTS shape for joined, multi-valued fields. None of it was reachable from dirctl: BuildQueries only ever built inclusion queries, so negation was usable only by hand-rolled SDK callers.

This adds an --exclude- twin for every value filter, plus tri-state booleans.

Include Exclude
--name --exclude-name
--version --exclude-version
--skill / --skill-id --exclude-skill / --exclude-skill-id
--domain / --domain-id --exclude-domain / --exclude-domain-id
--module / --module-id --exclude-module / --exclude-module-id
--locator --exclude-locator
--author --exclude-author
--created-at --exclude-created-at
--schema-version --exclude-schema-version
--annotation --exclude-annotation
--scan-severity --exclude-scan-severity
dirctl search --exclude-skill "natural_language_processing"
dirctl search --domain "life_science/*" --exclude-author "bot*"
dirctl search --skill python --exclude-skill nlp   # has python, does not have nlp
dirctl search --trusted=false                      # signature not trusted

--verified, --trusted and --safe become tri-state. Cobra already parsed --trusted=false; it just silently meant "do not filter". It now emits a query with value "false", which QueryToFilters has understood since #1983. An absent flag still does not filter, so nothing changes for existing invocations.

Design notes

Separate flags rather than an inline ! marker. ! composes cleanly with wildcards (!nlp*) but awkwardly with comparison operators (!>=1.0.0, and !=1.0.0 means different things on a field that supports comparisons versus one that does not) and ambiguously with : — --annotation '!urgent:true' cannot be told apart from a key legitimately named !urgent without an escape. Separate flags leave the value grammar untouched: ! stays an ordinary character.

FilterValues{Include, Exclude}. The server ORs a filter's included values but ANDs each exclusion as its own NOT EXISTS, so the two cannot share a slice — called out in #1940's own write-up. Splitting at the flag means pflag does the separation and BuildQueries needs no parsing.

Filters is now driven by one valueFilters() table carrying flag name, both help strings and the query type, so registration and query building are a single loop each and a future filter is one entry instead of three edits. Nothing outside the package read the old fields; the only follow-through was nlsearch.go, where the extractor takes SchemaVersions.Include (an excluded version has no taxonomy to point at).

Booleans keep the =false form rather than gaining --exclude-trusted — it costs no new flag surface.

Notes for reviewers

  • The flags land on pull, export and install too, since all four share registerFilterFlags. Verified: 14 exclude flags on each.
  • dirctl install registers the filters as persistent flags, so tri-state detection depends on cobra sharing the *pflag.Flag pointer between a parent's persistent set and a subcommand's merged set. Covered by TestBuildQueriesTriStateThroughPersistentFlags.
  • --exclude-scan-severity keeps never-scanned records: it excludes records that have a report at or above the threshold, and an unscanned record has none. This matches the server's existing applyExcludedScanSeverities, and is documented next to the flag and in the CLI reference.
  • --safe=false is likewise not the complement of --safe — it compiles to EXISTS (scan_reports … is_safe = false), so a never-scanned record matches neither. --trusted=false and --verified=false are true complements.
  • Exclusion on a multi-valued field drops the record if any value matches, so --exclude-skill nlp drops a record whose skills are [nlp, python].

Testing

  • cli/cmd/search/filters_test.go (new): every include flag, every exclude flag, include+exclude on one field, repeatability, verbatim pass-through of >=, *, ! and :, tri-state booleans, the persistent-flag path, and the programmatic Filters fallback.
  • tests/e2e/local/02_search_test.go: 8 specs exercising the CLI → server → NOT EXISTS path, including the multi-valued case and the never-scanned severity case. These have not had a passing local run — the local e2e suite was cut short — so they are unproven until CI runs them.
  • task lint:go clean across all 7 modules; docs markdown and spelling clean.

Unblocks

#1977 — the policy CronJob Helm templates, whose prune-untrusted example renders --trusted=false.

@akijakya akijakya self-assigned this Aug 6, 2026
@akijakya
akijakya requested a review from a team as a code owner August 6, 2026 18:04
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Aug 6, 2026
@akijakya
akijakya force-pushed the feat/exclude-filter-dirctl branch from 3a370c2 to bd17e5a Compare August 6, 2026 19:21
@akijakya
akijakya requested a lite review from Copilot August 6, 2026 19:21

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for “exclude” (--exclude-*) search filters and tri‑state boolean filters (--trusted=false, etc.), with updated CLI docs/examples and expanded test coverage.

Changes:

  • Introduces include/exclude value filters and builds negated RecordQuery entries for --exclude-* flags.
  • Makes --verified, --trusted, and --safe tri-state by emitting queries for explicit =false.
  • Updates CLI reference/docs and adds unit + e2e tests covering negation and scan-severity exclusion behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/e2e/local/02_search_test.go Adds end-to-end coverage for --exclude-* behavior, multi-valued fields, and scan severity exclusion.
docs/content/dir/dir-cli-reference.md Documents tri-state booleans and introduces --exclude-* flag behavior and examples.
cli/cmd/search/search.go Updates CLI help examples to include tri-state booleans and new exclude filters.
cli/cmd/search/nlsearch.go Ensures NL extractor only uses included schema versions, not excluded ones.
cli/cmd/search/filters_test.go Adds unit tests for include/exclude query generation and tri-state boolean semantics.
cli/cmd/search/filters.go Implements include/exclude filter model, exclude scan-severity flag, and tri-state boolean query emission.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/content/dir/dir-cli-reference.md Resolved
Comment thread cli/cmd/search/filters.go Resolved

@csirmazbendeguz csirmazbendeguz 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.

lgtm

@akijakya
akijakya merged commit 7e731de into main Aug 7, 2026
12 checks passed
@akijakya
akijakya deleted the feat/exclude-filter-dirctl branch August 7, 2026 08:36
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.21875% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/cmd/search/nlsearch.go 0.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Expose RecordQuery negation as exclude filters in the dirctl CLI

4 participants