-
Notifications
You must be signed in to change notification settings - Fork 11
feat(toc,doc-index): add JIT-retrieval readiness checks and cached doc index #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ainetx
merged 4 commits into
constructorfabric:main
from
tkcoding:jit-retrieval-doc-index
Sep 1, 2026
+1,567
−10
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d5e2be7
feat(toc,doc-index): add JIT-retrieval readiness checks and cached do…
1854c12
fix(doc-index,toc): resolve CodeRabbit deep-review findings on PR #108
2a60188
fix(doc-index,toc): resolve PR #108 round-2 CodeRabbit findings
1e8384b
fix(doc-index): add missing CDSL markers to the doc-index CLI command
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """Studio doc-index command — build/reuse a cached structural index for a | ||
| Markdown file, so heading-based JIT retrieval reads a file's structure once, | ||
| not once per query. | ||
|
|
||
| Thin CLI wrapper around ``studio.utils.doc_index``. | ||
| """ | ||
|
|
||
| import argparse | ||
| import logging | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
| from ..utils.doc_index import get_or_build_doc_index | ||
| from ..utils.ui import ui | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| # @cpt-begin:cpt-studio-algo-traceability-validation-doc-index:p1:inst-doc-index-cmd | ||
| def cmd_doc_index(argv: List[str]) -> int: | ||
| """Build (or reuse the cached) structural index for a Markdown file.""" | ||
| p = argparse.ArgumentParser( | ||
| prog="cfs doc-index", | ||
| description=( | ||
| "Build or reuse a cached heading/section index for a Markdown file, " | ||
| "so navigation reads the file's structure once, not once per query." | ||
| ), | ||
| ) | ||
| p.add_argument("file", help="Markdown file path") | ||
| p.add_argument( | ||
| "--rebuild", | ||
| action="store_true", | ||
| help="Force a fresh build even if a valid cached index exists", | ||
| ) | ||
| args = p.parse_args(argv) | ||
|
|
||
| filepath = Path(args.file).resolve() | ||
| if not filepath.is_file(): | ||
| ui.result( | ||
| {"file": str(filepath), "status": "ERROR", "message": "File not found"}, | ||
| human_fn=lambda d: ui.error(f"{d['file']}: {d['message']}"), | ||
| ) | ||
| return 2 | ||
|
|
||
| try: | ||
| index = get_or_build_doc_index(filepath, force_rebuild=args.rebuild) | ||
| except (OSError, UnicodeDecodeError) as exc: | ||
| logger.warning("doc-index: cannot read %s: %s", filepath, exc) | ||
| ui.result( | ||
| {"file": str(filepath), "status": "ERROR", "message": f"Cannot read file: {exc}"}, | ||
| human_fn=lambda d: ui.error(f"{d['file']}: {d['message']}"), | ||
| ) | ||
| return 2 | ||
|
|
||
| output = { | ||
| "file": str(filepath), | ||
| "cache_hit": index["cache_hit"], | ||
| "total_lines": index["total_lines"], | ||
| "section_count": len(index["sections"]), | ||
| "sections": index["sections"], | ||
| } | ||
| ui.result(output, human_fn=_human_doc_index) | ||
| return 0 | ||
| # @cpt-end:cpt-studio-algo-traceability-validation-doc-index:p1:inst-doc-index-cmd | ||
|
|
||
|
|
||
| # @cpt-begin:cpt-studio-algo-traceability-validation-doc-index:p1:inst-doc-index-cmd-format | ||
| def _human_doc_index(data: dict) -> None: | ||
| ui.header("Doc Index") | ||
| ui.substep(data["file"]) | ||
| hit = "cache hit — reused existing index" if data["cache_hit"] else "cache miss — built fresh index" | ||
| ui.substep(hit) | ||
| ui.substep(f"{data['section_count']} section(s), {data['total_lines']} total lines") | ||
| for s in data["sections"]: | ||
| summary = f" — {s['summary']}" if s.get("summary") else "" | ||
| ui.substep(f" H{s['level']} [{s['line_start']}-{s['line_end']}] {s['heading']}{summary}") | ||
| ui.blank() | ||
| # @cpt-end:cpt-studio-algo-traceability-validation-doc-index:p1:inst-doc-index-cmd-format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JIT-readiness warnings invisible in human CLI output
Severity: Major
Problem
The human-readable output branch for a
WARN-only file (_human_validate_toc's finalelse:, line 134) prints onlyf"{path}: {status}"and never iteratesr.get("warnings", []), unlike theFAILbranch just above it which does. Since this PR's four new JIT-retrieval readiness checks (duplicate headings, heading-depth jumps, oversized sections, missing description) are warning-only by design, any file that trips only these new checks lands in this silent branch. (Anchored here at the newmax_section_lineswiring since line 134 itself isn't touched by this diff, but its behavior is what this PR's new warnings now depend on.) Separately,_human_doc_indexincommands/doc_index.pynever prints the target file name either.How to reproduce
cfs validate-toc file.md(human mode, no--json).Expected behavior
The new warning (e.g.
toc-heading-duplicate: ...) is printed, the same way an error would be underFAIL.Actual behavior
Output is just
file.md: WARNwith no indication of what's wrong — the JSON output (--json) does contain the warning, so the information exists but never reaches the default human-facing path.Impact
The PR's headline feature (JIT-readiness warnings) is effectively invisible to anyone using the default CLI output instead of
--json.Suggested correction
Add a branch for
status == "WARN"(or extend theelse) that iteratesr.get("warnings", [])the same way theFAILbranch iteratesr.get("errors", []); printdata["file"]in_human_doc_index.How to verify
Add/extend a
TestCmdValidateToccase: a file with exactly one warning and no errors, run throughcmd_validate_toc's human-output path, and assert the warning text appears in the captured output.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1854c12: _human_validate_toc now has an explicit
elif status == "WARN":branch that iteratesr.get("warnings", [])the same way the FAIL branch iterates errors, and _human_doc_index now printsdata['file']. Regression tests:test_warn_only_file_prints_warnings_in_human_output,test_all_four_jit_warnings_zero_errors_exits_clean_via_cli.