commit 13ef82d93b24447ca3a600e7e57689be57cd1ab6 Author: Zhongwei Li Date: Sun Nov 30 08:51:50 2025 +0800 Initial commit diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..74602e6 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,14 @@ +{ + "name": "sgrep", + "description": "Lightning-fast semantic code search with auto-indexing. Automatically manages sgrep watch during Claude sessions.", + "version": "1.2.0", + "author": { + "name": "Rika Labs" + }, + "skills": [ + "./skills" + ], + "hooks": [ + "./hooks/hooks.json" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3583f4 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# sgrep + +Lightning-fast semantic code search with auto-indexing. Automatically manages sgrep watch during Claude sessions. diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..1b0cae3 --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,59 @@ +{ + "description": "Automatically manage sgrep watch during Claude Code sessions", + "hooks": { + "SessionStart": [ + { + "matcher": "startup", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-start.sh", + "timeout": 30 + } + ] + }, + { + "matcher": "resume", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-start.sh", + "timeout": 30 + } + ] + }, + { + "matcher": "clear", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-start.sh", + "timeout": 30 + } + ] + }, + { + "matcher": "compact", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-start.sh", + "timeout": 30 + } + ] + } + ], + "SessionEnd": [ + { + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-stop.sh", + "timeout": 10 + } + ] + } + ] + } +} + diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..be64494 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:Rika-Labs/sgrep:plugins/sgrep", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "1cbdda1a94799072e0abbd6241fe7cda27bb34db", + "treeHash": "d1d6148129068a1c6d48e24303a0403ef66fdf3067ccad400aed75181595f08d", + "generatedAt": "2025-11-28T10:12:42.368938Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "sgrep", + "description": "Lightning-fast semantic code search with auto-indexing. Automatically manages sgrep watch during Claude sessions.", + "version": "1.2.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "a33b19dc48319070bf73946ea2f4ada2cce8f2d6a01ddc7980cdf9acb51fae58" + }, + { + "path": "hooks/hooks.json", + "sha256": "2efd8ca7023bf749abfe2f3e792e5d935922cc1b37350642b56a6b1125370a92" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "4eca2cfb11287ead918d2d00cedf5ad273cfe069c0e89258a93e9979e765c918" + }, + { + "path": "skills/sgrep/SKILL.md", + "sha256": "909d523f33d676ff5aa7f869f3e3b30d1f9504719eaac15de67b81b396f05231" + } + ], + "dirSha256": "d1d6148129068a1c6d48e24303a0403ef66fdf3067ccad400aed75181595f08d" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/sgrep/SKILL.md b/skills/sgrep/SKILL.md new file mode 100644 index 0000000..dcba030 --- /dev/null +++ b/skills/sgrep/SKILL.md @@ -0,0 +1,143 @@ +--- +name: sgrep +description: Use sgrep for semantic code search. Use when you need to find code by meaning rather than exact text matching. Perfect for finding concepts like "authentication logic", "error handling patterns", or "database connection pooling". +allowed-tools: Bash +--- + +# sgrep - Semantic Code Search + +Use `sgrep` to search code semantically using natural language queries. sgrep understands code meaning, not just text patterns. + +## When to Use + +- Finding code by concept or functionality ("where do we handle authentication?") +- Discovering related code patterns ("show me retry logic") +- Exploring codebase structure ("how is the database connection managed?") +- Searching for implementation patterns ("where do we validate user input?") + +## Prerequisites + +Ensure `sgrep` is installed: +```bash +curl -fsSL https://raw.githubusercontent.com/rika-labs/sgrep/main/scripts/install.sh | sh +``` + +## Basic Usage + +### Search Command + +```bash +sgrep search "your natural language query" +``` + +### Common Patterns + +**Find functionality:** +```bash +sgrep search "where do we handle user authentication?" +``` + +**Search with filters:** +```bash +sgrep search "error handling" --filters lang=rust +sgrep search "API endpoints" --glob "src/**/*.rs" +``` + +**Get more results:** +```bash +sgrep search "database queries" --limit 20 +``` + +**Show full context:** +```bash +sgrep search "retry logic" --context +``` + +## Command Options + +- `--limit ` or `-n `: Maximum results (default: 10) +- `--context` or `-c`: Show full chunk content instead of snippet +- `--path ` or `-p `: Repository path (default: current directory) +- `--glob `: File pattern filter (repeatable) +- `--filters key=value`: Metadata filters like `lang=rust` (repeatable) +- `--threads `: Maximum threads for parallel operations +- `--cpu-preset `: CPU usage preset (auto|low|medium|high|background) + +## Indexing + +If no index exists, sgrep will automatically create one on first search. To manually index: + +```bash +sgrep index # Index current directory +sgrep index --force # Rebuild from scratch +``` + +## Watch Mode + +The plugin automatically manages `sgrep watch` during Claude sessions. For manual watch: + +```bash +sgrep watch # Watch current directory +sgrep watch --debounce-ms 200 +``` + +## Configuration + +sgrep uses local embeddings by default: + +```bash +sgrep config # Show current configuration +sgrep config --init # Create default config file +sgrep config --show-model-dir # Show model cache directory +sgrep config --verify-model # Check if model files are present +``` + +If HuggingFace is blocked, set `HTTPS_PROXY` environment variable or see the [offline installation guide](https://github.com/rika-labs/sgrep#offline-installation). + +## Examples + +**Find authentication code:** +```bash +sgrep search "how do we authenticate users?" +``` + +**Find error handling:** +```bash +sgrep search "error handling patterns" --filters lang=rust +``` + +**Search specific file types:** +```bash +sgrep search "API rate limiting" --glob "src/**/*.rs" +``` + +**Get detailed results:** +```bash +sgrep search "database connection pooling" --context --limit 5 +``` + +## Understanding Results + +Results show: +- **File path and line numbers**: Where the code is located +- **Score**: Relevance score (higher is better) +- **Semantic score**: How well it matches the query meaning +- **Keyword score**: Text matching score +- **Code snippet**: Relevant code excerpt + +## Best Practices + +1. **Use natural language**: Ask questions like you would ask a colleague +2. **Be specific**: "authentication middleware" is better than "auth" +3. **Combine with filters**: Use `--filters lang=rust` to narrow by language +4. **Use globs**: `--glob "src/**/*.rs"` to search specific directories +5. **Check context**: Use `--context` when you need full function/class definitions + +## Integration with Claude + +When Claude needs to find code: +1. Use sgrep to search semantically +2. Review results to understand codebase structure +3. Use results to inform code changes or explanations +4. Combine multiple searches to build comprehensive understanding +