|
| 1 | +# Agent Instructions: Dice Project |
| 2 | + |
| 3 | +This document provides essential information for AI agents working on the Dice Project. Follow these guidelines to maintain consistency and ensure high-quality contributions. |
| 4 | + |
| 5 | +## 1. Project Overview |
| 6 | + |
| 7 | +The Dice Project is a lightweight Python CLI tool that simulates rolling one to six dice and displays the results using ASCII art. |
| 8 | + |
| 9 | +- **Primary Language:** Python 3.x |
| 10 | +- **Main Entry Point:** `dice.py` |
| 11 | +- **Architecture:** Procedural script with functional decomposition. |
| 12 | + |
| 13 | +## 2. Build, Run, and Test Commands |
| 14 | + |
| 15 | +### Running the Application |
| 16 | +To run the interactive CLI: |
| 17 | +```bash |
| 18 | +python dice.py |
| 19 | +``` |
| 20 | + |
| 21 | +### Testing |
| 22 | +There is currently no formal test suite. When adding tests: |
| 23 | +- **Framework:** Use `pytest` (standard for this project). |
| 24 | +- **Running all tests:** `pytest` |
| 25 | +- **Running a single test file:** `pytest path/to/test_file.py` |
| 26 | +- **Running a specific test:** `pytest path/to/test_file.py::test_function_name` |
| 27 | + |
| 28 | +### Linting and Formatting |
| 29 | +Maintain PEP 8 compliance. Recommended tools: |
| 30 | +- **Linting:** `flake8 dice.py` or `ruff check dice.py` |
| 31 | +- **Formatting:** `black dice.py` |
| 32 | + |
| 33 | +## 3. Code Style Guidelines |
| 34 | + |
| 35 | +### General Principles |
| 36 | +- **Simplicity:** Keep the logic straightforward. Avoid over-engineering for a single-file utility. |
| 37 | +- **Readability:** Prioritize clear, descriptive names over brevity. |
| 38 | + |
| 39 | +### Naming Conventions |
| 40 | +- **Functions:** Use `snake_case` (e.g., `generate_dice_faces_diagram`). |
| 41 | +- **Variables:** Use `snake_case` (e.g., `roll_results`). |
| 42 | +- **Constants:** Use `SCREAMING_SNAKE_CASE` (e.g., `DICE_ART`, `DIE_HEIGHT`). |
| 43 | +- **Internal Helpers:** Prefix with a single underscore (e.g., `_get_dice_faces`). |
| 44 | + |
| 45 | +### Imports |
| 46 | +- Place standard library imports at the top of the file. |
| 47 | +- Keep them alphabetized within their group. |
| 48 | +- Example: |
| 49 | + ```python |
| 50 | + import random |
| 51 | + import sys |
| 52 | + ``` |
| 53 | + |
| 54 | +### Documentation |
| 55 | +- Use triple-quoted docstrings for all functions. |
| 56 | +- The first line should be a concise summary. |
| 57 | +- Follow with a more detailed explanation if the function's logic or parameters aren't trivial. |
| 58 | +- Example: |
| 59 | + ```python |
| 60 | + def roll_dice(num_dice): |
| 61 | + """Return a list of random integers between 1 and 6.""" |
| 62 | + # implementation |
| 63 | + ``` |
| 64 | + |
| 65 | +### Formatting |
| 66 | +- **Indentation:** 4 spaces. |
| 67 | +- **Line Length:** Max 79-88 characters (standard PEP 8 / Black). |
| 68 | +- **Vertical Spacing:** Two blank lines between top-level functions. |
| 69 | + |
| 70 | +### Error Handling |
| 71 | +- Use `parse_input` to validate user input. |
| 72 | +- For fatal CLI errors, print a user-friendly message and use `raise SystemExit(1)`. |
| 73 | +- Avoid broad `except Exception:` blocks; catch specific exceptions. |
| 74 | + |
| 75 | +## 4. Project Conventions & Architecture |
| 76 | + |
| 77 | +### ASCII Art Management |
| 78 | +- All dice representations are stored in the `DICE_ART` dictionary. |
| 79 | +- Each entry is a tuple of strings representing the rows of the die. |
| 80 | +- Maintain the alignment and character usage (┌, ┐, └, ┘, │, ●) when modifying art. |
| 81 | + |
| 82 | +### Main Execution Block |
| 83 | +- Currently, the script executes its main logic at the bottom of the file. |
| 84 | +- **Refactoring Target:** When modifying `dice.py`, consider wrapping the execution logic in an `if __name__ == "__main__":` block to allow for better testability and modularity. |
| 85 | + |
| 86 | +### Input Validation |
| 87 | +- All user inputs must be stripped and validated against expected values before processing. |
| 88 | +- The `parse_input` function is the gatekeeper for valid dice counts. |
| 89 | + |
| 90 | +## 5. External Rules |
| 91 | + |
| 92 | +- **Cursor Rules:** No specific `.cursorrules` or `.cursor/rules/` detected. |
| 93 | +- **Copilot Instructions:** No `.github/copilot-instructions.md` detected. |
| 94 | +- **Standard Guidelines:** Default to standard Python best practices (PEP 8, PEP 257). |
| 95 | + |
| 96 | +## 6. Task-Specific Instructions |
| 97 | + |
| 98 | +### When Adding Features |
| 99 | +1. **Check for side effects:** Ensure changes to `DICE_ART` don't break `generate_dice_faces_diagram`. |
| 100 | +2. **Maintain ASCII alignment:** Use `DIE_HEIGHT` and `DIE_WIDTH` constants to ensure the diagram remains rectangular. |
| 101 | +3. **Self-Verification:** After making changes, run `python dice.py` and test with various inputs (1, 6, and invalid strings) to ensure the CLI still behaves as expected. |
| 102 | + |
| 103 | +### When Refactoring |
| 104 | +- Ensure that helper functions remain "private" (prefixed with `_`) if they are not intended for external use. |
| 105 | +- Maintain the docstring style and clarity. |
| 106 | + |
| 107 | +## Python Guidelines |
| 108 | + |
| 109 | +- Follow PEP 8 style conventions |
| 110 | +- Add type hints to all new and modified functions |
| 111 | +- Prefer specific exception types over bare `except` clauses |
| 112 | +- Use context managers for file I/O and database connections |
| 113 | +- Write descriptive error messages that include the offending value |
| 114 | + |
| 115 | +--- |
| 116 | +*Note: This file is intended for AI agents. If you are a human, feel free to update these guidelines as the project evolves.* |
0 commit comments