-
Notifications
You must be signed in to change notification settings - Fork 19
Feat - Add GitHub Copilot target (#149) #154
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
Open
momostallion
wants to merge
7
commits into
LobsterTrap:main
Choose a base branch
from
StateFarmIns:feat/copilot-target
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+545
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a94a6ab
feat: add GitHub Copilot target (#149)
momostallion 9548767
fix: require description in skill frontmatter, fix legacy path
momostallion d341809
docs: fix frontmatter section wording for copilot
momostallion 412183b
fix: ensure legacy skill cleanup runs even when skill dir exists
momostallion 978b12d
test: add regression test for legacy skill cleanup
momostallion bfd0d4a
docs: clarify copilot target paths and agent passthrough behavior
momostallion 2e00b4e
fix: use ~/.copilot/ for user-scope instructions and MCP paths
momostallion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| """GitHub Copilot target implementation.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import lola.config as config | ||
| import lola.frontmatter as fm | ||
| from .base import ( | ||
| BaseAssistantTarget, | ||
| ManagedInstructionsTarget, | ||
| MCPSupportMixin, | ||
| _generate_passthrough_command, | ||
| ) | ||
|
|
||
|
|
||
| class CopilotTarget(MCPSupportMixin, ManagedInstructionsTarget, BaseAssistantTarget): | ||
| """Target for GitHub Copilot (VS Code + Visual Studio). | ||
|
|
||
| Copilot supports: | ||
| - Skills in .copilot/skills/<name>/SKILL.md (with name+description frontmatter) | ||
| - Prompt files in .github/prompts/*.prompt.md | ||
| - Agents in .github/agents/*.agent.md | ||
| - Global instructions in .github/copilot-instructions.md | ||
| - MCP servers in .github/copilot/mcp.json | ||
| """ | ||
|
|
||
| name = "copilot" | ||
| supports_agents = True | ||
| INSTRUCTIONS_FILE = "copilot-instructions.md" | ||
|
|
||
| def get_skill_path(self, project_path: str, scope: str = "project") -> Path: | ||
| if scope == "user": | ||
| return Path.home() / ".copilot" / "skills" | ||
| return Path(project_path) / ".github" / "skills" | ||
|
|
||
| def get_command_path(self, project_path: str, scope: str = "project") -> Path: | ||
| if scope == "user": | ||
| return Path.home() / ".copilot" / "prompts" | ||
| return Path(project_path) / ".github" / "prompts" | ||
|
|
||
| def get_agent_path(self, project_path: str, scope: str = "project") -> Path: | ||
| if scope == "user": | ||
| return Path.home() / ".copilot" / "agents" | ||
| return Path(project_path) / ".github" / "agents" | ||
|
|
||
| def get_instructions_path(self, project_path: str, scope: str = "project") -> Path: | ||
| if scope == "user": | ||
| return Path.home() / ".copilot" / self.INSTRUCTIONS_FILE | ||
| return Path(project_path) / ".github" / self.INSTRUCTIONS_FILE | ||
|
|
||
| def get_mcp_path(self, project_path: str, scope: str = "project") -> Path: | ||
| if scope == "user": | ||
| return Path.home() / ".copilot" / "mcp.json" | ||
| return Path(project_path) / ".github" / "copilot" / "mcp.json" | ||
|
|
||
| def generate_skill( | ||
| self, | ||
| source_path: Path, | ||
| dest_path: Path, | ||
| skill_name: str, | ||
| project_path: str | None = None, # noqa: ARG002 | ||
| ) -> bool: | ||
| """Generate SKILL.md in .copilot/skills/<name>/ directory. | ||
|
|
||
| Copilot skills use a directory-per-skill structure with | ||
| name + description in YAML frontmatter. | ||
| """ | ||
| if not source_path.exists(): | ||
| return False | ||
|
|
||
| skill_file = source_path / config.SKILL_FILE | ||
| if not skill_file.exists(): | ||
| return False | ||
|
|
||
| content = skill_file.read_text() | ||
| frontmatter, body = fm.parse(content) | ||
|
|
||
| description = frontmatter.get("description") | ||
| if not description: | ||
| return False | ||
|
|
||
| skill_dir = dest_path / skill_name | ||
| skill_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # Build Copilot-compatible frontmatter (requires name + description) | ||
| import yaml | ||
|
|
||
| copilot_fm: dict = { | ||
| "name": skill_name, | ||
| "description": description, | ||
| } | ||
| if frontmatter.get("applyTo"): | ||
| copilot_fm["applyTo"] = frontmatter["applyTo"] | ||
| elif frontmatter.get("globs"): | ||
| copilot_fm["applyTo"] = frontmatter["globs"] | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| fm_str = yaml.dump( | ||
| copilot_fm, default_flow_style=False, sort_keys=False | ||
| ).rstrip() | ||
| output = f"---\n{fm_str}\n---\n{body}" | ||
|
|
||
| dest_file = skill_dir / "SKILL.md" | ||
| dest_file.write_text(output) | ||
| return True | ||
|
|
||
| def remove_skill(self, dest_path: Path, skill_name: str) -> bool: | ||
| """Remove a skill's directory.""" | ||
| import shutil | ||
|
|
||
| removed = False | ||
| skill_dir = dest_path / skill_name | ||
| if skill_dir.exists(): | ||
| shutil.rmtree(skill_dir) | ||
| removed = True | ||
| # Legacy cleanup: old .instructions.md format | ||
| legacy_file = ( | ||
| dest_path.parent / "instructions" / f"{skill_name}.instructions.md" | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if legacy_file.exists(): | ||
| legacy_file.unlink() | ||
| removed = True | ||
| return removed | ||
|
|
||
| def generate_command( | ||
| self, | ||
| source_path: Path, | ||
| dest_dir: Path, | ||
| cmd_name: str, | ||
| module_name: str, | ||
| ) -> bool: | ||
| filename = self.get_command_filename(module_name, cmd_name) | ||
| return _generate_passthrough_command(source_path, dest_dir, filename) | ||
|
|
||
| def get_command_filename(self, module_name: str, cmd_name: str) -> str: # noqa: ARG002 | ||
| """Copilot uses .prompt.md extension for commands.""" | ||
| return f"{cmd_name}.prompt.md" | ||
|
|
||
| def generate_agent( | ||
| self, | ||
| source_path: Path, | ||
| dest_dir: Path, | ||
| agent_name: str, | ||
| module_name: str, | ||
| ) -> bool: | ||
| """Generate agent file with .agent.md extension. | ||
|
|
||
| Copilot agents use YAML frontmatter with fields like: | ||
| - description: when to use this agent | ||
| - tools: list of tools the agent can use | ||
| """ | ||
| if not source_path.exists(): | ||
| return False | ||
| dest_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| filename = self.get_agent_filename(module_name, agent_name) | ||
| content = source_path.read_text() | ||
|
|
||
| (dest_dir / filename).write_text(content) | ||
| return True | ||
|
|
||
| def get_agent_filename(self, module_name: str, agent_name: str) -> str: # noqa: ARG002 | ||
| """Copilot uses .agent.md extension for agents.""" | ||
| return f"{agent_name}.agent.md" | ||
|
|
||
| def remove_command( | ||
| self, | ||
| dest_dir: Path, | ||
| cmd_name: str, | ||
| module_name: str, | ||
| ) -> bool: | ||
| """Delete command file (.prompt.md).""" | ||
| filename = self.get_command_filename(module_name, cmd_name) | ||
| cmd_file = dest_dir / filename | ||
| if cmd_file.exists(): | ||
| cmd_file.unlink() | ||
| # Legacy cleanup | ||
| legacy_file = dest_dir / f"{module_name}.{cmd_name}.prompt.md" | ||
| if legacy_file.exists(): | ||
| legacy_file.unlink() | ||
| return True | ||
|
|
||
| def remove_agent( | ||
| self, | ||
| dest_dir: Path, | ||
| agent_name: str, | ||
| module_name: str, | ||
| ) -> bool: | ||
| """Delete agent file (.agent.md).""" | ||
| filename = self.get_agent_filename(module_name, agent_name) | ||
| agent_file = dest_dir / filename | ||
| if agent_file.exists(): | ||
| agent_file.unlink() | ||
| # Legacy cleanup | ||
| legacy_file = dest_dir / f"{module_name}.{agent_name}.agent.md" | ||
| if legacy_file.exists(): | ||
| legacy_file.unlink() | ||
| return True | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.