AgentSkillsCN

semantic-file-search

通过相关性排序与片段提取,实现自然语言文件发现。结合语义搜索、grep模式与文件名匹配,帮助您在工作空间中快速定位代码。当您在不知晓确切路径的情况下,想要搜索组件、模式或实现方案时,可使用此技能。

SKILL.md
--- frontmatter
name: semantic-file-search
description: Natural language file discovery with relevance ranking and snippet extraction. Combines semantic search, grep patterns, and filename matching to find code across the workspace. Use when searching for components, patterns, or implementations without knowing exact paths.

Semantic File Search

Natural language file discovery with intelligent relevance ranking and context-aware snippet extraction.

What This Skill Does

Combines multiple search strategies (semantic understanding, grep pattern matching, and filename search) to find files matching natural language queries. Returns ranked results with code snippets showing match context and relevance scores. Automatically expands queries with common synonyms and patterns.

When to Use

  • Code exploration - "Find all components using DataStore subscriptions"
  • Pattern discovery - "Show me files that use the useChat hook"
  • Architecture understanding - "Where are authentication components located?"
  • Refactoring preparation - "Find all uses of the old API pattern"
  • Learning codebase - "Show me examples of file upload handling"

Search Strategies

1. Semantic Search (Base relevance: 0.5)

AI-powered natural language understanding - best for: "components that handle user authentication"

2. Grep Pattern Search (Base relevance: 0.3)

Exact code pattern matching - best for: "DataStore.observeQuery" or "useChat("

3. File Search (Base relevance: 0.2)

Filename and path patterns - best for: "*.stories.tsx" or "auth" in filename

Query Expansion

Automatically expands queries with domain-specific patterns:

QueryExpanded To
datastoreDataStore, observeQuery, DataStore.query, DataStore.save
component.tsx, .jsx, Component, export const
contextContext.Provider, useContext, createContext
hookuse[A-Z], useEffect, useState
aiopenai, anthropic, useChat, generateText

Usage Examples

Find Components by Functionality

code
User: "Find components using chat functionality"

Output:

code
Found 8 files matching "chat functionality"

1. src/components/ChatSidebar.tsx (relevance: 0.95)
   ➤   12 | const { messages, isLoading } = useChat({
       13 |   api: '/api/chat',

2. src/components/ChatInterface.tsx (relevance: 0.87)
   ➤   45 | const chatMessages = messages.filter(m => m.role === 'assistant');

Find DataStore Subscriptions

code
User: "Show me all files with DataStore subscriptions"

Expanded: DataStore, observeQuery, .subscribe(

Results: All context files and components using DataStore, ranked by relevance

Relevance Scoring

code
Total = Base Score + Term Frequency + Path Bonus + File Type Bonus

Base Score:
  - Semantic: 0.5
  - Grep: 0.3
  - File: 0.2

Bonuses:
  + 0.05 per query term in snippet
  + 0.10 if term in file path
  + 0.05 for source files (not .test.*)

Max: 1.0

Scope Filtering

Limit search using glob patterns:

typescript
// Find components only
{ scope: "src/components/**/*.{ts,tsx,js,jsx}" }

// Find tests only
{ scope: "**/*.{test,spec}.*" }

// Specific directory
{ scope: "src/context/**" }

Implementation

TypeScript Module: semantic-file-search.ts
Tests: semantic-file-search.test.ts
Documentation: SEMANTIC_FILE_SEARCH.md

typescript
import { executeSkill } from '.github/skills/semantic-file-search/semantic-file-search';

const result = await executeSkill({
  query: "Find DataStore subscriptions",
  scope: "src/**",
  limit: 10
});

Testing

bash
npm run test -- .github/skills/semantic-file-search/semantic-file-search.test.ts

Related Skills

Related Documentation