workspace/skills/clawsec/.clawhub/origin.json
New file @@ -0,0 +1,7 @@ { "version": 1, "registry": "https://clawhub.ai", "slug": "clawsec", "installedVersion": "1.0.0", "installedAt": 1773289622474 } workspace/skills/clawsec/_meta.json
New file @@ -0,0 +1,6 @@ { "ownerId": "kn7d8wr58n2zdc0fdyns416kbh81ff7d", "slug": "clawsec", "version": "1.0.0", "publishedAt": 1771512345942 } workspace/skills/clawsec/skill.md
New file @@ -0,0 +1,197 @@ # clawsec You are now acting as the ClawSec Monitor assistant. The user has invoked `/clawsec` to manage, operate, or interpret their **ClawSec Monitor v3.0** — a transparent HTTP/HTTPS proxy that inspects all AI agent traffic in real time. --- ## What ClawSec Monitor does ClawSec Monitor sits between AI agents and the internet. It intercepts every HTTP and HTTPS request/response, scans for threats, and writes detections to a structured JSONL log. **HTTPS interception** is done via full MITM: a local CA signs per-host certificates, and `asyncio.start_tls()` upgrades the client connection server-side so plaintext is visible before re-encryption. **Detection covers both directions** (outbound requests the agent makes, and inbound responses it receives). --- ## Detection patterns ### EXFIL patterns | Pattern name | What it matches | |---|---| | `ai_api_key` | `sk-ant-*`, `sk-live-*`, `sk-gpt-*`, `sk-pro-*` | | `aws_access_key` | `AKIA*`, `ASIA*` (AWS access key IDs) | | `private_key_pem` | `-----BEGIN RSA/OPENSSH/EC/DSA PRIVATE KEY-----` | | `ssh_key_file` | `.ssh/id_rsa`, `.ssh/id_ed25519`, `.ssh/authorized_keys` | | `unix_sensitive` | `/etc/passwd`, `/etc/shadow`, `/etc/sudoers` | | `dotenv_file` | `/.env`, `/.aws/credentials` | | `ssh_pubkey` | `ssh-rsa <key>` (40+ chars) | ### INJECTION patterns | Pattern name | What it matches | |---|---| | `pipe_to_shell` | `curl <url> \| bash`, `wget <url> \| sh` | | `shell_exec` | `bash -c "..."`, `sh -i "..."` | | `reverse_shell` | `nc <host> <port>` / `netcat` / `ncat` | | `destructive_rm` | `rm -rf /` | | `ssh_key_inject` | `echo ssh-rsa` (SSH key injection attempt) | --- ## All commands ```bash # Start the proxy (runs in foreground, Ctrl-C or SIGTERM to stop) python3 clawsec-monitor.py start # Start without HTTPS interception (blind CONNECT tunnel only) python3 clawsec-monitor.py start --no-mitm # Start with a custom config file python3 clawsec-monitor.py start --config /path/to/config.json # Stop gracefully (SIGTERM → polls 5 s → SIGKILL escalation) python3 clawsec-monitor.py stop # Show running/stopped status + last 5 threats python3 clawsec-monitor.py status # Dump last 10 threats as JSON python3 clawsec-monitor.py threats # Dump last N threats python3 clawsec-monitor.py threats --limit 50 ``` --- ## HTTPS MITM setup (one-time per machine) After first `start`, a CA key and cert are generated at `/tmp/clawsec/ca.crt`. ```bash # macOS sudo security add-trusted-cert -d -r trustRoot \ -k /Library/Keychains/System.keychain /tmp/clawsec/ca.crt # Ubuntu / Debian sudo cp /tmp/clawsec/ca.crt /usr/local/share/ca-certificates/clawsec.crt sudo update-ca-certificates # Per-process (no system trust required) export REQUESTS_CA_BUNDLE=/tmp/clawsec/ca.crt # Python requests export SSL_CERT_FILE=/tmp/clawsec/ca.crt # httpx export NODE_EXTRA_CA_CERTS=/tmp/clawsec/ca.crt # Node.js export CURL_CA_BUNDLE=/tmp/clawsec/ca.crt # curl ``` Then route agent traffic through the proxy: ```bash export HTTP_PROXY=http://127.0.0.1:8888 export HTTPS_PROXY=http://127.0.0.1:8888 ``` --- ## Config file reference ```json { "proxy_host": "127.0.0.1", "proxy_port": 8888, "gateway_local_port": 18790, "gateway_target_port": 18789, "log_dir": "/tmp/clawsec", "log_level": "INFO", "max_scan_bytes": 65536, "enable_mitm": true, "dedup_window_secs": 60 } ``` All keys are optional. Defaults are shown above. --- ## Threat log format Threats are appended to `/tmp/clawsec/threats.jsonl` (one JSON object per line): ```json { "direction": "outbound", "protocol": "https", "threat_type": "EXFIL", "pattern": "ai_api_key", "snippet": "Authorization: Bearer sk-ant-api01-...", "source": "127.0.0.1", "dest": "api.anthropic.com:443", "timestamp": "2026-02-19T13:41:59.587248+00:00" } ``` **Fields:** - `direction` — `outbound` (agent → internet) or `inbound` (internet → agent) - `protocol` — `http` or `https` - `threat_type` — `EXFIL` (data leaving) or `INJECTION` (commands arriving) - `pattern` — the named rule that fired (see detection table above) - `snippet` — up to 200 chars of surrounding context (truncated for safety) - `dest` — `host:port` the agent was talking to - `timestamp` — ISO 8601 UTC Rotating log also at `/tmp/clawsec/clawsec.log` (10 MB × 3 backups). Deduplication: same `(pattern, dest, direction)` suppressed for 60 seconds. --- ## Docker ```bash # Start docker compose -f docker-compose.clawsec.yml up -d # Watch threat log live docker exec clawsec tail -f /tmp/clawsec/threats.jsonl # Query threats docker exec clawsec python3 clawsec-monitor.py threats # Stop docker compose -f docker-compose.clawsec.yml down ``` CA persists in the `clawsec_data` Docker volume across restarts. --- ## Files | File | Purpose | |---|---| | `clawsec-monitor.py` | Main script (876 lines) | | `run_tests.py` | 28-test regression suite | | `Dockerfile.clawsec` | Python 3.12-slim image | | `docker-compose.clawsec.yml` | One-command deploy + healthcheck | | `requirements.clawsec.txt` | `cryptography>=42.0.0` | --- ## How to help the user When `/clawsec` is invoked, determine what the user needs and assist accordingly: 1. **Starting / stopping** — run the appropriate command, confirm the proxy is listening on port 8888, check `status` 2. **Interpreting threats** — run `python3 clawsec-monitor.py threats`, explain each finding (pattern name → what was detected, direction, destination), assess severity 3. **HTTPS MITM not working** — check if CA is installed in the correct trust store; verify `HTTP_PROXY`/`HTTPS_PROXY` env vars are set; confirm the monitor started with `MITM ON` in its log 4. **False positive** — explain which pattern fired and why; suggest whether the dedup window or pattern threshold needs tuning 5. **Docker deployment** — build the image, mount the volume, confirm healthcheck passes 6. **Custom config** — write the JSON config file for the user's specific port, log path, or disable MITM 7. **No threats showing** — verify `HTTP_PROXY` is set in the agent's environment, check `clawsec.log` for errors, confirm `threats.jsonl` exists Always check `python3 clawsec-monitor.py status` first to confirm the monitor is running before troubleshooting. --- *ClawSec Monitor v3.0 — See what your AI agents are really doing.* *GitHub: https://github.com/chrisochrisochriso-cmyk/clawsec-monitor* workspace/skills/find-skills/.clawhub/origin.json
New file @@ -0,0 +1,7 @@ { "version": 1, "registry": "https://clawhub.ai", "slug": "find-skills", "installedVersion": "0.1.0", "installedAt": 1773309832177 } workspace/skills/find-skills/SKILL.md
New file @@ -0,0 +1,133 @@ --- name: find-skills description: Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill. --- # Find Skills This skill helps you discover and install skills from the open agent skills ecosystem. ## When to Use This Skill Use this skill when the user: - Asks "how do I do X" where X might be a common task with an existing skill - Says "find a skill for X" or "is there a skill for X" - Asks "can you do X" where X is a specialized capability - Expresses interest in extending agent capabilities - Wants to search for tools, templates, or workflows - Mentions they wish they had help with a specific domain (design, testing, deployment, etc.) ## What is the Skills CLI? The Skills CLI (`npx skills`) is the package manager for the open agent skills ecosystem. Skills are modular packages that extend agent capabilities with specialized knowledge, workflows, and tools. **Key commands:** - `npx skills find [query]` - Search for skills interactively or by keyword - `npx skills add <package>` - Install a skill from GitHub or other sources - `npx skills check` - Check for skill updates - `npx skills update` - Update all installed skills **Browse skills at:** https://skills.sh/ ## How to Help Users Find Skills ### Step 1: Understand What They Need When a user asks for help with something, identify: 1. The domain (e.g., React, testing, design, deployment) 2. The specific task (e.g., writing tests, creating animations, reviewing PRs) 3. Whether this is a common enough task that a skill likely exists ### Step 2: Search for Skills Run the find command with a relevant query: ```bash npx skills find [query] ``` For example: - User asks "how do I make my React app faster?" → `npx skills find react performance` - User asks "can you help me with PR reviews?" → `npx skills find pr review` - User asks "I need to create a changelog" → `npx skills find changelog` The command will return results like: ``` Install with npx skills add <owner/repo@skill> vercel-labs/agent-skills@vercel-react-best-practices └ https://skills.sh/vercel-labs/agent-skills/vercel-react-best-practices ``` ### Step 3: Present Options to the User When you find relevant skills, present them to the user with: 1. The skill name and what it does 2. The install command they can run 3. A link to learn more at skills.sh Example response: ``` I found a skill that might help! The "vercel-react-best-practices" skill provides React and Next.js performance optimization guidelines from Vercel Engineering. To install it: npx skills add vercel-labs/agent-skills@vercel-react-best-practices Learn more: https://skills.sh/vercel-labs/agent-skills/vercel-react-best-practices ``` ### Step 4: Offer to Install If the user wants to proceed, you can install the skill for them: ```bash npx skills add <owner/repo@skill> -g -y ``` The `-g` flag installs globally (user-level) and `-y` skips confirmation prompts. ## Common Skill Categories When searching, consider these common categories: | Category | Example Queries | | --------------- | ---------------------------------------- | | Web Development | react, nextjs, typescript, css, tailwind | | Testing | testing, jest, playwright, e2e | | DevOps | deploy, docker, kubernetes, ci-cd | | Documentation | docs, readme, changelog, api-docs | | Code Quality | review, lint, refactor, best-practices | | Design | ui, ux, design-system, accessibility | | Productivity | workflow, automation, git | ## Tips for Effective Searches 1. **Use specific keywords**: "react testing" is better than just "testing" 2. **Try alternative terms**: If "deploy" doesn't work, try "deployment" or "ci-cd" 3. **Check popular sources**: Many skills come from `vercel-labs/agent-skills` or `ComposioHQ/awesome-claude-skills` ## When No Skills Are Found If no relevant skills exist: 1. Acknowledge that no existing skill was found 2. Offer to help with the task directly using your general capabilities 3. Suggest the user could create their own skill with `npx skills init` Example: ``` I searched for skills related to "xyz" but didn't find any matches. I can still help you with this task directly! Would you like me to proceed? If this is something you do often, you could create your own skill: npx skills init my-xyz-skill ``` workspace/skills/find-skills/_meta.json
New file @@ -0,0 +1,6 @@ { "ownerId": "kn77ajmmqw3cgnc3ay1x3e0ccd805hsw", "slug": "find-skills", "version": "0.1.0", "publishedAt": 1769698710765 } workspace/skills/multi-search-engine/.clawhub/origin.json
New file @@ -0,0 +1,7 @@ { "version": 1, "registry": "https://clawhub.ai", "slug": "multi-search-engine", "installedVersion": "2.0.1", "installedAt": 1773289670176 } workspace/skills/multi-search-engine/CHANGELOG.md
New file @@ -0,0 +1,15 @@ # Changelog ## v2.0.1 (2026-02-06) - Simplified documentation - Removed gov-related content - Optimized for ClawHub publishing ## v2.0.0 (2026-02-06) - Added 9 international search engines - Enhanced advanced search capabilities - Added DuckDuckGo Bangs support - Added WolframAlpha knowledge queries ## v1.0.0 (2026-02-04) - Initial release with 8 domestic search engines workspace/skills/multi-search-engine/CHANNELLOG.md
New file @@ -0,0 +1,48 @@ # Multi Search Engine ## 基本信息 - **名称**: multi-search-engine - **版本**: v2.0.1 - **描述**: 集成17个搜索引擎(8国内+9国际),支持高级搜索语法 - **发布时间**: 2026-02-06 ## 搜索引擎 **国内(8个)**: 百度、必应、360、搜狗、微信、头条、集思录 **国际(9个)**: Google、DuckDuckGo、Yahoo、Brave、Startpage、Ecosia、Qwant、WolframAlpha ## 核心功能 - 高级搜索操作符(site:, filetype:, intitle:等) - DuckDuckGo Bangs快捷命令 - 时间筛选(小时/天/周/月/年) - 隐私保护搜索 - WolframAlpha知识计算 ## 更新记录 ### v2.0.1 (2026-02-06) - 精简文档,优化发布 ### v2.0.0 (2026-02-06) - 新增9个国际搜索引擎 - 强化深度搜索能力 ### v1.0.0 (2026-02-04) - 初始版本:8个国内搜索引擎 ## 使用示例 ```javascript // Google搜索 web_fetch({"url": "https://www.google.com/search?q=python"}) // 隐私搜索 web_fetch({"url": "https://duckduckgo.com/html/?q=privacy"}) // 站内搜索 web_fetch({"url": "https://www.google.com/search?q=site:github.com+python"}) ``` MIT License workspace/skills/multi-search-engine/SKILL.md
New file @@ -0,0 +1,110 @@ --- name: "multi-search-engine" description: "Multi search engine integration with 17 engines (8 CN + 9 Global). Supports advanced search operators, time filters, site search, privacy engines, and WolframAlpha knowledge queries. No API keys required." --- # Multi Search Engine v2.0.1 Integration of 17 search engines for web crawling without API keys. ## Search Engines ### Domestic (8) - **Baidu**: `https://www.baidu.com/s?wd={keyword}` - **Bing CN**: `https://cn.bing.com/search?q={keyword}&ensearch=0` - **Bing INT**: `https://cn.bing.com/search?q={keyword}&ensearch=1` - **360**: `https://www.so.com/s?q={keyword}` - **Sogou**: `https://sogou.com/web?query={keyword}` - **WeChat**: `https://wx.sogou.com/weixin?type=2&query={keyword}` - **Toutiao**: `https://so.toutiao.com/search?keyword={keyword}` - **Jisilu**: `https://www.jisilu.cn/explore/?keyword={keyword}` ### International (9) - **Google**: `https://www.google.com/search?q={keyword}` - **Google HK**: `https://www.google.com.hk/search?q={keyword}` - **DuckDuckGo**: `https://duckduckgo.com/html/?q={keyword}` - **Yahoo**: `https://search.yahoo.com/search?p={keyword}` - **Startpage**: `https://www.startpage.com/sp/search?query={keyword}` - **Brave**: `https://search.brave.com/search?q={keyword}` - **Ecosia**: `https://www.ecosia.org/search?q={keyword}` - **Qwant**: `https://www.qwant.com/?q={keyword}` - **WolframAlpha**: `https://www.wolframalpha.com/input?i={keyword}` ## Quick Examples ```javascript // Basic search web_fetch({"url": "https://www.google.com/search?q=python+tutorial"}) // Site-specific web_fetch({"url": "https://www.google.com/search?q=site:github.com+react"}) // File type web_fetch({"url": "https://www.google.com/search?q=machine+learning+filetype:pdf"}) // Time filter (past week) web_fetch({"url": "https://www.google.com/search?q=ai+news&tbs=qdr:w"}) // Privacy search web_fetch({"url": "https://duckduckgo.com/html/?q=privacy+tools"}) // DuckDuckGo Bangs web_fetch({"url": "https://duckduckgo.com/html/?q=!gh+tensorflow"}) // Knowledge calculation web_fetch({"url": "https://www.wolframalpha.com/input?i=100+USD+to+CNY"}) ``` ## Advanced Operators | Operator | Example | Description | |----------|---------|-------------| | `site:` | `site:github.com python` | Search within site | | `filetype:` | `filetype:pdf report` | Specific file type | | `""` | `"machine learning"` | Exact match | | `-` | `python -snake` | Exclude term | | `OR` | `cat OR dog` | Either term | ## Time Filters | Parameter | Description | |-----------|-------------| | `tbs=qdr:h` | Past hour | | `tbs=qdr:d` | Past day | | `tbs=qdr:w` | Past week | | `tbs=qdr:m` | Past month | | `tbs=qdr:y` | Past year | ## Privacy Engines - **DuckDuckGo**: No tracking - **Startpage**: Google results + privacy - **Brave**: Independent index - **Qwant**: EU GDPR compliant ## Bangs Shortcuts (DuckDuckGo) | Bang | Destination | |------|-------------| | `!g` | Google | | `!gh` | GitHub | | `!so` | Stack Overflow | | `!w` | Wikipedia | | `!yt` | YouTube | ## WolframAlpha Queries - Math: `integrate x^2 dx` - Conversion: `100 USD to CNY` - Stocks: `AAPL stock` - Weather: `weather in Beijing` ## Documentation - `references/advanced-search.md` - Domestic search guide - `references/international-search.md` - International search guide - `CHANGELOG.md` - Version history ## License MIT workspace/skills/multi-search-engine/_meta.json
New file @@ -0,0 +1,6 @@ { "ownerId": "kn79j8kk7fb9w10jh83803j7f180a44m", "slug": "multi-search-engine", "version": "2.0.1", "publishedAt": 1770313848158 } workspace/skills/multi-search-engine/config.json
New file @@ -0,0 +1,22 @@ { "name": "multi-search-engine", "engines": [ {"name": "Baidu", "url": "https://www.baidu.com/s?wd={keyword}", "region": "cn"}, {"name": "Bing CN", "url": "https://cn.bing.com/search?q={keyword}&ensearch=0", "region": "cn"}, {"name": "Bing INT", "url": "https://cn.bing.com/search?q={keyword}&ensearch=1", "region": "cn"}, {"name": "360", "url": "https://www.so.com/s?q={keyword}", "region": "cn"}, {"name": "Sogou", "url": "https://sogou.com/web?query={keyword}", "region": "cn"}, {"name": "WeChat", "url": "https://wx.sogou.com/weixin?type=2&query={keyword}", "region": "cn"}, {"name": "Toutiao", "url": "https://so.toutiao.com/search?keyword={keyword}", "region": "cn"}, {"name": "Jisilu", "url": "https://www.jisilu.cn/explore/?keyword={keyword}", "region": "cn"}, {"name": "Google", "url": "https://www.google.com/search?q={keyword}", "region": "global"}, {"name": "Google HK", "url": "https://www.google.com.hk/search?q={keyword}", "region": "global"}, {"name": "DuckDuckGo", "url": "https://duckduckgo.com/html/?q={keyword}", "region": "global"}, {"name": "Yahoo", "url": "https://search.yahoo.com/search?p={keyword}", "region": "global"}, {"name": "Startpage", "url": "https://www.startpage.com/sp/search?query={keyword}", "region": "global"}, {"name": "Brave", "url": "https://search.brave.com/search?q={keyword}", "region": "global"}, {"name": "Ecosia", "url": "https://www.ecosia.org/search?q={keyword}", "region": "global"}, {"name": "Qwant", "url": "https://www.qwant.com/?q={keyword}", "region": "global"}, {"name": "WolframAlpha", "url": "https://www.wolframalpha.com/input?i={keyword}", "region": "global"} ] } workspace/skills/multi-search-engine/metadata.json
New file @@ -0,0 +1,7 @@ { "name": "multi-search-engine", "version": "2.0.1", "description": "Multi search engine with 17 engines (8 CN + 9 Global). Supports advanced operators, time filters, privacy engines.", "engines": 17, "requires_api_key": false } workspace/skills/multi-search-engine/references/international-search.md
New file @@ -0,0 +1,651 @@ # 国际搜索引擎深度搜索指南 ## 🔍 Google 深度搜索 ### 1.1 基础高级搜索操作符 | 操作符 | 功能 | 示例 | URL | |--------|------|------|-----| | `""` | 精确匹配 | `"machine learning"` | `https://www.google.com/search?q=%22machine+learning%22` | | `-` | 排除关键词 | `python -snake` | `https://www.google.com/search?q=python+-snake` | | `OR` | 或运算 | `machine learning OR deep learning` | `https://www.google.com/search?q=machine+learning+OR+deep+learning` | | `*` | 通配符 | `machine * algorithms` | `https://www.google.com/search?q=machine+*+algorithms` | | `()` | 分组 | `(apple OR microsoft) phones` | `https://www.google.com/search?q=(apple+OR+microsoft)+phones` | | `..` | 数字范围 | `laptop $500..$1000` | `https://www.google.com/search?q=laptop+%24500..%241000` | ### 1.2 站点与文件搜索 | 操作符 | 功能 | 示例 | |--------|------|------| | `site:` | 站内搜索 | `site:github.com python projects` | | `filetype:` | 文件类型 | `filetype:pdf annual report` | | `inurl:` | URL包含 | `inurl:login admin` | | `intitle:` | 标题包含 | `intitle:"index of" mp3` | | `intext:` | 正文包含 | `intext:password filetype:txt` | | `cache:` | 查看缓存 | `cache:example.com` | | `related:` | 相关网站 | `related:github.com` | | `info:` | 网站信息 | `info:example.com` | ### 1.3 时间筛选参数 | 参数 | 含义 | URL示例 | |------|------|---------| | `tbs=qdr:h` | 过去1小时 | `https://www.google.com/search?q=news&tbs=qdr:h` | | `tbs=qdr:d` | 过去24小时 | `https://www.google.com/search?q=news&tbs=qdr:d` | | `tbs=qdr:w` | 过去1周 | `https://www.google.com/search?q=news&tbs=qdr:w` | | `tbs=qdr:m` | 过去1月 | `https://www.google.com/search?q=news&tbs=qdr:m` | | `tbs=qdr:y` | 过去1年 | `https://www.google.com/search?q=news&tbs=qdr:y` | | `tbs=cdr:1,cd_min:1/1/2024,cd_max:12/31/2024` | 自定义日期范围 | 2024年全年 | ### 1.4 语言和地区筛选 | 参数 | 功能 | 示例 | |------|------|------| | `hl=en` | 界面语言 | `https://www.google.com/search?q=test&hl=en` | | `lr=lang_zh-CN` | 搜索结果语言 | `https://www.google.com/search?q=test&lr=lang_zh-CN` | | `cr=countryCN` | 国家/地区 | `https://www.google.com/search?q=test&cr=countryCN` | | `gl=us` | 地理位置 | `https://www.google.com/search?q=test&gl=us` | ### 1.5 特殊搜索类型 | 类型 | URL | 说明 | |------|-----|------| | 图片搜索 | `https://www.google.com/search?q={keyword}&tbm=isch` | `tbm=isch` 表示图片 | | 新闻搜索 | `https://www.google.com/search?q={keyword}&tbm=nws` | `tbm=nws` 表示新闻 | | 视频搜索 | `https://www.google.com/search?q={keyword}&tbm=vid` | `tbm=vid` 表示视频 | | 地图搜索 | `https://www.google.com/search?q={keyword}&tbm=map` | `tbm=map` 表示地图 | | 购物搜索 | `https://www.google.com/search?q={keyword}&tbm=shop` | `tbm=shop` 表示购物 | | 图书搜索 | `https://www.google.com/search?q={keyword}&tbm=bks` | `tbm=bks` 表示图书 | | 学术搜索 | `https://scholar.google.com/scholar?q={keyword}` | Google Scholar | ### 1.6 Google 深度搜索示例 ```javascript // 1. 搜索GitHub上的Python机器学习项目 web_fetch({"url": "https://www.google.com/search?q=site:github.com+python+machine+learning"}) // 2. 搜索2024年的PDF格式机器学习教程 web_fetch({"url": "https://www.google.com/search?q=machine+learning+tutorial+filetype:pdf&tbs=cdr:1,cd_min:1/1/2024"}) // 3. 搜索标题包含"tutorial"的Python相关页面 web_fetch({"url": "https://www.google.com/search?q=intitle:tutorial+python"}) // 4. 搜索过去一周的新闻 web_fetch({"url": "https://www.google.com/search?q=AI+breakthrough&tbs=qdr:w&tbm=nws"}) // 5. 搜索中文内容(界面英文,结果中文) web_fetch({"url": "https://www.google.com/search?q=人工智能&lr=lang_zh-CN&hl=en"}) // 6. 搜索特定价格范围的笔记本电脑 web_fetch({"url": "https://www.google.com/search?q=laptop+%241000..%242000+best+rating"}) // 7. 搜索排除Wikipedia的结果 web_fetch({"url": "https://www.google.com/search?q=python+programming+-wikipedia"}) // 8. 搜索学术文献 web_fetch({"url": "https://scholar.google.com/scholar?q=deep+learning+optimization"}) // 9. 搜索缓存页面(查看已删除内容) web_fetch({"url": "https://webcache.googleusercontent.com/search?q=cache:example.com"}) // 10. 搜索相关网站 web_fetch({"url": "https://www.google.com/search?q=related:stackoverflow.com"}) ``` --- ## 🦆 DuckDuckGo 深度搜索 ### 2.1 DuckDuckGo 特色功能 | 功能 | 语法 | 示例 | |------|------|------| | **Bangs 快捷** | `!缩写` | `!g python` → Google搜索 | | **密码生成** | `password` | `https://duckduckgo.com/?q=password+20` | | **颜色转换** | `color` | `https://duckduckgo.com/?q=+%23FF5733` | | **短链接** | `shorten` | `https://duckduckgo.com/?q=shorten+example.com` | | **二维码生成** | `qr` | `https://duckduckgo.com/?q=qr+hello+world` | | **生成UUID** | `uuid` | `https://duckduckgo.com/?q=uuid` | | **Base64编解码** | `base64` | `https://duckduckgo.com/?q=base64+hello` | ### 2.2 DuckDuckGo Bangs 完整列表 #### 搜索引擎 | Bang | 跳转目标 | 示例 | |------|---------|------| | `!g` | Google | `!g python tutorial` | | `!b` | Bing | `!b weather` | | `!y` | Yahoo | `!y finance` | | `!sp` | Startpage | `!sp privacy` | | `!brave` | Brave Search | `!brave tech` | #### 编程开发 | Bang | 跳转目标 | 示例 | |------|---------|------| | `!gh` | GitHub | `!gh tensorflow` | | `!so` | Stack Overflow | `!so javascript error` | | `!npm` | npmjs.com | `!npm express` | | `!pypi` | PyPI | `!pypi requests` | | `!mdn` | MDN Web Docs | `!mdn fetch api` | | `!docs` | DevDocs | `!docs python` | | `!docker` | Docker Hub | `!docker nginx` | #### 知识百科 | Bang | 跳转目标 | 示例 | |------|---------|------| | `!w` | Wikipedia | `!w machine learning` | | `!wen` | Wikipedia英文 | `!wen artificial intelligence` | | `!wt` | Wiktionary | `!wt serendipity` | | `!imdb` | IMDb | `!imdb inception` | #### 购物价格 | Bang | 跳转目标 | 示例 | |------|---------|------| | `!a` | Amazon | `!a wireless headphones` | | `!e` | eBay | `!e vintage watch` | | `!ali` | AliExpress | `!ali phone case` | #### 地图位置 | Bang | 跳转目标 | 示例 | |------|---------|------| | `!m` | Google Maps | `!m Beijing` | | `!maps` | OpenStreetMap | `!maps Paris` | ### 2.3 DuckDuckGo 搜索参数 | 参数 | 功能 | 示例 | |------|------|------| | `kp=1` | 严格安全搜索 | `https://duckduckgo.com/html/?q=test&kp=1` | | `kp=-1` | 关闭安全搜索 | `https://duckduckgo.com/html/?q=test&kp=-1` | | `kl=cn` | 中国区域 | `https://duckduckgo.com/html/?q=news&kl=cn` | | `kl=us-en` | 美国英文 | `https://duckduckgo.com/html/?q=news&kl=us-en` | | `ia=web` | 网页结果 | `https://duckduckgo.com/?q=test&ia=web` | | `ia=images` | 图片结果 | `https://duckduckgo.com/?q=test&ia=images` | | `ia=news` | 新闻结果 | `https://duckduckgo.com/?q=test&ia=news` | | `ia=videos` | 视频结果 | `https://duckduckgo.com/?q=test&ia=videos` | ### 2.4 DuckDuckGo 深度搜索示例 ```javascript // 1. 使用Bang跳转到Google搜索 web_fetch({"url": "https://duckduckgo.com/html/?q=!g+machine+learning"}) // 2. 直接搜索GitHub上的项目 web_fetch({"url": "https://duckduckgo.com/html/?q=!gh+react"}) // 3. 查找Stack Overflow答案 web_fetch({"url": "https://duckduckgo.com/html/?q=!so+python+list+comprehension"}) // 4. 生成密码 web_fetch({"url": "https://duckduckgo.com/?q=password+16"}) // 5. Base64编码 web_fetch({"url": "https://duckduckgo.com/?q=base64+hello+world"}) // 6. 颜色代码转换 web_fetch({"url": "https://duckduckgo.com/?q=%23FF5733"}) // 7. 搜索YouTube视频 web_fetch({"url": "https://duckduckgo.com/html/?q=!yt+python+tutorial"}) // 8. 查看Wikipedia web_fetch({"url": "https://duckduckgo.com/html/?q=!w+artificial+intelligence"}) // 9. 亚马逊商品搜索 web_fetch({"url": "https://duckduckgo.com/html/?q=!a+laptop"}) // 10. 生成二维码 web_fetch({"url": "https://duckduckgo.com/?q=qr+https://github.com"}) ``` --- ## 🔎 Brave Search 深度搜索 ### 3.1 Brave Search 特色功能 | 功能 | 参数 | 示例 | |------|------|------| | **独立索引** | 无依赖Google/Bing | 自有爬虫索引 | | **Goggles** | 自定义搜索规则 | 创建个性化过滤器 | | **Discussions** | 论坛讨论搜索 | 聚合Reddit等论坛 | | **News** | 新闻聚合 | 独立新闻索引 | ### 3.2 Brave Search 参数 | 参数 | 功能 | 示例 | |------|------|------| | `tf=pw` | 本周 | `https://search.brave.com/search?q=news&tf=pw` | | `tf=pm` | 本月 | `https://search.brave.com/search?q=tech&tf=pm` | | `tf=py` | 本年 | `https://search.brave.com/search?q=AI&tf=py` | | `safesearch=strict` | 严格安全 | `https://search.brave.com/search?q=test&safesearch=strict` | | `source=web` | 网页搜索 | 默认 | | `source=news` | 新闻搜索 | `https://search.brave.com/search?q=tech&source=news` | | `source=images` | 图片搜索 | `https://search.brave.com/search?q=cat&source=images` | | `source=videos` | 视频搜索 | `https://search.brave.com/search?q=music&source=videos` | ### 3.3 Brave Search Goggles(自定义过滤器) Goggles 允许创建自定义搜索规则: ``` $discard // 丢弃所有 $boost,site=stackoverflow.com // 提升Stack Overflow $boost,site=github.com // 提升GitHub $boost,site=docs.python.org // 提升Python文档 ``` ### 3.4 Brave Search 深度搜索示例 ```javascript // 1. 本周科技新闻 web_fetch({"url": "https://search.brave.com/search?q=technology&tf=pw&source=news"}) // 2. 本月AI发展 web_fetch({"url": "https://search.brave.com/search?q=artificial+intelligence&tf=pm"}) // 3. 图片搜索 web_fetch({"url": "https://search.brave.com/search?q=machine+learning&source=images"}) // 4. 视频教程 web_fetch({"url": "https://search.brave.com/search?q=python+tutorial&source=videos"}) // 5. 使用独立索引搜索 web_fetch({"url": "https://search.brave.com/search?q=privacy+tools"}) ``` --- ## 📊 WolframAlpha 知识计算搜索 ### 4.1 WolframAlpha 数据类型 | 类型 | 查询示例 | URL | |------|---------|-----| | **数学计算** | `integrate x^2 dx` | `https://www.wolframalpha.com/input?i=integrate+x%5E2+dx` | | **单位换算** | `100 miles to km` | `https://www.wolframalpha.com/input?i=100+miles+to+km` | | **货币转换** | `100 USD to CNY` | `https://www.wolframalpha.com/input?i=100+USD+to+CNY` | | **股票数据** | `AAPL stock` | `https://www.wolframalpha.com/input?i=AAPL+stock` | | **天气查询** | `weather in Beijing` | `https://www.wolframalpha.com/input?i=weather+in+Beijing` | | **人口数据** | `population of China` | `https://www.wolframalpha.com/input?i=population+of+China` | | **化学元素** | `properties of gold` | `https://www.wolframalpha.com/input?i=properties+of+gold` | | **营养成分** | `nutrition of apple` | `https://www.wolframalpha.com/input?i=nutrition+of+apple` | | **日期计算** | `days between Jan 1 2020 and Dec 31 2024` | 日期间隔计算 | | **时区转换** | `10am Beijing to New York` | 时区转换 | | **IP地址** | `8.8.8.8` | IP信息查询 | | **条形码** | `scan barcode 123456789` | 条码信息 | | **飞机航班** | `flight AA123` | 航班信息 | ### 4.2 WolframAlpha 深度搜索示例 ```javascript // 1. 计算积分 web_fetch({"url": "https://www.wolframalpha.com/input?i=integrate+sin%28x%29+from+0+to+pi"}) // 2. 解方程 web_fetch({"url": "https://www.wolframalpha.com/input?i=solve+x%5E2-5x%2B6%3D0"}) // 3. 货币实时汇率 web_fetch({"url": "https://www.wolframalpha.com/input?i=100+USD+to+CNY"}) // 4. 股票实时数据 web_fetch({"url": "https://www.wolframalpha.com/input?i=Apple+stock+price"}) // 5. 城市天气 web_fetch({"url": "https://www.wolframalpha.com/input?i=weather+in+Shanghai+tomorrow"}) // 6. 国家统计信息 web_fetch({"url": "https://www.wolframalpha.com/input?i=GDP+of+China+vs+USA"}) // 7. 化学计算 web_fetch({"url": "https://www.wolframalpha.com/input?i=molar+mass+of+H2SO4"}) // 8. 物理常数 web_fetch({"url": "https://www.wolframalpha.com/input?i=speed+of+light"}) // 9. 营养信息 web_fetch({"url": "https://www.wolframalpha.com/input?i=calories+in+banana"}) // 10. 历史日期 web_fetch({"url": "https://www.wolframalpha.com/input?i=events+on+July+20+1969"}) ``` --- ## 🔧 Startpage 隐私搜索 ### 5.1 Startpage 特色功能 | 功能 | 说明 | URL | |------|------|-----| | **代理浏览** | 匿名访问搜索结果 | 点击"匿名查看" | | **无追踪** | 不记录搜索历史 | 默认开启 | | **EU服务器** | 受欧盟隐私法保护 | 数据在欧洲 | | **代理图片** | 图片代理加载 | 隐藏IP | ### 5.2 Startpage 参数 | 参数 | 功能 | 示例 | |------|------|------| | `cat=web` | 网页搜索 | 默认 | | `cat=images` | 图片搜索 | `...&cat=images` | | `cat=video` | 视频搜索 | `...&cat=video` | | `cat=news` | 新闻搜索 | `...&cat=news` | | `language=english` | 英文结果 | `...&language=english` | | `time=day` | 过去24小时 | `...&time=day` | | `time=week` | 过去一周 | `...&time=week` | | `time=month` | 过去一月 | `...&time=month` | | `time=year` | 过去一年 | `...&time=year` | | `nj=0` | 关闭 family filter | `...&nj=0` | ### 5.3 Startpage 深度搜索示例 ```javascript // 1. 隐私搜索 web_fetch({"url": "https://www.startpage.com/sp/search?query=privacy+tools"}) // 2. 图片隐私搜索 web_fetch({"url": "https://www.startpage.com/sp/search?query=nature&cat=images"}) // 3. 本周新闻(隐私模式) web_fetch({"url": "https://www.startpage.com/sp/search?query=tech+news&time=week&cat=news"}) // 4. 英文结果搜索 web_fetch({"url": "https://www.startpage.com/sp/search?query=machine+learning&language=english"}) ``` --- ## 🌍 综合搜索策略 ### 6.1 按搜索目标选择引擎 | 搜索目标 | 首选引擎 | 备选引擎 | 原因 | |---------|---------|---------|------| | **学术研究** | Google Scholar | Google, Brave | 学术资源索引 | | **编程开发** | Google | GitHub(DuckDuckGo bang) | 技术文档全面 | | **隐私敏感** | DuckDuckGo | Startpage, Brave | 不追踪用户 | | **实时新闻** | Brave News | Google News | 独立新闻索引 | | **知识计算** | WolframAlpha | Google | 结构化数据 | | **中文内容** | Google HK | Bing | 中文优化好 | | **欧洲视角** | Qwant | Startpage | 欧盟合规 | | **环保支持** | Ecosia | DuckDuckGo | 搜索植树 | | **无过滤** | Brave | Startpage | 无偏见结果 | ### 6.2 多引擎交叉验证 ```javascript // 策略:同一关键词多引擎搜索,对比结果 const keyword = "climate change 2024"; // 获取不同视角 const searches = [ { engine: "Google", url: `https://www.google.com/search?q=${keyword}&tbs=qdr:m` }, { engine: "Brave", url: `https://search.brave.com/search?q=${keyword}&tf=pm` }, { engine: "DuckDuckGo", url: `https://duckduckgo.com/html/?q=${keyword}` }, { engine: "Ecosia", url: `https://www.ecosia.org/search?q=${keyword}` } ]; // 分析不同引擎的结果差异 ``` ### 6.3 时间敏感搜索策略 | 时效性要求 | 引擎选择 | 参数设置 | |-----------|---------|---------| | **实时(小时级)** | Google News, Brave News | `tbs=qdr:h`, `tf=pw` | | **近期(天级)** | Google, Brave | `tbs=qdr:d`, `time=day` | | **本周** | 所有引擎 | `tbs=qdr:w`, `tf=pw` | | **本月** | 所有引擎 | `tbs=qdr:m`, `tf=pm` | | **历史** | Google Scholar | 学术档案 | ### 6.4 专业领域深度搜索 #### 技术开发 ```javascript // GitHub 项目搜索 web_fetch({"url": "https://duckduckgo.com/html/?q=!gh+tensorflow+stars:%3E1000"}) // Stack Overflow 问题 web_fetch({"url": "https://duckduckgo.com/html/?q=!so+python+memory+leak"}) // MDN 文档 web_fetch({"url": "https://duckduckgo.com/html/?q=!mdn+javascript+async+await"}) // PyPI 包 web_fetch({"url": "https://duckduckgo.com/html/?q=!pypi+requests"}) // npm 包 web_fetch({"url": "https://duckduckgo.com/html/?q=!npm+express"}) ``` #### 学术研究 ```javascript // Google Scholar 论文 web_fetch({"url": "https://scholar.google.com/scholar?q=deep+learning+2024"}) // 搜索PDF论文 web_fetch({"url": "https://www.google.com/search?q=machine+learning+filetype:pdf+2024"}) // arXiv 论文 web_fetch({"url": "https://duckduckgo.com/html/?q=site:arxiv.org+quantum+computing"}) ``` #### 金融投资 ```javascript // 股票实时数据 web_fetch({"url": "https://www.wolframalpha.com/input?i=AAPL+stock"}) // 汇率转换 web_fetch({"url": "https://www.wolframalpha.com/input?i=EUR+to+USD"}) // 搜索财报PDF web_fetch({"url": "https://www.google.com/search?q=Apple+Q4+2024+earnings+filetype:pdf"}) ``` #### 新闻时事 ```javascript // Google新闻 web_fetch({"url": "https://www.google.com/search?q=breaking+news&tbm=nws&tbs=qdr:h"}) // Brave新闻 web_fetch({"url": "https://search.brave.com/search?q=world+news&source=news"}) // DuckDuckGo新闻 web_fetch({"url": "https://duckduckgo.com/html/?q=tech+news&ia=news"}) ``` --- ## 🛠️ 高级搜索技巧汇总 ### URL编码工具函数 ```javascript // URL编码关键词 function encodeKeyword(keyword) { return encodeURIComponent(keyword); } // 示例 const keyword = "machine learning"; const encoded = encodeKeyword(keyword); // "machine%20learning" ``` ### 批量搜索模板 ```javascript // 多引擎批量搜索函数 function generateSearchUrls(keyword) { const encoded = encodeURIComponent(keyword); return { google: `https://www.google.com/search?q=${encoded}`, google_hk: `https://www.google.com.hk/search?q=${encoded}`, duckduckgo: `https://duckduckgo.com/html/?q=${encoded}`, brave: `https://search.brave.com/search?q=${encoded}`, startpage: `https://www.startpage.com/sp/search?query=${encoded}`, bing_intl: `https://cn.bing.com/search?q=${encoded}&ensearch=1`, yahoo: `https://search.yahoo.com/search?p=${encoded}`, ecosia: `https://www.ecosia.org/search?q=${encoded}`, qwant: `https://www.qwant.com/?q=${encoded}` }; } // 使用示例 const urls = generateSearchUrls("artificial intelligence"); ``` ### 时间筛选快捷函数 ```javascript // Google时间筛选URL生成 function googleTimeSearch(keyword, period) { const periods = { hour: 'qdr:h', day: 'qdr:d', week: 'qdr:w', month: 'qdr:m', year: 'qdr:y' }; return `https://www.google.com/search?q=${encodeURIComponent(keyword)}&tbs=${periods[period]}`; } // 使用示例 const recentNews = googleTimeSearch("AI breakthrough", "week"); ``` --- ## 📝 完整搜索示例集 ```javascript // ==================== 技术开发 ==================== // 1. 搜索GitHub上高Star的Python项目 web_fetch({"url": "https://www.google.com/search?q=site:github.com+python+stars:%3E1000"}) // 2. Stack Overflow最佳答案 web_fetch({"url": "https://duckduckgo.com/html/?q=!so+best+way+to+learn+python"}) // 3. MDN文档查询 web_fetch({"url": "https://duckduckgo.com/html/?q=!mdn+promises"}) // 4. 搜索npm包 web_fetch({"url": "https://duckduckgo.com/html/?q=!npm+axios"}) // ==================== 学术研究 ==================== // 5. Google Scholar论文 web_fetch({"url": "https://scholar.google.com/scholar?q=transformer+architecture"}) // 6. 搜索PDF论文 web_fetch({"url": "https://www.google.com/search?q=attention+is+all+you+need+filetype:pdf"}) // 7. arXiv最新论文 web_fetch({"url": "https://duckduckgo.com/html/?q=site:arxiv.org+abs+quantum"}) // ==================== 新闻时事 ==================== // 8. Google最新新闻(过去1小时) web_fetch({"url": "https://www.google.com/search?q=breaking+news&tbs=qdr:h&tbm=nws"}) // 9. Brave本周科技新闻 web_fetch({"url": "https://search.brave.com/search?q=technology&tf=pw&source=news"}) // 10. DuckDuckGo新闻 web_fetch({"url": "https://duckduckgo.com/html/?q=world+news&ia=news"}) // ==================== 金融投资 ==================== // 11. 股票实时数据 web_fetch({"url": "https://www.wolframalpha.com/input?i=Tesla+stock"}) // 12. 货币汇率 web_fetch({"url": "https://www.wolframalpha.com/input?i=1+BTC+to+USD"}) // 13. 公司财报PDF web_fetch({"url": "https://www.google.com/search?q=Microsoft+annual+report+2024+filetype:pdf"}) // ==================== 知识计算 ==================== // 14. 数学计算 web_fetch({"url": "https://www.wolframalpha.com/input?i=derivative+of+x%5E3+sin%28x%29"}) // 15. 单位换算 web_fetch({"url": "https://www.wolframalpha.com/input?i=convert+100+miles+to+kilometers"}) // 16. 营养信息 web_fetch({"url": "https://www.wolframalpha.com/input?i=protein+in+chicken+breast"}) // ==================== 隐私保护搜索 ==================== // 17. DuckDuckGo隐私搜索 web_fetch({"url": "https://duckduckgo.com/html/?q=privacy+tools"}) // 18. Startpage匿名搜索 web_fetch({"url": "https://www.startpage.com/sp/search?query=secure+messaging"}) // 19. Brave无追踪搜索 web_fetch({"url": "https://search.brave.com/search?q=encryption+software"}) // ==================== 高级组合搜索 ==================== // 20. Google多条件精确搜索 web_fetch({"url": "https://www.google.com/search?q=%22machine+learning%22+site:github.com+filetype:pdf+2024"}) // 21. 排除特定站点的搜索 web_fetch({"url": "https://www.google.com/search?q=python+tutorial+-wikipedia+-w3schools"}) // 22. 价格范围搜索 web_fetch({"url": "https://www.google.com/search?q=laptop+%24800..%241200+best+review"}) // 23. 使用Bangs快速跳转 web_fetch({"url": "https://duckduckgo.com/html/?q=!g+site:medium.com+python"}) // 24. 图片搜索(Google) web_fetch({"url": "https://www.google.com/search?q=beautiful+landscape&tbm=isch"}) // 25. 学术引用搜索 web_fetch({"url": "https://scholar.google.com/scholar?q=author:%22Geoffrey+Hinton%22"}) ``` --- ## 🔐 隐私保护最佳实践 ### 搜索引擎隐私级别 | 引擎 | 追踪级别 | 数据保留 | 加密 | 推荐场景 | |------|---------|---------|------|---------| | **DuckDuckGo** | 无追踪 | 无保留 | 是 | 日常隐私搜索 | | **Startpage** | 无追踪 | 无保留 | 是 | 需要Google结果但保护隐私 | | **Brave** | 无追踪 | 无保留 | 是 | 独立索引,无偏见 | | **Qwant** | 无追踪 | 无保留 | 是 | 欧盟合规要求 | | **Google** | 高度追踪 | 长期保留 | 是 | 需要个性化结果 | | **Bing** | 中度追踪 | 长期保留 | 是 | 微软服务集成 | ### 隐私搜索建议 1. **日常使用**: DuckDuckGo 或 Brave 2. **需要Google结果但保护隐私**: Startpage 3. **学术研究**: Google Scholar(学术用途追踪较少) 4. **敏感查询**: 使用Tor浏览器 + DuckDuckGo onion服务 5. **跨设备同步**: 避免登录搜索引擎账户 --- ## 📚 参考资料 - [Google搜索操作符完整列表](https://support.google.com/websearch/answer/...) - [DuckDuckGo Bangs完整列表](https://duckduckgo.com/bang) - [Brave Search文档](https://search.brave.com/help/...) - [WolframAlpha示例](https://www.wolframalpha.com/examples/) workspace/skills/tavily-search/SKILL.md
New file @@ -0,0 +1,56 @@ --- name: tavily-search description: Tavily AI Search API integration for high-quality search results optimized for LLMs and RAG applications. Use when the user needs to search the web with Tavily's AI-powered search engine, which provides structured results with summaries, sources, and relevance scores. Particularly useful for research, fact-checking, and gathering up-to-date information from the web. --- # Tavily Search Integration with [Tavily](https://tavily.com) AI Search API - a search engine built specifically for AI applications. ## Prerequisites 1. Get a Tavily API key from https://tavily.com 2. Configure the key using one of these methods: - **.env file (推荐)**: 在 `~/.openclaw/.env` 文件中配置: ```json {"env": {"TAVILY_API_KEY": "your_key_here"}} ``` - **Environment variable**: `export TAVILY_API_KEY=your_key_here` - **Direct parameter**: Pass `api_key` when calling the function ## Usage ### Quick Search Use the search script for simple queries: ```bash python ~/.openclaw/workspace/skills/tavily-search/scripts/tavily_search.py "your search query" ``` ### Python API ```python from scripts.tavily_search import tavily_search results = tavily_search("AI latest news", max_results=5) for result in results: print(f"Title: {result['title']}") print(f"URL: {result['url']}") print(f"Content: {result['content']}") ``` ### Advanced Options The search supports various parameters: - `max_results`: Number of results (default: 5) - `search_depth`: "basic" or "advanced" - `include_images`: Include image URLs - `include_answer`: Include AI-generated answer ## Output Format Tavily returns structured results with: - `query`: The search query - `answer`: AI-generated answer (if requested) - `results`: List of search results with title, url, content, score, and published_date workspace/skills/tavily-search/scripts/tavily_search.py
New file @@ -0,0 +1,178 @@ #!/usr/bin/env python3 """ Tavily AI Search API Client Usage: python tavily_search.py "your search query" [--max-results 5] [--depth basic|advanced] """ import os import sys import json import argparse from pathlib import Path from typing import List, Dict, Any, Optional def get_tavily_key_from_env_file() -> Optional[str]: """Read Tavily API key from ~/.openclaw/.env file. Expected format: {"env": {"TAVILY_API_KEY": "your_key"}} """ env_file = Path.home() / ".openclaw" / ".env" if not env_file.exists(): return None try: with open(env_file, 'r', encoding='utf-8') as f: env_data = json.load(f) # Support nested structure: {"env": {"TAVILY_API_KEY": "..."}} if "env" in env_data: return env_data["env"].get("TAVILY_API_KEY") # Fallback to flat structure: {"TAVILY_API_KEY": "..."} return env_data.get("TAVILY_API_KEY") except (json.JSONDecodeError, IOError): return None def get_api_key(api_key: Optional[str] = None) -> str: """Get Tavily API key from various sources.""" # Priority: parameter > env var > .env file if api_key: return api_key env_key = os.environ.get("TAVILY_API_KEY") if env_key: return env_key env_file_key = get_tavily_key_from_env_file() if env_file_key: return env_file_key raise ValueError( "Tavily API key required. Set via one of:\n" " 1. TAVILY_API_KEY environment variable\n" " 2. ~/.openclaw/.env file (JSON format: {\"env\": {\"TAVILY_API_KEY\": \"...\"}})\n" " 3. Pass as api_key parameter\n" "\nGet your API key at: https://tavily.com" ) def tavily_search( query: str, max_results: int = 5, search_depth: str = "basic", include_answer: bool = False, include_images: bool = False, api_key: Optional[str] = None ) -> Dict[str, Any]: """ Search using Tavily AI Search API. Args: query: Search query string max_results: Number of results to return (1-20) search_depth: "basic" or "advanced" include_answer: Include AI-generated answer include_images: Include image URLs api_key: Tavily API key (optional, auto-detected from env/config) Returns: Dictionary containing search results """ api_key = get_api_key(api_key) try: import requests except ImportError: raise ImportError("requests package required. Install with: pip install requests") url = "https://api.tavily.com/search" payload = { "api_key": api_key, "query": query, "max_results": min(max(max_results, 1), 20), "search_depth": search_depth, "include_answer": include_answer, "include_images": include_images, } response = requests.post(url, json=payload, timeout=30) response.raise_for_status() return response.json() def format_results(results: Dict[str, Any]) -> str: """Format search results for display.""" output = [] if "answer" in results and results["answer"]: output.append("=" * 60) output.append("AI ANSWER") output.append("=" * 60) output.append(results["answer"]) output.append("") output.append("=" * 60) output.append("SEARCH RESULTS") output.append("=" * 60) output.append(f"Query: {results.get('query', 'N/A')}") output.append("") for i, result in enumerate(results.get("results", []), 1): output.append(f"{i}. {result.get('title', 'No title')}") output.append(f" URL: {result.get('url', 'N/A')}") if result.get('published_date'): output.append(f" Published: {result['published_date']}") if result.get('score'): output.append(f" Relevance: {result['score']:.2f}") content = result.get('content', '') if content: # Truncate long content if len(content) > 300: content = content[:297] + "..." output.append(f" {content}") output.append("") return "\n".join(output) def main(): parser = argparse.ArgumentParser(description="Tavily AI Search") parser.add_argument("query", help="Search query") parser.add_argument("--max-results", type=int, default=5, help="Number of results (1-20)") parser.add_argument("--depth", choices=["basic", "advanced"], default="basic", help="Search depth") parser.add_argument("--answer", action="store_true", help="Include AI-generated answer") parser.add_argument("--images", action="store_true", help="Include images") parser.add_argument("--json", action="store_true", help="Output raw JSON") args = parser.parse_args() try: results = tavily_search( query=args.query, max_results=args.max_results, search_depth=args.depth, include_answer=args.answer, include_images=args.images ) if args.json: print(json.dumps(results, indent=2, ensure_ascii=False)) else: print(format_results(results)) except ValueError as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) except Exception as e: print(f"Search failed: {e}", file=sys.stderr) sys.exit(1) if __name__ == "__main__": main()