oracle_rows: track freshness plainly; phast_status reports the Oracle cache

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FAqjv1sLfUad2bMcsmPbRT
This commit is contained in:
teahubxyzandClaude Fable 5.1 committed 2026-10-29 00:44:27 +00:00
1 parent 717ec9f14e
commit 9ccbf48bdf
1 file changed
+7 -6
+7 -6
View File
@@ -45,24 +45,24 @@ def oracle_rows() -> list[dict[str, Any]]:
now = time.time()
if _oracle["rows"] and now - _oracle["at"] < ORACLE_TTL:
return _oracle["rows"]
text = ""
text, fresh = "", ""
try:
response = httpx.get(ORACLE + "/search.json", timeout=30, headers={"User-Agent": "phast-app/0.2"})
if response.status_code == 200:
text = response.text
text, fresh = response.text, response.headers.get("last-modified", "")
try:
ORACLE_CACHE.write_text(text)
except OSError:
pass
except httpx.HTTPError:
text = ""
pass
if not text and not _oracle["rows"] and ORACLE_CACHE.exists():
text = ORACLE_CACHE.read_text()
text, fresh = ORACLE_CACHE.read_text(), "cache"
if text:
payload = json.loads(text)
columns = payload["columns"]
_oracle["rows"] = [dict(zip(columns, row)) for row in payload["rows"]]
_oracle["fresh"] = response.headers.get("last-modified", "") if text and "response" in locals() else ""
_oracle["fresh"] = fresh
_oracle["at"] = now
return _oracle["rows"]
@@ -302,7 +302,8 @@ m = FastMCP(
@m.tool()
def phast_status() -> dict:
return {"ok": True, "actor": actor(), "version": "0.2.0"}
return {"ok": True, "actor": actor(), "version": "0.2.1", "oracle": ORACLE,
"oracle_capabilities": len(_oracle["rows"]), "oracle_fresh": _oracle["fresh"]}
@m.tool()