|
4 | 4 | import os
|
5 | 5 | import re
|
6 | 6 | import sys
|
| 7 | +import urllib.request |
| 8 | +import urllib.error |
| 9 | +from pathlib import Path |
7 | 10 |
|
8 | 11 | from lmnr.sdk.evaluations import Evaluation
|
9 | 12 |
|
|
16 | 19 | EVAL_DIR = "evals"
|
17 | 20 |
|
18 | 21 |
|
| 22 | +def add_cursor_rules(): |
| 23 | + """Download laminar.mdc file from a hardcoded public URL and save it to .cursor/rules/laminar.mdc""" |
| 24 | + # Hardcoded URL for the laminar.mdc file |
| 25 | + url = "https://raw.githubusercontent.com/lmnr-ai/lmnr/dev/rules/laminar.mdc" |
| 26 | + |
| 27 | + # Create .cursor/rules directory if it doesn't exist |
| 28 | + rules_dir = Path(".cursor/rules") |
| 29 | + rules_dir.mkdir(parents=True, exist_ok=True) |
| 30 | + |
| 31 | + # Define the target file path |
| 32 | + target_file = rules_dir / "laminar.mdc" |
| 33 | + |
| 34 | + try: |
| 35 | + LOG.info(f"Downloading laminar.mdc from {url}") |
| 36 | + |
| 37 | + # Download the file |
| 38 | + with urllib.request.urlopen(url) as response: |
| 39 | + content = response.read() |
| 40 | + |
| 41 | + # Write the content to the target file (this will overwrite if it exists) |
| 42 | + with open(target_file, 'wb') as f: |
| 43 | + f.write(content) |
| 44 | + |
| 45 | + LOG.info(f"Successfully downloaded laminar.mdc to {target_file}") |
| 46 | + |
| 47 | + except urllib.error.URLError as e: |
| 48 | + LOG.error(f"Failed to download file from {url}: {e}") |
| 49 | + sys.exit(1) |
| 50 | + except Exception as e: |
| 51 | + LOG.error(f"Unexpected error: {e}") |
| 52 | + sys.exit(1) |
| 53 | + |
| 54 | + |
19 | 55 | async def run_evaluation(args):
|
20 | 56 | sys.path.append(os.getcwd())
|
21 | 57 |
|
@@ -103,8 +139,16 @@ def cli():
|
103 | 139 | help="Fail on error",
|
104 | 140 | )
|
105 | 141 |
|
| 142 | + parser_download = subparsers.add_parser( |
| 143 | + "add-cursor-rules", |
| 144 | + description="Download laminar.mdc file and add it to .cursor/rules", |
| 145 | + help="Download laminar.mdc file and add it to .cursor/rules", |
| 146 | + ) |
| 147 | + |
106 | 148 | parsed = parser.parse_args()
|
107 | 149 | if parsed.subcommand == "eval":
|
108 | 150 | asyncio.run(run_evaluation(parsed))
|
| 151 | + elif parsed.subcommand == "add-cursor-rules": |
| 152 | + add_cursor_rules() |
109 | 153 | else:
|
110 | 154 | parser.print_help()
|
0 commit comments