Skip to content

Commit 947d146

Browse files
authored
refactor(skill/tools): delegate list_wiki_dir and read_wiki_file_for_skill to canonical agent tools (#79)
1 parent dbf79d1 commit 947d146

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

openkb/skill/tools.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
"""Path-scoped IO tools for the skill-create agent.
22
33
The skill-create agent runs with these capabilities:
4-
* READ wiki structure — ``list_wiki_dir``
5-
* READ wiki markdown — ``read_wiki_file_for_skill``
4+
* READ wiki structure — ``list_wiki_dir`` (delegates to
5+
``openkb.agent.tools.list_wiki_files``)
6+
* READ wiki markdown — ``read_wiki_file_for_skill`` (delegates to
7+
``openkb.agent.tools.read_wiki_file``)
68
* READ PageIndex source pages — ``get_skill_page_content`` (delegates to
79
``openkb.agent.tools.get_wiki_page_content``)
810
* READ wiki images — ``read_skill_image`` (delegates to
911
``openkb.agent.tools.read_wiki_image``)
1012
* WRITE under skill root — ``write_skill_file``
1113
12-
The first four wrap the canonical wiki tools in ``openkb/agent/tools.py``
13-
so the skill agent traverses the wiki the same way the query agent does —
14-
no separate retrieval semantics, no second implementation to drift.
14+
The first four are thin wrappers around the canonical wiki tools in
15+
``openkb/agent/tools.py`` so the skill agent traverses the wiki the same
16+
way the query agent does — no separate retrieval semantics, no second
17+
implementation to drift.
1518
1619
These helpers enforce write boundaries at the Python level — every write
1720
resolves its target path, then verifies it stays inside the skill root.
@@ -23,41 +26,34 @@
2326

2427
from openkb.agent.tools import (
2528
get_wiki_page_content as _get_wiki_page_content,
29+
list_wiki_files as _list_wiki_files,
30+
read_wiki_file as _read_wiki_file,
2631
read_wiki_image as _read_wiki_image,
2732
)
2833

2934

3035
def list_wiki_dir(directory: str, wiki_root: str) -> str:
3136
"""List ``.md`` files in a wiki subdirectory.
3237
38+
Thin wrapper around :func:`openkb.agent.tools.list_wiki_files`.
39+
3340
Args:
3441
directory: Path relative to *wiki_root* (e.g. ``"concepts"``).
3542
wiki_root: Absolute path to ``<kb>/wiki``.
3643
"""
37-
root = Path(wiki_root).resolve()
38-
target = (root / directory).resolve()
39-
if not target.is_relative_to(root):
40-
return "Access denied: path escapes wiki root."
41-
if not target.exists() or not target.is_dir():
42-
return "No files found."
43-
names = sorted(p.name for p in target.iterdir() if p.suffix == ".md")
44-
return "\n".join(names) if names else "No files found."
44+
return _list_wiki_files(directory, wiki_root)
4545

4646

4747
def read_wiki_file_for_skill(path: str, wiki_root: str) -> str:
4848
"""Read a Markdown file from the wiki.
4949
50+
Thin wrapper around :func:`openkb.agent.tools.read_wiki_file`.
51+
5052
Args:
5153
path: File path relative to *wiki_root* (e.g. ``"concepts/attention.md"``).
5254
wiki_root: Absolute path to ``<kb>/wiki``.
5355
"""
54-
root = Path(wiki_root).resolve()
55-
full = (root / path).resolve()
56-
if not full.is_relative_to(root):
57-
return "Access denied: path escapes wiki root."
58-
if not full.exists():
59-
return f"File not found: {path}"
60-
return full.read_text(encoding="utf-8")
56+
return _read_wiki_file(path, wiki_root)
6157

6258

6359
def get_skill_page_content(doc_name: str, pages: str, wiki_root: str) -> str:

0 commit comments

Comments
 (0)