Use when the user asks about a Calibre ebook library or book collection: find books, search metadata or full text in EPUB/AZW3 files, or locate book paths via Calibre databases.
98
98%
Does it follow best practices?
Impact
99%
1.80xAverage score across 4 eval scenarios
Passed
No known issues
#!/usr/bin/env python3
import argparse
import json
import os
import sqlite3
import sys
def emit_error(message, code, return_code=2):
print(json.dumps({"error": message, "error_code": code}))
return return_code
def list_books(db_path, limit=200):
if not os.path.exists(db_path):
return emit_error(f"DB not found: {db_path}", "DB_NOT_FOUND", 2)
conn = sqlite3.connect(db_path)
cur = conn.cursor()
try:
cur.execute("SELECT b.id, b.title FROM books b ORDER BY b.title LIMIT ?", (limit,))
rows = cur.fetchall()
res = [{"id": int(r[0]), "title": r[1]} for r in rows]
print(json.dumps(res, indent=2, ensure_ascii=False))
return 0
except Exception as e:
return emit_error(str(e), "LIST_ERROR", 3)
if __name__ == '__main__':
p = argparse.ArgumentParser(description='List books from Calibre metadata.db')
p.add_argument('--db-path', required=True, help='Path to metadata.db')
p.add_argument('--limit', type=int, default=200)
args = p.parse_args()
sys.exit(list_books(args.db_path, args.limit))evals
scenario-1
scenario-2
scenario-3
scenario-4
references
sample-library
Arthur C. Clarke
Warp Drive Studies (993)
Bertrand Russell
The Problems of Philosophy (4)
The Problems of Philosophy (997)
Jules Verne
Leviathan Under the Pacific (998)
Twenty Thousand Leagues under the Sea (1)
Twenty Thousand Leagues under the Sea (999)
Karl Marx
The Communist Manifesto (6)
The Communist Manifesto (995)
The Prince of the Workers (994)
scripts