feat(sources): admin page to add and remove git sources (TODO.md L4)

This commit is contained in:
2026-08-26 18:42:28 -04:00
parent b2d8696741
commit 1925bb66a8
30 changed files with 2673 additions and 110 deletions
+24 -9
View File
@@ -15,9 +15,12 @@ stale button state (§7.4 adaptation, phase locked decisions).
Pipeline (the canonical "mirror the repos" action — phase locked
decisions):
1. resolve the ``BOR_GIT_SOURCES`` URLs — empty/missing fails loudly
(``no git sources configured``) instead of silently importing the
legacy local directories;
1. resolve the effective git sources — the ``git_sources`` DB rows,
else the ``BOR_GIT_SOURCES`` fallback
(:func:`app.rag.git_sources.effective_git_sources`, shared with the
CLI) — empty on both origins fails loudly (``no git sources
configured``) instead of silently importing the legacy local
directories;
2. :func:`scripts.git_sync.clone_or_pull` each repo into
``BOR_SOURCES_DIR/<repo-name>/`` (phase 28 — reused, not
re-implemented; a failing repo aborts before any import);
@@ -44,6 +47,8 @@ from fastapi import APIRouter, Depends, HTTPException
from app.config import get_settings
from app.core.auth import require_admin
from app.db import SessionLocal
from app.rag.git_sources import effective_git_sources
from app.rag.importer import ImportSummary, import_sources
from app.rag.llm import LLMClient
from app.rag.overview import regenerate_overview
@@ -141,13 +146,23 @@ async def _run_sync() -> None:
_status.error = None
try:
settings = get_settings()
git_urls = settings.git_source_list
# The background task has no request session: open a short-lived
# one around the shared phase-35 resolver (DB rows win, the
# BOR_GIT_SOURCES list is a fallback while the table is empty).
db = SessionLocal()
try:
git_urls, origin = effective_git_sources(db)
finally:
db.close()
if not git_urls:
# The button targets BOR_GIT_SOURCES only (manual --source
# dirs have no repo to clone) — an empty config fails loudly
# instead of silently importing the legacy directories.
raise GitSyncError("no git sources configured (BOR_GIT_SOURCES)")
logger.info("sync: started repos=%d", len(git_urls))
# The button targets git sources only (manual --source dirs
# have no repo to clone) — an empty config on *both* origins
# fails loudly instead of silently importing the legacy
# directories.
raise GitSyncError(
"no git sources configured (git_sources table empty and BOR_GIT_SOURCES unset)"
)
logger.info("sync: started repos=%d origin=%s", len(git_urls), origin)
sources_root = Path(settings.sources_dir).expanduser()
sources = [clone_or_pull(url, sources_root / repo_name(url)) for url in git_urls]
llm = LLMClient()