Skip to content

feat: GetFolderDescription tool — per-file description registry with LLM auto-generation#53

Draft
Simon-Free wants to merge 2 commits intoSafeRL-Lab:mainfrom
Simon-Free:pr7-folder-description
Draft

feat: GetFolderDescription tool — per-file description registry with LLM auto-generation#53
Simon-Free wants to merge 2 commits intoSafeRL-Lab:mainfrom
Simon-Free:pr7-folder-description

Conversation

@Simon-Free
Copy link
Copy Markdown

@Simon-Free Simon-Free commented Apr 17, 2026

Summary

Add a GetFolderDescription tool that returns a recursive tree of code files with one-line descriptions, and a folder_desc/ package that backs it. Files get their description from either an inline # [desc] ... [/desc] tag on the first line (free, instant) or a cached LLM call (parallel, 8 workers). Useful for understanding a codebase at a glance without walking every file.

Files

File +/- What
folder_desc/__init__.py +4 Package marker + public re-export
folder_desc/cache.py +54 JSON cache keyed by file path + mtime; get_cached_desc / set_cached_desc
folder_desc/describer.py +108 extract_inline_desc, _read_preview, describe_file, describe_files_parallel (ThreadPoolExecutor, 8 workers)
folder_desc/tree.py +111 _is_code_file, _collect_files, build_tree_string, get_folder_description orchestrator
folder_desc/tools.py +41 Self-registering GetFolderDescription ToolDef
tools/__init__.py +1 Add "folder_desc.tools" to the extension module list
tests/test_folder_desc.py +132 Unit: cache keying, mtime invalidation, tree building, inline-tag extraction, parallel describe
tests/test_folder_description_e2e.py +67 E2E: agent.run with mocked providers.stream ? LLM calls GetFolderDescription against a tmp_path tree with inline tags ? tool_result contains both filenames and both [desc] tags

Inline tag convention

First-line pattern: # [desc] short one-line description [/desc]. Pattern is language-agnostic (# works for Python / Shell / Ruby / ...). The first line of a newly-created file is a cheap contract - no runtime cost, no LLM call, no cache invalidation needed. Files without the tag fall back to an LLM-generated description written into the JSON cache.

Backwards compatibility

config["disabled_tools"] = ["GetFolderDescription"] will remove the schema from the LLM view once #55 lands (which adds the registry-level gate). Until then, the tool is always registered but only fires when the LLM calls it - no other tool / command invokes it.

Minor cleanup

extract_inline_desc lost its except OSError: pass + unconditional return None pattern; the except now return Nones explicitly, and the loop-break dance is replaced by next(iter(f), "") to read the first line. Same behaviour, cleaner control flow, no silent pass.

Ref #43

@Simon-Free Simon-Free marked this pull request as draft April 17, 2026 19:46
nekocheik pushed a commit to nekocheik/cheetahclaws-fork that referenced this pull request Apr 19, 2026
… attribution

Add SILVERHAWK-FORK.md explaining:
- Why Silverhawk forks cheetahclaws (V2 chat brick pivot per user directive)
- What's customized (5 commits mapped: license, MCP, Matrix, a2a, wiring)
- Integration map pointers (docs/cheetahclaws-arch-map.md,
  docs-silverhawk/mcp-silverhawk-plug.md)
- Upstream tracking + contribution-back candidates (license fix)
- License Apache-2.0 matches upstream

Separate from upstream README.md (preserved as-is) to keep delta clear.

refs SafeRL-Lab#32 SafeRL-Lab#33 SafeRL-Lab#34 SafeRL-Lab#35 SafeRL-Lab#46 SafeRL-Lab#53
test_folder_description_e2e drives agent.run with a mocked stream: the
LLM issues a GetFolderDescription tool_call against a real tmp_path tree,
and the tool_result is inspected to assert both filenames and their
inline [desc] tags appear in the returned tree.

Also tighten extract_inline_desc: replace the `except OSError: pass`
followed by an unconditional `return None` with an explicit
`return None` inside the except -- same behaviour, no silent pass, and
reads the first line via `next(iter(f), "")` instead of a for-loop-break
so the control flow is a single straight line.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant