Runs common Buck2 queries for dependency analysis, target inspection, and build graph exploration. Use when investigating dependencies, finding reverse dependencies, filtering by rule type, or understanding target relationships in the monorepo.
This skill provides enhanced Buck2 query capabilities with better formatting, common query shortcuts, and pattern matching. It helps you understand the build graph, analyze dependencies, and investigate target relationships without memorizing complex query syntax.
Use this skill when:
This skill provides:
scripts/query_helper.py - Enhanced query runner with shortcutsreferences/query_patterns.md - Common query examples and patternsCommon queries made simple:
# Find what depends on a target
python3 scripts/query_helper.py rdeps //src/lib/mylib
# List all dependencies
python3 scripts/query_helper.py deps //src/tools/mytool
# Find all Rust binaries
python3 scripts/query_helper.py kind rust_binary //src/...
# Inspect target attributes
python3 scripts/query_helper.py attrs //src/lib/mylib
Direct dependencies:
# All direct dependencies
python3 scripts/query_helper.py deps root//buck/tools/tdutil:tdutil
# Formatted output with types
python3 scripts/query_helper.py deps --show-kind root//buck/tools/tdutil:tdutil
Transitive dependencies:
# All transitive dependencies
python3 scripts/query_helper.py deps --transitive root//buck/tools/tdutil:tdutil
# Limit depth
python3 scripts/query_helper.py deps --transitive --depth 2 root//buck/tools/tdutil:tdutil
What depends on this target:
# Direct reverse deps
python3 scripts/query_helper.py rdeps //src/lib/common
# Within a specific scope
python3 scripts/query_helper.py rdeps --scope //src/... //src/lib/common
# Show why each target depends on it
python3 scripts/query_helper.py rdeps --explain //src/lib/common
Find targets by rule type:
# All Rust binaries
python3 scripts/query_helper.py kind rust_binary //src/...
# All Rust libraries
python3 scripts/query_helper.py kind rust_library //src/...
# All Deno targets
python3 scripts/query_helper.py kind deno //src/tools/...
# Multiple types
python3 scripts/query_helper.py kind "rust_binary|rust_test" //src/...
View target configuration:
# All attributes
python3 scripts/query_helper.py attrs //src/lib/mylib
# Specific attributes
python3 scripts/query_helper.py attrs --fields srcs,deps //src/lib/mylib
# JSON output for scripting
python3 scripts/query_helper.py attrs --json //src/lib/mylib
Buck2 queries work on sets of targets:
# Single target
buck2 query //src/lib:mylib
# All targets in package
buck2 query //src/lib:
# All targets recursively
buck2 query //src/...
# Pattern matching
buck2 query "//src/lib/...:test" # All targets named 'test'
deps() - Find dependencies:
# Direct dependencies
buck2 query "deps('root//buck/tools/tdutil:tdutil')"
# With depth limit (1 = direct deps)
buck2 query "deps('root//buck/tools/tdutil:tdutil', 1)"
# Filter results
buck2 query "deps('root//buck/tools/tdutil:tdutil') ^ third-party//..."
rdeps() - Find reverse dependencies:
# What depends on this target
buck2 query "rdeps('//src/...', '//src/lib:common')"
# With depth limit
buck2 query "rdeps('//src/...', '//src/lib:common', 1)"
kind() - Filter by rule type:
# All Rust binaries
buck2 query "kind('rust_binary', '//src/...')"
# Regex patterns
buck2 query "kind('rust_.*', '//src/...')"
attrfilter() - Filter by attribute:
# Targets with specific visibility
buck2 query "attrfilter(visibility, PUBLIC, //src/...)"
# Targets with specific source files
buck2 query "attrfilter(srcs, main.rs, //src/...)"
Combine queries with set operators:
# Union (either A or B)
buck2 query "//src/lib/... + //src/tools/..."
# Intersection (both A and B)
buck2 query "deps('//src/tools:mytool') ^ //third-party/..."
# Difference (A but not B)
buck2 query "//src/... - //src/tests/..."
deps - Show dependencies:
# Basic usage
python3 scripts/query_helper.py deps TARGET
# Options:
--transitive Include all transitive dependencies
--depth N Limit to N levels deep
--show-kind Show rule type for each target
--exclude PATTERN Exclude targets matching pattern
rdeps - Show reverse dependencies:
# Basic usage
python3 scripts/query_helper.py rdeps TARGET
# Options:
--scope PATTERN Search within this scope (default: //...)
--depth N Limit to N levels
--explain Show dependency chain
--show-kind Show rule type
kind - Filter by type:
# Basic usage
python3 scripts/query_helper.py kind TYPE_PATTERN SCOPE
# Examples:
python3 scripts/query_helper.py kind rust_binary //src/...
python3 scripts/query_helper.py kind "rust_.*" //src/...
python3 scripts/query_helper.py kind deno //src/tools/...
attrs - Inspect attributes:
# Basic usage
python3 scripts/query_helper.py attrs TARGET
# Options:
--fields F1,F2 Show only specific fields
--json Output as JSON
--raw Show raw Buck2 output
path - Find dependency path:
# Find how TARGET1 depends on TARGET2
python3 scripts/query_helper.py path TARGET1 TARGET2
cycles - Detect dependency cycles:
# Check for cycles in scope
python3 scripts/query_helper.py cycles //src/...
Why is this target being built?
# Find what pulled it in
python3 scripts/query_helper.py rdeps --explain --scope //src/... //target
What are all the dependencies?
# See full dependency tree
python3 scripts/query_helper.py deps --transitive --show-kind //target
What will break if I change this?
# Find all reverse dependencies
python3 scripts/query_helper.py rdeps //src/lib/old-api
# Limit to specific scope
python3 scripts/query_helper.py rdeps --scope //src/apps/... //src/lib/old-api
Can I make this internal?
# See who depends on it
python3 scripts/query_helper.py rdeps //src/lib/maybe-private
# If output is empty or only same package, can make it private
Find all third-party dependencies:
# For a specific target
python3 scripts/query_helper.py deps --transitive //target | grep third-party
# All third-party deps in a scope
buck2 query "deps('//src/...') ^ //third-party/..."
Find unused dependencies:
# List all deps
python3 scripts/query_helper.py attrs --fields deps //target
# Compare with actual usage in source files
Find large dependency trees:
# Count transitive dependencies
python3 scripts/query_helper.py deps --transitive //target | wc -l
# Compare across targets to find heavy ones
for target in $(buck2 targets //src/tools:); do
count=$(python3 scripts/query_helper.py deps --transitive $target | wc -l)
echo "$count $target"
done | sort -rn
Targets with many reverse dependencies might be bottlenecks:
# Find most depended-on targets
for target in $(buck2 targets //src/lib:); do
count=$(python3 scripts/query_helper.py rdeps --scope //src/... $target | wc -l)
echo "$count $target"
done | sort -rn | head -10
# Find all tests
python3 scripts/query_helper.py kind ".*_test" //src/...
# Find code with no tests
# (targets with no reverse deps that are tests)
# Who can see this target?
python3 scripts/query_helper.py attrs --fields visibility //target
# Find all PUBLIC targets
buck2 query "attrfilter(visibility, PUBLIC, //src/...)"
# Find affected tests for changed targets
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
buck2 run root//buck/tools/tdutil:tdutil -- \
--output "$TARGETS_FILE" --universe depot//src/...
while IFS= read -r target; do
python3 scripts/query_helper.py rdeps --scope //src/... "$target" | \
grep _test
done < "$TARGETS_FILE" | sort -u
# Find what changed between commits
jj diff --stat | cut -f2 | while read file; do
# Find which targets own this file
buck2 query "owner('$file')"
done | while read target; do
# Find tests for each target
python3 scripts/query_helper.py rdeps $target | grep test
done | sort -u
# Direct dependencies
buck2 query "deps('//target', 1)"
# All dependencies
buck2 query "deps('//target')"
# Reverse dependencies
buck2 query "rdeps('//...', '//target')"
# Filter by type
buck2 query "kind('rust_binary', '//src/...')"
# Find path between targets
buck2 query "allpaths('//from', '//to')"
# Targets owning files
buck2 query "owner('src/lib/foo.rs')"
# Default (list of targets)
buck2 query "deps('//target')"
# JSON for scripting
buck2 query "deps('//target')" --json
# Show attributes
buck2 query "deps('//target')" --output-attribute srcs,deps
Problem: Query on //... is very slow
Solutions:
//src/... instead of //...deps('//target', 2) instead of deps('//target')deps('//target') - //third-party/...Problem: Query returns empty set
Verify:
# Target exists?
buck2 targets //path:target
# Scope includes target?
buck2 targets //scope/...
# Query syntax correct?
buck2 query "kind('type', '//scope/...')" # Note the quotes
Problem: Query includes unexpected targets
Debug:
# Use --output-attribute to see why
buck2 query "deps('//target')" --output-attribute deps
# Visualize dependency graph
buck2 query "deps('//target')" --dot | dot -Tpng > deps.png
--dot output with Graphviz for visualizationAdd to your shell rc file:
alias bq='buck2 query'
alias bqdeps='python3 /path/to/scripts/query_helper.py deps'
alias bqrdeps='python3 /path/to/scripts/query_helper.py rdeps'
alias bqkind='python3 /path/to/scripts/query_helper.py kind'
npx skills add thoughtpolice/buck2-query-helper下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer