Skip to content

feat: TOC link attach, 1-based pages, and profile stage wiring - #291

Merged
EricNGOntos merged 10 commits into
mainfrom
feat/wuchengke/toc-link-attach-calibration
Aug 15, 2026
Merged

EricNGOntos merged 10 commits into
mainfrom
feat/wuchengke/toc-link-attach-calibration

Conversation

@EricNGOntos

Copy link
Copy Markdown
Contributor

Summary

  • Attach TOC-page hyperlinks before calibration; treat get_links() dest pages as already 1-based (no off-by-one +1).
  • Wire profile flags for staged debug (stop_after_asset_probe, skip_toc_anchoring) and run asset probe before TOC.
  • Keep contained-TOC graft / anchoring path; fix circular imports via lazy calibration imports and update graft contract mocks.

Test plan

  • make check
  • pytest TOC graft + link attach/match contracts
  • Stage0→1 on HVAC PDF: links 70/76 all offset +5 (资格复审 1→6)
  • Stage2 calibration submit still needs follow-up (JSON abort) — not claimed fixed here

Made with Cursor

EricNGOntos and others added 8 commits August 13, 2026 15:05
- Introduced `_clear_toc_anchor_state` method to reset TOC anchor-related attributes in `ProfileCoordinator`.
- Updated `PageAnatomyMap` and `AgentBlackboard` to include new fields for `skeleton_anchor`, `skeleton_nodes`, and `pending_skeleton_anchors`.
- Integrated `run_toc_anchoring` in the extraction pipeline to improve TOC processing.
- Added serialization and deserialization functions for `skeleton_anchor` and `title_node` to support new data structures.
- Refactored `extract_section_skeletons` to utilize persisted `skeleton_anchor` for section boundary resolution.
- Added `rapidocr-onnxruntime` as a dependency for OCR capabilities.
- Implemented `_run_text_scan` method in `ProfileCoordinator` to handle text extraction from PDF pages.
- Updated `PageAnatomyMap` to include `page_full_text_cache` for storing scanned text.
- Enhanced TOC anchoring logic to utilize cached page text for improved accuracy.
- Refactored various tools to leverage the new text scanning functionality, ensuring seamless integration with existing workflows.
- Removed `run_toc` and `_run_toc` methods from `ProfileCoordinator` to streamline TOC processing.
- Eliminated `page_full_text_cache` from `PageAnatomyMap` and related logic to simplify data handling.
- Updated tests to reflect changes in TOC extraction and anatomy map structure, ensuring consistency in functionality.
- Removed `min_pages` parameter from `validate_shard_plan` and related functions to simplify validation logic.
- Updated `ProfileCoordinator` to clarify comments regarding single-shard placeholder usage.
- Refactored `propose_shard_plan` and `validate_anatomy_map` to enhance clarity and maintainability.
- Adjusted tests to reflect the removal of `min_pages` and ensure consistency with updated validation logic.
- Introduced `_attach_toc_page_links` method to attach hyperlinks to TOC entries before calibration.
- Updated `run_toc_anchoring` to conditionally skip anchoring based on settings.
- Refactored `ProfileCoordinator` to ensure asset probes are executed in the correct order relative to TOC processing.
- Enhanced `collect_toc_page_links` to normalize page link destinations and improve link matching logic.
- Updated `profile_document` to include a new parameter for skipping TOC anchoring during profiling.
- Adjusted tests to validate the new TOC processing flow and ensure correct asset probing order.
- Moved import statements for `anchor_hierarchy`, `finalize_calibration_result`, `pick_primary_offset`, `calibrate_offset`, and `graft_contained_toc` to the top of the file for better readability.
- Removed redundant import statements to enhance clarity and maintainability of the `toc_anchoring.py` file.
Lazy imports in toc_anchoring broke module-level mocks; point patches at
orchestrator/service/procedure instead.

Co-authored-by: Cursor <cursoragent@cursor.com>


def test_classify_toc_relationship_is_not_on_c4_module() -> None:
import app.services.page_memory.skeleton_extractor as skeleton_extractor
EricNGOntos and others added 2 commits August 15, 2026 12:22
Contract tests were still patching symbols on toc_anchoring that are only
imported inside functions after the circular-import refactor.

Co-authored-by: Cursor <cursoragent@cursor.com>
api and worker both use top-level `app`, so a combined pytest run can
leave stale module bindings; patch the defining function globals and run
the suites separately in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
@EricNGOntos
EricNGOntos merged commit f6c5001 into main Aug 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants