Skip to main content
ClaudeWave
Skill85 estrellas del repoactualizado 3mo ago

code-search-assistant

Search code repositories for code related to a given code snippet, ranking results by call chain similarity, textual similarity, and functional similarity. Use when finding related code, locating similar implementations, discovering code dependencies, or identifying code that performs similar operations. Outputs ranked file lists with matching code snippets and relevance scores.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE /tmp/code-search-assistant && cp -r /tmp/code-search-assistant/skills/code-search-assistant ~/.claude/skills/code-search-assistant
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

# Code Search Assistant

## Overview

Search codebases to find code related to a given snippet using multi-dimensional similarity analysis: call chain patterns, textual structure, and functional behavior. Results are ranked and presented with matching code snippets.

## Workflow

### 1. Analyze Input Snippet

Extract key characteristics from the provided code snippet:

**Structural elements**:
- Function/method calls made
- Classes/types used
- Control flow patterns (loops, conditionals, try-catch)
- Data structures (arrays, objects, maps)

**Functional elements**:
- Purpose/intent of the code
- Input/output behavior
- Side effects (I/O, state changes, API calls)
- Domain concepts (authentication, validation, transformation)

**Textual elements**:
- Variable and function names
- String literals and constants
- Comments and documentation
- Code tokens and keywords

### 2. Define Search Scope

Determine where to search:
- **Full repository**: Search all code files
- **Specific directories**: Focus on relevant modules
- **File type filter**: Limit to specific languages

Use Glob to identify candidate files:
```
**/*.js, **/*.py, **/*.java, etc.
```

### 3. Search by Call Chain Similarity

Find code with similar function call patterns and dependencies.

**Search strategy**:
1. Extract function/method calls from input snippet
2. Use Grep to find files containing those function calls
3. Read matching files to analyze call sequences
4. Score based on:
   - Number of shared function calls (weight: 40%)
   - Order of function calls (weight: 30%)
   - Shared imported modules/libraries (weight: 30%)

**Example**:
```javascript
// Input snippet calls: fetch(), JSON.parse(), setState()
// High match: Code that calls fetch() → JSON.parse() → setState()
// Medium match: Code that calls fetch() and setState() in different order
// Low match: Code that only calls fetch()
```

### 4. Search by Textual Similarity

Find code with similar structure and token patterns.

**Search strategy**:
1. Extract key identifiers from input snippet (function names, variable names)
2. Use Grep to find files with similar identifiers
3. Read matching files to compare code structure
4. Score based on:
   - Shared variable/function names (weight: 35%)
   - Similar control flow structure (weight: 35%)
   - Shared keywords and operators (weight: 30%)

**Similarity indicators**:
- Same loop patterns (for, while, forEach, map)
- Similar conditional logic (if-else chains, switch statements)
- Matching data structure operations (array methods, object access)
- Similar string/number operations

### 5. Search by Functional Similarity

Find code that performs similar operations or solves similar problems.

**Search strategy**:
1. Identify the functional purpose of input snippet
2. Search for code with similar purpose using semantic patterns
3. Look for:
   - Similar input/output transformations
   - Equivalent algorithms (different implementations, same result)
   - Parallel business logic
   - Alternative approaches to same problem

**Functional categories**:
- **Data transformation**: Mapping, filtering, reducing, sorting
- **Validation**: Input checking, format validation, constraint enforcement
- **I/O operations**: File reading/writing, API calls, database queries
- **Authentication/Authorization**: Login, permission checks, token handling
- **Error handling**: Try-catch patterns, error recovery, logging

**Search patterns**:
```
// For validation code, search for:
- "validate", "check", "verify" in function names
- Conditional checks with error throwing
- Regular expression patterns

// For API calls, search for:
- HTTP client usage (fetch, axios, requests)
- Endpoint URLs or API patterns
- Response handling and error cases
```

### 6. Rank and Score Results

Combine similarity scores to rank results:

**Scoring formula**:
```
Total Score = (Call Chain Score × 0.35) +
              (Textual Score × 0.30) +
              (Functional Score × 0.35)
```

**Score ranges**:
- 0.8-1.0: Very high similarity (likely duplicate or variant)
- 0.6-0.8: High similarity (related implementation)
- 0.4-0.6: Medium similarity (similar patterns or purpose)
- 0.2-0.4: Low similarity (some shared elements)
- 0.0-0.2: Minimal similarity (weak connection)

**Ranking adjustments**:
- Boost files in same directory (+10%)
- Boost files with similar names (+5%)
- Penalize test files (-10%) unless input is a test
- Penalize generated/vendor code (-20%)

### 7. Format Results

Present results in ranked order with context:

**Result format**:
```markdown
## Search Results for: [Brief snippet description]

### 1. [file_path] (Score: 0.85)

**Similarity breakdown**:
- Call chain: 0.90 (shares fetch, JSON.parse, setState calls)
- Textual: 0.75 (similar variable names and structure)
- Functional: 0.90 (performs same data fetching and state update)

**Matching code** (lines 45-62):
```[language]
[relevant code snippet from the file]
```

**Why it matches**: [Brief explanation of similarity]

---

### 2. [file_path] (Score: 0.72)
[... repeat format ...]
```

**Output guidelines**:
- Show top 10 results by default
- Include file path with line numbers
- Show relevant code snippet (10-20 lines)
- Explain why each result matches
- Group results by score tier if many results

## Search Optimization Tips

**For better call chain matching**:
- Include import statements in input snippet
- Provide complete function calls with arguments
- Include chained method calls

**For better textual matching**:
- Use descriptive variable names in input
- Include comments describing intent
- Provide complete code blocks, not fragments

**For better functional matching**:
- Describe what the code does in comments
- Include typical input/output examples
- Show error handling patterns

## Example Usage

**Input snippet**:
```javascript
async function fetchUserData(userId) {
  try {
    const response = await fetch(`/api/users/${userId}`);
    const data = await response.json();
    retur
abstract-domain-explorerSkill

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

abstract-invariant-generatorSkill

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

abstract-state-analyzerSkill

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

abstract-trace-summarizerSkill

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

acsl-annotation-assistantSkill

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

agent-browserSkill

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

ambiguity-detectorSkill

Detects and analyzes ambiguous language in software requirements and user stories. Use when reviewing requirements documents, user stories, specifications, or any software requirement text to identify vague quantifiers, unclear scope, undefined terms, missing edge cases, subjective language, and incomplete specifications. Provides detailed analysis with clarifying questions and suggested improvements.

api-design-assistantSkill

Design and review APIs with suggestions for endpoints, parameters, return types, and best practices. Use when designing new APIs from requirements, reviewing existing API designs, generating API documentation, or getting implementation guidance. Supports REST APIs with focus on endpoint structure, request/response schemas, authentication, pagination, filtering, versioning, and OpenAPI specifications. Triggers when users ask to design, review, document, or improve APIs.