feat(skills): explain nanobot usage from bundled documentation (#6176)

* feat(skills): add nanobot documentation guide with bundled docs

* docs: prefer graphical setup and align bundled guides with runtime

* docs: lead provider setup with built-in endpoint defaults

* fix: preserve documentation packaging and lookup across install paths

* fix(skills): narrow documentation loading to relevant sections

* refactor(skills): keep documentation guidance concise

* fix(docs): complete first-use workflows and clarify runtime boundaries

* style(docs): remove manual paragraph wrapping

* docs: guide first-run users to conversational setup help

* docs: fold README installation alternatives and details

* docs: separate README alert marker from its body

* docs: clarify README onboarding and runtime boundaries
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-13 00:44:25 +08:00
1 parent 23941355a8
commit cd2a863710
61 files changed
+1729 -634

No files matched your search

+36 -3
View File
@@ -8,6 +8,8 @@ from pathlib import Path
import pytest
from nanobot.agent.skills import SkillsLoader
from nanobot.agent.tools.filesystem import ListDirTool, WriteFileTool
from nanobot.agent.tools.search import GrepTool
def _write_skill(
@@ -298,7 +300,7 @@ def test_disabled_skills_excluded_from_build_skills_summary(tmp_path: Path) -> N
assert "beta" in summary
def test_build_skills_summary_uses_relative_roots_in_agent_workspace(tmp_path: Path) -> None:
def test_build_skills_summary_keeps_builtin_root_absolute_in_agent_workspace(tmp_path: Path) -> None:
workspace = tmp_path / "ws"
workspace_skills = workspace / "skills"
workspace_skills.mkdir(parents=True)
@@ -309,14 +311,45 @@ def test_build_skills_summary_uses_relative_roots_in_agent_workspace(tmp_path: P
summary = SkillsLoader(workspace, builtin_skills_dir=builtin).build_skills_summary()
assert str(workspace_skills) not in summary
assert str(builtin) not in summary
assert f"### Built-in skills (`{builtin.resolve()}`)" in summary
assert str(workspace_path) not in summary
assert str(builtin_path) not in summary
assert summary.count("(`skills`)") == 2
assert summary.count("(`skills`)") == 1
assert "`alpha/SKILL.md`" in summary
assert "`beta/SKILL.md`" in summary
async def test_builtin_summary_root_supports_restricted_reference_search(tmp_path: Path) -> None:
workspace = tmp_path / "ws"
workspace.mkdir()
builtin = tmp_path / "builtin"
_write_skill(builtin, "documentation", body="# Documentation")
references = builtin / "documentation" / "references"
references.mkdir()
guide = references / "usage.md"
guide.write_text("Choose a timezone", encoding="utf-8")
summary = SkillsLoader(workspace, builtin_skills_dir=builtin).build_skills_summary()
heading = next(line for line in summary.splitlines() if line.startswith("### Built-in skills"))
reference_path = str(Path(heading.split("`")[1]) / "documentation" / "references")
options = {
"workspace": workspace,
"allowed_dir": workspace,
"restrict_to_workspace": True,
"extra_read_allowed_dirs": [builtin],
}
listing = await ListDirTool(**options).execute(path=reference_path)
matches = await GrepTool(**options).execute(
pattern="timezone", path=reference_path, glob="*.md", output_mode="files_with_matches",
)
assert "usage.md" in listing
assert "usage.md" in matches
rejected = await WriteFileTool(**options).execute(path=str(guide), content="replace")
assert rejected.is_error
assert guide.read_text(encoding="utf-8") == "Choose a timezone"
def test_build_skills_summary_keeps_absolute_roots_for_selected_project(tmp_path: Path) -> None:
workspace = tmp_path / "ws"
workspace_skills = workspace / "skills"
+103
View File
@@ -0,0 +1,103 @@
"""Documentation stays available across installs and rebuilds."""
import ctypes
import os
import shutil
import subprocess
import sys
from pathlib import Path
from types import SimpleNamespace
from zipfile import ZipFile
import pytest
from hatch_build import WebUIBuildHook
def test_editable_install_refreshes_skill_documentation(tmp_path: Path) -> None:
docs = tmp_path / "docs"
(docs / "guides").mkdir(parents=True)
(docs / "README.md").write_text("Documentation index", encoding="utf-8")
guide = docs / "guides" / "setup.md"
guide.write_text("Setup instructions", encoding="utf-8")
hook = WebUIBuildHook(
str(tmp_path), {}, None, {}, "", "wheel",
SimpleNamespace(display_info=lambda message: None),
)
build_data = {}
hook.initialize("editable", build_data)
references = tmp_path / "nanobot/skills/nanobot-document/references"
assert (references / "README.md").read_bytes() == (docs / "README.md").read_bytes()
assert (references / "guides/setup.md").read_bytes() == guide.read_bytes()
guide.unlink()
(docs / "README.md").write_text("Updated index", encoding="utf-8")
hook.initialize("editable", {})
assert not (references / "guides/setup.md").exists()
assert (references / "README.md").read_text(encoding="utf-8") == "Updated index"
@pytest.mark.skipif(sys.platform != "win32", reason="Windows directory handles")
def test_editable_install_refreshes_docs_with_open_reference_directory(tmp_path: Path) -> None:
docs = tmp_path / "docs"
docs.mkdir()
(docs / "README.md").write_text("Documentation index", encoding="utf-8")
hook = WebUIBuildHook(
str(tmp_path), {}, None, {}, "", "wheel",
SimpleNamespace(display_info=lambda message: None),
)
hook.initialize("editable", {})
references = tmp_path / "nanobot/skills/nanobot-document/references"
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
kernel32.CreateFileW.restype = ctypes.c_void_p
# Allow file updates while holding the directory against removal, as an
# editor or file watcher can do while rebuilding an editable install.
handle = kernel32.CreateFileW(
ctypes.c_wchar_p(str(references)), 1, 3, None, 3, 0x02000000, None,
)
assert handle != ctypes.c_void_p(-1).value, ctypes.WinError(ctypes.get_last_error())
try:
(docs / "README.md").write_text("Updated index", encoding="utf-8")
hook.initialize("editable", {})
finally:
kernel32.CloseHandle(ctypes.c_void_p(handle))
assert (references / "README.md").read_text(encoding="utf-8") == "Updated index"
@pytest.mark.parametrize("ignore_references", [False, True])
def test_wheel_bundles_documentation_once(tmp_path: Path, ignore_references: bool) -> None:
repository = Path(__file__).resolve().parents[1]
(tmp_path / "docs").mkdir()
(tmp_path / "docs/README.md").write_text("Documentation index", encoding="utf-8")
(tmp_path / "nanobot").mkdir()
(tmp_path / "nanobot/__init__.py").write_text("", encoding="utf-8")
shutil.copyfile(repository / "nanobot/build_info.py", tmp_path / "nanobot/build_info.py")
shutil.copyfile(repository / "hatch_build.py", tmp_path / "hatch_build.py")
(tmp_path / "pyproject.toml").write_text(
'[project]\nname = "documentation-build-test"\nversion = "0.0.0"\n'
'[tool.hatch.build]\ninclude = ["nanobot/**/*.py", "nanobot/skills/**/*.md"]\n'
'[tool.hatch.build.hooks.custom]\n'
'[tool.hatch.build.targets.wheel]\npackages = ["nanobot"]\n',
encoding="utf-8",
)
if ignore_references:
(tmp_path / ".gitignore").write_text(
"/nanobot/skills/nanobot-document/references/\n", encoding="utf-8",
)
result = subprocess.run(
[sys.executable, "-c", "import hatchling.build; hatchling.build.build_wheel('dist')"],
cwd=tmp_path,
env={**os.environ, "NANOBOT_SKIP_WEBUI_BUILD": "1"},
capture_output=True,
text=True,
check=False,
)
assert result.returncode == 0, result.stdout + result.stderr
with ZipFile(next((tmp_path / "dist").glob("*.whl"))) as wheel:
bundled_index = "nanobot/skills/nanobot-document/references/README.md"
assert wheel.namelist().count(bundled_index) == 1
assert wheel.read(bundled_index) == b"Documentation index"