Initial commit: OpenClaw 워크스페이스 버전관리 시작
설정·스크립트·스킬·문서·큐레이션 메모리 추적. 시크릿(credentials/identity)·런타임 상태(state/logs/sessions/sqlite)· 백업(clobbered/bak)·dream 캐시는 .gitignore로 제외. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: briefing-mail
|
||||
description: Compose and send scheduled morning/evening briefing emails with Gmail, Google Calendar, YouTube new-video checks, and Naver Blog new-post checks. Use when asked to create, run, debug, refine, or schedule recurring briefing mails, market briefings, daily digest emails, or summary emails for the owner.
|
||||
---
|
||||
|
||||
# briefing-mail
|
||||
|
||||
Use the bundled script for repeatable briefing-mail work.
|
||||
|
||||
## Workflow
|
||||
|
||||
1. Run `scripts/briefing_mail.py morning` for the morning briefing.
|
||||
2. Run `scripts/briefing_mail.py evening` for the evening briefing.
|
||||
3. If the user asks to change layout/content, edit the script rather than rebuilding the flow ad hoc.
|
||||
4. Keep the email concise. Omit YouTube/blog sections entirely when there are no new items.
|
||||
5. Keep blog summaries easy to read from a stock/investing/economy perspective.
|
||||
6. Use Gmail via `gog`; confirm external sends only when the user has not already asked for the send/schedule.
|
||||
|
||||
## Files
|
||||
|
||||
- Script: `scripts/briefing_mail.py`
|
||||
|
||||
Read the script only when you need to modify logic or debug failures.
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import runpy
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
TARGET = Path('/Users/snowoyh/.openclaw/workspace/scripts/briefing_mail.py')
|
||||
|
||||
if not TARGET.exists():
|
||||
raise SystemExit(f'target script not found: {TARGET}')
|
||||
|
||||
os.chdir(TARGET.parent)
|
||||
sys.argv = [str(TARGET), *sys.argv[1:]]
|
||||
runpy.run_path(str(TARGET), run_name='__main__')
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
name: claude-code-session
|
||||
description: Claude Code Remote Control 세션을 다중 인스턴스로 관리. 프로필(이름↔workdir)을 등록해두고 자연어로 세션을 열고 닫고 목록을 본다. Use when the owner says "클로드 세션 열어줘"·"X 세션 열어줘"·"openclaw-2 닫아줘"·"세션 목록"·"프로필 추가/삭제/수정", or whenever a request needs a new Python script / debugging / refactoring that 클로 cannot safely do itself — queue a spec under `~/.openclaw/dev-requests/` then open a session so the owner can connect from a phone and have Claude Code handle it.
|
||||
---
|
||||
|
||||
# Claude Code Remote Control 세션 (다중 세션 + 프로필)
|
||||
|
||||
## 데이터 모델
|
||||
|
||||
- **프로필**: 이름 ↔ workdir 매핑. `~/.openclaw/state/claude_sessions.json`에 JSON으로 저장. 첫 실행 시 `openclaw → ~/.openclaw` 자동 시드.
|
||||
- **세션**: 프로필을 기반으로 떠있는 클로드 데몬. 기본 프로필은 라벨 `ai.claude-session.YYMMDD-<N>`로 생성한다. plist 파일 존재 = 등록됨, `launchctl print state=running` = 떠있음. 2026-05-20 이전 구형 `<profile>-<N>`, `openclaw-YYYYMMDD-<N>`, `oc-YY-MM-DD-<N>` 세션도 조회·종료 가능.
|
||||
- **번호링**: `open` 호출 시 해당 프로필·날짜에서 빈 번호(1부터) 자동 할당. 닫으면 그 번호 재사용 가능.
|
||||
|
||||
## 툴
|
||||
|
||||
`scripts/session_tool.py` (Python) — 모든 동작은 이 툴 한 개로 처리. 클로는 자연어 요청을 아래 매핑으로 라우팅.
|
||||
|
||||
### 자연어 매핑
|
||||
|
||||
| 관리자님 발화 | 툴 호출 |
|
||||
|---|---|
|
||||
| "클로드 세션 열어줘" / "세션 열어줘" | `session_tool.py session open` (default profile=openclaw, `YYMMDD-N` 자동) |
|
||||
| "X 세션 열어줘" | `session_tool.py session open X` (프로필 X 등록 전이면 안내, 오늘 날짜 + 빈 번호 자동) |
|
||||
| "260520-2 닫아줘" / "클로드2 닫아줘" | `session_tool.py session close 260520-2` |
|
||||
| "세션 목록" / "안 닫힌 세션" | `session_tool.py session list` |
|
||||
| "260520-1 상태" | `session_tool.py session status 260520-1` |
|
||||
| "프로필 목록" / "등록된 폴더" | `session_tool.py profile list` |
|
||||
| "프로필 추가 X /path/to/X" | `session_tool.py profile add X /path/to/X` |
|
||||
| "프로필 삭제 X" | `session_tool.py profile remove X` (활성 세션 있으면 거부) |
|
||||
| "프로필 X 폴더 변경 /new/path" | `session_tool.py profile edit X /new/path` (활성 세션 있으면 거부) |
|
||||
|
||||
이름 매핑 주의: 관리자님이 "클로드N", "openclawN", "openclaw N" 등 다양하게 부르더라도 내부적으로는 오늘 날짜를 넣은 `YYMMDD-<N>` 형식으로 변환해서 호출 (예: 2026-05-20에 "클로드3" → `260520-3`). 단, 기존 구형 `<profile>-<N>`, `openclaw-YYYYMMDD-<N>`, `oc-YY-MM-DD-<N>` 세션명은 그대로 close/status 가능.
|
||||
|
||||
## 운영 메모
|
||||
|
||||
- 세션 plist는 ephemeral — `open` 시 `~/Library/LaunchAgents/ai.claude-session.YYMMDD-<N>.plist` 생성·bootstrap, `close` 시 bootout·plist 삭제. 따라서 LaunchAgents 폴더 스캔이 곧 활성 세션 목록.
|
||||
- 모든 세션 `RunAtLoad=false`, `KeepAlive=false` (on-demand). 자동 종료 옵션은 미구현 (`claude remote-control` 본체가 idle timeout 미지원). 작업 끝나면 `close` 권장.
|
||||
- 로그: `~/.openclaw/logs/claude-session-<session-name>.{log,err.log}`
|
||||
|
||||
## 레거시 세션과의 관계
|
||||
|
||||
- 기존 `ai.openclaw.claude-remote-control` (라벨: `openclaw`, plist: `ai.openclaw.claude-remote-control.plist`)는 본 툴이 건드리지 않음 — `ensure_session.sh`가 그대로 관리.
|
||||
- `session_tool.py session list`에는 참고용으로 `openclaw (legacy)` 줄이 함께 표시됨 (running/stopped 상태만).
|
||||
- 새로 다중 세션 운영하려면 본 툴(`session_tool.py`)만 쓰면 충분. 레거시 세션은 단일 세션으로 유지하거나 `ensure_session.sh close`로 정리해도 무방.
|
||||
|
||||
## 보안
|
||||
|
||||
- Remote Control 접속은 관리자님 Claude 구독 계정 인증 필수 — 외부망 노출 자동 차단
|
||||
- 세션 workdir 안의 자격증명은 그 세션을 통해 모두 노출 가능 — 외부 프로젝트 디렉터리를 프로필로 등록할 때 그 디렉터리에 민감 자료가 있는지 확인 후 등록
|
||||
- 작업 끝나면 `close` 권장 (분실·탈취 시 노출 창 최소화)
|
||||
|
||||
## 개발 요청 큐와의 연계
|
||||
|
||||
추가 진입점 신규 .py 작성·디버깅·리팩토링이 필요한 요청이 들어왔을 때(클로 본인이 직접 처리하면 검증·디버깅 사이클이 부족해 위험): 명세를 `~/.openclaw/dev-requests/<id>.md`에 큐잉한 뒤 `session open openclaw`로 정비공 세션을 띄우고, 관리자님께 "폰/웹에서 접속해서 dev-requests 처리 부탁드립니다" 안내. 또한 응답 안내 시 `~/.openclaw/dev-requests/`에 미처리 명세가 있으면 "대기 중인 개발 요청 N건" 함께 안내.
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
# Claude Code Remote Control on-demand controller (클로 스킬용)
|
||||
#
|
||||
# 사용법:
|
||||
# ensure_session.sh open — Remote Control daemon 시작 (이미 떠있으면 안내만)
|
||||
# ensure_session.sh close — daemon 종료
|
||||
# ensure_session.sh status — 현재 상태
|
||||
#
|
||||
# launchd 등록 라벨: ai.openclaw.claude-remote-control (RunAtLoad=false, KeepAlive=false)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
LABEL="ai.openclaw.claude-remote-control"
|
||||
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
|
||||
SERVICE="gui/$UID/$LABEL"
|
||||
|
||||
bootstrap_if_needed() {
|
||||
if ! launchctl print "$SERVICE" >/dev/null 2>&1; then
|
||||
if [ ! -f "$PLIST" ]; then
|
||||
echo "ERROR: plist 없음: $PLIST"
|
||||
exit 1
|
||||
fi
|
||||
launchctl bootstrap "gui/$UID" "$PLIST"
|
||||
fi
|
||||
}
|
||||
|
||||
is_running() {
|
||||
local state
|
||||
state=$(launchctl print "$SERVICE" 2>/dev/null | awk -F'=' '/^[[:space:]]*state[[:space:]]*=/{gsub(/[[:space:]]/,"",$2);print $2;exit}')
|
||||
[ "$state" = "running" ]
|
||||
}
|
||||
|
||||
cmd="${1:-status}"
|
||||
|
||||
case "$cmd" in
|
||||
open|start)
|
||||
bootstrap_if_needed
|
||||
if is_running; then
|
||||
echo "이미 동작 중. claude.ai/code 또는 Claude 앱에서 'openclaw' 세션에 접속하세요."
|
||||
else
|
||||
launchctl kickstart "$SERVICE" >/dev/null 2>&1 || true
|
||||
sleep 2
|
||||
if is_running; then
|
||||
echo "Claude Code 원격 세션 시작됨. claude.ai/code 또는 Claude 앱에서 'openclaw' 세션에 접속하세요."
|
||||
else
|
||||
echo "ERROR: 시작 실패. 로그: ~/.openclaw/logs/claude-remote-control.err.log"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
close|stop)
|
||||
if launchctl print "$SERVICE" >/dev/null 2>&1; then
|
||||
launchctl bootout "$SERVICE" 2>/dev/null || true
|
||||
echo "Claude Code 원격 세션 종료됨."
|
||||
else
|
||||
echo "이미 종료 상태."
|
||||
fi
|
||||
;;
|
||||
status)
|
||||
if launchctl print "$SERVICE" >/dev/null 2>&1 && is_running; then
|
||||
echo "동작 중. claude.ai/code 또는 Claude 앱에서 'openclaw' 세션 접속 가능."
|
||||
else
|
||||
echo "종료 상태. 'open' 명령으로 시작 가능."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {open|close|status}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,444 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Claude Code Remote Control 세션 관리 툴 (다중 세션 + 프로필 CRUD).
|
||||
|
||||
데이터 모델:
|
||||
profile: 이름 ↔ workdir 매핑. `~/.openclaw/state/claude_sessions.json`에 저장.
|
||||
session: profile 기반으로 떠있는 클로드 데몬. plist 파일 존재 여부가 곧 세션 등록.
|
||||
라벨 `ai.claude-session.YYMMDD-<N>` (N은 날짜별 1부터 빈 번호 채움).
|
||||
|
||||
서브커맨드:
|
||||
profile list
|
||||
profile add <name> <workdir>
|
||||
profile remove <name>
|
||||
profile edit <name> <new-workdir>
|
||||
session open [profile=openclaw]
|
||||
session close <session-name>
|
||||
session list
|
||||
session status <session-name>
|
||||
|
||||
레거시 `ai.openclaw.claude-remote-control`는 본 툴이 건드리지 않음 (기존
|
||||
ensure_session.sh가 계속 관리). `session list`에서 참고용으로만 노출.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
HOME = Path.home()
|
||||
OPENCLAW_ROOT = HOME / '.openclaw'
|
||||
STATE_DIR = OPENCLAW_ROOT / 'state'
|
||||
STATE_FILE = STATE_DIR / 'claude_sessions.json'
|
||||
LOG_DIR = OPENCLAW_ROOT / 'logs'
|
||||
LA_DIR = HOME / 'Library' / 'LaunchAgents'
|
||||
CLAUDE_BIN = Path(os.environ.get('CLAUDE_BIN', HOME / '.local' / 'bin' / 'claude'))
|
||||
LABEL_PREFIX = 'ai.claude-session.'
|
||||
LEGACY_LABEL = 'ai.openclaw.claude-remote-control'
|
||||
DEFAULT_PROFILE = 'openclaw'
|
||||
DEFAULT_PROFILE_WORKDIR = OPENCLAW_ROOT
|
||||
NAME_RE = re.compile(r'^[a-z][a-z0-9_-]*$')
|
||||
SESSION_RE = re.compile(
|
||||
r'^(?:(?P<date_compact>\d{6})|'
|
||||
r'(?P<profile_compact>[a-z][a-z0-9_-]*?)-(?P<date_compact_profile>\d{6})|'
|
||||
r'(?P<profile_dash>[a-z][a-z0-9_-]*?)-(?P<date_dash>\d{2}-\d{2}-\d{2})|'
|
||||
r'(?P<profile_dated>[a-z][a-z0-9_-]*?)-(?P<date8>\d{8})|'
|
||||
r'(?P<profile_legacy>[a-z][a-z0-9_-]*))-(?P<n>[1-9]\d*)$'
|
||||
)
|
||||
|
||||
|
||||
# ───────── state I/O ─────────
|
||||
|
||||
def _load_state() -> dict:
|
||||
if not STATE_FILE.exists():
|
||||
return {'profiles': {DEFAULT_PROFILE: {'workdir': str(DEFAULT_PROFILE_WORKDIR)}}}
|
||||
try:
|
||||
data = json.loads(STATE_FILE.read_text())
|
||||
except json.JSONDecodeError as e:
|
||||
raise SystemExit(f'state 파일 파싱 실패: {STATE_FILE} ({e})')
|
||||
data.setdefault('profiles', {})
|
||||
if DEFAULT_PROFILE not in data['profiles']:
|
||||
data['profiles'][DEFAULT_PROFILE] = {'workdir': str(DEFAULT_PROFILE_WORKDIR)}
|
||||
return data
|
||||
|
||||
|
||||
def _save_state(data: dict) -> None:
|
||||
STATE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
tmp = STATE_FILE.with_suffix('.json.tmp')
|
||||
tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2))
|
||||
tmp.replace(STATE_FILE)
|
||||
|
||||
|
||||
def _validate_name(name: str, kind: str = '이름') -> None:
|
||||
if not NAME_RE.match(name):
|
||||
raise SystemExit(f'{kind} 형식 오류: {name!r} (소문자·숫자·`_`·`-`만, 첫 글자는 소문자)')
|
||||
|
||||
|
||||
def _resolve_workdir(workdir: str) -> str:
|
||||
p = Path(workdir).expanduser()
|
||||
if not p.is_dir():
|
||||
raise SystemExit(f'workdir 없음 또는 디렉터리 아님: {p}')
|
||||
return str(p.resolve())
|
||||
|
||||
|
||||
# ───────── launchctl wrappers ─────────
|
||||
|
||||
def _uid() -> int:
|
||||
return os.getuid()
|
||||
|
||||
|
||||
def _today() -> str:
|
||||
try:
|
||||
return datetime.now(ZoneInfo('Asia/Seoul')).strftime('%y%m%d')
|
||||
except Exception:
|
||||
return datetime.now().strftime('%y%m%d')
|
||||
|
||||
|
||||
def _session_name(profile: str, n: int, date: str | None = None) -> str:
|
||||
if date:
|
||||
if profile == DEFAULT_PROFILE:
|
||||
return f'{date}-{n}'
|
||||
return f'{profile}-{date}-{n}'
|
||||
return f'{profile}-{n}'
|
||||
|
||||
|
||||
def _label(session_name: str) -> str:
|
||||
return f'{LABEL_PREFIX}{session_name}'
|
||||
|
||||
|
||||
def _plist_path(session_name: str) -> Path:
|
||||
return LA_DIR / f'{_label(session_name)}.plist'
|
||||
|
||||
|
||||
def _service(label: str) -> str:
|
||||
return f'gui/{_uid()}/{label}'
|
||||
|
||||
|
||||
def _launchctl_print(label: str) -> Optional[str]:
|
||||
p = subprocess.run(['launchctl', 'print', _service(label)], capture_output=True, text=True)
|
||||
if p.returncode != 0:
|
||||
return None
|
||||
return p.stdout
|
||||
|
||||
|
||||
def _is_running(label: str) -> bool:
|
||||
out = _launchctl_print(label)
|
||||
if not out:
|
||||
return False
|
||||
for line in out.splitlines():
|
||||
m = re.match(r'\s*state\s*=\s*(\S+)', line)
|
||||
if m:
|
||||
return m.group(1) == 'running'
|
||||
return False
|
||||
|
||||
|
||||
def _bootstrap(plist: Path) -> None:
|
||||
subprocess.run(['launchctl', 'bootstrap', f'gui/{_uid()}', str(plist)], check=True)
|
||||
|
||||
|
||||
def _bootout(label: str) -> None:
|
||||
subprocess.run(['launchctl', 'bootout', _service(label)], capture_output=True)
|
||||
# bootout이 비동기적이라 잠깐 라벨이 graveyard에 남는다.
|
||||
# `launchctl print`가 실패할 때까지 짧게 폴링해서 후속 bootstrap 충돌 방지.
|
||||
import time
|
||||
for _ in range(20): # 최대 ~2초
|
||||
if _launchctl_print(label) is None:
|
||||
return
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
def _kickstart(label: str) -> None:
|
||||
subprocess.run(['launchctl', 'kickstart', _service(label)], capture_output=True)
|
||||
|
||||
|
||||
# ───────── plist 생성 ─────────
|
||||
|
||||
PLIST_TEMPLATE = '''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>{label}</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>{claude_bin}</string>
|
||||
<string>remote-control</string>
|
||||
<string>--name</string>
|
||||
<string>{session_name}</string>
|
||||
</array>
|
||||
|
||||
<key>WorkingDirectory</key>
|
||||
<string>{workdir}</string>
|
||||
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PATH</key>
|
||||
<string>{path_env}</string>
|
||||
<key>HOME</key>
|
||||
<string>{home}</string>
|
||||
</dict>
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
<string>{stdout}</string>
|
||||
|
||||
<key>StandardErrorPath</key>
|
||||
<string>{stderr}</string>
|
||||
|
||||
<key>RunAtLoad</key>
|
||||
<false/>
|
||||
|
||||
<key>KeepAlive</key>
|
||||
<false/>
|
||||
|
||||
<key>ProcessType</key>
|
||||
<string>Background</string>
|
||||
</dict>
|
||||
</plist>
|
||||
'''
|
||||
|
||||
|
||||
def _write_plist(session_name: str, workdir: str) -> Path:
|
||||
LA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
label = _label(session_name)
|
||||
path = _plist_path(session_name)
|
||||
path.write_text(PLIST_TEMPLATE.format(
|
||||
label=label,
|
||||
claude_bin=CLAUDE_BIN,
|
||||
session_name=session_name,
|
||||
workdir=workdir,
|
||||
path_env=f'{HOME}/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin',
|
||||
home=HOME,
|
||||
stdout=LOG_DIR / f'claude-session-{session_name}.log',
|
||||
stderr=LOG_DIR / f'claude-session-{session_name}.err.log',
|
||||
))
|
||||
return path
|
||||
|
||||
|
||||
# ───────── 활성 세션 스캔 ─────────
|
||||
|
||||
def _list_active_sessions() -> list[dict]:
|
||||
"""LaunchAgents 폴더 스캔. 본 툴이 만든 plist만."""
|
||||
out = []
|
||||
if not LA_DIR.exists():
|
||||
return out
|
||||
for plist in sorted(LA_DIR.glob(f'{LABEL_PREFIX}*.plist')):
|
||||
label = plist.stem
|
||||
suffix = label[len(LABEL_PREFIX):]
|
||||
m = SESSION_RE.match(suffix)
|
||||
if not m:
|
||||
continue
|
||||
profile = (
|
||||
m.group('profile_compact') or m.group('profile_dash') or
|
||||
m.group('profile_dated') or m.group('profile_legacy') or DEFAULT_PROFILE
|
||||
)
|
||||
if profile == 'oc':
|
||||
profile = DEFAULT_PROFILE
|
||||
date = (
|
||||
m.group('date_compact') or m.group('date_compact_profile') or
|
||||
m.group('date_dash') or m.group('date8')
|
||||
)
|
||||
n = int(m.group('n'))
|
||||
running = _is_running(label)
|
||||
workdir = _read_plist_workdir(plist)
|
||||
out.append({
|
||||
'session': suffix,
|
||||
'profile': profile,
|
||||
'date': date,
|
||||
'n': n,
|
||||
'workdir': workdir,
|
||||
'running': running,
|
||||
'plist': plist,
|
||||
'label': label,
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
def _read_plist_workdir(plist: Path) -> str:
|
||||
p = subprocess.run(['/usr/libexec/PlistBuddy', '-c', 'Print :WorkingDirectory', str(plist)],
|
||||
capture_output=True, text=True)
|
||||
return p.stdout.strip() if p.returncode == 0 else '?'
|
||||
|
||||
|
||||
def _legacy_running() -> bool:
|
||||
return _is_running(LEGACY_LABEL)
|
||||
|
||||
|
||||
def _next_free_number(profile: str, date: str) -> int:
|
||||
used = {s['n'] for s in _list_active_sessions() if s['profile'] == profile and s.get('date') == date}
|
||||
n = 1
|
||||
while n in used:
|
||||
n += 1
|
||||
return n
|
||||
|
||||
|
||||
# ───────── 커맨드 핸들러 ─────────
|
||||
|
||||
def cmd_profile_list(args) -> int:
|
||||
state = _load_state()
|
||||
print(f'{"NAME":<16} WORKDIR')
|
||||
for name, prof in sorted(state['profiles'].items()):
|
||||
print(f'{name:<16} {prof["workdir"]}')
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_profile_add(args) -> int:
|
||||
_validate_name(args.name, '프로필 이름')
|
||||
workdir = _resolve_workdir(args.workdir)
|
||||
state = _load_state()
|
||||
if args.name in state['profiles']:
|
||||
raise SystemExit(f"이미 등록된 프로필: {args.name} → {state['profiles'][args.name]['workdir']}")
|
||||
state['profiles'][args.name] = {'workdir': workdir}
|
||||
_save_state(state)
|
||||
print(f'프로필 추가됨: {args.name} → {workdir}')
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_profile_remove(args) -> int:
|
||||
state = _load_state()
|
||||
if args.name not in state['profiles']:
|
||||
raise SystemExit(f'등록되지 않은 프로필: {args.name}')
|
||||
if args.name == DEFAULT_PROFILE:
|
||||
raise SystemExit(f"기본 프로필 '{DEFAULT_PROFILE}'은 삭제 불가.")
|
||||
active = [s for s in _list_active_sessions() if s['profile'] == args.name]
|
||||
if active:
|
||||
names = ', '.join(s['session'] for s in active)
|
||||
raise SystemExit(f'활성 세션이 있어 삭제 불가: {names} (먼저 close)')
|
||||
del state['profiles'][args.name]
|
||||
_save_state(state)
|
||||
print(f'프로필 삭제됨: {args.name}')
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_profile_edit(args) -> int:
|
||||
state = _load_state()
|
||||
if args.name not in state['profiles']:
|
||||
raise SystemExit(f'등록되지 않은 프로필: {args.name}')
|
||||
workdir = _resolve_workdir(args.workdir)
|
||||
active = [s for s in _list_active_sessions() if s['profile'] == args.name]
|
||||
if active:
|
||||
names = ', '.join(s['session'] for s in active)
|
||||
raise SystemExit(f'활성 세션이 있어 변경 불가: {names} (먼저 close)')
|
||||
state['profiles'][args.name]['workdir'] = workdir
|
||||
_save_state(state)
|
||||
print(f'프로필 수정됨: {args.name} → {workdir}')
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_session_open(args) -> int:
|
||||
profile = args.profile or DEFAULT_PROFILE
|
||||
_validate_name(profile, '프로필 이름')
|
||||
state = _load_state()
|
||||
prof = state['profiles'].get(profile)
|
||||
if not prof:
|
||||
raise SystemExit(f'등록되지 않은 프로필: {profile} (먼저 `profile add` 실행)')
|
||||
workdir = prof['workdir']
|
||||
if not Path(workdir).is_dir():
|
||||
raise SystemExit(f'프로필 workdir 없음: {workdir}')
|
||||
date = _today()
|
||||
n = _next_free_number(profile, date)
|
||||
session_name = _session_name(profile, n, date)
|
||||
label = _label(session_name)
|
||||
plist = _write_plist(session_name, workdir)
|
||||
try:
|
||||
_bootstrap(plist)
|
||||
except subprocess.CalledProcessError as e:
|
||||
plist.unlink(missing_ok=True)
|
||||
raise SystemExit(f'launchctl bootstrap 실패: {e}')
|
||||
_kickstart(label)
|
||||
import time
|
||||
time.sleep(2)
|
||||
if _is_running(label):
|
||||
print(f'세션 시작됨: {session_name} (workdir={workdir})')
|
||||
print(f"claude.ai/code 또는 Claude 앱에서 '{session_name}' 클릭하여 접속하세요.")
|
||||
return 0
|
||||
print(f'WARN: {session_name} bootstrap은 됐는데 running 확인 실패. 로그: {LOG_DIR}/claude-session-{session_name}.err.log',
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
def cmd_session_close(args) -> int:
|
||||
target = args.name
|
||||
m = SESSION_RE.match(target)
|
||||
if not m:
|
||||
raise SystemExit(f"세션 이름 형식 오류: {target} (예: 260520-1)")
|
||||
label = _label(target)
|
||||
plist = _plist_path(target)
|
||||
if not plist.exists() and not _launchctl_print(label):
|
||||
raise SystemExit(f'세션 없음: {target}')
|
||||
_bootout(label)
|
||||
plist.unlink(missing_ok=True)
|
||||
print(f'세션 종료됨: {target}')
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_session_list(args) -> int:
|
||||
sessions = _list_active_sessions()
|
||||
print(f'{"SESSION":<24} {"STATE":<8} WORKDIR')
|
||||
legacy_state = 'running' if _legacy_running() else 'stopped'
|
||||
print(f'{"openclaw (legacy)":<24} {legacy_state:<8} {OPENCLAW_ROOT}')
|
||||
for s in sessions:
|
||||
state = 'running' if s['running'] else 'stopped'
|
||||
print(f'{s["session"]:<24} {state:<8} {s["workdir"]}')
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_session_status(args) -> int:
|
||||
target = args.name
|
||||
m = SESSION_RE.match(target)
|
||||
if not m:
|
||||
raise SystemExit(f"세션 이름 형식 오류: {target} (예: 260520-1)")
|
||||
label = _label(target)
|
||||
if _is_running(label):
|
||||
print(f'{target} 동작 중')
|
||||
return 0
|
||||
if _plist_path(target).exists():
|
||||
print(f'{target} 등록됐으나 정지 상태')
|
||||
return 1
|
||||
print(f'{target} 없음')
|
||||
return 2
|
||||
|
||||
|
||||
# ───────── argparse ─────────
|
||||
|
||||
def _build_parser() -> argparse.ArgumentParser:
|
||||
p = argparse.ArgumentParser(prog='session_tool', description=__doc__.splitlines()[0] if __doc__ else None)
|
||||
sub = p.add_subparsers(dest='group', required=True)
|
||||
|
||||
pp = sub.add_parser('profile', help='프로필(이름↔workdir) CRUD')
|
||||
psub = pp.add_subparsers(dest='cmd', required=True)
|
||||
psub.add_parser('list', help='등록된 프로필 출력').set_defaults(func=cmd_profile_list)
|
||||
pa = psub.add_parser('add', help='프로필 추가')
|
||||
pa.add_argument('name'); pa.add_argument('workdir'); pa.set_defaults(func=cmd_profile_add)
|
||||
pr = psub.add_parser('remove', help='프로필 삭제 (활성 세션 없을 때만)')
|
||||
pr.add_argument('name'); pr.set_defaults(func=cmd_profile_remove)
|
||||
pe = psub.add_parser('edit', help='프로필 workdir 변경 (활성 세션 없을 때만)')
|
||||
pe.add_argument('name'); pe.add_argument('workdir'); pe.set_defaults(func=cmd_profile_edit)
|
||||
|
||||
sp = sub.add_parser('session', help='세션 (실제 떠있는 클로드 인스턴스) 관리')
|
||||
ssub = sp.add_subparsers(dest='cmd', required=True)
|
||||
so = ssub.add_parser('open', help='세션 열기 (빈 번호 자동 할당)')
|
||||
so.add_argument('profile', nargs='?'); so.set_defaults(func=cmd_session_open)
|
||||
sc = ssub.add_parser('close', help='세션 종료')
|
||||
sc.add_argument('name'); sc.set_defaults(func=cmd_session_close)
|
||||
ssub.add_parser('list', help='활성 세션 목록').set_defaults(func=cmd_session_list)
|
||||
ss = ssub.add_parser('status', help='세션 상태')
|
||||
ss.add_argument('name'); ss.set_defaults(func=cmd_session_status)
|
||||
return p
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = _build_parser()
|
||||
args = parser.parse_args(argv)
|
||||
return args.func(args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,142 @@
|
||||
---
|
||||
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: Check the Leaderboard First
|
||||
|
||||
Before running a CLI search, check the [skills.sh leaderboard](https://skills.sh/) to see if a well-known skill already exists for the domain. The leaderboard ranks skills by total installs, surfacing the most popular and battle-tested options.
|
||||
|
||||
For example, top skills for web development include:
|
||||
- `vercel-labs/agent-skills` — React, Next.js, web design (100K+ installs each)
|
||||
- `anthropics/skills` — Frontend design, document processing (100K+ installs)
|
||||
|
||||
### Step 3: Search for Skills
|
||||
|
||||
If the leaderboard doesn't cover the user's need, run the find command:
|
||||
|
||||
```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`
|
||||
|
||||
### Step 4: Verify Quality Before Recommending
|
||||
|
||||
**Do not recommend a skill based solely on search results.** Always verify:
|
||||
|
||||
1. **Install count** — Prefer skills with 1K+ installs. Be cautious with anything under 100.
|
||||
2. **Source reputation** — Official sources (`vercel-labs`, `anthropics`, `microsoft`) are more trustworthy than unknown authors.
|
||||
3. **GitHub stars** — Check the source repository. A skill from a repo with <100 stars should be treated with skepticism.
|
||||
|
||||
### Step 5: 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 count and source
|
||||
3. The install command they can run
|
||||
4. A link to learn more at skills.sh
|
||||
|
||||
Example response:
|
||||
|
||||
```
|
||||
I found a skill that might help! The "react-best-practices" skill provides
|
||||
React and Next.js performance optimization guidelines from Vercel Engineering.
|
||||
(185K installs)
|
||||
|
||||
To install it:
|
||||
npx skills add vercel-labs/agent-skills@react-best-practices
|
||||
|
||||
Learn more: https://skills.sh/vercel-labs/agent-skills/react-best-practices
|
||||
```
|
||||
|
||||
### Step 6: 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
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"registry": "https://clawhub.ai",
|
||||
"slug": "summarize-pro",
|
||||
"installedVersion": "1.0.0",
|
||||
"installedAt": 1777007491847
|
||||
}
|
||||
@@ -0,0 +1,678 @@
|
||||
---
|
||||
name: summarize-pro
|
||||
description: When user asks to summarize text, articles, documents, meetings, emails, YouTube transcripts, books, PDFs, reports, conversations, or any long content. Also handles bullet points, key takeaways, action items, TL;DR, ELI5, executive summaries, chapter summaries, comparison summaries, translation summaries, thread summaries, and custom-length summaries. 20-feature AI summarizer with multiple formats, languages, and export options. All processing happens locally — NO external API calls, NO network requests, NO data sent to any server.
|
||||
metadata: {"clawdbot":{"emoji":"📝","requires":{"tools":["read","write"]}}}
|
||||
---
|
||||
|
||||
# Summarize Pro — Your AI Summarization Engine
|
||||
|
||||
You are a powerful text summarizer. You take any long content and produce clear, concise, actionable summaries. You're fast, accurate, and adapt to the user's preferred format. You speak like a smart assistant — brief but thorough.
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
User: "summarize this: [pastes long article]"
|
||||
User: "tldr: [pastes text]"
|
||||
User: "summarize in 3 bullets"
|
||||
User: "eli5: quantum computing"
|
||||
User: "key takeaways from this meeting: [pastes notes]"
|
||||
User: "action items from this: [pastes email]"
|
||||
User: "summarize in hindi"
|
||||
User: "executive summary of this report: [pastes text]"
|
||||
User: "compare these two articles: [article 1] vs [article 2]"
|
||||
User: "summarize in 50 words"
|
||||
User: "chapter summary: [pastes book chapter]"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## First Run Setup
|
||||
|
||||
On first message, create data directory:
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.openclaw/summarize-pro
|
||||
```
|
||||
|
||||
Initialize settings if not exist:
|
||||
|
||||
```json
|
||||
// ~/.openclaw/summarize-pro/settings.json
|
||||
{
|
||||
"default_format": "bullets",
|
||||
"default_length": "medium",
|
||||
"default_language": "english",
|
||||
"summaries_count": 0,
|
||||
"words_processed": 0,
|
||||
"streak_days": 0,
|
||||
"last_used": null,
|
||||
"favorite_format": null
|
||||
}
|
||||
```
|
||||
|
||||
Initialize history:
|
||||
|
||||
```json
|
||||
// ~/.openclaw/summarize-pro/history.json
|
||||
[]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Data Storage
|
||||
|
||||
All data stored under `~/.openclaw/summarize-pro/`:
|
||||
|
||||
- `settings.json` — user preferences and stats
|
||||
- `history.json` — summary history with timestamps
|
||||
- `saved.json` — user's saved/bookmarked summaries
|
||||
- `templates.json` — custom summary templates
|
||||
|
||||
## Security & Privacy
|
||||
|
||||
**All data stays local.** This skill:
|
||||
- Only reads/writes files under `~/.openclaw/summarize-pro/`
|
||||
- Makes NO external API calls or network requests
|
||||
- Sends NO data to any server, email, or messaging service
|
||||
- Does NOT access any external service, API, or URL
|
||||
- All summarization is done by the AI model itself — no third-party summarizer
|
||||
|
||||
### Why These Permissions Are Needed
|
||||
- `read`: To read settings, history, and saved summaries from local JSON files
|
||||
- `write`: To save summaries, update stats, and store user preferences
|
||||
|
||||
---
|
||||
|
||||
## When To Activate
|
||||
|
||||
Respond when user says any of:
|
||||
- **"summarize"** or **"summary"** — summarize any text
|
||||
- **"tldr"** or **"tl;dr"** — quick summary
|
||||
- **"eli5"** — explain like I'm 5
|
||||
- **"key takeaways"** — extract main points
|
||||
- **"action items"** — extract to-dos from text
|
||||
- **"bullet points"** — bullet format summary
|
||||
- **"executive summary"** — formal business summary
|
||||
- **"compare"** + two texts — comparison summary
|
||||
- **"summarize in [language]"** — translated summary
|
||||
- **"summarize in [X] words"** — custom length
|
||||
- **"chapter summary"** — book/document chapter
|
||||
- **"meeting notes"** or **"meeting summary"** — meeting format
|
||||
- **"email summary"** — email digest format
|
||||
- **"thread summary"** — conversation/thread summary
|
||||
- **"save summary"** — bookmark a summary
|
||||
- **"summary history"** — view past summaries
|
||||
- **"summary stats"** — view usage statistics
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 1: Quick Summary (Default)
|
||||
|
||||
When user pastes text or says **"summarize this"**:
|
||||
|
||||
1. Analyze the text length and content type
|
||||
2. Produce a summary in the user's default format
|
||||
|
||||
**Default output format:**
|
||||
|
||||
```
|
||||
📝 SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
[3-5 bullet points capturing the main ideas]
|
||||
|
||||
📊 Stats: [X] words → [Y] words ([Z]% reduction)
|
||||
```
|
||||
|
||||
Always show the word reduction stats at the bottom.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 2: TL;DR Mode
|
||||
|
||||
When user says **"tldr"** or **"tl;dr"** followed by text:
|
||||
|
||||
Produce a 1-2 sentence summary. Maximum 50 words. Be punchy and direct.
|
||||
|
||||
```
|
||||
🔥 TL;DR
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
[1-2 sentence summary — direct, no fluff]
|
||||
|
||||
📊 [X] words → [Y] words
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 3: Bullet Points
|
||||
|
||||
When user says **"summarize in bullets"** or **"bullet points"**:
|
||||
|
||||
```
|
||||
📋 KEY POINTS
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
• [Point 1 — clear and actionable]
|
||||
• [Point 2 — specific detail]
|
||||
• [Point 3 — important context]
|
||||
• [Point 4 — conclusion or next step]
|
||||
• [Point 5 — if needed]
|
||||
|
||||
📊 [X] words → [Y] words ([Z]% reduction)
|
||||
```
|
||||
|
||||
Keep to 3-7 bullets. Each bullet should be 1 sentence.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 4: ELI5 (Explain Like I'm 5)
|
||||
|
||||
When user says **"eli5"** followed by text or topic:
|
||||
|
||||
Simplify complex content into language a child could understand. Use simple words, analogies, and examples.
|
||||
|
||||
```
|
||||
🧒 ELI5
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
[Simple explanation using everyday language and fun analogies]
|
||||
|
||||
💡 In one sentence: [ultra-simple version]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 5: Key Takeaways
|
||||
|
||||
When user says **"key takeaways"** or **"main points"**:
|
||||
|
||||
Extract the most important insights — things the reader MUST know.
|
||||
|
||||
```
|
||||
🎯 KEY TAKEAWAYS
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
1. [Most important insight]
|
||||
2. [Second most important]
|
||||
3. [Third most important]
|
||||
4. [Fourth — if significant]
|
||||
5. [Fifth — if significant]
|
||||
|
||||
💡 Bottom line: [One sentence conclusion]
|
||||
```
|
||||
|
||||
Numbered list, ranked by importance. Max 5-7 takeaways.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 6: Action Items Extractor
|
||||
|
||||
When user says **"action items"** or **"extract todos"** or **"what do I need to do"**:
|
||||
|
||||
Scan text for tasks, deadlines, responsibilities, and commitments.
|
||||
|
||||
```
|
||||
✅ ACTION ITEMS
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
□ [Task 1] — [who] — [deadline if mentioned]
|
||||
□ [Task 2] — [who] — [deadline if mentioned]
|
||||
□ [Task 3] — [who] — [deadline if mentioned]
|
||||
|
||||
⏰ Deadlines found: [list any dates mentioned]
|
||||
👤 People mentioned: [names found in text]
|
||||
```
|
||||
|
||||
If no clear action items found, say so honestly.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 7: Executive Summary
|
||||
|
||||
When user says **"executive summary"** or **"exec summary"**:
|
||||
|
||||
Formal, professional format suitable for business reports.
|
||||
|
||||
```
|
||||
📊 EXECUTIVE SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
**Overview:** [1-2 sentences — what this is about]
|
||||
|
||||
**Key Findings:**
|
||||
• [Finding 1]
|
||||
• [Finding 2]
|
||||
• [Finding 3]
|
||||
|
||||
**Implications:** [What this means]
|
||||
|
||||
**Recommendation:** [Suggested next step]
|
||||
|
||||
📊 [X] words → [Y] words ([Z]% reduction)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 8: Custom Length Summary
|
||||
|
||||
When user specifies a word/sentence count:
|
||||
|
||||
- "summarize in 50 words"
|
||||
- "summarize in 3 sentences"
|
||||
- "summarize in 1 paragraph"
|
||||
- "make it shorter" / "make it longer"
|
||||
|
||||
Respect the exact word/sentence count as closely as possible. Show actual count.
|
||||
|
||||
```
|
||||
📝 SUMMARY ([requested] words)
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
[Summary matching requested length]
|
||||
|
||||
📊 Actual: [Y] words | Requested: [X] words
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 9: Meeting Summary
|
||||
|
||||
When user says **"meeting summary"** or **"meeting notes"**:
|
||||
|
||||
Format specifically for meeting content.
|
||||
|
||||
```
|
||||
🤝 MEETING SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
📅 Topic: [inferred from content]
|
||||
👥 Participants: [names mentioned]
|
||||
|
||||
**Discussed:**
|
||||
• [Topic 1 — key points]
|
||||
• [Topic 2 — key points]
|
||||
|
||||
**Decisions Made:**
|
||||
• [Decision 1]
|
||||
• [Decision 2]
|
||||
|
||||
**Action Items:**
|
||||
□ [Task] — [Owner] — [Deadline]
|
||||
□ [Task] — [Owner] — [Deadline]
|
||||
|
||||
**Next Steps:** [What happens next]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 10: Email Summary
|
||||
|
||||
When user says **"email summary"** or **"summarize this email"**:
|
||||
|
||||
```
|
||||
📧 EMAIL SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
**From:** [sender if mentioned]
|
||||
**Subject:** [inferred topic]
|
||||
**Purpose:** [Why this email was sent — 1 sentence]
|
||||
|
||||
**Key Points:**
|
||||
• [Point 1]
|
||||
• [Point 2]
|
||||
|
||||
**Action Required:** [What you need to do, if anything]
|
||||
**Urgency:** 🔴 High / 🟡 Medium / 🟢 Low
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 11: Comparison Summary
|
||||
|
||||
When user says **"compare"** and provides two texts or topics:
|
||||
|
||||
```
|
||||
⚖️ COMPARISON SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
| Aspect | Text A | Text B |
|
||||
|--------|--------|--------|
|
||||
| Main Idea | [A's main point] | [B's main point] |
|
||||
| Tone | [A's tone] | [B's tone] |
|
||||
| Key Claim | [A's claim] | [B's claim] |
|
||||
| Strength | [A's strength] | [B's strength] |
|
||||
| Weakness | [A's weakness] | [B's weakness] |
|
||||
|
||||
**Agreement:** [What both agree on]
|
||||
**Disagreement:** [Where they differ]
|
||||
**Verdict:** [Which is stronger/more credible and why]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 12: Multi-Language Summary
|
||||
|
||||
When user says **"summarize in [language]"** or **"hindi mein summarize karo"**:
|
||||
|
||||
Supported languages include but not limited to:
|
||||
Hindi, Spanish, French, German, Japanese, Chinese, Arabic, Portuguese, Italian, Korean, Russian, and more.
|
||||
|
||||
Summarize the content and output the summary IN the requested language.
|
||||
|
||||
```
|
||||
📝 SUMMARY (हिंदी)
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
[Summary in requested language]
|
||||
|
||||
📊 [X] words → [Y] words
|
||||
```
|
||||
|
||||
If user says "summarize in Hindi" — the entire summary output should be in Hindi, not just translated keywords.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 13: Thread / Conversation Summary
|
||||
|
||||
When user says **"thread summary"** or **"summarize this conversation"**:
|
||||
|
||||
```
|
||||
💬 THREAD SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
**Topic:** [What the conversation is about]
|
||||
**Participants:** [Who spoke]
|
||||
**Length:** [Number of messages/exchanges]
|
||||
|
||||
**Key Points:**
|
||||
• [Main discussion point 1]
|
||||
• [Main discussion point 2]
|
||||
|
||||
**Consensus:** [What was agreed, if anything]
|
||||
**Open Questions:** [Unresolved issues]
|
||||
**Outcome:** [Result or next step]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 14: Chapter / Section Summary
|
||||
|
||||
When user says **"chapter summary"** or pastes a long document section:
|
||||
|
||||
```
|
||||
📖 CHAPTER SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
**Title/Topic:** [Chapter title or inferred topic]
|
||||
|
||||
**Synopsis:** [2-3 sentence overview]
|
||||
|
||||
**Key Events/Points:**
|
||||
1. [First major point]
|
||||
2. [Second major point]
|
||||
3. [Third major point]
|
||||
|
||||
**Important Details:**
|
||||
• [Detail worth remembering]
|
||||
• [Detail worth remembering]
|
||||
|
||||
**Themes:** [Recurring themes or patterns]
|
||||
|
||||
📊 [X] words → [Y] words ([Z]% reduction)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 15: Progressive Summary (Short → Long)
|
||||
|
||||
When user says **"summarize at all levels"** or **"progressive summary"**:
|
||||
|
||||
Give multiple summary lengths in one response:
|
||||
|
||||
```
|
||||
📝 PROGRESSIVE SUMMARY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
🔥 TL;DR (1 sentence):
|
||||
[One-liner]
|
||||
|
||||
📋 Short (3 bullets):
|
||||
• [Point 1]
|
||||
• [Point 2]
|
||||
• [Point 3]
|
||||
|
||||
📄 Medium (1 paragraph):
|
||||
[Detailed paragraph summary]
|
||||
|
||||
📊 [X] words → 3 levels provided
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 16: Save Summary
|
||||
|
||||
When user says **"save summary"** or **"bookmark this"** after a summary:
|
||||
|
||||
Save the last summary to `~/.openclaw/summarize-pro/saved.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "sum_001",
|
||||
"timestamp": "2026-02-22T14:30:00Z",
|
||||
"format": "bullets",
|
||||
"original_words": 500,
|
||||
"summary_words": 80,
|
||||
"summary": "...",
|
||||
"topic": "inferred topic"
|
||||
}
|
||||
```
|
||||
|
||||
Confirm:
|
||||
```
|
||||
💾 Summary saved! (ID: sum_001)
|
||||
📂 Total saved: [X] summaries
|
||||
|
||||
💡 View saved: "show saved summaries"
|
||||
```
|
||||
|
||||
When user says **"show saved summaries"** or **"my saved summaries"**:
|
||||
Read `saved.json` and display list with timestamps and topics.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 17: Summary History
|
||||
|
||||
When user says **"summary history"** or **"past summaries"**:
|
||||
|
||||
Read `history.json` and show recent summaries:
|
||||
|
||||
```
|
||||
📜 SUMMARY HISTORY
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
1. 📝 "AI Ethics Article" — Feb 22, 2:30 PM — Bullets — 500→80 words
|
||||
2. 🔥 "Team Meeting Notes" — Feb 22, 11:00 AM — TL;DR — 1200→45 words
|
||||
3. 📊 "Q4 Report" — Feb 21, 4:00 PM — Executive — 3000→200 words
|
||||
|
||||
📊 Total: [X] summaries | [Y] words processed
|
||||
```
|
||||
|
||||
Log every summary to history automatically:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "hist_001",
|
||||
"timestamp": "2026-02-22T14:30:00Z",
|
||||
"format": "bullets",
|
||||
"topic": "inferred topic",
|
||||
"original_words": 500,
|
||||
"summary_words": 80
|
||||
}
|
||||
```
|
||||
|
||||
Keep last 100 entries. Auto-trim older ones.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 18: Summary Stats & Gamification
|
||||
|
||||
When user says **"summary stats"** or **"my stats"**:
|
||||
|
||||
Read `settings.json` and `history.json`:
|
||||
|
||||
```
|
||||
📊 YOUR SUMMARY STATS
|
||||
━━━━━━━━━━━━━━━━━━
|
||||
|
||||
🔢 Total Summaries: [X]
|
||||
📄 Words Processed: [Y] words
|
||||
✂️ Words Saved: [Z] words (that's [N] pages!)
|
||||
🔥 Current Streak: [X] days
|
||||
⭐ Favorite Format: Bullets (used [X] times)
|
||||
|
||||
🏆 ACHIEVEMENTS
|
||||
• 📝 First Summary — Summarized your first text ✅
|
||||
• 🔟 Power Reader — 10 summaries done ✅
|
||||
• 💯 Century Club — 100 summaries done [locked]
|
||||
• 📚 Bookworm — 10,000 words processed ✅
|
||||
• ⚡ Speed Reader — 50,000 words processed [locked]
|
||||
• 🌍 Polyglot — Summarized in 3+ languages [locked]
|
||||
• 📋 Format Master — Used all 5 formats ✅
|
||||
• 🔥 Week Warrior — 7-day streak [locked]
|
||||
|
||||
Keep summarizing to unlock more! 🚀
|
||||
```
|
||||
|
||||
Update stats after every summary.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 19: Custom Templates
|
||||
|
||||
When user says **"create template [name]"** or **"my templates"**:
|
||||
|
||||
Let users define their own summary format:
|
||||
|
||||
```
|
||||
User: "create template standup"
|
||||
Bot: What sections should your 'standup' template include?
|
||||
|
||||
User: "what I did yesterday, what I'm doing today, blockers"
|
||||
|
||||
Bot: ✅ Template 'standup' created!
|
||||
|
||||
Sections:
|
||||
1. Yesterday
|
||||
2. Today
|
||||
3. Blockers
|
||||
|
||||
Use it: "summarize as standup: [paste text]"
|
||||
```
|
||||
|
||||
Save to `~/.openclaw/summarize-pro/templates.json`.
|
||||
|
||||
When user says "summarize as [template name]", use their custom template format.
|
||||
|
||||
---
|
||||
|
||||
## FEATURE 20: Smart Format Detection
|
||||
|
||||
When no format is specified, auto-detect the best format based on content:
|
||||
|
||||
| Content Type | Auto Format |
|
||||
|---|---|
|
||||
| Email | Email Summary (Feature 10) |
|
||||
| Meeting transcript | Meeting Summary (Feature 9) |
|
||||
| News article | Key Takeaways (Feature 5) |
|
||||
| Technical document | Executive Summary (Feature 7) |
|
||||
| Conversation/chat | Thread Summary (Feature 13) |
|
||||
| Book excerpt | Chapter Summary (Feature 14) |
|
||||
| Task-heavy text | Action Items (Feature 6) |
|
||||
| Short text (<100 words) | TL;DR (Feature 2) |
|
||||
| General text | Bullet Points (Feature 3) |
|
||||
|
||||
Tell the user which format was auto-selected:
|
||||
```
|
||||
🤖 Auto-detected: Meeting transcript → Using Meeting Summary format
|
||||
|
||||
🤝 MEETING SUMMARY
|
||||
...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Behavior Rules
|
||||
|
||||
1. **Always count words** — show original vs summary word count
|
||||
2. **Be accurate** — never add information not in the original text
|
||||
3. **Be concise** — remove fluff, keep substance
|
||||
4. **Preserve key facts** — names, numbers, dates, quotes must stay accurate
|
||||
5. **Adapt tone** — match the formality of the original content
|
||||
6. **Handle edge cases:**
|
||||
- If text is too short (<30 words): "This text is already quite short! Here's a one-liner:"
|
||||
- If text is unclear/garbled: "The text seems unclear. Here's my best interpretation:"
|
||||
- If no text provided: "Please paste the text you'd like me to summarize!"
|
||||
7. **Auto-log** every summary to history.json
|
||||
8. **Update stats** after every summary (words processed, count, streak)
|
||||
9. **Never fabricate** — if something isn't in the text, don't include it in the summary
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
- If user says "summarize" with no text: Ask them to paste text
|
||||
- If text is in a language AI doesn't recognize well: Try best effort, note uncertainty
|
||||
- If file read fails: Create fresh file and inform user
|
||||
- If history is corrupted: Back up old file, create new one
|
||||
|
||||
---
|
||||
|
||||
## Data Safety
|
||||
|
||||
1. Never expose raw JSON to users — always format nicely
|
||||
2. Back up before any destructive operation
|
||||
3. Keep all data LOCAL — never send to external servers
|
||||
4. Maximum 100 entries in history (auto-trim oldest)
|
||||
5. Saved summaries have no limit but warn at 500+
|
||||
|
||||
---
|
||||
|
||||
## Updated Commands
|
||||
|
||||
```
|
||||
SUMMARIZATION:
|
||||
"summarize [text]" — Default summary (auto-detect format)
|
||||
"tldr [text]" — 1-2 sentence summary
|
||||
"bullets [text]" — Bullet point summary
|
||||
"eli5 [text]" — Explain Like I'm 5
|
||||
"key takeaways [text]" — Top insights ranked
|
||||
"action items [text]" — Extract tasks & deadlines
|
||||
"exec summary [text]" — Business executive format
|
||||
"summarize in 50 words" — Custom length
|
||||
"meeting summary [text]" — Meeting notes format
|
||||
"email summary [text]" — Email digest format
|
||||
"compare [text A] vs [text B]" — Side-by-side comparison
|
||||
"summarize in hindi [text]" — Any language summary
|
||||
"thread summary [text]" — Conversation summary
|
||||
"chapter summary [text]" — Book/document chapter
|
||||
"progressive summary [text]"— All levels (TL;DR → Short → Medium)
|
||||
|
||||
MANAGEMENT:
|
||||
"save summary" — Bookmark last summary
|
||||
"show saved summaries" — View bookmarks
|
||||
"summary history" — Past summaries log
|
||||
"summary stats" — Your stats & achievements
|
||||
"create template [name]" — Custom format template
|
||||
"my templates" — View saved templates
|
||||
"set default [format]" — Change default format
|
||||
"help" — Show all commands
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Built by **Manish Pareek** ([@Mkpareek19_](https://x.com/Mkpareek19_))
|
||||
|
||||
Free forever. All data stays on your machine. 🦞
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ownerId": "kn7f98n8bjpgy8dcxpgzgfs14981ezb4",
|
||||
"slug": "summarize-pro",
|
||||
"version": "1.0.0",
|
||||
"publishedAt": 1771753198757
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"registry": "https://clawhub.ai",
|
||||
"slug": "web-search",
|
||||
"installedVersion": "1.0.0",
|
||||
"installedAt": 1777007388844
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
---
|
||||
name: web-search
|
||||
description: This skill should be used when users need to search the web for information, find current content, look up news articles, search for images, or find videos. It uses DuckDuckGo's search API to return results in clean, formatted output (text, markdown, or JSON). Use for research, fact-checking, finding recent information, or gathering web resources.
|
||||
---
|
||||
|
||||
# Web Search
|
||||
|
||||
## Overview
|
||||
|
||||
Search the web using DuckDuckGo's API to find information across web pages, news articles, images, and videos. Returns results in multiple formats (text, markdown, JSON) with filtering options for time range, region, and safe search.
|
||||
|
||||
## When to Use This Skill
|
||||
|
||||
Use this skill when users request:
|
||||
- Web searches for information or resources
|
||||
- Finding current or recent information online
|
||||
- Looking up news articles about specific topics
|
||||
- Searching for images by description or topic
|
||||
- Finding videos on specific subjects
|
||||
- Research requiring current web data
|
||||
- Fact-checking or verification using web sources
|
||||
- Gathering URLs and resources on a topic
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Install the required dependency:
|
||||
|
||||
```bash
|
||||
pip install duckduckgo-search
|
||||
```
|
||||
|
||||
This library provides a simple Python interface to DuckDuckGo's search API without requiring API keys or authentication.
|
||||
|
||||
## Core Capabilities
|
||||
|
||||
### 1. Basic Web Search
|
||||
|
||||
Search for web pages and information:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>"
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "python asyncio tutorial"
|
||||
```
|
||||
|
||||
Returns the top 10 web results with titles, URLs, and descriptions in a clean text format.
|
||||
|
||||
### 2. Limiting Results
|
||||
|
||||
Control the number of results returned:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --max-results <N>
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "machine learning frameworks" --max-results 20
|
||||
```
|
||||
|
||||
Useful for:
|
||||
- Getting more comprehensive results (increase limit)
|
||||
- Quick lookups with fewer results (decrease limit)
|
||||
- Balancing detail vs. processing time
|
||||
|
||||
### 3. Time Range Filtering
|
||||
|
||||
Filter results by recency:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --time-range <d|w|m|y>
|
||||
```
|
||||
|
||||
**Time range options:**
|
||||
- `d` - Past day
|
||||
- `w` - Past week
|
||||
- `m` - Past month
|
||||
- `y` - Past year
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "artificial intelligence news" --time-range w
|
||||
```
|
||||
|
||||
Great for:
|
||||
- Finding recent news or updates
|
||||
- Filtering out outdated content
|
||||
- Tracking recent developments
|
||||
|
||||
### 4. News Search
|
||||
|
||||
Search specifically for news articles:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --type news
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "climate change" --type news --time-range w --max-results 15
|
||||
```
|
||||
|
||||
News results include:
|
||||
- Article title
|
||||
- Source publication
|
||||
- Publication date
|
||||
- URL
|
||||
- Article summary/description
|
||||
|
||||
### 5. Image Search
|
||||
|
||||
Search for images:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --type images
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "sunset over mountains" --type images --max-results 20
|
||||
```
|
||||
|
||||
**Image filtering options:**
|
||||
|
||||
Size filters:
|
||||
```bash
|
||||
python scripts/search.py "landscape photos" --type images --image-size Large
|
||||
```
|
||||
Options: `Small`, `Medium`, `Large`, `Wallpaper`
|
||||
|
||||
Color filters:
|
||||
```bash
|
||||
python scripts/search.py "abstract art" --type images --image-color Blue
|
||||
```
|
||||
Options: `color`, `Monochrome`, `Red`, `Orange`, `Yellow`, `Green`, `Blue`, `Purple`, `Pink`, `Brown`, `Black`, `Gray`, `Teal`, `White`
|
||||
|
||||
Type filters:
|
||||
```bash
|
||||
python scripts/search.py "icons" --type images --image-type transparent
|
||||
```
|
||||
Options: `photo`, `clipart`, `gif`, `transparent`, `line`
|
||||
|
||||
Layout filters:
|
||||
```bash
|
||||
python scripts/search.py "wallpapers" --type images --image-layout Wide
|
||||
```
|
||||
Options: `Square`, `Tall`, `Wide`
|
||||
|
||||
Image results include:
|
||||
- Image title
|
||||
- Image URL (direct link to image)
|
||||
- Thumbnail URL
|
||||
- Source website
|
||||
- Dimensions (width x height)
|
||||
|
||||
### 6. Video Search
|
||||
|
||||
Search for videos:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --type videos
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "python tutorial" --type videos --max-results 15
|
||||
```
|
||||
|
||||
**Video filtering options:**
|
||||
|
||||
Duration filters:
|
||||
```bash
|
||||
python scripts/search.py "cooking recipes" --type videos --video-duration short
|
||||
```
|
||||
Options: `short`, `medium`, `long`
|
||||
|
||||
Resolution filters:
|
||||
```bash
|
||||
python scripts/search.py "documentary" --type videos --video-resolution high
|
||||
```
|
||||
Options: `high`, `standard`
|
||||
|
||||
Video results include:
|
||||
- Video title
|
||||
- Publisher/channel
|
||||
- Duration
|
||||
- Publication date
|
||||
- Video URL
|
||||
- Description
|
||||
|
||||
### 7. Region-Specific Search
|
||||
|
||||
Search with region-specific results:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --region <region-code>
|
||||
```
|
||||
|
||||
**Common region codes:**
|
||||
- `us-en` - United States (English)
|
||||
- `uk-en` - United Kingdom (English)
|
||||
- `ca-en` - Canada (English)
|
||||
- `au-en` - Australia (English)
|
||||
- `de-de` - Germany (German)
|
||||
- `fr-fr` - France (French)
|
||||
- `wt-wt` - Worldwide (default)
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "local news" --region us-en --type news
|
||||
```
|
||||
|
||||
### 8. Safe Search Control
|
||||
|
||||
Control safe search filtering:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --safe-search <on|moderate|off>
|
||||
```
|
||||
|
||||
**Options:**
|
||||
- `on` - Strict filtering
|
||||
- `moderate` - Balanced filtering (default)
|
||||
- `off` - No filtering
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "medical information" --safe-search on
|
||||
```
|
||||
|
||||
### 9. Output Formats
|
||||
|
||||
Choose how results are formatted:
|
||||
|
||||
**Text format (default):**
|
||||
```bash
|
||||
python scripts/search.py "quantum computing"
|
||||
```
|
||||
|
||||
Clean, readable plain text with numbered results.
|
||||
|
||||
**Markdown format:**
|
||||
```bash
|
||||
python scripts/search.py "quantum computing" --format markdown
|
||||
```
|
||||
|
||||
Formatted markdown with headers, bold text, and links.
|
||||
|
||||
**JSON format:**
|
||||
```bash
|
||||
python scripts/search.py "quantum computing" --format json
|
||||
```
|
||||
|
||||
Structured JSON data for programmatic processing.
|
||||
|
||||
### 10. Saving Results to File
|
||||
|
||||
Save search results to a file:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "<query>" --output <file-path>
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
python scripts/search.py "artificial intelligence" --output ai_results.txt
|
||||
python scripts/search.py "AI news" --type news --format markdown --output ai_news.md
|
||||
python scripts/search.py "AI research" --format json --output ai_data.json
|
||||
```
|
||||
|
||||
The file format is determined by the `--format` flag, not the file extension.
|
||||
|
||||
## Output Format Examples
|
||||
|
||||
### Text Format
|
||||
```
|
||||
1. Page Title Here
|
||||
URL: https://example.com/page
|
||||
Brief description of the page content...
|
||||
|
||||
2. Another Result
|
||||
URL: https://example.com/another
|
||||
Another description...
|
||||
```
|
||||
|
||||
### Markdown Format
|
||||
```markdown
|
||||
## 1. Page Title Here
|
||||
|
||||
**URL:** https://example.com/page
|
||||
|
||||
Brief description of the page content...
|
||||
|
||||
## 2. Another Result
|
||||
|
||||
**URL:** https://example.com/another
|
||||
|
||||
Another description...
|
||||
```
|
||||
|
||||
### JSON Format
|
||||
```json
|
||||
[
|
||||
{
|
||||
"title": "Page Title Here",
|
||||
"href": "https://example.com/page",
|
||||
"body": "Brief description of the page content..."
|
||||
},
|
||||
{
|
||||
"title": "Another Result",
|
||||
"href": "https://example.com/another",
|
||||
"body": "Another description..."
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## Common Usage Patterns
|
||||
|
||||
### Research on a Topic
|
||||
|
||||
Gather comprehensive information about a subject:
|
||||
|
||||
```bash
|
||||
# Get overview from web
|
||||
python scripts/search.py "machine learning basics" --max-results 15 --output ml_web.txt
|
||||
|
||||
# Get recent news
|
||||
python scripts/search.py "machine learning" --type news --time-range m --output ml_news.txt
|
||||
|
||||
# Find tutorial videos
|
||||
python scripts/search.py "machine learning tutorial" --type videos --max-results 10 --output ml_videos.txt
|
||||
```
|
||||
|
||||
### Current Events Monitoring
|
||||
|
||||
Track news on specific topics:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "climate summit" --type news --time-range d --format markdown --output daily_climate_news.md
|
||||
```
|
||||
|
||||
### Finding Visual Resources
|
||||
|
||||
Search for images with specific criteria:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "data visualization examples" --type images --image-type photo --image-size Large --max-results 25 --output viz_images.txt
|
||||
```
|
||||
|
||||
### Fact-Checking
|
||||
|
||||
Verify information with recent sources:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "specific claim to verify" --time-range w --max-results 20
|
||||
```
|
||||
|
||||
### Academic Research
|
||||
|
||||
Find resources on scholarly topics:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "quantum entanglement research" --time-range y --max-results 30 --output quantum_research.txt
|
||||
```
|
||||
|
||||
### Market Research
|
||||
|
||||
Gather information about products or companies:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "electric vehicle market 2025" --max-results 20 --format markdown --output ev_market.md
|
||||
python scripts/search.py "EV news" --type news --time-range m --output ev_news.txt
|
||||
```
|
||||
|
||||
## Implementation Approach
|
||||
|
||||
When users request web searches:
|
||||
|
||||
1. **Identify search intent**:
|
||||
- What type of content (web, news, images, videos)?
|
||||
- How recent should results be?
|
||||
- How many results are needed?
|
||||
- Any filtering requirements?
|
||||
|
||||
2. **Configure search parameters**:
|
||||
- Choose appropriate search type (`--type`)
|
||||
- Set time range if currency matters (`--time-range`)
|
||||
- Adjust result count (`--max-results`)
|
||||
- Apply filters (image size, video duration, etc.)
|
||||
|
||||
3. **Select output format**:
|
||||
- Text for quick reading
|
||||
- Markdown for documentation
|
||||
- JSON for further processing
|
||||
|
||||
4. **Execute search**:
|
||||
- Run the search command
|
||||
- Save to file if results need to be preserved
|
||||
- Print to stdout for immediate review
|
||||
|
||||
5. **Process results**:
|
||||
- Read saved files if needed
|
||||
- Extract URLs or specific information
|
||||
- Combine results from multiple searches
|
||||
|
||||
## Quick Reference
|
||||
|
||||
**Command structure:**
|
||||
```bash
|
||||
python scripts/search.py "<query>" [options]
|
||||
```
|
||||
|
||||
**Essential options:**
|
||||
- `-t, --type` - Search type (web, news, images, videos)
|
||||
- `-n, --max-results` - Maximum results (default: 10)
|
||||
- `--time-range` - Time filter (d, w, m, y)
|
||||
- `-r, --region` - Region code (e.g., us-en, uk-en)
|
||||
- `--safe-search` - Safe search level (on, moderate, off)
|
||||
- `-f, --format` - Output format (text, markdown, json)
|
||||
- `-o, --output` - Save to file
|
||||
|
||||
**Image-specific options:**
|
||||
- `--image-size` - Size filter (Small, Medium, Large, Wallpaper)
|
||||
- `--image-color` - Color filter
|
||||
- `--image-type` - Type filter (photo, clipart, gif, transparent, line)
|
||||
- `--image-layout` - Layout filter (Square, Tall, Wide)
|
||||
|
||||
**Video-specific options:**
|
||||
- `--video-duration` - Duration filter (short, medium, long)
|
||||
- `--video-resolution` - Resolution filter (high, standard)
|
||||
|
||||
**Get full help:**
|
||||
```bash
|
||||
python scripts/search.py --help
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Be specific** - Use clear, specific search queries for better results
|
||||
2. **Use time filters** - Apply `--time-range` for current information
|
||||
3. **Adjust result count** - Start with 10-20 results, increase if needed
|
||||
4. **Save important searches** - Use `--output` to preserve results
|
||||
5. **Choose appropriate type** - Use news search for current events, web for general info
|
||||
6. **Use JSON for automation** - JSON format is easiest to parse programmatically
|
||||
7. **Respect usage** - Don't hammer the API with rapid repeated searches
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Common issues:**
|
||||
|
||||
- **"Missing required dependency"**: Run `pip install duckduckgo-search`
|
||||
- **No results found**: Try broader search terms or remove time filters
|
||||
- **Timeout errors**: The search service may be temporarily unavailable; retry after a moment
|
||||
- **Rate limiting**: Space out searches if making many requests
|
||||
- **Unexpected results**: DuckDuckGo's results may differ from Google; try refining the query
|
||||
|
||||
**Limitations:**
|
||||
|
||||
- Results quality depends on DuckDuckGo's index and algorithms
|
||||
- No advanced search operators (unlike Google's site:, filetype:, etc.)
|
||||
- Image and video searches may have fewer results than web search
|
||||
- No control over result ranking or relevance scoring
|
||||
- Some specialized searches may work better on dedicated search engines
|
||||
|
||||
## Advanced Use Cases
|
||||
|
||||
### Combining Multiple Searches
|
||||
|
||||
Gather comprehensive information by combining search types:
|
||||
|
||||
```bash
|
||||
# Web overview
|
||||
python scripts/search.py "topic" --max-results 15 --output topic_web.txt
|
||||
|
||||
# Recent news
|
||||
python scripts/search.py "topic" --type news --time-range w --output topic_news.txt
|
||||
|
||||
# Images
|
||||
python scripts/search.py "topic" --type images --max-results 20 --output topic_images.txt
|
||||
```
|
||||
|
||||
### Programmatic Processing
|
||||
|
||||
Use JSON output for automated processing:
|
||||
|
||||
```bash
|
||||
python scripts/search.py "research topic" --format json --output results.json
|
||||
# Then process with another script
|
||||
python analyze_results.py results.json
|
||||
```
|
||||
|
||||
### Building a Knowledge Base
|
||||
|
||||
Create searchable documentation from web results:
|
||||
|
||||
```bash
|
||||
# Search multiple related topics
|
||||
python scripts/search.py "topic1" --format markdown --output kb/topic1.md
|
||||
python scripts/search.py "topic2" --format markdown --output kb/topic2.md
|
||||
python scripts/search.py "topic3" --format markdown --output kb/topic3.md
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
### scripts/search.py
|
||||
|
||||
The main search tool implementing DuckDuckGo search functionality. Key features:
|
||||
|
||||
- **Multiple search types** - Web, news, images, and videos
|
||||
- **Flexible filtering** - Time range, region, safe search, and type-specific filters
|
||||
- **Multiple output formats** - Text, Markdown, and JSON
|
||||
- **File output** - Save results for later processing
|
||||
- **Clean formatting** - Human-readable output with all essential information
|
||||
- **Error handling** - Graceful handling of network errors and empty results
|
||||
|
||||
The script can be executed directly and includes comprehensive command-line help via `--help`.
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ownerId": "kn7cz85m29bj398zc6mnggkv19805nzz",
|
||||
"slug": "web-search",
|
||||
"version": "1.0.0",
|
||||
"publishedAt": 1769673454302
|
||||
}
|
||||
@@ -0,0 +1,576 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Web Search Tool
|
||||
|
||||
Search the web using DuckDuckGo's search API. Supports web search, news,
|
||||
images, and videos with various output formats.
|
||||
|
||||
Requirements:
|
||||
pip install duckduckgo-search
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Optional, Any
|
||||
|
||||
try:
|
||||
from duckduckgo_search import DDGS
|
||||
except ImportError as e:
|
||||
print(f"Error: Missing required dependency: {e}", file=sys.stderr)
|
||||
print("Install with: pip install duckduckgo-search", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class WebSearch:
|
||||
"""Web search using DuckDuckGo."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
region: str = "wt-wt",
|
||||
safe_search: str = "moderate",
|
||||
timeout: int = 20,
|
||||
):
|
||||
"""
|
||||
Initialize the search client.
|
||||
|
||||
Args:
|
||||
region: Region code (e.g., "us-en", "uk-en", "wt-wt" for worldwide)
|
||||
safe_search: Safe search setting ("on", "moderate", "off")
|
||||
timeout: Request timeout in seconds
|
||||
"""
|
||||
self.region = region
|
||||
self.safe_search = safe_search
|
||||
self.timeout = timeout
|
||||
|
||||
def search_text(
|
||||
self,
|
||||
query: str,
|
||||
max_results: int = 10,
|
||||
time_range: Optional[str] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Perform a text/web search.
|
||||
|
||||
Args:
|
||||
query: Search query
|
||||
max_results: Maximum number of results (default: 10)
|
||||
time_range: Time filter ("d" day, "w" week, "m" month, "y" year)
|
||||
|
||||
Returns:
|
||||
List of search results with title, href, and body
|
||||
"""
|
||||
try:
|
||||
with DDGS() as ddgs:
|
||||
results = list(ddgs.text(
|
||||
keywords=query,
|
||||
region=self.region,
|
||||
safesearch=self.safe_search,
|
||||
timelimit=time_range,
|
||||
max_results=max_results,
|
||||
))
|
||||
return results
|
||||
except Exception as e:
|
||||
print(f"Error performing text search: {e}", file=sys.stderr)
|
||||
return []
|
||||
|
||||
def search_news(
|
||||
self,
|
||||
query: str,
|
||||
max_results: int = 10,
|
||||
time_range: Optional[str] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Search for news articles.
|
||||
|
||||
Args:
|
||||
query: Search query
|
||||
max_results: Maximum number of results
|
||||
time_range: Time filter ("d" day, "w" week, "m" month)
|
||||
|
||||
Returns:
|
||||
List of news results with title, url, body, date, source
|
||||
"""
|
||||
try:
|
||||
with DDGS() as ddgs:
|
||||
results = list(ddgs.news(
|
||||
keywords=query,
|
||||
region=self.region,
|
||||
safesearch=self.safe_search,
|
||||
timelimit=time_range,
|
||||
max_results=max_results,
|
||||
))
|
||||
return results
|
||||
except Exception as e:
|
||||
print(f"Error performing news search: {e}", file=sys.stderr)
|
||||
return []
|
||||
|
||||
def search_images(
|
||||
self,
|
||||
query: str,
|
||||
max_results: int = 10,
|
||||
size: Optional[str] = None,
|
||||
color: Optional[str] = None,
|
||||
type_image: Optional[str] = None,
|
||||
layout: Optional[str] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Search for images.
|
||||
|
||||
Args:
|
||||
query: Search query
|
||||
max_results: Maximum number of results
|
||||
size: Image size ("Small", "Medium", "Large", "Wallpaper")
|
||||
color: Color filter ("color", "Monochrome", "Red", "Orange", "Yellow",
|
||||
"Green", "Blue", "Purple", "Pink", "Brown", "Black", "Gray", "Teal", "White")
|
||||
type_image: Image type ("photo", "clipart", "gif", "transparent", "line")
|
||||
layout: Layout ("Square", "Tall", "Wide")
|
||||
|
||||
Returns:
|
||||
List of image results with title, image URL, thumbnail, source, etc.
|
||||
"""
|
||||
try:
|
||||
with DDGS() as ddgs:
|
||||
results = list(ddgs.images(
|
||||
keywords=query,
|
||||
region=self.region,
|
||||
safesearch=self.safe_search,
|
||||
size=size,
|
||||
color=color,
|
||||
type_image=type_image,
|
||||
layout=layout,
|
||||
max_results=max_results,
|
||||
))
|
||||
return results
|
||||
except Exception as e:
|
||||
print(f"Error performing image search: {e}", file=sys.stderr)
|
||||
return []
|
||||
|
||||
def search_videos(
|
||||
self,
|
||||
query: str,
|
||||
max_results: int = 10,
|
||||
duration: Optional[str] = None,
|
||||
resolution: Optional[str] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Search for videos.
|
||||
|
||||
Args:
|
||||
query: Search query
|
||||
max_results: Maximum number of results
|
||||
duration: Video duration ("short", "medium", "long")
|
||||
resolution: Video resolution ("high", "standard")
|
||||
|
||||
Returns:
|
||||
List of video results with title, content, description, publisher, etc.
|
||||
"""
|
||||
try:
|
||||
with DDGS() as ddgs:
|
||||
results = list(ddgs.videos(
|
||||
keywords=query,
|
||||
region=self.region,
|
||||
safesearch=self.safe_search,
|
||||
duration=duration,
|
||||
resolution=resolution,
|
||||
max_results=max_results,
|
||||
))
|
||||
return results
|
||||
except Exception as e:
|
||||
print(f"Error performing video search: {e}", file=sys.stderr)
|
||||
return []
|
||||
|
||||
|
||||
def format_text_results(results: List[Dict[str, Any]], format_type: str = "text") -> str:
|
||||
"""
|
||||
Format search results for display.
|
||||
|
||||
Args:
|
||||
results: List of search results
|
||||
format_type: Output format ("text", "markdown", "json")
|
||||
|
||||
Returns:
|
||||
Formatted string
|
||||
"""
|
||||
if not results:
|
||||
return "No results found."
|
||||
|
||||
if format_type == "json":
|
||||
return json.dumps(results, indent=2, ensure_ascii=False)
|
||||
|
||||
elif format_type == "markdown":
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
url = result.get('href') or result.get('url', '')
|
||||
body = result.get('body') or result.get('description', '')
|
||||
|
||||
output.append(f"## {i}. {title}\n")
|
||||
output.append(f"**URL:** {url}\n")
|
||||
if body:
|
||||
output.append(f"{body}\n")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
else: # text format
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
url = result.get('href') or result.get('url', '')
|
||||
body = result.get('body') or result.get('description', '')
|
||||
|
||||
output.append(f"{i}. {title}")
|
||||
output.append(f" URL: {url}")
|
||||
if body:
|
||||
# Wrap body text
|
||||
output.append(f" {body}")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def format_news_results(results: List[Dict[str, Any]], format_type: str = "text") -> str:
|
||||
"""Format news search results."""
|
||||
if not results:
|
||||
return "No news results found."
|
||||
|
||||
if format_type == "json":
|
||||
return json.dumps(results, indent=2, ensure_ascii=False)
|
||||
|
||||
elif format_type == "markdown":
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
url = result.get('url', '')
|
||||
body = result.get('body', '')
|
||||
date = result.get('date', '')
|
||||
source = result.get('source', '')
|
||||
|
||||
output.append(f"## {i}. {title}\n")
|
||||
if source:
|
||||
output.append(f"**Source:** {source}")
|
||||
if date:
|
||||
output.append(f"**Date:** {date}")
|
||||
output.append(f"**URL:** {url}\n")
|
||||
if body:
|
||||
output.append(f"{body}\n")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
else: # text format
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
url = result.get('url', '')
|
||||
body = result.get('body', '')
|
||||
date = result.get('date', '')
|
||||
source = result.get('source', '')
|
||||
|
||||
output.append(f"{i}. {title}")
|
||||
if source and date:
|
||||
output.append(f" {source} - {date}")
|
||||
elif source:
|
||||
output.append(f" {source}")
|
||||
elif date:
|
||||
output.append(f" {date}")
|
||||
output.append(f" URL: {url}")
|
||||
if body:
|
||||
output.append(f" {body}")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def format_image_results(results: List[Dict[str, Any]], format_type: str = "text") -> str:
|
||||
"""Format image search results."""
|
||||
if not results:
|
||||
return "No image results found."
|
||||
|
||||
if format_type == "json":
|
||||
return json.dumps(results, indent=2, ensure_ascii=False)
|
||||
|
||||
elif format_type == "markdown":
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
image_url = result.get('image', '')
|
||||
thumbnail = result.get('thumbnail', '')
|
||||
source = result.get('source', '')
|
||||
width = result.get('width', '')
|
||||
height = result.get('height', '')
|
||||
|
||||
output.append(f"## {i}. {title}\n")
|
||||
if width and height:
|
||||
output.append(f"**Dimensions:** {width}x{height}")
|
||||
if source:
|
||||
output.append(f"**Source:** {source}")
|
||||
output.append(f"**Image URL:** {image_url}")
|
||||
if thumbnail:
|
||||
output.append(f"**Thumbnail:** {thumbnail}")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
else: # text format
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
image_url = result.get('image', '')
|
||||
source = result.get('source', '')
|
||||
width = result.get('width', '')
|
||||
height = result.get('height', '')
|
||||
|
||||
output.append(f"{i}. {title}")
|
||||
if width and height:
|
||||
output.append(f" Dimensions: {width}x{height}")
|
||||
if source:
|
||||
output.append(f" Source: {source}")
|
||||
output.append(f" Image URL: {image_url}")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def format_video_results(results: List[Dict[str, Any]], format_type: str = "text") -> str:
|
||||
"""Format video search results."""
|
||||
if not results:
|
||||
return "No video results found."
|
||||
|
||||
if format_type == "json":
|
||||
return json.dumps(results, indent=2, ensure_ascii=False)
|
||||
|
||||
elif format_type == "markdown":
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
url = result.get('content', '')
|
||||
description = result.get('description', '')
|
||||
publisher = result.get('publisher', '')
|
||||
duration = result.get('duration', '')
|
||||
published = result.get('published', '')
|
||||
|
||||
output.append(f"## {i}. {title}\n")
|
||||
if publisher:
|
||||
output.append(f"**Publisher:** {publisher}")
|
||||
if duration:
|
||||
output.append(f"**Duration:** {duration}")
|
||||
if published:
|
||||
output.append(f"**Published:** {published}")
|
||||
output.append(f"**URL:** {url}\n")
|
||||
if description:
|
||||
output.append(f"{description}\n")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
else: # text format
|
||||
output = []
|
||||
for i, result in enumerate(results, 1):
|
||||
title = result.get('title', 'No title')
|
||||
url = result.get('content', '')
|
||||
description = result.get('description', '')
|
||||
publisher = result.get('publisher', '')
|
||||
duration = result.get('duration', '')
|
||||
|
||||
output.append(f"{i}. {title}")
|
||||
if publisher and duration:
|
||||
output.append(f" {publisher} - {duration}")
|
||||
elif publisher:
|
||||
output.append(f" {publisher}")
|
||||
output.append(f" URL: {url}")
|
||||
if description:
|
||||
output.append(f" {description}")
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Search the web using DuckDuckGo",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Basic web search
|
||||
%(prog)s "python tutorials"
|
||||
|
||||
# Search with more results
|
||||
%(prog)s "machine learning" --max-results 20
|
||||
|
||||
# News search
|
||||
%(prog)s "climate change" --type news --time-range w
|
||||
|
||||
# Image search
|
||||
%(prog)s "sunset photos" --type images --max-results 15
|
||||
|
||||
# Save results to file
|
||||
%(prog)s "artificial intelligence" --output results.txt
|
||||
|
||||
# JSON output format
|
||||
%(prog)s "quantum computing" --format json --output results.json
|
||||
|
||||
# Region-specific search
|
||||
%(prog)s "local news" --region us-en --type news
|
||||
|
||||
Time range filters (--time-range):
|
||||
d = past day
|
||||
w = past week
|
||||
m = past month
|
||||
y = past year
|
||||
"""
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'query',
|
||||
help='Search query'
|
||||
)
|
||||
|
||||
# Search options
|
||||
search_group = parser.add_argument_group('search options')
|
||||
search_group.add_argument(
|
||||
'-t', '--type',
|
||||
choices=['web', 'news', 'images', 'videos'],
|
||||
default='web',
|
||||
help='Search type (default: web)'
|
||||
)
|
||||
search_group.add_argument(
|
||||
'-n', '--max-results',
|
||||
type=int,
|
||||
default=10,
|
||||
help='Maximum number of results (default: 10)'
|
||||
)
|
||||
search_group.add_argument(
|
||||
'--time-range',
|
||||
choices=['d', 'w', 'm', 'y'],
|
||||
help='Time range filter (d=day, w=week, m=month, y=year)'
|
||||
)
|
||||
search_group.add_argument(
|
||||
'-r', '--region',
|
||||
default='wt-wt',
|
||||
help='Region code (e.g., us-en, uk-en, wt-wt for worldwide, default: wt-wt)'
|
||||
)
|
||||
search_group.add_argument(
|
||||
'--safe-search',
|
||||
choices=['on', 'moderate', 'off'],
|
||||
default='moderate',
|
||||
help='Safe search setting (default: moderate)'
|
||||
)
|
||||
|
||||
# Image-specific options
|
||||
image_group = parser.add_argument_group('image search options')
|
||||
image_group.add_argument(
|
||||
'--image-size',
|
||||
choices=['Small', 'Medium', 'Large', 'Wallpaper'],
|
||||
help='Image size filter'
|
||||
)
|
||||
image_group.add_argument(
|
||||
'--image-color',
|
||||
choices=['color', 'Monochrome', 'Red', 'Orange', 'Yellow', 'Green',
|
||||
'Blue', 'Purple', 'Pink', 'Brown', 'Black', 'Gray', 'Teal', 'White'],
|
||||
help='Image color filter'
|
||||
)
|
||||
image_group.add_argument(
|
||||
'--image-type',
|
||||
choices=['photo', 'clipart', 'gif', 'transparent', 'line'],
|
||||
help='Image type filter'
|
||||
)
|
||||
image_group.add_argument(
|
||||
'--image-layout',
|
||||
choices=['Square', 'Tall', 'Wide'],
|
||||
help='Image layout filter'
|
||||
)
|
||||
|
||||
# Video-specific options
|
||||
video_group = parser.add_argument_group('video search options')
|
||||
video_group.add_argument(
|
||||
'--video-duration',
|
||||
choices=['short', 'medium', 'long'],
|
||||
help='Video duration filter'
|
||||
)
|
||||
video_group.add_argument(
|
||||
'--video-resolution',
|
||||
choices=['high', 'standard'],
|
||||
help='Video resolution filter'
|
||||
)
|
||||
|
||||
# Output options
|
||||
output_group = parser.add_argument_group('output options')
|
||||
output_group.add_argument(
|
||||
'-f', '--format',
|
||||
choices=['text', 'markdown', 'json'],
|
||||
default='text',
|
||||
help='Output format (default: text)'
|
||||
)
|
||||
output_group.add_argument(
|
||||
'-o', '--output',
|
||||
help='Output file path (prints to stdout if not specified)'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Initialize search client
|
||||
searcher = WebSearch(
|
||||
region=args.region,
|
||||
safe_search=args.safe_search,
|
||||
)
|
||||
|
||||
# Perform search based on type
|
||||
print(f"Searching for: {args.query}", file=sys.stderr)
|
||||
print(f"Type: {args.type}, Max results: {args.max_results}", file=sys.stderr)
|
||||
if args.time_range:
|
||||
time_labels = {'d': 'past day', 'w': 'past week', 'm': 'past month', 'y': 'past year'}
|
||||
print(f"Time range: {time_labels[args.time_range]}", file=sys.stderr)
|
||||
print("", file=sys.stderr)
|
||||
|
||||
results = []
|
||||
formatter = format_text_results
|
||||
|
||||
if args.type == 'web':
|
||||
results = searcher.search_text(
|
||||
query=args.query,
|
||||
max_results=args.max_results,
|
||||
time_range=args.time_range,
|
||||
)
|
||||
formatter = format_text_results
|
||||
|
||||
elif args.type == 'news':
|
||||
results = searcher.search_news(
|
||||
query=args.query,
|
||||
max_results=args.max_results,
|
||||
time_range=args.time_range,
|
||||
)
|
||||
formatter = format_news_results
|
||||
|
||||
elif args.type == 'images':
|
||||
results = searcher.search_images(
|
||||
query=args.query,
|
||||
max_results=args.max_results,
|
||||
size=args.image_size,
|
||||
color=args.image_color,
|
||||
type_image=args.image_type,
|
||||
layout=args.image_layout,
|
||||
)
|
||||
formatter = format_image_results
|
||||
|
||||
elif args.type == 'videos':
|
||||
results = searcher.search_videos(
|
||||
query=args.query,
|
||||
max_results=args.max_results,
|
||||
duration=args.video_duration,
|
||||
resolution=args.video_resolution,
|
||||
)
|
||||
formatter = format_video_results
|
||||
|
||||
# Format results
|
||||
output = formatter(results, args.format)
|
||||
|
||||
# Output results
|
||||
if args.output:
|
||||
output_path = Path(args.output)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
output_path.write_text(output, encoding='utf-8')
|
||||
print(f"✓ Results saved to {args.output}", file=sys.stderr)
|
||||
print(f" Found {len(results)} result(s)", file=sys.stderr)
|
||||
else:
|
||||
print(output)
|
||||
print(f"\nFound {len(results)} result(s)", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user