Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ path = musher.cache_path() # cache directory path
- `fetch_asset()` — fetch individual assets by logical path
- Sync (`Client`) and async (`AsyncClient`) clients
- Typed handles: `SkillHandle`, `PromptHandle`, `ToolsetHandle`, `AgentSpecHandle`
- `bundle.select()` — filter resources by type
- `bundle.select()` — filter resources by type; with no filters it selects the whole bundle, `config` and `other` files included
- Content-addressable cache with TTL and garbage collection
- Cache management: `cache_info()`, `cache_remove()`, `cache_clear()`, `cache_clean()`, `cache_path()`
- `export_claude_plugin()` / `install_claude_skills()` — Claude integration
Expand Down
15 changes: 12 additions & 3 deletions src/musher/_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,15 @@ def select(
toolsets: list[str] | None = None,
agent_specs: list[str] | None = None,
) -> BundleSelection:
"""Return a filtered subset of this bundle's resources."""
"""Return a filtered subset of this bundle's resources.

With no filter, the selection is the whole bundle: its ``files()`` are
every file, ``config`` and ``other`` assets included. With any filter,
they are the files of the selected skills, prompts, toolsets and agent
specs.
"""
self._build_handles()
assert self._file_handles is not None # noqa: S101
assert self._skill_handles is not None # noqa: S101
assert self._prompt_handles is not None # noqa: S101
assert self._toolset_handles is not None # noqa: S101
Expand All @@ -270,8 +277,10 @@ def select(
sel_toolsets = _filter_map(self._toolset_handles, toolsets)
sel_agent_specs = _filter_map(self._agent_spec_handles, agent_specs)

# Collect files belonging to selected resources
sel_files: dict[str, FileHandle] = {}
# No filter selects everything, untyped files included; a filter selects
# the files of the resources it names.
unfiltered = all(f is None for f in (skills, prompts, toolsets, agent_specs))
sel_files: dict[str, FileHandle] = dict(self._file_handles) if unfiltered else {}
for sh in sel_skills.values():
for fh in sh.files():
sel_files[fh.logical_path] = fh
Expand Down
33 changes: 30 additions & 3 deletions tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def _make_resolve() -> ResolveResult:
})


def _make_bundle_with_typed_assets() -> Bundle:
"""Create a bundle with assets of various types for handle testing."""
assets: dict[str, Asset] = {}
def _make_bundle_with_typed_assets(extra: dict[str, Asset] | None = None) -> Bundle:
"""Create a bundle with assets of various types for handle testing, plus ``extra``."""
assets: dict[str, Asset] = dict(extra or {})

# Skill assets (a skill folder with SKILL.md)
assets["skills/search/SKILL.md"] = Asset(
Expand Down Expand Up @@ -295,6 +295,33 @@ def test_select_prompts_subset(self):
assert len(sel.prompts()) == 1
assert len(sel.skills()) == 0

def test_select_with_no_filters_keeps_untyped_files(self):
"""#19: select() with no filters is the whole bundle, config and other files included."""
untyped = {
path: Asset(
asset_id=path,
logical_path=path,
asset_type=asset_type,
content=b"x",
content_sha256=path,
size_bytes=1,
)
for path, asset_type in (
("config/settings.yaml", AssetType.CONFIG),
("assets/logo.svg", AssetType.OTHER),
)
}
bundle = _make_bundle_with_typed_assets(untyped)

sel = bundle.select()

assert {f.logical_path for f in sel.files()} == {f.logical_path for f in bundle.files()}
assert sel.file("config/settings.yaml") is not None
assert sel.file("assets/logo.svg") is not None
# A filter still selects only the files of the resources it names.
filtered = bundle.select(skills=["search"])
assert filtered.file("config/settings.yaml") is None

def test_select_empty(self):
bundle = _make_bundle_with_typed_assets()
sel = bundle.select(skills=[], prompts=[], toolsets=[], agent_specs=[])
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading