refactor: restructure project with CLI tool, multi-engine support, and skill-builder compliant SKILL.md

- Replace setup.py with pyproject.toml (uv-compatible)
- Add CLI entry point (web-search) with 9 subcommands
- Add multi-engine architecture (14 web + 7 special sources)
- Add WeChat/CLS/WallStreetCN/ArXiv/Twitter search engines
- Remove old src/ and examples/ directories
- Remove redundant requirements.txt and setup.py
- Update README.md and SKILL.md with full documentation
- SKILL.md now compliant with skill-builder standards (frontmatter, triggers, structure)
This commit is contained in:
vex1023 committed 2026-05-14 16:31:54 +08:00
1 parent 80ac14491e
commit 87935b59ce
29 files changed
+2364 -354

No files matched your search

+1
View File
@@ -0,0 +1 @@
"""Core data types and base classes."""
+48
View File
@@ -0,0 +1,48 @@
"""
Core data types and base classes for search engines.
Provides:
- SearchResult: Standard result dataclass used across all engines
- SearchEngine: Abstract base class for all search engine implementations
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any, Optional
@dataclass
class SearchResult:
"""Represents a single search result."""
title: str = ""
url: str = ""
snippet: str = ""
source: str = ""
rank: int = 0
category: str = ""
extra: dict[str, Any] = field(default_factory=dict)
class SearchEngine(ABC):
"""Abstract base class for search engines."""
def __init__(self, name: str, config: Optional[dict[str, Any]] = None):
self.name = name
self.config = config or {}
@abstractmethod
async def search(
self, query: str, max_results: int = 10, **kwargs
) -> list[SearchResult]:
"""Execute a search and return results."""
...
def build_url(self, query: str, **kwargs) -> str:
"""Build a search URL for this engine (optional)."""
return ""
async def close(self):
"""Clean up resources."""
pass
+70
View File
@@ -0,0 +1,70 @@
"""Load and manage engine configuration from engines.json."""
from __future__ import annotations
import json
import os
from typing import Any, Optional
_CONFIG_PATH = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
"config", "engines.json",
)
def _load_config(path: Optional[str] = None) -> dict[str, Any]:
config_path = path or _CONFIG_PATH
with open(config_path, "r", encoding="utf-8") as f:
return json.load(f)
def get_search_engines(path: Optional[str] = None) -> list[dict[str, Any]]:
return _load_config(path).get("search_engines", [])
def get_news_sources(path: Optional[str] = None) -> list[dict[str, Any]]:
return _load_config(path).get("news_sources", [])
def get_academic_sources(path: Optional[str] = None) -> list[dict[str, Any]]:
return _load_config(path).get("academic_sources", [])
def get_wechat_sources(path: Optional[str] = None) -> list[dict[str, Any]]:
return _load_config(path).get("wechat_sources", [])
def get_social_sources(path: Optional[str] = None) -> list[dict[str, Any]]:
return _load_config(path).get("social_sources", [])
def get_special_engines(path: Optional[str] = None) -> list[dict[str, Any]]:
return _load_config(path).get("special_engines", [])
def get_engine(name: str, path: Optional[str] = None):
config = _load_config(path)
for category in ["search_engines", "news_sources", "academic_sources",
"wechat_sources", "social_sources", "special_engines"]:
for engine in config.get(category, []):
if engine["name"].lower() == name.lower():
return engine
return None
def get_all_sources(path: Optional[str] = None) -> list[dict[str, Any]]:
config = _load_config(path)
all_sources = []
for category in ["search_engines", "news_sources", "academic_sources",
"wechat_sources", "social_sources", "special_engines"]:
all_sources.extend(config.get(category, []))
return all_sources
def list_source_categories(path: Optional[str] = None) -> dict[str, int]:
"""Return a dict mapping category name to count of sources."""
config = _load_config(path)
categories = [
"search_engines", "news_sources", "academic_sources",
"wechat_sources", "social_sources", "special_engines",
]
return {cat: len(config.get(cat, [])) for cat in categories}