<?xml version="1.0" encoding="UTF-8"?>
<cursorrules>
<purpose>
You are an AI assistant responsible for helping a developer create a LLM prompt library and maintain Python code quality.
</purpose>
<instructions>
<instruction>Create a main folder called `prompt-library` to house all prompts.</instruction>
<instruction>Divide the library into two main categories: `agents` and `one-off-tasks`.</instruction>
<instruction>Within the `agents` folder, create subcategories for `creative` and `engineering` tasks.</instruction>
<instruction>Under `creative`, include subfolders for image-generation, fabrication, story-generation, and quote-generation.</instruction>
<instruction>Under `engineering`, create subfolders for code-generation, code-review, bug-finding, and style-enforcement.</instruction>
<instruction>In `one-off-tasks`, include subfolders for image-generation, lore-writing, code-generation, and code-review.</instruction>
<instruction>Create a `templates` folder to store reusable prompt structures.</instruction>
<instruction>Include a comprehensive README.md file at the root level.</instruction>
</instructions>
<python_standards>
<project_structure>
<standard>Maintain clear project structure with separate directories for source code, tests (`tests/`), and documentation (`docs/`).</standard>
<standard>Use modular design with distinct files for models, services, controllers, and utilities.</standard>
<standard>Create separate files for AI components (chat models, prompts, output parsers, chat history, documents/loaders, stores, retrievers, tools)</standard>
<standard>Follow modular design patterns for LangChain/LangGraph components</standard>
<standard>Use UV (https://docs.astral.sh/uv) for dependency management and virtual environments</standard>
<standard>Follow composition over inheritance principle.</standard>
<standard>Use design patterns like Adapter, Decorator, and Bridge when appropriate.</standard>
</project_structure>
<code_quality>
<standard>Add typing annotations to ALL functions and classes with return types.</standard>
<standard>Include PEP 257-compliant docstrings in Google style for all functions and classes.</standard>
<standard>Implement robust error handling and logging using loguru with context capture.</standard>
<standard>Use descriptive variable and function names.</standard>
<standard>Add detailed comments for complex logic.</standard>
<standard>Provide rich error context for debugging.</standard>
<standard>Follow DRY (Don't Repeat Yourself) and KISS (Keep It Simple, Stupid) principles.</standard>
</code_quality>
<testing>
<standard>Use pytest exclusively for all testing (no unittest module).</standard>
<standard>Place all tests in `./tests/` directory.</standard>
<standard>Include `__init__.py` files in all test directories.</standard>
<standard>Add type annotations and docstrings to all tests.</standard>
<standard>Use pytest markers to categorize tests (e.g., `@pytest.mark.unit`, `@pytest.mark.integration`).</standard>
<standard>Mark cursor-generated code with `@pytest.mark.cursor`.</standard>
<standard>Strive for 100% unit test code coverage.</standard>
<standard>Use pytest-recording for tests involving Langchain runnables (limited to unit/integration tests)</standard>
<standard>Implement proper Discord.py testing using discord.ext.test</standard>
<standard>Use typer.testing.CliRunner for CLI application testing</standard>
<standard>For file-based tests, use tmp_path fixture to handle test files.</standard>
<standard>Avoid context managers for pytest mocks, use mocker.patch instead.</standard>
</testing>
<dependency_management>
<standard>Use uv (https://docs.astral.sh/uv) for dependency management.</standard>
<standard>Use `uv sync` to install dependencies, avoid `uv pip install`.</standard>
<standard>Use Ruff for code style consistency.</standard>
<standard>Document Ruff rules in pyproject.toml with stability indicators.</standard>
<standard>Use UV for all package management operations</standard>
<standard>Prefer `uv sync` over `uv pip install` for dependency installation</standard>
<standard>Maintain clear dependency specifications in pyproject.toml</standard>
</dependency_management>
<langchain_standards>
<standard>Mark tests involving Langchain runnables with @pytest.mark.vcr (except evaluation tests).</standard>
<standard>Use proper VCR.py configuration for HTTP interaction recording.</standard>
<standard>Implement proper typing for all Langchain components.</standard>
<standard>Follow Langchain's component structure guidelines.</standard>
</langchain_standards>
<langchain_integration>
<standard>Implement proper typing for all LangChain components</standard>
<standard>Follow component structure guidelines from LangChain documentation</standard>
<standard>Use VCR.py for recording HTTP interactions in tests</standard>
<standard>Create distinct files for different LangChain component types</standard>
<reference>https://python.langchain.com/v0.2/docs/concepts/#few-shot-prompting</reference>
</langchain_integration>
<design_patterns>
<pattern>
<name>Composition Over Inheritance</name>
<description>Favor object composition over class inheritance to avoid subclass explosion and enhance flexibility</description>
</pattern>
<pattern>
<name>Decorator Pattern</name>
<description>Use for dynamically adjusting behavior of objects without modifying their structure</description>
</pattern>
<pattern>
<name>Adapter Pattern</name>
<description>Allow incompatible interfaces to work together, promoting flexibility and reusability</description>
</pattern>
<pattern>
<name>Global Object Pattern</name>
<description>Use for creating module-level objects that provide methods for actions</description>
</pattern>
</design_patterns>
</python_standards>
<configuration_standards>
<ruff_rules>
<standard>Document all Ruff rules in pyproject.toml with inline comments.</standard>
<standard>Include stability indicators for each rule:
- โ๏ธ (stable)
- ๐งช (unstable/preview)
- โ ๏ธ (deprecated)
- โ (removed)
- ๐ ๏ธ (auto-fixable)
</standard>
<standard>Keep rule descriptions under 160 characters when possible.</standard>
<standard>Reference Ruff version from .pre-commit-config.yaml.</standard>
<example>
<![CDATA[
[tool.ruff.lint]
select = [
"D200", # fits-on-one-line: One-line docstring should fit on one line (stable)
"E226", # missing-whitespace-around-arithmetic-operator: Missing whitespace around arithmetic operator (unstable)
]
]]>
</example>
</ruff_rules>
<tool_configurations>
<standard>Document configuration options for:
- pylint (reference: pylint.pycqa.org)
- pyright (reference: microsoft.github.io/pyright)
- mypy (reference: mypy.readthedocs.io)
- commitizen (reference: commitizen-tools.github.io)
</standard>
<standard>Include descriptive comments for each configuration option.</standard>
</tool_configurations>
<test_imports>
<standard>Import necessary pytest types in TYPE_CHECKING block:
- CaptureFixture
- FixtureRequest
- LogCaptureFixture
- MonkeyPatch
- MockerFixture
- VCRRequest (when using pytest-recording)
</standard>
</test_imports>
</configuration_standards>
<testing_practices>
<fixtures>
<standard>Use pytest fixtures for reusable test components.</standard>
<standard>Utilize tmp_path fixture for file-based tests.</standard>
<example>
<![CDATA[
@pytest.fixture()
def mock_pdf_file(tmp_path: Path) -> Path:
"""Create a mock PDF file for testing purposes.
This fixture creates a temporary directory and copies a test PDF file into it.
Args:
tmp_path (Path): The temporary path provided by pytest.
Returns:
Path: Path to the mock PDF file.
"""
test_pdf_path: Path = tmp_path / "test.pdf"
shutil.copy("fixtures/test.pdf", test_pdf_path)
return test_pdf_path
]]>
</example>
</fixtures>
<test_organization>
<standard>Mirror source code directory structure in tests directory.</standard>
<standard>Use appropriate pytest markers for test categorization.</standard>
<standard>Include comprehensive docstrings for all test functions.</standard>
<example>
<![CDATA[
@pytest.mark.slow()
@pytest.mark.services()
@pytest.mark.vcr(
allow_playback_repeats=True,
match_on=["method", "scheme", "port", "path", "query"],
ignore_localhost=False
)
def test_load_documents(
mocker: MockerFixture,
mock_pdf_file: Path,
vcr: Any
) -> None:
"""Test the loading of documents from a PDF file.
Verifies that the load_documents function correctly processes PDF files.
Args:
mocker: The pytest-mock fixture
mock_pdf_file: Path to test PDF
vcr: VCR.py fixture
"""
# Test implementation
]]>
</example>
</test_organization>
</testing_practices>
<examples>
<example>
<![CDATA[
Example folder structure:
prompt-library/
โ
โโโ agents/
โ โโโ creative/
โ โ โโโ image-generation/
โ โ โโโ fabrication/
โ โ โโโ story-generation/
โ โ โโโ quote-generation/
โ โ
โ โโโ engineering/
โ โ๏ฟฝ๏ฟฝโ code-generation/
โ โโโ code-review/
โ โโโ bug-finding/
โ โโโ style-enforcement/
โ
โโโ one-off-tasks/
โ โโโ image-generation/
โ โโโ lore-writing/
โ โ โโโ helldivers2/
โ โ โโโ johnhelldiver/
โ โ โโโ prompt.xml
โ โ โโโ prompt_schema.xsd
โ โ โโโ Justfile
โ โ โโโ README.md
โ โ โโโ metadata.json
โ โ โโโ examples/
โ โ โโโ example1.md
โ โ โโโ example2.md
โ โโโ code-generation/
โ โโโ code-review/
โ
โโโ templates/
โ โโโ prompt_template.xml
โ โโโ readme_template.md
โ โโโ metadata_template.json
โ
โโโ README.md
]]>
</example>
<example>
<![CDATA[
Example README.md content:
# Prompt Library
This repository contains a structured collection of prompts for various AI tasks.
## Structure
- `agents/`: Prompts for continuous use in agentic systems
- `one-off-tasks/`: Prompts for single-use scenarios
- `templates/`: Reusable prompt structures
## Usage
[Include guidelines on how to use and contribute to the library]
]]>
</example>
<example>
<![CDATA[
Example prompt.xml for John Helldiver:
<?xml version="1.0" encoding="UTF-8"?>
<prompt>
<context>
You are a skilled lore writer for the Helldivers 2 universe. Your task is to create a compelling backstory for John Helldiver, a legendary commando known for his exceptional skills and unwavering dedication to the mission.
</context>
<instruction>
Write a brief but engaging backstory for John Helldiver, highlighting his:
1. Origin and early life
2. Key missions and accomplishments
3. Unique personality traits
4. Signature weapons or equipment
5. Relationships with other Helldivers or characters
</instruction>
<example>
Here's an example of a brief backstory for another character:
Sarah "Stormbreaker" Chen, born on a remote Super Earth colony, joined the Helldivers at 18 after her home was destroyed by Terminid forces. Known for her unparalleled skill with the Arc Thrower, Sarah has become a legend for single-handedly holding off waves of Bug attacks during the Battle of New Helsinki. Her stoic demeanor and tactical genius have earned her the respect of both rookies and veterans alike.
</example>
<output_format>
Provide a cohesive narrative of 200-300 words that captures the essence of John Helldiver's legendary status while maintaining the gritty, militaristic tone of the Helldivers universe.
</output_format>
</prompt>
]]>
</example>
<example>
<![CDATA[
Example README.md for John Helldiver:
# John Helldiver Backstory Prompt
## Purpose
This prompt is designed to generate a compelling backstory for John Helldiver, a legendary commando in the Helldivers 2 universe. It aims to create a rich, engaging narrative that fits seamlessly into the game's lore.
## Usage
1. Use this prompt with a large language model capable of creative writing and understanding context.
2. Provide the prompt to the model without modification.
3. The generated output should be a 200-300 word backstory that can be used as-is or as a foundation for further development.
## Expected Output
A brief but detailed backstory covering John Helldiver's origin, key accomplishments, personality traits, equipment, and relationships within the Helldivers universe.
## Special Considerations
- Ensure the tone matches the gritty, militaristic style of Helldivers 2.
- The backstory should emphasize John's exceptional skills and dedication to his missions.
- Feel free to iterate on the output, using it as a starting point for more detailed character development.
]]>
</example>
<example>
<![CDATA[
Example metadata.json for John Helldiver:
{
"promptName": "JohnHelldiverBackstory",
"version": "1.0",
"targetModel": "gpt4o",
"author": "YourName",
"creationDate": "2024-12-08",
"lastTestedDate": "2024-12-08",
"tags": ["Helldivers2", "lore", "character-backstory", "sci-fi"],
"description": "Generates a backstory for John Helldiver, a legendary commando in the Helldivers 2 universe",
"performanceMetrics": {
"averageOutputQuality": 4.5,
"successRate": 0.95
},
"promptStructure": "Four-level prompt (Context, Instruction, Example, Output Format)"
}
]]>
</example>
<example>
<![CDATA[
Example examples/example1.md for John Helldiver:
# Example Output 1: John Helldiver Backstory
John "Hellfire" Helldiver was born in the underground bunkers of Super Earth during the height of the Bug War. Raised by veteran Helldivers, John's childhood was a brutal training regimen that forged him into a living weapon. At 16, he led his first mission against a Terminid hive, earning his call sign "Hellfire" after single-handedly destroying the hive with nothing but a flamethrower and sheer determination.
Known for his uncanny ability to turn the tide of impossible battles, John has become a symbol of hope for humanity. His most famous exploit came during the Siege of New Atlantis, where he held off waves of Automaton forces for 72 hours straight, allowing thousands of civilians to evacuate. John's preferred loadout includes a customized Liberator assault rifle and the experimental P-7 "Punisher" sidearm, both gifts from Super Earth's top weapons engineers.
Despite his legendary status, John remains a man of few words, letting his actions speak louder than any speech could. His unwavering loyalty to Super Earth and his fellow Helldivers is matched only by his hatred for the enemies of democracy. Rookies whisper that John Helldiver doesn't sleep; he just waits for the next drop.
(Word count: 182)
]]>
</example>
<example>
<![CDATA[
Example prompt_schema.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="prompt">
<xs:complexType>
<xs:sequence>
<xs:element name="context" type="xs:string"/>
<xs:element name="instruction" type="xs:string"/>
<xs:element name="example" type="xs:string"/>
<xs:element name="output_format" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
]]>
</example>
<example>
<![CDATA[
Example Justfile:
lint:
xmllint --schema prompt_schema.xsd prompt.xml --noout
]]>
</example>
</examples>
<reasoning>
<point>Hierarchical structure allows for easy navigation and scalability.</point>
<point>Separation of agents and one-off tasks ensures quick access to appropriate prompts.</point>
<point>Detailed subcategories simplify locating prompts for specific tasks.</point>
<point>Structure accommodates both general categories and specific use cases.</point>
<point>Templates folder promotes consistency in prompt creation.</point>
<point>README file provides clear documentation for all users.</point>
</reasoning>
</cursorrules>