-
Couldn't load subscription status.
- Fork 2
Add a dda command to automatically sync cursor rules in other coding agent files #179
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?
Conversation
746b659 to
406707b
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.
LGTM, I'll let some thoughts on slack
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.
Thanks a lot for this ! Please ask for re-review once you've had another look :)
For the naming convention, I think ai is fine, but only if we choose to also merge all mcp commands under here (so we'd have dda ai mcp ...). @ofek what do you think ?
tests/cli/ai/rules/test_sync.py
Outdated
| @pytest.fixture(name="create_temp_file_or_dir") | ||
| def fixt_create_temp_file_or_dir(): | ||
| """Fixture to create and clean up temporary files and directories.""" | ||
| created_paths: list[Path] = [] | ||
|
|
||
| def _create_temp_file_or_dir(location: Path, *, force_file: bool = False) -> None: | ||
| for parent in reversed(location.parents): | ||
| # Create and keep track of created parent directories for cleanup | ||
| if not parent.exists(): | ||
| parent.mkdir() | ||
| created_paths.append(parent) | ||
|
|
||
| # Create the requested file or directory and keep track of it for cleanup | ||
| # Assume that if the file path does not have an extension, it is a directory | ||
| # The force_file flag can be used to override this behavior | ||
| if location.suffix == "" and not force_file: | ||
| location.mkdir() | ||
| else: | ||
| location.touch() | ||
| created_paths.append(location) | ||
|
|
||
| yield _create_temp_file_or_dir | ||
| for path in reversed(created_paths): | ||
| if path.exists(): | ||
| if path.is_dir(): | ||
| path.rmdir() | ||
| else: | ||
| path.unlink() | ||
|
|
||
|
|
||
| @pytest.fixture(name="create_cursor_rules") | ||
| def fixt_create_cursor_rules(create_temp_file_or_dir): | ||
| def _create_cursor_rules(rules_data: dict[str, str], cursor_rules_dir: Path) -> None: | ||
| """Create cursor rule files with given content.""" | ||
| for filename, content in rules_data.items(): | ||
| rule_file = cursor_rules_dir / filename | ||
| create_temp_file_or_dir(rule_file, force_file=True) | ||
| rule_file.write_text(content, encoding="utf-8") | ||
|
|
||
| return _create_cursor_rules |
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.
I think this is very similar to what I implemented in tests/cli/info/owners/test_code.py. Since the same code is now reused in multiple places, could we consider making these fixtures generic and sharing them by putting them in conftest.py ?
tests/cli/ai/rules/test_sync.py
Outdated
| return _create_cursor_rules | ||
|
|
||
|
|
||
| def test_sync_basic_functionality( |
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.
I think we can merge a few of these and use pytest.mark.parametrize. What do you think ?
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.
Human approval ✔️
| f.write(new_content) | ||
| app.display_success(f"Successfully fixed {target_file}") | ||
| else: | ||
| unsynced_targets.append(str(target_file)) |
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.
| unsynced_targets.append(str(target_file)) | |
| unsynced_targets.append(str(target_file)) |
tests/cli/validate/__init__.py
Outdated
| @@ -0,0 +1,3 @@ | |||
| # SPDX-FileCopyrightText: 2025-present Datadog, Inc. <dev@datadoghq.com> | |||
| # | |||
| # SPDX-License-Identifier: MIT No newline at end of file | |||
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.
NIT: Could you add a line feed here?
tests/cli/validate/test_ai-rules.py
Outdated
|
|
||
|
|
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.
Fix tests + use fixture folder instead
b3bb9f5 to
c02c318
Compare
c02c318 to
4e2c733
Compare
7d9cb8b to
2254a55
Compare
Create a new
dda validatetree used for AI and Coding agent related utilities.Implement
dda validate ai-rulescommand to automatically synchronize Cursor rules to other coding agent files.Default usage will pick all the rules in
.cursor/rulesand add them in CLAUDE.md file, so that claude can use the rules defined for Cursor.Also adds a
--fixflag to be used locally to sync the rules