-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add anteroom tool support (#60) #61
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,216 @@ | ||
| """Anteroom AI tool integration.""" | ||
|
|
||
| import re | ||
| import shutil | ||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
| from devsync.ai_tools.base import AITool | ||
| from devsync.core.models import AIToolType, InstallationScope, Instruction | ||
|
|
||
| START_MARKER = "<!-- devsync:start:{name} -->" | ||
| END_MARKER = "<!-- devsync:end:{name} -->" | ||
| SECTION_PATTERN = r"<!-- devsync:start:{name} -->\n.*?\n<!-- devsync:end:{name} -->" | ||
|
|
||
|
|
||
| class AnteroomTool(AITool): | ||
| """Integration for Anteroom. | ||
|
|
||
| Anteroom reads a single ANTEROOM.md file at the project root. | ||
| DevSync manages individual instruction sections using HTML comment markers: | ||
|
|
||
| <!-- devsync:start:instruction-name --> | ||
| ... instruction content ... | ||
| <!-- devsync:end:instruction-name --> | ||
| """ | ||
|
|
||
| @property | ||
| def tool_type(self) -> AIToolType: | ||
| """Return the AI tool type identifier.""" | ||
| return AIToolType.ANTEROOM | ||
|
|
||
| @property | ||
| def tool_name(self) -> str: | ||
| """Return human-readable tool name.""" | ||
| return "Anteroom" | ||
|
|
||
| def is_installed(self) -> bool: | ||
| """Check if Anteroom is installed on the system. | ||
|
|
||
| Returns: | ||
| True if aroom binary is found on PATH or ~/.anteroom/ exists | ||
| """ | ||
| if shutil.which("aroom") is not None: | ||
| return True | ||
| config_dir = Path.home() / ".anteroom" | ||
| return config_dir.exists() | ||
|
|
||
| def get_instructions_directory(self) -> Path: | ||
| """Get the directory where instructions should be installed. | ||
|
|
||
| Raises: | ||
| NotImplementedError: Anteroom only supports project-level installation | ||
| """ | ||
| raise NotImplementedError( | ||
| f"{self.tool_name} global installation is not supported. " | ||
| "Anteroom uses project-level ANTEROOM.md only. " | ||
| "Please use project-level installation instead (--scope project)." | ||
| ) | ||
|
|
||
| def get_instruction_file_extension(self) -> str: | ||
| """Get the file extension for Anteroom instructions. | ||
|
|
||
| Returns: | ||
| File extension including the dot | ||
| """ | ||
| return ".md" | ||
|
|
||
| def get_project_instructions_directory(self, project_root: Path) -> Path: | ||
| """Get the directory for project-specific Anteroom instructions. | ||
|
|
||
| ANTEROOM.md lives at the project root. | ||
|
|
||
| Args: | ||
| project_root: Path to the project root directory | ||
|
|
||
| Returns: | ||
| Path to project root | ||
| """ | ||
| return project_root | ||
|
|
||
| def get_instruction_path( | ||
| self, | ||
| instruction_name: str, | ||
| scope: InstallationScope = InstallationScope.GLOBAL, | ||
| project_root: Optional[Path] = None, | ||
| ) -> Path: | ||
| """Get the path to ANTEROOM.md. | ||
|
|
||
| Args: | ||
| instruction_name: Name of the instruction (unused for path) | ||
| scope: Installation scope (must be PROJECT) | ||
| project_root: Project root path | ||
|
|
||
| Returns: | ||
| Path to ANTEROOM.md | ||
|
|
||
| Raises: | ||
| ValueError: If scope is PROJECT but project_root is None | ||
| NotImplementedError: If scope is GLOBAL | ||
| """ | ||
| if scope == InstallationScope.GLOBAL: | ||
| raise NotImplementedError( | ||
| f"{self.tool_name} global installation is not supported. " | ||
| "Please use project-level installation instead (--scope project)." | ||
| ) | ||
| if project_root is None: | ||
| raise ValueError("project_root is required for PROJECT scope") | ||
| return project_root / "ANTEROOM.md" | ||
|
|
||
| def instruction_exists( | ||
| self, | ||
| instruction_name: str, | ||
| scope: InstallationScope = InstallationScope.GLOBAL, | ||
| project_root: Optional[Path] = None, | ||
| ) -> bool: | ||
| """Check if an instruction section exists in ANTEROOM.md. | ||
|
|
||
| Args: | ||
| instruction_name: Name of the instruction | ||
| scope: Installation scope | ||
| project_root: Project root path | ||
|
|
||
| Returns: | ||
| True if the instruction's section markers exist in ANTEROOM.md | ||
| """ | ||
| try: | ||
| path = self.get_instruction_path(instruction_name, scope, project_root) | ||
| if not path.exists(): | ||
| return False | ||
| content = path.read_text(encoding="utf-8") | ||
| start = START_MARKER.format(name=instruction_name) | ||
| return start in content | ||
| except (FileNotFoundError, ValueError, NotImplementedError): | ||
| return False | ||
|
|
||
| def install_instruction( | ||
| self, | ||
| instruction: Instruction, | ||
| overwrite: bool = False, | ||
| scope: InstallationScope = InstallationScope.GLOBAL, | ||
| project_root: Optional[Path] = None, | ||
| ) -> Path: | ||
| """Install an instruction as a section in ANTEROOM.md. | ||
|
|
||
| Args: | ||
| instruction: Instruction to install | ||
| overwrite: Whether to overwrite existing section | ||
| scope: Installation scope | ||
| project_root: Project root path | ||
|
|
||
| Returns: | ||
| Path to ANTEROOM.md | ||
|
|
||
| Raises: | ||
| FileExistsError: If instruction section exists and overwrite=False | ||
| """ | ||
| path = self.get_instruction_path(instruction.name, scope, project_root) | ||
|
|
||
| start = START_MARKER.format(name=instruction.name) | ||
| end = END_MARKER.format(name=instruction.name) | ||
| section = f"{start}\n{instruction.content}\n{end}" | ||
|
|
||
| if path.exists(): | ||
| content = path.read_text(encoding="utf-8") | ||
| if start in content: | ||
| if not overwrite: | ||
| raise FileExistsError(f"Instruction already exists in ANTEROOM.md: {instruction.name}") | ||
| pattern = SECTION_PATTERN.format(name=re.escape(instruction.name)) | ||
| content = re.sub(pattern, section, content, flags=re.DOTALL) | ||
| path.write_text(content, encoding="utf-8") | ||
| return path | ||
| if content and not content.endswith("\n"): | ||
| content += "\n" | ||
| content += "\n" + section + "\n" | ||
| path.write_text(content, encoding="utf-8") | ||
| else: | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
| path.write_text(section + "\n", encoding="utf-8") | ||
|
|
||
| return path | ||
|
|
||
| def uninstall_instruction( | ||
| self, | ||
| instruction_name: str, | ||
| scope: InstallationScope = InstallationScope.GLOBAL, | ||
| project_root: Optional[Path] = None, | ||
| ) -> bool: | ||
| """Remove an instruction section from ANTEROOM.md. | ||
|
|
||
| Args: | ||
| instruction_name: Name of instruction to remove | ||
| scope: Installation scope | ||
| project_root: Project root path | ||
|
|
||
| Returns: | ||
| True if section was removed, False if it didn't exist | ||
| """ | ||
| try: | ||
| path = self.get_instruction_path(instruction_name, scope, project_root) | ||
| if not path.exists(): | ||
| return False | ||
|
|
||
| content = path.read_text(encoding="utf-8") | ||
| start = START_MARKER.format(name=instruction_name) | ||
| if start not in content: | ||
| return False | ||
|
|
||
| pattern = SECTION_PATTERN.format(name=re.escape(instruction_name)) | ||
| new_content = re.sub(pattern, "", content, flags=re.DOTALL) | ||
| new_content = re.sub(r"\n{3,}", "\n\n", new_content).strip() | ||
| if new_content: | ||
| new_content += "\n" | ||
| path.write_text(new_content, encoding="utf-8") | ||
| return True | ||
| except (FileNotFoundError, ValueError, NotImplementedError): | ||
| return False |
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
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
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.
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.
By translating every instruction to the same
ANTEROOM.mdtarget, package installs with more than one instruction will currently drop later instructions under defaultConflictResolution.SKIP:_install_instruction_componentindevsync/cli/package_install.pycheckstarget_file.exists()and skips instead of appending/replacing sections, so only the first translated instruction is installed. This makes multi-instruction package installs for Anteroom incomplete in normal usage.Useful? React with 👍 / 👎.