Skip to content

alivirgo/Major-AI-Skills / plugins/mas-efficiency-pack/skills/selective-grep-filtering

selective-grep-filtering

Verified

Narrow code searches with file globs, literal matching, and relevant directories to reduce unrelated results.

Surgical Grep Filtering & Glob Targeting Protocol

Overview

When searching a repository for a specific method or constant ("handlePaymentCallback"), naive agents execute broad, unconstrained searches across the entire workspace directory.

Unfiltered searches return hundreds of false-positive matches:

  1. Test Snapshots & Fixtures: Matches in 50 Jest/Vitest snapshots that aren't part of production logic.
  2. Minified Bundles & Source Maps: Matches in .map or dist/ files that dump unreadable minified code into context.
  3. Markdown Documentation: Matches in changelogs, READMEs, and tutorials.

The Surgical Grep Filtering Protocol constrains the search space using strict file extension globs, target directory scopes, and exact literal matching (IsRegex: false), returning strictly the 1 to 3 production source matches.


Unconstrained Search vs. Surgical Glob Filtering

┌─────────────────────────────────────────────────────────────┐
│                 Search Precision Comparison                 │
│                                                             │
│  Unconstrained Workspace Search (140 Matches / 6,200 Toks): │
│  • 80 matches in `tests/__snapshots__/`                     │
│  • 45 matches in `dist/bundle.js`                           │
│  • 12 matches in `docs/architecture.md`                     │
│  • 3 matches in `src/services/`                             │
│  ↳ 6,200 tokens billed, agent gets lost in snapshots        │
│                                                             │
│  Surgical Glob Filtering (3 Matches / 85 Tokens - 98.6% Cut):│
│  • Includes: `["src/**/*.ts", "!**/*.spec.ts"]`             │
│  • Match: `src/services/billing.ts:42`                      │
│  • Match: `src/routes/payment.ts:18`                        │
│  ↳ 85 clean tokens, 100% production source hits             │
└─────────────────────────────────────────────────────────────┘

The 3 Pillars of Surgical Search

┌───────────────────────────────────────────────────────────────────────────┐
│ 1. TARGET DIRECTORY ONLY: Confine `SearchPath` to `src/` or `pkg/`        │
│ 2. EXCLUDE TESTS & SPECS: Add `!**/*.test.ts`, `!**/*.spec.py`            │
│ 3. LITERAL MATCHING BY DEFAULT: Set `IsRegex: false` (Prevents regex bugs)│
└───────────────────────────────────────────────────────────────────────────┘

Production Tool Invocation Standards

When invoking grep_search in Antigravity IDE / Claude Code:

{
  "Query": "handlePaymentCallback",
  "SearchPath": "c:/Users/ASUS/Documents/Newfolder/Antigravity/Major AI Skills/src",
  "CaseInsensitive": false,
  "IsRegex": false,
  "MatchPerLine": true,
  "Includes": [
    "**/*.ts",
    "!**/*.test.ts",
    "!**/*.spec.ts",
    "!**/__mocks__/**"
  ],
  "toolAction": "Searching for payment callback in production TS sources",
  "toolSummary": "Surgical Grep Search"
}

CLI Ripgrep Equivalent Commands

When running ripgrep directly via terminal:

# Surgical search: TypeScript production files only (excluding tests and mocks)
rg "handlePaymentCallback" src/ -t ts --glob '!**/*.test.ts' --glob '!**/__mocks__/**'

# Search Python source files only
rg "def authenticate_user" src/ -t py --glob '!tests/**'

Benchmark Comparison

Searching for a common error handler across a 1,500-file repository:

Search ConfigurationMatches ReturnedTokens IngestedAccuracy / Signal
Unfiltered Global Grep185 matches8,400 tokens12% (Flooded with snapshots & docs)
Case-Insensitive Regex240 matches11,200 tokens8% (Catches comments & prose)
Surgical Glob Protocol2 matches70 tokens100% (Exact production targets)

Agent Operational Directive

MANDATORY: Agents executing code searches must scope SearchPath to active source directories (src/, app/, pkg/) and populate the Includes array with specific filetype globs and test exclusion filters (!**/*.test.*).

receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall