From 06e3c6bdb9fcbf7e93f12e23447d3da78e830e18 Mon Sep 17 00:00:00 2001 From: vex1023 Date: Mon, 18 May 2026 11:28:50 +0800 Subject: [PATCH] chore: rename skill.md to SKILL.md; update README; add -o path validation --- README.md | 9 +++++++-- skill.md => SKILL.md | 13 +++++++++++++ scripts/cli.py | 8 +++++++- 3 files changed, 27 insertions(+), 3 deletions(-) rename skill.md => SKILL.md (94%) diff --git a/README.md b/README.md index ddf1588..f2e55e5 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,11 @@ Multi-source web search CLI tool — search across **28 engines** from your term ## Quick Start ```bash -# Install with uv (recommended) +# Option 1: pip install (recommended for CodeBuddy Agent use) cd web-search-skills +pip install -e . + +# Option 2: uv tool install (alternative) uv tool install -e . # Now use globally from anywhere @@ -20,6 +23,8 @@ Or run directly without install: python ws.py wechat 蒙面财经 ``` +> Requires Python 3.8+. After `pip install -e .`, the `web-search` command is available globally. + ## Usage ```bash @@ -46,7 +51,7 @@ web-search [options] |-------------------|----------------------------------------------| | `-n N` | Max results per source (default: 10) | | `-j` | JSON output | -| `-o FILE` | Save to JSON file | +| `-o FILE` | Save to JSON file (path restricted to current directory) | | `-s NAME [...]` | Specific source(s) — engine names or categories (e.g. `-s "Hacker News" V2EX`, `-s web news`) | | `-r cn/global` | Region filter (web search) | | `--site SITE` | Restrict to site (baidu command only) | diff --git a/skill.md b/SKILL.md similarity index 94% rename from skill.md rename to SKILL.md index f2bfb32..be8f472 100644 --- a/skill.md +++ b/SKILL.md @@ -158,6 +158,9 @@ web-search health ## Python API (for programmatic use) +> **Tip:** For Agent use, prefer invoking the `web-search` CLI command directly (see examples above). +> The API import below only works when running from the project root directory. + ```python from scripts.unified_search import UnifiedSearch @@ -177,6 +180,16 @@ async def main(): ## Important Notes +### Installation +The `web-search` CLI must be installed first before use: +```bash +cd web-search-skills +pip install -e . +``` +This registers `web-search` as a global command. Requires Python 3.8+. + +### Known Limitations + - **WeChat** via Sogou has anti-scraping limits, may return empty - **财联社 / 华尔街见闻** need JS rendering → returns search page URL, not parsed results - **Baidu Qianfan** requires `BAIDU_API_KEY` env var diff --git a/scripts/cli.py b/scripts/cli.py index ffce1e0..b0e534e 100644 --- a/scripts/cli.py +++ b/scripts/cli.py @@ -415,7 +415,7 @@ async def _run_search(args): _print_results(results, fmt="json" if args.json else "text") - # Save to file if requested + # Save to file if requested (with basic path-sanitization) if args.output: output_data = json.dumps( [{ @@ -440,6 +440,12 @@ async def _run_search(args): indent=2, ) output_path = os.path.abspath(args.output) + # Restrict output to the project root or current working directory + allowed_base = os.path.abspath(os.getcwd()) + if not output_path.startswith(allowed_base): + print(f"错误: 输出路径超出允许范围 ({allowed_base})", file=sys.stderr) + sys.exit(1) + os.makedirs(os.path.dirname(output_path), exist_ok=True) with open(output_path, "w", encoding="utf-8") as f: f.write(output_data) print(f"\n结果已保存至: {output_path}")