Skip to content

Commit 6b070cc

Browse files
tzhouamclaude
andcommitted
Accept index links to the knowledge root
A link such as [Knowledge](../..) from repos/<repo>/_index.md resolves to the knowledge root, which check_index_links looked up among head's directories and never found (top-level files have dirname "", the link resolves to "."), so it reported index_link_broken for a valid link. The root is now a directory every tree has; a link above it still escapes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9195850 commit 6b070cc

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎doc/architecture/SPEC/knowledge_service/l1.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
再只对路径做百分号解码;引用定义、标题、转义、代码段/代码块、
3939
HTML 块/注释都由解析器按渲染器的方式处理,不手写匹配。URL、纯锚点不算目标。
4040
对每个新增或改动的 `_index.md`:
41-
- 本次新增的链接必须解析到 head 中的文件或目录、不得逃出知识树(`index_link_broken` /
41+
- 本次新增的链接必须解析到 head 中的文件或目录(知识树根目录本身,如 `../..`,算已存在的目录)、不得逃出知识树(`index_link_broken` /
4242
`index_link_escapes`,绝对路径保留各自的 `/…` 身份且一律算逃逸;base 已有的链接不重新判定——
4343
有些指向 `doc/`)。
4444
- 保留:base 的链接(按解析后的路径)必须仍在 head 的链接里,否则 `index_link_dropped`——把链接挪进

‎src/infermatrix_copilot/knowledge_service/l1.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ def check_index_links(base: Mapping[str, str], head: Mapping[str, str]) -> list[
483483
continue
484484
if resolved == ".." or resolved.startswith(("../", "/")):
485485
issues.append(Issue("index_link_escapes", path, written))
486+
elif resolved in (".", ""):
487+
continue # the knowledge root itself: a directory every tree has
486488
elif resolved not in head and not any(d == resolved or d.startswith(resolved + "/")
487489
for d in head_dirs):
488490
issues.append(Issue("index_link_broken", path, written))

‎test/test_kb_init_l1.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,12 @@ def test_only_kb_init_may_pass_bootstrap():
306306
if path not in allowed and re.search(r"bootstrap\s*=\s*True", path.read_text(encoding="utf-8"))
307307
]
308308
assert offenders == []
309+
310+
311+
def test_index_links_accept_the_knowledge_root_and_its_directories():
312+
base = _base()
313+
head = dict(base)
314+
head["repos/old/_index.md"] += "- [Knowledge](../..)\n- [Knowledge](../../)\n- [Repos](..)\n"
315+
assert check_index_links(base, head) == []
316+
head["repos/old/_index.md"] += "- [Above](../../..)\n"
317+
assert [(i.code, i.detail) for i in check_index_links(base, head)] == [("index_link_escapes", "../../..")]

0 commit comments

Comments
 (0)