breviabook 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- breviabook-0.1.0/.claude/settings.local.json +22 -0
- breviabook-0.1.0/.env.example +21 -0
- breviabook-0.1.0/.github/workflows/ci.yml +42 -0
- breviabook-0.1.0/.github/workflows/release.yml +51 -0
- breviabook-0.1.0/.gitignore +52 -0
- breviabook-0.1.0/.pre-commit-config.yaml +24 -0
- breviabook-0.1.0/CHANGELOG.md +29 -0
- breviabook-0.1.0/CLAUDE.md +72 -0
- breviabook-0.1.0/LICENSE +202 -0
- breviabook-0.1.0/NOTICE +24 -0
- breviabook-0.1.0/PKG-INFO +258 -0
- breviabook-0.1.0/PRPs/000--phase-0-scaffold.md +151 -0
- breviabook-0.1.0/PRPs/001--phase-1-ir-epub-parser.md +123 -0
- breviabook-0.1.0/PRPs/002--phase-2-markdown-renderer.md +103 -0
- breviabook-0.1.0/PRPs/003--phase-3-chunker-checkpoint.md +110 -0
- breviabook-0.1.0/PRPs/004--phase-4-condenser.md +116 -0
- breviabook-0.1.0/PRPs/005--phase-5-synthesis-length-control.md +109 -0
- breviabook-0.1.0/PRPs/006--phase-6-image-selector-epub-renderer.md +100 -0
- breviabook-0.1.0/PRPs/007--phase-7-pdf-renderer.md +104 -0
- breviabook-0.1.0/PRPs/008--phase-8-pdf-parser.md +111 -0
- breviabook-0.1.0/PRPs/009--phase-9-more-providers.md +113 -0
- breviabook-0.1.0/PRPs/010--phase-10-translation-glossary.md +99 -0
- breviabook-0.1.0/PRPs/011--phase-11-vision-image-ranking.md +101 -0
- breviabook-0.1.0/PRPs/012--phase-12-polish.md +93 -0
- breviabook-0.1.0/PRPs/feat--cli-tui.md +53 -0
- breviabook-0.1.0/PRPs/feat--usage-cost-reporting.md +71 -0
- breviabook-0.1.0/PRPs/mvp--cli-pipeline-wiring.md +112 -0
- breviabook-0.1.0/PRPs/templates/prp_base.md +79 -0
- breviabook-0.1.0/README.md +223 -0
- breviabook-0.1.0/breviabook/__init__.py +3 -0
- breviabook-0.1.0/breviabook/cli.py +216 -0
- breviabook-0.1.0/breviabook/condense/__init__.py +1 -0
- breviabook-0.1.0/breviabook/condense/chunker.py +95 -0
- breviabook-0.1.0/breviabook/condense/common.py +108 -0
- breviabook-0.1.0/breviabook/condense/condenser.py +206 -0
- breviabook-0.1.0/breviabook/condense/prompts.py +86 -0
- breviabook-0.1.0/breviabook/condense/synthesizer.py +200 -0
- breviabook-0.1.0/breviabook/config.py +59 -0
- breviabook-0.1.0/breviabook/images/__init__.py +1 -0
- breviabook-0.1.0/breviabook/images/selector.py +55 -0
- breviabook-0.1.0/breviabook/images/vision_ranker.py +131 -0
- breviabook-0.1.0/breviabook/ir/__init__.py +1 -0
- breviabook-0.1.0/breviabook/ir/models.py +111 -0
- breviabook-0.1.0/breviabook/llm/__init__.py +1 -0
- breviabook-0.1.0/breviabook/llm/base.py +52 -0
- breviabook-0.1.0/breviabook/llm/factory.py +98 -0
- breviabook-0.1.0/breviabook/llm/key_pool.py +33 -0
- breviabook-0.1.0/breviabook/llm/pricing.py +25 -0
- breviabook-0.1.0/breviabook/llm/providers/__init__.py +1 -0
- breviabook-0.1.0/breviabook/llm/providers/gemini.py +19 -0
- breviabook-0.1.0/breviabook/llm/providers/litellm_base.py +101 -0
- breviabook-0.1.0/breviabook/llm/providers/ollama.py +61 -0
- breviabook-0.1.0/breviabook/llm/providers/openai.py +28 -0
- breviabook-0.1.0/breviabook/llm/providers/openrouter.py +19 -0
- breviabook-0.1.0/breviabook/llm/rate_limit.py +59 -0
- breviabook-0.1.0/breviabook/llm/usage.py +54 -0
- breviabook-0.1.0/breviabook/parsers/__init__.py +1 -0
- breviabook-0.1.0/breviabook/parsers/base.py +20 -0
- breviabook-0.1.0/breviabook/parsers/epub_parser.py +276 -0
- breviabook-0.1.0/breviabook/parsers/pdf_parser.py +325 -0
- breviabook-0.1.0/breviabook/parsers/toc_inference.py +62 -0
- breviabook-0.1.0/breviabook/persistence/__init__.py +1 -0
- breviabook-0.1.0/breviabook/persistence/checkpoint.py +64 -0
- breviabook-0.1.0/breviabook/pipeline.py +289 -0
- breviabook-0.1.0/breviabook/render/__init__.py +1 -0
- breviabook-0.1.0/breviabook/render/base.py +48 -0
- breviabook-0.1.0/breviabook/render/epub_renderer.py +174 -0
- breviabook-0.1.0/breviabook/render/html.py +63 -0
- breviabook-0.1.0/breviabook/render/md_renderer.py +100 -0
- breviabook-0.1.0/breviabook/render/pdf_renderer.py +99 -0
- breviabook-0.1.0/breviabook/translate/__init__.py +1 -0
- breviabook-0.1.0/breviabook/translate/glossary.py +35 -0
- breviabook-0.1.0/breviabook/translate/translator.py +186 -0
- breviabook-0.1.0/breviabook/ui/__init__.py +1 -0
- breviabook-0.1.0/breviabook/ui/banner.py +38 -0
- breviabook-0.1.0/breviabook/ui/progress.py +183 -0
- breviabook-0.1.0/breviabook/utils/__init__.py +1 -0
- breviabook-0.1.0/breviabook/utils/jsonx.py +31 -0
- breviabook-0.1.0/breviabook/utils/security.py +62 -0
- breviabook-0.1.0/breviabook/utils/tokens.py +65 -0
- breviabook-0.1.0/docs/ROADMAP.md +372 -0
- breviabook-0.1.0/pyproject.toml +96 -0
- breviabook-0.1.0/tests/__init__.py +0 -0
- breviabook-0.1.0/tests/conftest.py +23 -0
- breviabook-0.1.0/tests/fixtures/_build_sample_epub.py +109 -0
- breviabook-0.1.0/tests/fixtures/_build_sample_pdf.py +56 -0
- breviabook-0.1.0/tests/fixtures/sample.epub +0 -0
- breviabook-0.1.0/tests/fixtures/sample.pdf +0 -0
- breviabook-0.1.0/tests/test_checkpoint.py +73 -0
- breviabook-0.1.0/tests/test_chunker.py +96 -0
- breviabook-0.1.0/tests/test_cli.py +41 -0
- breviabook-0.1.0/tests/test_condenser.py +209 -0
- breviabook-0.1.0/tests/test_epub_parser.py +87 -0
- breviabook-0.1.0/tests/test_epub_renderer.py +94 -0
- breviabook-0.1.0/tests/test_glossary.py +37 -0
- breviabook-0.1.0/tests/test_image_selector.py +56 -0
- breviabook-0.1.0/tests/test_ir_models.py +46 -0
- breviabook-0.1.0/tests/test_key_pool.py +32 -0
- breviabook-0.1.0/tests/test_llm_factory.py +98 -0
- breviabook-0.1.0/tests/test_md_renderer.py +116 -0
- breviabook-0.1.0/tests/test_pdf_parser.py +97 -0
- breviabook-0.1.0/tests/test_pdf_renderer.py +81 -0
- breviabook-0.1.0/tests/test_pipeline.py +247 -0
- breviabook-0.1.0/tests/test_pricing.py +18 -0
- breviabook-0.1.0/tests/test_providers.py +95 -0
- breviabook-0.1.0/tests/test_rate_limit.py +109 -0
- breviabook-0.1.0/tests/test_synthesizer.py +175 -0
- breviabook-0.1.0/tests/test_toc_inference.py +58 -0
- breviabook-0.1.0/tests/test_tokens.py +41 -0
- breviabook-0.1.0/tests/test_translator.py +162 -0
- breviabook-0.1.0/tests/test_ui.py +72 -0
- breviabook-0.1.0/tests/test_usage.py +99 -0
- breviabook-0.1.0/tests/test_vision_ranker.py +101 -0
- breviabook-0.1.0/uv.lock +2935 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(git init *)",
|
|
5
|
+
"Bash(git config *)",
|
|
6
|
+
"Bash(curl -fsSL https://www.apache.org/licenses/LICENSE-2.0.txt -o LICENSE)",
|
|
7
|
+
"Bash(uv run *)",
|
|
8
|
+
"Bash(brew --prefix)",
|
|
9
|
+
"Bash(DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib uv run pytest -q)",
|
|
10
|
+
"Bash(DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib uv run python -m tests.fixtures._build_sample_pdf)",
|
|
11
|
+
"Bash(ollama ps *)",
|
|
12
|
+
"Bash(ollama stop *)",
|
|
13
|
+
"Bash(DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib uv run *)",
|
|
14
|
+
"Bash(curl -s -o /dev/null -w \"%{http_code}\" https://pypi.org/pypi/brevia/json)",
|
|
15
|
+
"Bash(DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib uv lock)",
|
|
16
|
+
"Bash(DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib uv build)",
|
|
17
|
+
"Bash(git grep *)",
|
|
18
|
+
"Bash(gh repo *)",
|
|
19
|
+
"Bash(gh run *)"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Brevia configuration — copy to .env and edit. NEVER commit your real .env.
|
|
2
|
+
# See docs/ROADMAP.md §9.
|
|
3
|
+
|
|
4
|
+
# --- Provider selection ---
|
|
5
|
+
LLM_PROVIDER=ollama
|
|
6
|
+
OLLAMA_ENDPOINT=http://localhost:11434
|
|
7
|
+
|
|
8
|
+
# Default model. gemma4:e4b is fast and light (Gemma 4 edge, ~12GB RAM, 128K ctx).
|
|
9
|
+
# For best long-document summarization quality on a 36GB machine, prefer: qwen3:30b
|
|
10
|
+
# (Qwen3-30B-A3B MoE — ~3.3B active params so it stays fast, 256K context).
|
|
11
|
+
DEFAULT_MODEL=gemma4:e4b
|
|
12
|
+
|
|
13
|
+
# --- API keys (cloud providers; Phase 9). Comma-separated for key rotation. ---
|
|
14
|
+
OPENAI_API_KEY=
|
|
15
|
+
GEMINI_API_KEY=
|
|
16
|
+
OPENROUTER_API_KEY=
|
|
17
|
+
|
|
18
|
+
# --- Condensation defaults ---
|
|
19
|
+
DEFAULT_TARGET_RATIO=0.30
|
|
20
|
+
DEFAULT_CHUNK_TOKENS=2000
|
|
21
|
+
IMAGE_STRATEGY=keep_referenced # keep_referenced | vision_ranked
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
quality:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- name: Install weasyprint system libraries
|
|
15
|
+
run: |
|
|
16
|
+
sudo apt-get update
|
|
17
|
+
sudo apt-get install -y libpango-1.0-0 libpangocairo-1.0-0 \
|
|
18
|
+
libgdk-pixbuf-2.0-0 libffi-dev libcairo2
|
|
19
|
+
|
|
20
|
+
- name: Install uv
|
|
21
|
+
uses: astral-sh/setup-uv@v5
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
run: uv python install 3.11
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --all-extras --dev
|
|
28
|
+
|
|
29
|
+
- name: Ruff (lint)
|
|
30
|
+
run: uv run ruff check .
|
|
31
|
+
|
|
32
|
+
- name: Ruff (format check)
|
|
33
|
+
run: uv run ruff format --check .
|
|
34
|
+
|
|
35
|
+
- name: Mypy (strict)
|
|
36
|
+
run: uv run mypy --strict breviabook
|
|
37
|
+
|
|
38
|
+
- name: Pytest
|
|
39
|
+
run: uv run pytest -q
|
|
40
|
+
|
|
41
|
+
- name: License audit (fail on any GPL/AGPL dependency)
|
|
42
|
+
run: uv run pip-licenses --fail-on "GPL"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
# Publish to PyPI on a version tag (e.g. v0.1.0) via PyPI Trusted Publishing (OIDC) — no
|
|
4
|
+
# API tokens stored. One-time setup on PyPI: add a "trusted publisher" for project
|
|
5
|
+
# "breviabook" pointing at owner=willywg, repo=breviabook, workflow=release.yml,
|
|
6
|
+
# environment=pypi. See https://docs.pypi.org/trusted-publishers/
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags: ["v*"]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v5
|
|
20
|
+
|
|
21
|
+
- name: Verify tag matches package version
|
|
22
|
+
run: |
|
|
23
|
+
TAG="${GITHUB_REF_NAME#v}"
|
|
24
|
+
PKG="$(uv run python -c 'import breviabook; print(breviabook.__version__)')"
|
|
25
|
+
echo "tag=$TAG package=$PKG"
|
|
26
|
+
test "$TAG" = "$PKG" || { echo "::error::tag v$TAG != package version $PKG"; exit 1; }
|
|
27
|
+
|
|
28
|
+
- name: Build sdist and wheel
|
|
29
|
+
run: uv build
|
|
30
|
+
|
|
31
|
+
- uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist
|
|
34
|
+
path: dist/
|
|
35
|
+
|
|
36
|
+
publish:
|
|
37
|
+
needs: build
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
environment:
|
|
40
|
+
name: pypi
|
|
41
|
+
url: https://pypi.org/p/breviabook
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write # required for Trusted Publishing
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/download-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: dist
|
|
48
|
+
path: dist/
|
|
49
|
+
|
|
50
|
+
- name: Publish to PyPI
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# --- Secrets & local config (see ROADMAP §12: never commit API keys) ---
|
|
2
|
+
.env
|
|
3
|
+
.env.*
|
|
4
|
+
!.env.example
|
|
5
|
+
*.key
|
|
6
|
+
secrets/
|
|
7
|
+
|
|
8
|
+
# --- Job state / checkpoints / databases (never commit, ROADMAP §12) ---
|
|
9
|
+
*.sqlite
|
|
10
|
+
*.sqlite3
|
|
11
|
+
*.db
|
|
12
|
+
checkpoints/
|
|
13
|
+
.breviabook/
|
|
14
|
+
output/
|
|
15
|
+
out/
|
|
16
|
+
|
|
17
|
+
# --- Reference repos must stay OUTSIDE the tree (ROADMAP §14) ---
|
|
18
|
+
# (kept here as a guard in case someone clones them in by accident)
|
|
19
|
+
TranslateBooksWithLLMs/
|
|
20
|
+
ollama-ebook-summary/
|
|
21
|
+
OllamaBook-Summarize/
|
|
22
|
+
|
|
23
|
+
# --- Python ---
|
|
24
|
+
__pycache__/
|
|
25
|
+
*.py[cod]
|
|
26
|
+
*$py.class
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.eggs/
|
|
29
|
+
build/
|
|
30
|
+
dist/
|
|
31
|
+
.venv/
|
|
32
|
+
venv/
|
|
33
|
+
env/
|
|
34
|
+
.python-version
|
|
35
|
+
|
|
36
|
+
# --- Tooling caches ---
|
|
37
|
+
.mypy_cache/
|
|
38
|
+
.ruff_cache/
|
|
39
|
+
.pytest_cache/
|
|
40
|
+
.coverage
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
|
|
44
|
+
# --- Editors / OS ---
|
|
45
|
+
.vscode/
|
|
46
|
+
.idea/
|
|
47
|
+
*.swp
|
|
48
|
+
.DS_Store
|
|
49
|
+
|
|
50
|
+
# --- Test artifacts (keep fixtures, ignore generated) ---
|
|
51
|
+
tests/output/
|
|
52
|
+
*.generated.*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Pre-commit hooks (ROADMAP §4). Install with: uv run pre-commit install
|
|
2
|
+
repos:
|
|
3
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
4
|
+
rev: v0.5.7
|
|
5
|
+
hooks:
|
|
6
|
+
- id: ruff
|
|
7
|
+
args: [--fix]
|
|
8
|
+
- id: ruff-format
|
|
9
|
+
|
|
10
|
+
- repo: local
|
|
11
|
+
hooks:
|
|
12
|
+
- id: mypy
|
|
13
|
+
name: mypy (strict)
|
|
14
|
+
entry: uv run mypy --strict breviabook
|
|
15
|
+
language: system
|
|
16
|
+
types: [python]
|
|
17
|
+
pass_filenames: false
|
|
18
|
+
|
|
19
|
+
- id: pytest
|
|
20
|
+
name: pytest
|
|
21
|
+
entry: uv run pytest -q
|
|
22
|
+
language: system
|
|
23
|
+
types: [python]
|
|
24
|
+
pass_filenames: false
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to BreviaBook are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/), and the project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] — 2026-06-25
|
|
8
|
+
|
|
9
|
+
First public release. Condenses large technical ebooks (EPUB/PDF) to ~25–50% while
|
|
10
|
+
preserving code, tables, and meaningful figures, with optional same-pass translation.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Format-agnostic IR (`Document → Chapter → Block`) with EPUB and PDF parsers (no
|
|
14
|
+
GPL/AGPL deps: own EPUB builder, `pdfplumber`/`pypdf`, never `ebooklib`/PyMuPDF).
|
|
15
|
+
- Hierarchical condensation (per-chunk condense + per-chapter synthesis with length
|
|
16
|
+
control); **code blocks are never summarized or split**.
|
|
17
|
+
- Integrated translation of the condensed book, with optional glossary; runs in resilient
|
|
18
|
+
batches that retry and fall back to source text instead of crashing.
|
|
19
|
+
- Image preservation (Strategy A) plus optional vision ranking (`--rank-images`).
|
|
20
|
+
- Outputs: EPUB (own builder), PDF (weasyprint, optional `[pdf]` extra), Markdown.
|
|
21
|
+
- Multi-provider LLM via litellm: Ollama, OpenAI, Gemini, OpenRouter, and any
|
|
22
|
+
OpenAI-compatible endpoint; key rotation and failover.
|
|
23
|
+
- Live TUI: banner, per-phase progress bars, and a real-time token/cost usage panel.
|
|
24
|
+
- `--reasoning-effort` control; thinking is **disabled by default** for Gemini (rewriting
|
|
25
|
+
tasks gain nothing from it and it costs ~3.6× more).
|
|
26
|
+
- `--dry-run` token/page/compression/cost estimate; per-run usage report; compression and
|
|
27
|
+
approximate page counts; `--resume` from a JSONL checkpoint.
|
|
28
|
+
|
|
29
|
+
[0.1.0]: https://github.com/willywg/breviabook/releases/tag/v0.1.0
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# CLAUDE.md — BreviaBook
|
|
2
|
+
|
|
3
|
+
Guidance for AI agents working in this repository. The complete specification and
|
|
4
|
+
phased build plan live in **[docs/ROADMAP.md](docs/ROADMAP.md)** — that document is
|
|
5
|
+
the source of truth; this file is the quick operating manual.
|
|
6
|
+
|
|
7
|
+
## What BreviaBook is
|
|
8
|
+
|
|
9
|
+
A CLI that takes a large technical ebook (EPUB/PDF, 200–400 pages) and produces a
|
|
10
|
+
**condensed version** (~25–50% of the original) that preserves **code, formulas, and
|
|
11
|
+
essential images/diagrams**, optionally **translated** in the same pass. Outputs
|
|
12
|
+
EPUB, PDF, and Markdown. Multi-provider LLM (Ollama, OpenAI, Gemini, OpenRouter, and
|
|
13
|
+
any OpenAI-compatible endpoint).
|
|
14
|
+
|
|
15
|
+
## Core architectural principle (read first)
|
|
16
|
+
|
|
17
|
+
Everything flows through a **format-agnostic Intermediate Representation (IR)** —
|
|
18
|
+
`Document → Chapter → Block` (pydantic). Parsers produce IR, the condenser/translator
|
|
19
|
+
transform IR text blocks, renderers consume IR. **`code` and `image` blocks are never
|
|
20
|
+
summarized or split.** Adding a format = one parser or one renderer, nothing else.
|
|
21
|
+
See ROADMAP §3 and §6 for the model and folder layout.
|
|
22
|
+
|
|
23
|
+
Pipeline: `parse → chunk → condense → synthesize → (translate) → image-select → render`,
|
|
24
|
+
with checkpoint/resume between chunking and translation. See ROADMAP §5.
|
|
25
|
+
|
|
26
|
+
## License rules — NON-NEGOTIABLE (ROADMAP §14)
|
|
27
|
+
|
|
28
|
+
- Project license: **Apache-2.0**.
|
|
29
|
+
- **Clean-room only.** The reference repos (TranslateBooksWithLLMs, ollama-ebook-summary,
|
|
30
|
+
OllamaBook-Summarize) are **study material, never copy material**. Never copy/paste or
|
|
31
|
+
line-by-line translate their code. Keep them OUTSIDE this tree (`~/projects/open-source/`),
|
|
32
|
+
never vendor or submodule them.
|
|
33
|
+
- **No AGPL/GPL runtime dependencies — ever.** Forbidden: `ebooklib`, `PyMuPDF`/`fitz`.
|
|
34
|
+
Use the permissive substitutes below. CI enforces this with `pip-licenses --fail-on "GPL"`.
|
|
35
|
+
- **Never commit** API keys or job databases (`.env`, `*.sqlite` are gitignored).
|
|
36
|
+
|
|
37
|
+
## Tech stack (permissive only)
|
|
38
|
+
|
|
39
|
+
- Python **3.11+**, package manager **`uv`**.
|
|
40
|
+
- CLI: `typer` + `rich`. Config: `pydantic` v2 + `python-dotenv`.
|
|
41
|
+
- EPUB: our own builder with `zipfile` (stdlib) + `lxml`/`beautifulsoup4` — **not ebooklib**.
|
|
42
|
+
- PDF read: `pdfplumber` + `pypdf` — **not PyMuPDF**. PDF write: `weasyprint`.
|
|
43
|
+
- Tokens: `tiktoken` (char-based fallback). LLM: `litellm` (preferred) and/or `httpx`.
|
|
44
|
+
- NER glossary (late phase): `spacy`.
|
|
45
|
+
|
|
46
|
+
## Quality gates (must pass from Phase 0)
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv run ruff check . # lint (rules: E,F,I,UP,B,SIM)
|
|
50
|
+
uv run ruff format --check . # format
|
|
51
|
+
uv run mypy --strict breviabook # types — strict mode, type the whole pipeline
|
|
52
|
+
uv run pytest # tests (pytest + pytest-asyncio)
|
|
53
|
+
uv run pip-licenses --fail-on "GPL" # license audit — blocks any GPL/AGPL dep
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`ruff` and `mypy` must pass clean from the first commit. Use a deterministic **mock
|
|
57
|
+
provider** for pipeline tests; don't call a real LLM in tests.
|
|
58
|
+
|
|
59
|
+
## Workflow
|
|
60
|
+
|
|
61
|
+
This project is driven by the **PRP (Product Requirement Prompt) workflow**. Each phase
|
|
62
|
+
in ROADMAP §10 (Phase 0 → Phase 12) becomes one PRP under `PRPs/`. Build phases **in
|
|
63
|
+
order**; each must be functional and tested before the next. **MVP = Phases 0–7.**
|
|
64
|
+
|
|
65
|
+
## Things NOT to do (ROADMAP §12)
|
|
66
|
+
|
|
67
|
+
- Don't copy TBL's 1:1 placeholder reinjection — we build a fresh EPUB from scratch.
|
|
68
|
+
- Don't use ~450-token chunks; summarization needs ~2000-token chunks.
|
|
69
|
+
- Never split a `code` block or a table across chunks.
|
|
70
|
+
- Validate entry paths when unpacking EPUBs (zip-slip). Don't forward provider keys to an
|
|
71
|
+
arbitrary `--api-endpoint` (SSRF). See `breviabook/utils/security.py`.
|
|
72
|
+
- "Output longer than input" is a red flag — detect and warn.
|
breviabook-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
breviabook-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
BreviaBook
|
|
2
|
+
Copyright 2026 William Wong Garay
|
|
3
|
+
|
|
4
|
+
This product includes software developed by William Wong Garay and contributors.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
|
7
|
+
file except in compliance with the License. You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
-------------------------------------------------------------------------------
|
|
12
|
+
Attribution (no code reused)
|
|
13
|
+
-------------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
BreviaBook's architecture was studied and inspired by the following open-source projects.
|
|
16
|
+
No code from these projects is reused in BreviaBook; they served as study material only
|
|
17
|
+
(clean-room reimplementation — see docs/ROADMAP.md §14):
|
|
18
|
+
|
|
19
|
+
* TranslateBooksWithLLMs (hydropix) — provider-layer and checkpoint patterns
|
|
20
|
+
* ollama-ebook-summary (cognitivetech) — chapter-aware chunking lessons
|
|
21
|
+
* OllamaBook-Summarize (sanjaymarison) — table-of-contents inference idea
|
|
22
|
+
|
|
23
|
+
BreviaBook depends only on permissively licensed (MIT/BSD/Apache) libraries; it uses no
|
|
24
|
+
GPL/AGPL dependencies at runtime.
|