moonlight-lupin/agent-skills / research/library-rag
library-rag
UnverifiedSemantic search over a personal library using Nemotron-3-Embed-1B embeddings + sqlite-vec. Index books, documents, any text corpus; query by meaning. Includes EPUB→Markdown conversion and MCP server for auto-available search tools.
| File | Kind | Size |
|---|---|---|
| .gitignore | other | 305 B |
| LICENSE | other | 1.3 KB |
| README.md | markdown | 11.8 KB |
| SKILL.md | skill md | 18.9 KB |
| references/chunking-strategies.md | markdown | 5.8 KB |
| references/epub-conversion.md | markdown | 3.8 KB |
| references/openrouter-embeddings.md | markdown | 4.1 KB |
| references/portable-rag-per-skill.md | markdown | 12.1 KB |
| references/rag-pipeline-review.md | markdown | 9.7 KB |
| requirements-dev.txt | markdown | 167 B |
| requirements.txt | manifest | 286 B |
| scripts/convert_epub_library.py | script | 13.0 KB |
| scripts/convert_pdf_library.py | script | 6.0 KB |
| scripts/mcp_server.py | script | 10.9 KB |
| scripts/rag_common.py | script | 8.7 KB |
| scripts/rag_index.py | script | 23.4 KB |
| scripts/rag_query.py | script | 6.8 KB |
| tests/conftest.py | script | 188 B |
| tests/test_chunking.py | script | 5.0 KB |
| tests/test_convert.py | script | 4.6 KB |
| tests/test_convert_pdf.py | script | 4.1 KB |
| tests/test_index_search.py | script | 4.8 KB |
| tests/test_indexing_atomicity.py | script | 4.8 KB |
| tests/test_prune_vacuum.py | script | 5.5 KB |
| tests/test_rag_common.py | script | 4.9 KB |
tests/test_convert.py
View on GitHubimport pytest
import convert_epub_library as cv
def test_slugify_basic():
assert cv.slugify("Hello, World!") == "hello-world"
def test_slugify_truncates():
assert cv.slugify("a" * 100, max_len=10) == "a" * 10
def test_split_into_chapters_below_threshold_returns_empty():
text = "CHAPTER 1\nFirst\nbody one\nCHAPTER 2\nSecond\nbody two"
assert cv.split_into_chapters(text) == []
def test_split_into_chapters():
text = "\n".join(f"CHAPTER {n}\nTitle {n}\nSome body for chapter {n}." for n in range(1, 6))
chapters = cv.split_into_chapters(text)
assert len(chapters) == 5
assert chapters[0]["num"] == 1
assert chapters[0]["title"] == "Title 1"
assert chapters[0]["slug"].startswith("ch01-")
def test_split_into_chapters_word_numbers():
text = "\n".join(
f"CHAPTER {w}\nTitle {w}\nSome body for chapter {w}."
for w in ("One", "Two", "Three", "Four", "Five")
)
chapters = cv.split_into_chapters(text)
assert len(chapters) == 5
assert chapters[0]["num"] == "One" # word label preserved
assert chapters[0]["slug"].startswith("ch01-") # filename uses sequential ordinal
assert chapters[4]["slug"].startswith("ch05-")
def test_split_into_chapters_numbered_dot_style():
text = "\n".join(f"{n}. Section {n}\nSome body content for section {n}." for n in range(1, 6))
chapters = cv.split_into_chapters(text)
assert len(chapters) == 5
assert chapters[0]["num"] == 1
assert chapters[0]["title"] == "Section 1"
def test_split_into_chapters_excludes_date_false_positives():
# Bare-number style, but two entries are really dates — must not become chapters.
text = (
"1\nIn some countries the rule applies.\n\n"
"2\nThe second provision is as follows.\n\n"
"1\nJanuary 2026 was the effective date.\n\n"
"31\nDecember 2017 marked the transition.\n\n"
"3\nThe third provision continues here.\n\n"
"4\nThe fourth provision concludes."
)
labels = cv.audit_chapter_markers(text)
titles = [t for _, t in labels]
assert not any("January" in t or "December" in t for t in titles)
# the four genuine provisions survive (>3, so a real chapter split happens)
assert len(cv.split_into_chapters(text)) == 4
def test_looks_like_false_anchor():
assert cv._looks_like_false_anchor("January 2026")
assert cv._looks_like_false_anchor(" ")
assert cv._looks_like_false_anchor("174")
assert not cv._looks_like_false_anchor("In some countries the rule applies.")
def test_fix_yaml_title_leaks(tmp_path):
f = tmp_path / "a.md"
f.write_text("---\ntitle: Main Title\n leaked subtitle\nauthor: X\n---\n\nbody\n")
fixed = cv.fix_yaml_title_leaks(tmp_path)
assert fixed == 1
assert "leaked subtitle" not in f.read_text()
def test_write_chapter_md_drops_empty_fields(tmp_path):
name = cv.write_chapter_md(
"slug",
{"num": 1, "title": "Chap", "slug": "ch01-chap", "content": "body text"},
{"author": "A", "year": "", "title": "Book", "source_file": "x.epub"},
md_dir=tmp_path,
)
text = (tmp_path / name).read_text()
assert "author: A" in text
assert "book: Book" in text
assert "year:" not in text # empty field dropped
assert "edition:" not in text # absent field dropped
assert "license:" not in text # no hardcoded license line
def test_convert_epub_end_to_end(tmp_path):
pytest.importorskip("ebooklib")
from ebooklib import epub
book = epub.EpubBook()
book.set_identifier("id"); book.set_title("T"); book.set_language("en")
book.add_author("A")
body = "".join(
f"<h2>CHAPTER {n}</h2><p>Title {n}</p><p>{'word ' * 50}</p>" for n in range(1, 6)
)
item = epub.EpubHtml(title="b", file_name="b.xhtml", lang="en")
item.content = f"<html><body>{body}</body></html>"
book.add_item(item)
book.add_item(epub.EpubNcx()); book.add_item(epub.EpubNav())
book.spine = ["nav", item]
epath = tmp_path / "book.epub"
epub.write_epub(str(epath), book)
md_root = tmp_path / "lib" / "markdown"
staging = tmp_path / "staging"
res = cv.convert_epub(str(epath), "my-book", title="T", author="A", year="2024",
md_root=md_root, staging_dir=staging)
assert res["chapters"] == 5
mds = sorted((md_root / "my-book" / "chapters").glob("*.md"))
assert len(mds) == 5
# raw + extracted text staged OUTSIDE the indexed markdown root
assert (staging / "raw" / "book.epub").exists()
assert list((staging / "text").glob("*.txt"))
assert staging not in md_root.parents
first = mds[0].read_text()
assert first.startswith("---")
assert "book: T" in first
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |