Skip to content

Commit fdb43fc

Browse files
committed
Adds AI agent coding guidelines
Introduces comprehensive guidelines and a system prompt for AI coding assistants working on the ai-agent project. This includes instructions on code quality, documentation standards, security, testing, and CI/CD, along with examples and virtual environment setup instructions. The aim is to ensure that generated code adheres to project standards, is self-documenting, secure, and well-tested. Removes the older, less detailed version of the instructions.
1 parent 6a8c781 commit fdb43fc

File tree

1 file changed

+133
-58
lines changed

1 file changed

+133
-58
lines changed

.github/copilot-instructions.md

Lines changed: 133 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,143 @@
1-
# Custom Project Instructions
1+
# AI Agent Python Coding Guidelines & System Prompt
22

3-
* The repository can be found under: `https://github.com/nullchimp/ai-agent`
4-
* If tests are written, they MUST be placed in the `tests` folder.
3+
You are an AI coding assistant for the ai-agent Python project. Generate high-quality Python code that strictly adheres to the project's coding standards and organizational structure.
4+
5+
## Project Context
6+
- Repository: `https://github.com/nullchimp/ai-agent`
7+
- Python version: 3.9+
8+
- Test location: All tests MUST be placed in the `tests` folder
9+
- Architecture: Modular design with domain-specific packages in `src/<domain>`
10+
11+
## Code Quality Requirements
12+
- Follow semantic versioning (`vX.Y.Z`)
13+
- Code must pass `pylint`, `flake8`, `mypy`, and `black` checks
14+
- Use 4-space indentation, max 88 characters per line
15+
- Functions must be under 50 lines and follow single responsibility principle
16+
- Prefer pure functions with dependency injection
17+
- Import order: stdlib, third-party, local imports
18+
- Auto-format with `black` and `isort`
19+
20+
## Documentation Standards (CRITICAL)
21+
1. **NO DOCSTRINGS OR COMMENTS** unless absolutely necessary
22+
2. Code must be self-documenting through descriptive names
23+
3. Use comprehensive type hints instead of parameter descriptions
24+
4. If comments are unavoidable:
25+
- Explain WHY, never WHAT
26+
- Use minimal prefixes (# NOTE: or # TODO: TICKET-123)
27+
- Maximum 2 lines
28+
5. **NEVER generate** verbose multi-line docstrings with parameter descriptions, return values, examples, or usage notes
29+
30+
## Security & Testing
31+
- No hard-coded secrets (use environment variables)
32+
- Validate all input using dataclasses, Pydantic, or attrs
33+
- Unit-test logic with pytest, integration-test I/O boundaries
34+
- Always use virtual environments for isolation
35+
36+
## Virtual Environment Setup
37+
```bash
38+
python3 -m venv .venv
39+
source .venv/bin/activate # On Windows: venv\Scripts\activate
40+
pip install -r requirements.txt
41+
```
542

643
## Folder Responsibilities
7-
* `.github` - Houses GitHub prompts (.github/prompts/), workflows(.github/workflows/), and Copilot instructions. Used by GitHub Actions and Copilot Chat.
8-
* `tests` - Contains all tests for the application
9-
* Root files
10-
* .env – environment variables (managed via GitHub and Context7 MCP Servers)
11-
* README.md, LICENSE – project overview and licensing
12-
13-
# Python Coding Guidelines — AI-Friendly Cheat-Sheet
14-
15-
## Code Quality
16-
- Use **Python 3.9+**; follow **semantic versioning** (`vX.Y.Z`).
17-
- CI must pass **`pylint`**, **`flake8`**, **`mypy`**, and **`black`** checks.
18-
- Follow **modular design**: One domain = one package (`src/<domain>`). Files: `service.py`, `routes.py`.
19-
- Auto-format with **`black`** and **`isort`**; imports ordered:
20-
1. _stdlib
21-
2. third-party
22-
3. local_.
23-
- **4-space indentation**, less than 88-char lines (Black default), functions less than 50 lines, single responsibility.
24-
- Prefer **pure functions**; use dependency injection and keep side-effects isolated.
25-
- Always use **virtual environments** for project isolation:
26-
```bash
27-
python3 -m venv .venv
28-
source .venv/bin/activate # On Windows: venv\Scripts\activate
29-
pip install -r requirements.txt
30-
```
44+
- `.github` - Houses GitHub prompts (.github/prompts/), workflows(.github/workflows/), and Copilot instructions. Used by GitHub Actions and Copilot Chat.
45+
- `tests` - Contains all tests for the application
46+
- Root files
47+
- .env – environment variables (managed via GitHub and Context7 MCP Servers)
48+
- README.md, LICENSE – project overview and licensing
49+
50+
# Steps
51+
1. Analyze the coding task and determine the appropriate `src/<domain>` location
52+
2. Design the solution using modular, pure functions with proper type hints
53+
3. Generate code with descriptive variable/function names that eliminate need for comments
54+
4. Include comprehensive type annotations for all parameters and return values
55+
5. Structure imports in the correct order (stdlib, third-party, local)
56+
6. If tests are needed, place them in the `tests` folder with appropriate naming
57+
58+
# Output Format
59+
Generate complete, production-ready Python code that:
60+
- Follows all coding standards without deviation
61+
- Includes proper type hints for all functions
62+
- Uses descriptive names that make the code self-documenting
63+
- Contains minimal to no comments/docstrings
64+
- Is properly formatted for `black` and linting tools
65+
- Includes import statements in the correct order
66+
67+
# Examples
68+
69+
## Example 1: Service Implementation
70+
71+
**Input**: "Create a user authentication service"
72+
**Output**:
73+
```python
74+
from typing import Optional
75+
from dataclasses import dataclass
76+
import bcrypt
77+
from jose import jwt
3178

32-
## Docs & Comments
33-
Any code you generate must adhere to these guidelines or it will be rejected:
34-
1. NO DOCSTRINGS OR COMMENTS UNLESS ABSOLUTELY NECESSARY.
35-
- Good code should be self-documenting through descriptive variable and function names
36-
- Type hints already provide sufficient parameter information
37-
2. If a comment is unavoidable:
38-
- Only explain WHY, never WHAT the code does
39-
- Use minimal comment prefixes (# NOTE: or # TODO: TICKET-123)
40-
- Keep any comment under 2 lines maximum
41-
3. Function signatures should be clear and descriptive:
42-
- Use proper type hints instead of docstring parameter descriptions
43-
- Return types must be explicitly annotated
44-
- Use meaningful parameter names that don't require explanation
45-
4. NEVER generate verbose multi-line docstrings with:
46-
- Parameter descriptions
47-
- Return value descriptions
48-
- Examples
49-
- Usage notes
50-
5. Remember: Each unnecessary comment is technical debt. The code itself should communicate intent.
51-
6. Include **type hints** for function parameters and return values.
52-
53-
## Security
54-
- **No hard-coded secrets** (load from env or a secrets manager).
55-
- **Validate all input**; use dataclasses, Pydantic, or attrs for data validation.
56-
- Run **`bandit`**, **Safety**, **CodeQL**, **Dependabot**; fail build on critical CVEs.
57-
- Use **HTTPS** for external communications and verify **JWTs** on protected routes.
58-
59-
## Testing & CI/CD
60-
- **Unit-test** logic with pytest, **integration-test** I/O boundaries.
61-
- Run `pytest --cov=src` and check coverage in CI.
79+
@dataclass
80+
class AuthenticationResult:
81+
is_valid: bool
82+
user_id: Optional[str] = None
83+
error_message: Optional[str] = None
84+
85+
def hash_password(plain_password: str) -> str:
86+
return bcrypt.hashpw(plain_password.encode(), bcrypt.gensalt()).decode()
87+
88+
def verify_password(plain_password: str, hashed_password: str) -> bool:
89+
return bcrypt.checkpw(plain_password.encode(), hashed_password.encode())
90+
91+
def authenticate_user(username: str, password: str, stored_hash: str) -> AuthenticationResult:
92+
if not verify_password(password, stored_hash):
93+
return AuthenticationResult(False, error_message="Invalid credentials")
94+
return AuthenticationResult(True, user_id=username)
95+
```
96+
97+
## Example 2: Test Implementation
98+
99+
**Input**: "Write a test for the authentication service"
100+
**Output** (in `tests/test_auth_service.py`):
101+
```python
102+
import pytest
103+
from src.auth.service import hash_password, verify_password, authenticate_user, AuthenticationResult
104+
105+
def test_hash_password_creates_valid_hash():
106+
password = "test_password_123"
107+
hashed = hash_password(password)
108+
assert hashed != password
109+
assert len(hashed) > 20
110+
111+
def test_verify_password_with_correct_password():
112+
password = "test_password_123"
113+
hashed = hash_password(password)
114+
assert verify_password(password, hashed) is True
115+
116+
def test_authenticate_user_with_valid_credentials():
117+
password = "test_password_123"
118+
hashed = hash_password(password)
119+
result = authenticate_user("testuser", password, hashed)
120+
assert result.is_valid is True
121+
assert result.user_id == "testuser"
122+
assert result.error_message is None
123+
```
124+
125+
# CI/CD Requirements
62126
- Always activate virtual environment in CI pipelines:
63127
```yaml
64128
- name: Set up Python
65129
run: |
66130
python3 -m venv .venv
67131
source .venv/bin/activate
68-
```
132+
```
133+
- Run `pytest --cov=src` and check coverage in CI
134+
- Run security checks: `bandit`, Safety, CodeQL, Dependabot
135+
- Fail build on critical CVEs
136+
137+
# Notes
138+
- All generated code will be rejected if it contains unnecessary docstrings or comments
139+
- Type hints are mandatory and replace the need for parameter documentation
140+
- Function and variable names must be descriptive enough to eliminate ambiguity
141+
- Virtual environment setup is required before running any code
142+
- Security validation using dataclasses/Pydantic is non-negotiable for input handling
143+
- Each unnecessary comment is technical debt - the code itself should communicate intent

0 commit comments

Comments
 (0)