(args: argparse.Namespace)
| 390 | |
| 391 | |
| 392 | def cmd_evidence(args: argparse.Namespace) -> int: |
| 393 | state = read_state() |
| 394 | evidence_chapters: list[dict[str, Any]] = [] |
| 395 | processed = 0 |
| 396 | |
| 397 | for chapter in state["chapters"]: |
| 398 | chapter_name = chapter["chapter"] |
| 399 | chapter_query = chapter.get("query") or chapter.get("theme") or chapter_name |
| 400 | chapter_search = afml_search( |
| 401 | query=chapter_query, |
| 402 | chapter=chapter_name, |
| 403 | top_k=args.top_k, |
| 404 | include_text=False, |
| 405 | ) |
| 406 | chapter_hits = filter_hits_to_chapter(chapter_search.get("results", []), chapter_name) |
| 407 | chapter_anchor = summarize_hit(chapter_hits[0]) if chapter_hits else chapter.get("afml_anchor", {}) |
| 408 | chapter["afml_anchor"] = chapter_anchor |
| 409 | |
| 410 | chapter_evidence: dict[str, Any] = { |
| 411 | "chapter": chapter_name, |
| 412 | "query": chapter_query, |
| 413 | "anchor": chapter_anchor, |
| 414 | "sections": [], |
| 415 | } |
| 416 | |
| 417 | for section in chapter["sections"]: |
| 418 | if args.only_pending and section["status"] != "pending": |
| 419 | continue |
| 420 | processed += 1 |
| 421 | |
| 422 | module = section["module"] |
| 423 | module_query = MODULE_QUERIES.get(module, module.replace("_", " ")) |
| 424 | search_out = afml_search( |
| 425 | query=module_query, |
| 426 | chapter=chapter_name, |
| 427 | top_k=args.top_k, |
| 428 | include_text=False, |
| 429 | ) |
| 430 | search_hits = filter_hits_to_chapter(search_out.get("results", []), chapter_name) |
| 431 | |
| 432 | ctx_out = afml_get_context( |
| 433 | query=module_query, |
| 434 | chapter=chapter_name, |
| 435 | top_k=args.top_k_context, |
| 436 | window=args.window, |
| 437 | ) |
| 438 | contexts = [ |
| 439 | c for c in ctx_out.get("contexts", []) if chapter_eq(str(c.get("hit", {}).get("chapter", "")), chapter_name) |
| 440 | ] |
| 441 | |
| 442 | primary_hit: dict[str, Any] = {} |
| 443 | if contexts: |
| 444 | primary_hit = contexts[0].get("hit", {}) |
| 445 | elif search_hits: |
| 446 | primary_hit = search_hits[0] |
| 447 | |
| 448 | if primary_hit: |
| 449 | section["afml_anchor"] = summarize_hit(primary_hit) |
nothing calls this directly
no test coverage detected