fix: address 4 review items — remove dead INTENTS dict, drop unused --limit from paper-navigation, add -> int return types, guard subsection section_path

This commit is contained in:
LLLin000 2026-07-05 14:46:26 +08:00
parent 1e6edad7ba
commit 4dbeb5ae50
5 changed files with 4 additions and 11 deletions

View file

@ -464,7 +464,6 @@ def build_parser() -> argparse.ArgumentParser:
p_paper_navigation = sub.add_parser("paper-navigation", help="Navigate paper structure through the Layer 4 gateway")
p_paper_navigation.add_argument("query", help="Paper identifier or DOI for structural navigation")
p_paper_navigation.add_argument("--json", action="store_true", help="Output JSON")
p_paper_navigation.add_argument("--limit", type=int, default=5, help="Max results (default 5)")
p_scoped_fetch = sub.add_parser("scoped-fetch", help="Fetch paper content scoped by query through the Layer 4 gateway")
p_scoped_fetch.add_argument("query", help="Paper identifier, title, or scoped query for targeted fetch")

View file

@ -5,7 +5,7 @@ from __future__ import annotations
from paperforge.retrieval import gateway
def run(args):
def run(args) -> int:
"""Execute ``content-discovery`` via the Layer 4 gateway."""
result = gateway.route_gateway(
args.vault_path,

View file

@ -5,7 +5,7 @@ from __future__ import annotations
from paperforge.retrieval import gateway
def run(args):
def run(args) -> int:
"""Execute ``paper-lookup`` via the Layer 4 gateway."""
result = gateway.route_gateway(
args.vault_path,

View file

@ -18,13 +18,6 @@ from paperforge.memory.db import get_connection, get_memory_db_path
logger = logging.getLogger(__name__)
# Map gateway intent names to build_query_plan intent strings
INTENTS: dict[str, str] = {
"paper-lookup": "known-paper",
"content-discovery": "content",
"paper-navigation": "known-paper",
"scoped-fetch": "known-paper",
}
def route_gateway(

View file

@ -13,12 +13,13 @@ def build_structure_tree(structured_blocks: list[dict[str, Any]]) -> dict[str, A
role = block.get("role")
text = str(block.get("text", "")).strip()
if role in {"section_heading", "subsection_heading", "introduction_heading", "abstract_heading"} and text:
parent_title = nodes[-1]["title"] if nodes else ""
current_section = {
"node_id": f"sec:{block.get('block_id')}",
"kind": "section",
"title": text,
"level": 1 if role != "subsection_heading" else 2,
"section_path": [text] if role != "subsection_heading" else [nodes[-1]["title"], text] if nodes else [text],
"section_path": [text] if role != "subsection_heading" else [parent_title, text],
"page_span": [block.get("page", 0), block.get("page", 0)],
"block_span": [[block.get("page", 0), block.get("block_id", "")]],
"children": [],