AgentSkillsCN

advanced_tools

使用基于Rust的工具(ripgrep、fd、tree)实现高性能文本搜索、文件操作和批量重构。包含安全的批量替换,并提供干运行预览。

SKILL.md
--- frontmatter
name: "advanced_tools"
version: "1.1.0"
description: "High-performance text search, file operations, and batch refactoring using Rust-based tools (ripgrep, fd, tree). Includes safe batch replacement with dry-run preview."
routing_keywords:
  [
    "search",
    "grep",
    "find",
    "ripgrep",
    "regex",
    "match",
    "content",
    "text",
    "advanced",
    "refactor",
    "replace",
    "batch",
    "tree",
    "directory",
  ]
authors: ["omni-dev-fusion"]
intents:
  - "Search code with regex"
  - "Find text in files"
  - "Find patterns in code"
  - "Count matches in codebase"
  - "Batch replace across files"
  - "Preview refactoring changes"
  - "View directory tree"

You have loaded the Advanced Tools Skill.

Architecture

This skill provides three categories of tools:

CategoryToolsUse For
Searchsmart_search, smart_findFast text and file discovery
Visualizetree_viewDirectory structure visualization
Mutationregex_replace, batch_replaceSafe text transformation

What to Use Instead

TaskUse SkillTool
Search code structure (AST)code_toolssearch_code, search_directory
Code refactoringcode_toolsstructural_replace, structural_preview
File I/Ofilesystemread_file, save_file
Surgical file readfilesystemread_file_context

Key Differences

Text Search (advanced_tools) vs AST Search (code_tools)

Aspectadvanced_tools (ripgrep)code_tools (AST)
Search TypeText patternsCode structure
Exampleclass \w+ finds "class" textclass $NAME finds classes
ScopeLiteralSemantic
Use CaseFinding text, TODO commentsRefactoring, pattern matching

Single Replace vs Batch Replace

Aspectregex_replacebatch_replace
FilesSingle fileMultiple files
PreviewNoYes (dry-run)
SafetyManual reviewAutomatic diff
Use CaseOne-off changesMass refactoring

Available Tools

Search Commands

smart_search

Fast regex search using ripgrep with structured output.

python
def smart_search(
    pattern: str,
    path: str = ".",
    file_type: str = None,
    context_lines: int = 2,
    max_results: int = 50,
) -> dict[str, Any]

smart_find

Fast file finding using fd with pattern matching.

python
def smart_find(
    pattern: str = ".",
    path: str = ".",
    extension: str = None,
    max_results: int = 100,
) -> dict[str, Any]

Visualization Commands

tree_view

Directory tree visualization (requires tree command).

python
def tree_view(
    path: str = ".",
    depth: int = 3,
    ignore_hidden: bool = True,
) -> dict[str, Any]

Mutation Commands

regex_replace

Single file regex replacement using sed.

python
def regex_replace(
    file_path: str,
    pattern: str,
    replacement: str,
) -> dict[str, Any]

batch_replace

Batch refactoring with dry-run safety (RECOMMENDED for refactoring).

python
def batch_replace(
    pattern: str,
    replacement: str,
    file_glob: str = "**/*",
    dry_run: bool = True,  # Safety: default is preview
    max_files: int = 50,
) -> dict[str, Any]

Common Patterns

Finding Function Definitions

code
pattern: def \w+
file_type: py

Finding TODO Comments

code
pattern: TODO|FIXME|HACK
context_lines: 1

Batch Refactoring (Safe)

python
# Step 1: Preview changes
result = batch_replace(
    pattern="old_function",
    replacement="new_function",
    file_glob="**/*.py",
    dry_run=True,  # Preview mode
)

# Step 2: Review diffs
for change in result["changes"]:
    print(change["diff"])

# Step 3: Apply if满意
result = batch_replace(
    pattern="old_function",
    replacement="new_function",
    file_glob="**/*.py",
    dry_run=False,  # Live mode
)

References

Optimization Tips

  1. Use file_type/glob filters - Restricts search to specific languages
  2. Narrow path scope - Search specific directories, not whole repo
  3. Use context_lines sparingly - More context = more output = more tokens
  4. Use specific regex - "def test_" matches fewer than "test"
  5. Always dry-run first - Use dry_run=True for batch_replace

Best Practices

  1. Start with broad search, narrow with results
  2. Use context_lines to understand matches
  3. Check stats.elapsed_ms - if high, add filters
  4. For refactoring: always preview with dry-run before applying
  5. Combine with read_file for full context