homelab-codex-ws/kb/runbooks/mail-body-ingest-run.md
oskar 3292ab54e2 feat(kb): SPLIT service+runbook — 10 serwisow -> 20 dokumentow
Wzorzec mechaniczny: sekcje deploy/verify/install/testy wycinane do
kb/runbooks/<serwis>-*.md, reszta zostaje dokumentem type: service.
Wzajemne `links` w obie strony. Tresc sekcji nietknieta — przenoszone
doslownie, dodany wylacznie naglowek H1 nowego runbooka.

kb-query, paperless-worker, planner-agent, ha-diag-agent, ollama-piha,
narty27, home-assistant, ha-mcp, job-gmail-header-backfill, job-mail-body-ingest.

Weryfikacja: dla kazdego pliku multizbior niepustych linii
(main + runbook) == oryginal z HEAD. Zero zgubionych, zero dodanych.

Recon szacowal 13 splitow service+runbook; faktycznie 2-typowych jest 10,
pozostale 5 (paperless, nextcloud, gokapi, fleet-prometheus, deploy-runner)
sa 3-typowe i ida osobno jako splity wielotypowe.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-04 16:53:57 +02:00

1.5 KiB

okf type visibility status updated links
0.1 runbook private active 2026-07-22
../services/job-mail-body-ingest.md

mail-body-ingest — uruchomienie i testy

Usage

# Dry run (default) — parse, quote-strip, classify, chunk, count. Zero Ollama calls, zero
# DB writes (including the threading UPDATE):
mail-body-ingest --dsn postgresql://kb:<pw>@piha:5433/kb --archive-root /home/oskar/kb/mail/archive

# Etap A pilot — last 12 months only (plan Decyzja 9):
mail-body-ingest --dsn ... --since 2025-07-01 --apply > mail-ingest-etapA.log 2>&1

# Smoke-test slice:
mail-body-ingest --dsn ... --apply --limit 10

DSN can also come from KB_DSN, Ollama URL from OLLAMA_URL (default http://localhost:11434 — this job is meant to run where Ollama lives).

Tests

pip install -e "jobs/mail-body-ingest[dev]"
cd jobs/mail-body-ingest && pytest

Pure unit tests (48), no DB/Ollama — run() is tested by monkeypatching asyncpg.connect and aiohttp.ClientSession with in-memory fakes, .eml bytes written to tmp_path. Covers: quote-strip (EN/PL/Outlook markers, bare > lines), HTML->text (style/script/blockquote/ gmail_quote skipping), newsletter classification, threading extraction, prefix building, body extraction (plain-preferred, HTML fallback, attachment-only), the typed/compat32 parse fallback, stats balance, idempotency (second run inserts nothing new), newsletter chunks never reaching Ollama, Ollama-offline batch isolation, and dimension-mismatch abort.