mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-10 08:52:21 +02:00
Squash Odysseus development history
This commit is contained in:
+41
-12
@@ -25,21 +25,52 @@ from pathlib import Path
|
||||
|
||||
_DATA_DIR = _REPO_ROOT / "data" / "deep_research"
|
||||
|
||||
# The CLI's --status takes the user-facing label "complete", but the writer
|
||||
# in services/research/research_handler.py stores `status="done"` when a run
|
||||
# finishes (and the legacy src/research_handler.py does the same). Without
|
||||
# this alias, --status complete filters every finished record out and the
|
||||
# user sees an empty list. Map at filter time so the on-disk corpus is the
|
||||
# source of truth and the CLI surface stays the friendlier word. The other
|
||||
# choices ("running", "cancelled", "error") are stored verbatim, so they
|
||||
# fall through unchanged.
|
||||
_STATUS_CLI_TO_STORED = {"complete": "done"}
|
||||
|
||||
|
||||
def _status_matches(stored, requested: str) -> bool:
|
||||
stored = (stored or "")
|
||||
if not isinstance(stored, str):
|
||||
stored = ""
|
||||
target = _STATUS_CLI_TO_STORED.get(requested, requested)
|
||||
return stored == target
|
||||
|
||||
|
||||
def _load_path(path: Path) -> dict | None:
|
||||
try:
|
||||
data = json.loads(path.read_text())
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return None
|
||||
return data if isinstance(data, dict) else None
|
||||
|
||||
|
||||
def _load(rp_id: str) -> dict | None:
|
||||
path = _DATA_DIR / f"{rp_id}.json"
|
||||
if not path.exists():
|
||||
return None
|
||||
try:
|
||||
return json.loads(path.read_text())
|
||||
except json.JSONDecodeError:
|
||||
return None
|
||||
return _load_path(path)
|
||||
|
||||
|
||||
def _preview_text(value, limit: int = 200) -> str:
|
||||
"""Truncated preview tolerant of non-string values. A stored research
|
||||
record whose ``query`` is a non-string (legacy/corrupt JSON) would crash
|
||||
``(value or "")[:200]`` with a TypeError; coerce non-strings to ""."""
|
||||
text = value if isinstance(value, str) else ""
|
||||
return text[:limit]
|
||||
|
||||
|
||||
def _summarize(rp_id: str, data: dict) -> dict:
|
||||
return {
|
||||
"id": rp_id,
|
||||
"query": (data.get("query") or "")[:200],
|
||||
"query": _preview_text(data.get("query")),
|
||||
"category": data.get("category") or "",
|
||||
"status": data.get("status") or "",
|
||||
"started_at": data.get("started_at") or "",
|
||||
@@ -56,11 +87,10 @@ def cmd_list(args):
|
||||
out = []
|
||||
for path in sorted(_DATA_DIR.glob("*.json")):
|
||||
rp_id = path.stem
|
||||
try:
|
||||
data = json.loads(path.read_text())
|
||||
except Exception:
|
||||
data = _load_path(path)
|
||||
if data is None:
|
||||
continue
|
||||
if args.status and (data.get("status") or "") != args.status:
|
||||
if args.status and not _status_matches(data.get("status"), args.status):
|
||||
continue
|
||||
out.append(_summarize(rp_id, data))
|
||||
out.sort(key=lambda r: r.get("started_at") or "", reverse=True)
|
||||
@@ -100,9 +130,8 @@ def cmd_search(args):
|
||||
out = []
|
||||
for path in _DATA_DIR.glob("*.json"):
|
||||
rp_id = path.stem
|
||||
try:
|
||||
data = json.loads(path.read_text())
|
||||
except Exception:
|
||||
data = _load_path(path)
|
||||
if data is None:
|
||||
continue
|
||||
haystack = " ".join([
|
||||
(data.get("query") or "").lower(),
|
||||
|
||||
Reference in New Issue
Block a user