-
Notifications
You must be signed in to change notification settings - Fork 75
feat: discover JSON agents & skills from project-level .code_puppy directory #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: discover JSON agents & skills from project-level .code_puppy directory #170
Conversation
📝 WalkthroughWalkthroughdiscover_json_agents now searches both the user agents directory and a project-scoped Changes
Sequence DiagramsequenceDiagram
participant Caller as Caller
participant Discover as discover_json_agents()
participant UserConfig as get_user_agents_directory()
participant ProjectConfig as get_project_agents_directory()
participant UserFS as User Agent Dir
participant ProjectFS as Project Agent Dir
Caller->>Discover: invoke discovery
Discover->>UserConfig: request user agents path
UserConfig-->>Discover: return path or None
alt user path present
Discover->>UserFS: scan files, validate JSON
UserFS-->>Discover: user agents map
else
Discover-->>Discover: user agents map = {}
end
Discover->>ProjectConfig: request project agents path
ProjectConfig-->>Discover: return path or None
alt project path present
Discover->>ProjectFS: scan files, validate JSON
ProjectFS-->>Discover: project agents map
Discover->>Discover: merge maps (project overrides user on name collisions)
else
Discover-->>Discover: keep user agents only
end
Discover-->>Caller: return merged agent-name → file-path map
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
776e195 to
3c530af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
code_puppy/plugins/agent_skills/config.py (1)
13-48:⚠️ Potential issue | 🟡 MinorStale docstring: default directory list is outdated.
The docstring on line 19 still says
Default: ['~/.code_puppy/skills', './skills']but the actual defaults now include 5 directories (adding~/.claude/skills,~/.wibey/skills, and<CWD>/.code_puppy/skills).📝 Suggested fix
"""Get configured skill directories. Returns: List of skill directory paths from configuration. Reads from puppy.cfg [puppy] section under 'skill_directories' key. - Default: ['~/.code_puppy/skills', './skills'] + Default: ['~/.code_puppy/skills', '~/.claude/skills', '~/.wibey/skills', + '<CWD>/.code_puppy/skills', '<CWD>/skills'] The directories are stored as a JSON list in the config. """code_puppy/plugins/agent_skills/discovery.py (1)
26-40:⚠️ Potential issue | 🟡 MinorDocstring for
get_default_skill_directories()is incomplete.The docstring lists only
~/.code_puppy/skills,./.code_puppy/skills, and./skills, but the actual return value now also includes~/.claude/skillsand~/.wibey/skills.📝 Suggested fix
def get_default_skill_directories() -> List[Path]: """Return default directories to scan for skills. Returns: - ~/.code_puppy/skills (user skills) + - ~/.claude/skills (Claude skills) + - ~/.wibey/skills (WIBey skills) - ./.code_puppy/skills (project config skills) - ./skills (project skills) """
🧹 Nitpick comments (3)
code_puppy/agents/json_agent.py (1)
170-185: Consider adding debug-level logging when skipping invalid agent files.Both scan loops silently swallow all exceptions. While this is appropriate for discovery (one bad file shouldn't break everything), having debug logging would aid troubleshooting when an agent file is unexpectedly ignored.
♻️ Suggested improvement
+ import logging + logger = logging.getLogger(__name__) + for json_file in user_agents_dir.glob("*.json"): try: agent = JSONAgent(str(json_file)) agents[agent.name] = str(json_file) - except Exception: + except Exception as e: + logger.debug("Skipping invalid agent file %s: %s", json_file, e) continueApply the same pattern to the project-level loop.
tests/agents/test_project_agent_integration.py (1)
38-53: Prefermonkeypatch.chdir()over manual CWD save/restore.The manual
os.getcwd()/os.chdir()intry/finallyworks butmonkeypatch.chdir()is safer (auto-restores even on unexpected failures) and more concise. This pattern is already used in the other test files in this PR (e.g.,tests/test_json_agents.py).♻️ Example for test_discover_project_agent_via_cwd
- def test_discover_project_agent_via_cwd(self, tmp_path): + def test_discover_project_agent_via_cwd(self, tmp_path, monkeypatch): """Test that changing to a directory with .code_puppy discovers agents.""" # ... setup ... - original_cwd = os.getcwd() - try: - os.chdir(str(project_dir)) - - with patch( - "code_puppy.config.get_user_agents_directory", - return_value=str(empty_user_dir), - ): - agents = discover_json_agents() - - assert "project-agent" in agents - assert agents["project-agent"] == str(agent_file) - finally: - os.chdir(original_cwd) + monkeypatch.chdir(str(project_dir)) + + with patch( + "code_puppy.config.get_user_agents_directory", + return_value=str(empty_user_dir), + ): + agents = discover_json_agents() + + assert "project-agent" in agents + assert agents["project-agent"] == str(agent_file)Apply the same pattern to the other three test methods.
tests/agents/test_json_agent_extended.py (1)
377-398: Repeated inlineimport osacross multiple test methods.
import osappears inside 5 different test methods (lines 383, 428, 450, 466, 503) instead of at the module level. Move it to the top-level imports for consistency.♻️ Suggested fix
Add at the top of the file alongside other imports:
import json +import os from unittest.mock import patchThen remove the inline
import osfrom each test method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@code_puppy/plugins/agent_skills/discovery.py`:
- Around line 34-38: get_default_skill_directories currently returns only three
paths; update it to include the two missing home-dir skill paths so tests
expecting five directories pass. Specifically, add Path.home() / ".claude" /
"skills" and Path.home() / ".wibey" / "skills" to the list returned by
get_default_skill_directories (alongside the existing Path.home() /
".code_puppy" / "skills", Path.cwd() / ".code_puppy" / "skills", and Path.cwd()
/ "skills") so the order matches the test expectations.
In `@tests/plugins/test_agent_skills.py`:
- Around line 148-153: The test expects get_default_skill_directories() to
return five paths but the implementation currently returns only three; update
the get_default_skill_directories function to include the two missing home
subdirectories (Path.home() / ".claude" / "skills" and Path.home() / ".wibey" /
"skills") and ensure the returned list ordering matches the test: Path.home() /
".code_puppy" / "skills", Path.home() / ".claude" / "skills", Path.home() /
".wibey" / "skills", Path.cwd() / ".code_puppy" / "skills", Path.cwd() /
"skills".
🧹 Nitpick comments (1)
tests/agents/test_json_agent_extended.py (1)
377-398: Prefermonkeypatch.chdirover manualos.chdirwith try/finally.Several tests in
TestDiscoverJsonAgentsuse manualos.chdir/os.getcwd()with try/finally for CWD isolation. pytest'smonkeypatch.chdir()automatically restores the original directory and is already used intests/test_json_agents.pyfor the same purpose. This would also eliminate the repeatedimport osinside test methods.Example refactor for test_discover_valid_agents
- def test_discover_valid_agents(self, tmp_path): + def test_discover_valid_agents(self, tmp_path, monkeypatch): """Test discovering valid JSON agents.""" # ... setup ... with patch("code_puppy.config.get_user_agents_directory") as mock_get_user_dir: mock_get_user_dir.return_value = str(tmp_path) - import os - original_cwd = os.getcwd() isolated_dir = tmp_path / "isolated" isolated_dir.mkdir() - os.chdir(str(isolated_dir)) + monkeypatch.chdir(isolated_dir) - try: - agents = discover_json_agents() + agents = discover_json_agents() - assert len(agents) == 2 - assert "agent1" in agents - assert "agent2" in agents - assert agents["agent1"] == str(agent1_file) - assert agents["agent2"] == str(agent2_file) - finally: - os.chdir(original_cwd) + assert len(agents) == 2 + assert "agent1" in agents + assert "agent2" in agents + assert agents["agent1"] == str(agent1_file) + assert agents["agent2"] == str(agent2_file)Apply the same pattern to
test_discover_skip_invalid_agents,test_discover_no_agents_directory,test_discover_empty_directory, andtest_discover_duplicate_names.
…rectory - Add get_project_agents_directory() to config.py - Extend discover_json_agents() to search both user and project directories - Project agents override user agents on name collision - Add .code_puppy/skills to skills discovery paths - Add comprehensive tests for project-level agent discovery This allows teams to version-control and share custom agents and skills by placing them in .code_puppy/agents/ and .code_puppy/skills/ within their repository.
3c530af to
13a8330
Compare
Summary
Adds support for discovering and loading JSON agents and skills from a project-level
.code_puppydirectory, enabling teams to version-control and share custom agents and skills within their repository.Changes
get_project_agents_directory()toconfig.pydiscover_json_agents()to search both user and project directories.code_puppy/skillsto skills discovery pathsTesting
tests/agents/test_project_agent_integration.pytests/agents/test_json_agent_extended.pyImpact
This allows teams to:
🤖 Generated with Code Puppy
Summary by CodeRabbit
New Features
Chores
Tests