Coverage for little_loops / cli / backfill_worker.py: 0%
19 statements
« prev ^ index » next coverage.py v7.12.0, created at 2026-06-26 17:38 -0500
« prev ^ index » next coverage.py v7.12.0, created at 2026-06-26 17:38 -0500
1"""Detached backfill worker spawned by the session_start hook (BUG-1882).
3Invoked as ``python -m little_loops.cli.backfill_worker <db_path> <path>``,
4where *path* is either a single ``.jsonl`` transcript file or a project folder
5whose ``*.jsonl`` files are globbed. Runs :func:`backfill_incremental` and
6exits. Because it is spawned with ``start_new_session=True`` it outlives the
7short-lived hook subprocess.
8"""
10from __future__ import annotations
12import sys
13from pathlib import Path
16def main(argv: list[str] | None = None) -> int:
17 args = argv if argv is not None else sys.argv[1:]
18 if len(args) < 2:
19 print(
20 f"Usage: {sys.argv[0]} <db_path> <jsonl_file_or_project_dir>",
21 file=sys.stderr,
22 )
23 return 1
25 db_path = Path(args[0])
26 path_arg = Path(args[1])
28 if path_arg.is_file() and args[1].endswith(".jsonl"):
29 jsonl_files: list[Path] = [path_arg]
30 elif path_arg.is_dir():
31 jsonl_files = list(path_arg.glob("*.jsonl"))
32 else:
33 print(f"backfill_worker: path not found: {args[1]!r}", file=sys.stderr)
34 return 1
36 from little_loops.session_store import backfill_incremental
38 backfill_incremental(db_path, jsonl_files=jsonl_files)
39 return 0
42if __name__ == "__main__":
43 sys.exit(main())