search-first
affaan-m/ECC
在撰寫自訂程式碼之前,請透過呼叫研究員代理程式,先研究現有的工具、函式庫及設計模式。
...展開全部/search-first — 編寫程式前先做研究
將「在實作前先搜尋現有解決方案」的工作流程系統化。
觸發條件
在以下情況下使用此技巧:
- 開始開發新功能,且該功能很可能已有現成解決方案時
- 新增依賴項或整合功能時
- 使用者要求「新增 X 功能」,而您正準備撰寫程式碼時
- 在建立新的公用程式、輔助函式或抽象層之前
工作流程
┌─────────────────────────────────────────────┐
│ 0. TOOL AVAILABILITY PREFLIGHT │
│ Check search channels before relying on │
│ them; report skipped channels honestly │
├─────────────────────────────────────────────┤
│ 1. NEED ANALYSIS │
│ Define what functionality is needed │
│ Identify language/framework constraints │
├─────────────────────────────────────────────┤
│ 2. PARALLEL SEARCH (researcher agent) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ npm / │ │ MCP / │ │ GitHub / │ │
│ │ PyPI │ │ Skills │ │ Web │ │
│ └──────────┘ └──────────┘ └──────────┘ │
├─────────────────────────────────────────────┤
│ 3. EVALUATE │
│ Score candidates (functionality, maint, │
│ community, docs, license, deps) │
├─────────────────────────────────────────────┤
│ 4. DECIDE │
│ ┌─────────┐ ┌──────────┐ ┌─────────┐ │
│ │ Adopt │ │ Extend │ │ Build │ │
│ │ as-is │ │ /Wrap │ │ Custom │ │
│ └─────────┘ └──────────┘ └─────────┘ │
├─────────────────────────────────────────────┤
│ 5. IMPLEMENT │
│ Install package / Configure MCP / │
│ Write minimal custom code │
└─────────────────────────────────────────────┘
決策矩陣
| 訊號 | 行動 |
|---|---|
| 完全符合、維護良好、MIT/Apache 授權 | 採用 — 直接安裝並使用 |
| 部分符合,基礎良好 | 擴展 — 安裝 + 撰寫輕量級封裝程式 |
| 多個弱匹配 | 組合 — 整合 2 至 3 個小型套件 |
| 未找到合適的選項 | 建構 — 編寫自訂解決方案,但需以研究為依據 |
使用方法
步驟 0:工具可用性預檢
此為代理程式指引,並非可執行的設定腳本。請僅檢查 與您當前任務及專案相關的管道。
| 通道 | 檢查 | 若缺失 |
|---|---|---|
| 儲存庫搜尋 | rg --files 及目標 rg 查詢 |
說明僅檢查了可見的檔案 |
| 套件註冊表 | npm --version, python -m pip --version,或專案套件管理員 |
使用 web/docs 搜尋功能,並避免聲稱涵蓋註冊表 |
| GitHub CLI | gh auth status |
僅使用公開的 Web 或本機 Git 歷史紀錄 |
| MCP/文件工具 | 可用工具清單或本機 MCP 設定 | 回退至官方文件/網頁搜尋 |
| 技能目錄 | ls ~/.claude/skills ~/.codex/skills (如適用) |
假設沒有可用的本地技能目錄 |
快速模式(內嵌)
在撰寫實用程式或新增功能之前,請先在腦中思考:
- 這在儲存庫中是否已經存在? →
rg先瀏覽相關模組/測試 - 這是常見的問題嗎?→ 搜尋 npm/PyPI
- 是否有對應的 MCP?→ 查閱
~/.claude/settings.json並搜尋 - 是否有相關技能?→ 確認
~/.claude/skills/ - 是否有 GitHub 實作範例或範本? → 在撰寫全新程式碼前,先透過 GitHub 程式碼搜尋功能尋找持續維護的開源軟體
完整模式(代理程式)
若需實現非平凡的功能,請啟動研究員代理程式:
Agent(subagent_type="general-purpose", prompt="
Research existing tools for: [DESCRIPTION]
Language/framework: [LANG]
Constraints: [ANY]
Search: npm/PyPI, MCP servers, Claude Code skills, GitHub
Return: Structured comparison with recommendation
")
較舊版的 Claude Code 文件可能會稱此為 Task(...);請使用當前由活躍框架所提供的
代理/子代理工具名稱。
依類別搜尋快捷方式
開發工具
- 程式碼檢查 →
eslint,ruff,textlint,markdownlint - 格式化 →
prettier,black,gofmt - 測試 →
jest,pytest,go test - 提交前檢查 →
husky,lint-staged,pre-commit
AI/LLM 整合
- Claude SDK → 請參閱 Context7 獲取最新文件
- 提示詞管理 → 檢查 MCP 伺服器
- 文件處理 →
unstructured,pdfplumber,mammoth
資料與 API
- HTTP 客戶端 →
httpx(Python),ky/undici(Node) - 驗證 →
zod(TS),pydantic(Python) - 資料庫 → 首先檢查 MCP 伺服器
內容與發佈
- Markdown 處理 →
remark,unified,markdown-it - 圖片優化 →
sharp,imagemin
整合點
搭配規劃器代理程式
規劃者應在第 1 階段(架構審查)之前呼叫研究員:
- 研究員識別可用的工具
- 規劃者將其納入實施計畫
- 避免在計畫中「重造輪子」
搭配架構師代理
架構師應就以下事項諮詢研究員:
- 技術堆疊的決策
- 整合模式的探索
- 現有參考架構
運用迭代檢索技巧
結合以上要素以進行漸進式探索:
- 週期 1:廣泛搜尋(npm、PyPI、MCP)
- 週期 2:詳細評估頂尖候選方案
- 循環 3:測試與專案限制條件的相容性
範例
範例 1:「新增失效連結檢查」
Need: Check markdown files for broken links
Search: npm "markdown dead link checker"
Found: textlint-rule-no-dead-link (score: 9/10)
Action: ADOPT — npm install textlint-rule-no-dead-link
Result: Zero custom code, battle-tested solution
範例 2:「新增 HTTP 客戶端封裝函式」
Need: Resilient HTTP client with retries and timeout handling
Search: npm "http client retry", PyPI "httpx retry"
Found: got (Node) with retry plugin, httpx (Python) with built-in retry
Action: ADOPT — use got/httpx directly with retry config
Result: Zero custom code, production-proven libraries
範例 3:「新增設定檔語法檢查工具」
Need: Validate project config files against a schema
Search: npm "config linter schema", "json schema validator cli"
Found: ajv-cli (score: 8/10)
Action: ADOPT + EXTEND — install ajv-cli, write project-specific schema
Result: 1 package + 1 schema file, no custom validation logic
反模式
- 直接跳到程式碼:在未確認是否已有現成工具的情況下撰寫工具程式
- 忽略 MCP:未檢查 MCP 伺服器是否已提供該功能
- 靜默跳過:當搜尋通道不可用時,卻回報「未找到任何結果」
- 過度客製化:對函式庫進行過度封裝,以致喪失其優勢
- 依賴項膨脹:為了單一的小功能而安裝龐大的套件
---
name: search-first
description: Research existing tools, libraries, and patterns before writing custom code by invoking a researcher agent.
---
# /search-first — Research Before You Code
Systematizes the "search for existing solutions before implementing" workflow.
## Trigger
Use this skill when:
- Starting a new feature that likely has existing solutions
- Adding a dependency or integration
- The user asks "add X functionality" and you're about to write code
- Before creating a new utility, helper, or abstraction
## Workflow
```
┌─────────────────────────────────────────────┐
│ 0. TOOL AVAILABILITY PREFLIGHT │
│ Check search channels before relying on │
│ them; report skipped channels honestly │
├─────────────────────────────────────────────┤
│ 1. NEED ANALYSIS │
│ Define what functionality is needed │
│ Identify language/framework constraints │
├─────────────────────────────────────────────┤
│ 2. PARALLEL SEARCH (researcher agent) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ npm / │ │ MCP / │ │ GitHub / │ │
│ │ PyPI │ │ Skills │ │ Web │ │
│ └──────────┘ └──────────┘ └──────────┘ │
├─────────────────────────────────────────────┤
│ 3. EVALUATE │
│ Score candidates (functionality, maint, │
│ community, docs, license, deps) │
├─────────────────────────────────────────────┤
│ 4. DECIDE │
│ ┌─────────┐ ┌──────────┐ ┌─────────┐ │
│ │ Adopt │ │ Extend │ │ Build │ │
│ │ as-is │ │ /Wrap │ │ Custom │ │
│ └─────────┘ └──────────┘ └─────────┘ │
├─────────────────────────────────────────────┤
│ 5. IMPLEMENT │
│ Install package / Configure MCP / │
│ Write minimal custom code │
└─────────────────────────────────────────────┘
```
## Decision Matrix
| Signal | Action |
|--------|--------|
| Exact match, well-maintained, MIT/Apache | **Adopt** — install and use directly |
| Partial match, good foundation | **Extend** — install + write thin wrapper |
| Multiple weak matches | **Compose** — combine 2-3 small packages |
| Nothing suitable found | **Build** — write custom, but informed by research |
## How to Use
### Step 0: Tool Availability Preflight
This is agent guidance, not an executable setup script. Check only the channels
that are relevant to the task and project in front of you.
| Channel | Check | If missing |
|---------|-------|------------|
| Repository search | `rg --files` and targeted `rg` queries | State that only visible files were inspected |
| Package registry | `npm --version`, `python -m pip --version`, or project package manager | Use web/docs search and avoid claiming registry coverage |
| GitHub CLI | `gh auth status` | Use public web or local git history only |
| MCP/docs tools | Available tool list or local MCP config | Fall back to official docs/web search |
| Skills directory | `ls ~/.claude/skills ~/.codex/skills` where applicable | Say no local skill catalog was available |
### Quick Mode (inline)
Before writing a utility or adding functionality, mentally run through:
0. Does this already exist in the repo? → `rg` through relevant modules/tests first
1. Is this a common problem? → Search npm/PyPI
2. Is there an MCP for this? → Check `~/.claude/settings.json` and search
3. Is there a skill for this? → Check `~/.claude/skills/`
4. Is there a GitHub implementation/template? → Run GitHub code search for maintained OSS before writing net-new code
### Full Mode (agent)
For non-trivial functionality, launch the researcher agent:
```
Agent(subagent_type="general-purpose", prompt="
Research existing tools for: [DESCRIPTION]
Language/framework: [LANG]
Constraints: [ANY]
Search: npm/PyPI, MCP servers, Claude Code skills, GitHub
Return: Structured comparison with recommendation
")
```
Older Claude Code docs may call this `Task(...)`; use the current agent/subagent
tool name exposed by the active harness.
## Search Shortcuts by Category
### Development Tooling
- Linting → `eslint`, `ruff`, `textlint`, `markdownlint`
- Formatting → `prettier`, `black`, `gofmt`
- Testing → `jest`, `pytest`, `go test`
- Pre-commit → `husky`, `lint-staged`, `pre-commit`
### AI/LLM Integration
- Claude SDK → Context7 for latest docs
- Prompt management → Check MCP servers
- Document processing → `unstructured`, `pdfplumber`, `mammoth`
### Data & APIs
- HTTP clients → `httpx` (Python), `ky`/`undici` (Node)
- Validation → `zod` (TS), `pydantic` (Python)
- Database → Check for MCP servers first
### Content & Publishing
- Markdown processing → `remark`, `unified`, `markdown-it`
- Image optimization → `sharp`, `imagemin`
## Integration Points
### With planner agent
The planner should invoke researcher before Phase 1 (Architecture Review):
- Researcher identifies available tools
- Planner incorporates them into the implementation plan
- Avoids "reinventing the wheel" in the plan
### With architect agent
The architect should consult researcher for:
- Technology stack decisions
- Integration pattern discovery
- Existing reference architectures
### With iterative-retrieval skill
Combine for progressive discovery:
- Cycle 1: Broad search (npm, PyPI, MCP)
- Cycle 2: Evaluate top candidates in detail
- Cycle 3: Test compatibility with project constraints
## Examples
### Example 1: "Add dead link checking"
```
Need: Check markdown files for broken links
Search: npm "markdown dead link checker"
Found: textlint-rule-no-dead-link (score: 9/10)
Action: ADOPT — npm install textlint-rule-no-dead-link
Result: Zero custom code, battle-tested solution
```
### Example 2: "Add HTTP client wrapper"
```
Need: Resilient HTTP client with retries and timeout handling
Search: npm "http client retry", PyPI "httpx retry"
Found: got (Node) with retry plugin, httpx (Python) with built-in retry
Action: ADOPT — use got/httpx directly with retry config
Result: Zero custom code, production-proven libraries
```
### Example 3: "Add config file linter"
```
Need: Validate project config files against a schema
Search: npm "config linter schema", "json schema validator cli"
Found: ajv-cli (score: 8/10)
Action: ADOPT + EXTEND — install ajv-cli, write project-specific schema
Result: 1 package + 1 schema file, no custom validation logic
```
## Anti-Patterns
- **Jumping to code**: Writing a utility without checking if one exists
- **Ignoring MCP**: Not checking if an MCP server already provides the capability
- **Silent skipping**: Reporting "nothing found" when a search channel was unavailable
- **Over-customizing**: Wrapping a library so heavily it loses its benefits
- **Dependency bloat**: Installing a massive package for one small feature
所有檔案
1 個檔案安裝 search-first
請下載並將技能檔案解壓縮至您的 .claude/skills/ 目錄中。
下載 ZIP複製儲存庫並將技能檔案複製到您的專案中。
git clone https://github.com/affaan-m/ECC/tree/main/skills/search-first # Copy SKILL.md to your .claude/skills/ directory
複製





首頁
