@@ -289,13 +289,20 @@ def _find_source_filename(doc_name: str, kb_dir: Path) -> str:
289289 return f"{ doc_name } .pdf"
290290
291291
292- def _write_summary (wiki_dir : Path , doc_name : str , source_file : str , summary : str , brief : str = "" ) -> None :
293- """Write summary page with frontmatter."""
292+ def _write_summary (wiki_dir : Path , doc_name : str , source_file : str , summary : str ,
293+ brief : str = "" , doc_type : str = "short" ) -> None :
294+ """Write summary page with frontmatter.
295+
296+ For short docs, includes a ``source_doc`` field linking to the full
297+ source text in ``sources/{doc_name}.md``.
298+ """
294299 summaries_dir = wiki_dir / "summaries"
295300 summaries_dir .mkdir (parents = True , exist_ok = True )
296301 fm_lines = [f"sources: [{ source_file } ]" ]
297302 if brief :
298303 fm_lines .append (f"brief: { brief } " )
304+ if doc_type == "short" :
305+ fm_lines .append (f"source_doc: sources/{ doc_name } .md" )
299306 frontmatter = "---\n " + "\n " .join (fm_lines ) + "\n ---\n \n "
300307 (summaries_dir / f"{ doc_name } .md" ).write_text (frontmatter + summary , encoding = "utf-8" )
301308
@@ -442,12 +449,15 @@ def _backlink_concepts(wiki_dir: Path, doc_name: str, concept_slugs: list[str])
442449def _update_index (
443450 wiki_dir : Path , doc_name : str , concept_names : list [str ],
444451 doc_brief : str = "" , concept_briefs : dict [str , str ] | None = None ,
452+ doc_type : str = "short" ,
445453) -> None :
446454 """Append document and concept entries to index.md.
447455
448456 When ``doc_brief`` or entries in ``concept_briefs`` are provided, entries
449- are written as ``- [[link]] — brief text``. Existing entries are detected
450- by the link part only, so updating a brief on a re-compile works correctly.
457+ are written as ``- [[link]] (type) — brief text``. Existing entries are
458+ detected by the link part only, so updating a brief on a re-compile works.
459+ ``doc_type`` is ``"short"`` or ``"pageindex"`` — shown in the entry so the
460+ query agent knows how to access detailed content.
451461 """
452462 if concept_briefs is None :
453463 concept_briefs = {}
@@ -463,7 +473,7 @@ def _update_index(
463473
464474 doc_link = f"[[summaries/{ doc_name } ]]"
465475 if doc_link not in text :
466- doc_entry = f"- { doc_link } "
476+ doc_entry = f"- { doc_link } ( { doc_type } ) "
467477 if doc_brief :
468478 doc_entry += f" — { doc_brief } "
469479 if "## Documents" in text :
@@ -498,6 +508,7 @@ async def _compile_concepts(
498508 doc_name : str ,
499509 max_concurrency : int ,
500510 doc_brief : str = "" ,
511+ doc_type : str = "short" ,
501512) -> None :
502513 """Shared Steps 2-4: concepts plan → generate/update → index.
503514
@@ -635,7 +646,8 @@ async def _gen_update(concept: dict) -> tuple[str, str, bool, str]:
635646
636647 # --- Step 4: Update index (code only) ---
637648 _update_index (wiki_dir , doc_name , concept_names ,
638- doc_brief = doc_brief , concept_briefs = concept_briefs_map )
649+ doc_brief = doc_brief , concept_briefs = concept_briefs_map ,
650+ doc_type = doc_type )
639651
640652
641653async def compile_short_doc (
@@ -684,6 +696,7 @@ async def compile_short_doc(
684696 await _compile_concepts (
685697 wiki_dir , kb_dir , model , system_msg , doc_msg ,
686698 summary , doc_name , max_concurrency , doc_brief = doc_brief ,
699+ doc_type = "short" ,
687700 )
688701
689702
@@ -726,4 +739,5 @@ async def compile_long_doc(
726739 await _compile_concepts (
727740 wiki_dir , kb_dir , model , system_msg , doc_msg ,
728741 overview , doc_name , max_concurrency , doc_brief = doc_description ,
742+ doc_type = "pageindex" ,
729743 )
0 commit comments