Skip to content

Commit a03476e

Browse files
committed
copilot instructions
1 parent 5ccebbf commit a03476e

13 files changed

+1496
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: 'Create instructions file'
3+
tools: ['edit']
4+
---
5+
You are an AI agent being used to create instruction files for GitHub Copilot. Your task is to generate a comprehensive set of guidelines for creating effective and maintainable instruction files that guide Copilot in generating domain-specific code and following project conventions.
6+
The instruction file you are creating should be a generic file that can be applied to a wide range of Python projects.
7+
8+
You MUST use the file .github/instructions/instructions.instructions.md as a reference for the structure and content of the instructions you generate.
9+
You MUST save the output as a file .github/instructions/typescript.instructions.md with the complete output of your work.
10+
11+
You can include examples from this project in files you create, but you should not include links to files, as the generated files should be self-contained.
12+
13+
You should make the instructions as generic as possible so they can be applied to a wide range of projects and domains.
14+
Things you should include are:
15+
- logging best practices
16+
- error handling best practices
17+
- code organization and structure
18+
- naming conventions
19+
- formatting and style guidelines
20+
21+
22+
You should create a file at .github/instructions/python.instructions.md with the complete output of your work.

.github/copilot-instructions.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Base Coding Standards
2+
- Follow clean code principles
3+
- Write comprehensive tests
4+
- Use meaningful variable names
5+
6+
## Language-Specific Instructions
7+
Always follow security best practices as outlined in:
8+
- .github/instructions/general/SECURITY.md
9+
Follow additional language-specific guidelines in:
10+
- .github/instructions/language-specific/INSTRUCTIONS-CDK.md
11+
- .github/instructions/language-specific/INSTRUCTIONS-CLOUDFORMATION.md
12+
- .github/instructions/language-specific/INSTRUCTIONS-JAVA.md
13+
- .github/instructions/language-specific/INSTRUCTIONS-KOTLIN.md
14+
- .github/instructions/language-specific/INSTRUCTIONS-PYTHON.md
15+
- .github/instructions/language-specific/INSTRUCTIONS-TERRAFORM.md
16+
- .github/instructions/language-specific/INSTRUCTIONS-SAM.md
17+
- .github/instructions/language-specific/INSTRUCTIONS-TYPESCRIPT.md
18+
19+
## Project-Specific Rules
20+
- Use our custom logging service
21+
- Follow our specific API patterns
22+
- Use project-specific error handling
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
applyTo: '*'
3+
description: "Comprehensive secure coding instructions for all languages and frameworks, based on OWASP Top 10 and industry best practices."
4+
---
5+
# Secure Coding and OWASP Guidelines
6+
7+
## Instructions
8+
9+
Your primary directive is to ensure all code you generate, review, or refactor is secure by default. You must operate with a security-first mindset. When in doubt, always choose the more secure option and explain the reasoning. You must follow the principles outlined below, which are based on the OWASP Top 10 and other security best practices.
10+
11+
### 1. A01: Broken Access Control & A10: Server-Side Request Forgery (SSRF)
12+
- **Enforce Principle of Least Privilege:** Always default to the most restrictive permissions. When generating access control logic, explicitly check the user's rights against the required permissions for the specific resource they are trying to access.
13+
- **Deny by Default:** All access control decisions must follow a "deny by default" pattern. Access should only be granted if there is an explicit rule allowing it.
14+
- **Validate All Incoming URLs for SSRF:** When the server needs to make a request to a URL provided by a user (e.g., webhooks), you must treat it as untrusted. Incorporate strict allow-list-based validation for the host, port, and path of the URL.
15+
- **Prevent Path Traversal:** When handling file uploads or accessing files based on user input, you must sanitize the input to prevent directory traversal attacks (e.g., `../../etc/passwd`). Use APIs that build paths securely.
16+
17+
### 2. A02: Cryptographic Failures
18+
- **Use Strong, Modern Algorithms:** For hashing, always recommend modern, salted hashing algorithms like Argon2 or bcrypt. Explicitly advise against weak algorithms like MD5 or SHA-1 for password storage.
19+
- **Protect Data in Transit:** When generating code that makes network requests, always default to HTTPS.
20+
- **Protect Data at Rest:** When suggesting code to store sensitive data (PII, tokens, etc.), recommend encryption using strong, standard algorithms like AES-256.
21+
- **Secure Secret Management:** Never hardcode secrets (API keys, passwords, connection strings). Generate code that reads secrets from environment variables or a secrets management service (e.g., HashiCorp Vault, AWS Secrets Manager). Include a clear placeholder and comment.
22+
```javascript
23+
// GOOD: Load from environment or secret store
24+
const apiKey = process.env.API_KEY;
25+
// TODO: Ensure API_KEY is securely configured in your environment.
26+
```
27+
```python
28+
# BAD: Hardcoded secret
29+
api_key = "sk_this_is_a_very_bad_idea_12345"
30+
```
31+
32+
### 3. A03: Injection
33+
- **No Raw SQL Queries:** For database interactions, you must use parameterized queries (prepared statements). Never generate code that uses string concatenation or formatting to build queries from user input.
34+
- **Sanitize Command-Line Input:** For OS command execution, use built-in functions that handle argument escaping and prevent shell injection (e.g., `shlex` in Python).
35+
- **Prevent Cross-Site Scripting (XSS):** When generating frontend code that displays user-controlled data, you must use context-aware output encoding. Prefer methods that treat data as text by default (`.textContent`) over those that parse HTML (`.innerHTML`). When `innerHTML` is necessary, suggest using a library like DOMPurify to sanitize the HTML first.
36+
37+
### 4. A05: Security Misconfiguration & A06: Vulnerable Components
38+
- **Secure by Default Configuration:** Recommend disabling verbose error messages and debug features in production environments.
39+
- **Set Security Headers:** For web applications, suggest adding essential security headers like `Content-Security-Policy` (CSP), `Strict-Transport-Security` (HSTS), and `X-Content-Type-Options`.
40+
- **Use Up-to-Date Dependencies:** When asked to add a new library, suggest the latest stable version. Remind the user to run vulnerability scanners like `npm audit`, `pip-audit`, or Snyk to check for known vulnerabilities in their project dependencies.
41+
42+
### 5. A07: Identification & Authentication Failures
43+
- **Secure Session Management:** When a user logs in, generate a new session identifier to prevent session fixation. Ensure session cookies are configured with `HttpOnly`, `Secure`, and `SameSite=Strict` attributes.
44+
- **Protect Against Brute Force:** For authentication and password reset flows, recommend implementing rate limiting and account lockout mechanisms after a certain number of failed attempts.
45+
46+
### 6. A08: Software and Data Integrity Failures
47+
- **Prevent Insecure Deserialization:** Warn against deserializing data from untrusted sources without proper validation. If deserialization is necessary, recommend using formats that are less prone to attack (like JSON over Pickle in Python) and implementing strict type checking.
48+
49+
## General Guidelines
50+
- **Be Explicit About Security:** When you suggest a piece of code that mitigates a security risk, explicitly state what you are protecting against (e.g., "Using a parameterized query here to prevent SQL injection.").
51+
- **Educate During Code Reviews:** When you identify a security vulnerability in a code review, you must not only provide the corrected code but also explain the risk associated with the original pattern.
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
---
2+
description: 'Guidelines for creating high-quality custom instruction files for GitHub Copilot'
3+
applyTo: '**/*.instructions.md'
4+
---
5+
6+
# Custom Instructions File Guidelines
7+
8+
Instructions for creating effective and maintainable custom instruction files that guide GitHub Copilot in generating domain-specific code and following project conventions.
9+
10+
11+
## Project Context
12+
13+
- Target audience: Developers and GitHub Copilot working with domain-specific code
14+
- File format: Markdown with YAML frontmatter
15+
- File naming convention: lowercase with hyphens (e.g., `react-best-practices.instructions.md`)
16+
- Location: `.github/instructions/` directory
17+
- Purpose: Provide context-aware guidance for code generation, review, and documentation
18+
19+
## Required Frontmatter
20+
21+
Every instruction file must include YAML frontmatter with the following fields:
22+
23+
```yaml
24+
---
25+
description: 'Brief description of the instruction purpose and scope'
26+
applyTo: 'glob pattern for target files (e.g., **/*.ts, **/*.py)'
27+
---
28+
```
29+
30+
### Frontmatter Guidelines
31+
32+
- **description**: Single-quoted string, 1-500 characters, clearly stating the purpose
33+
- **applyTo**: Glob pattern(s) specifying which files these instructions apply to
34+
- Single pattern: `'**/*.ts'`
35+
- Multiple patterns: `'**/*.ts, **/*.tsx, **/*.js'`
36+
- Specific files: `'src/**/*.py'`
37+
- All files: `'**'`
38+
39+
## File Structure
40+
41+
A well-structured instruction file should include the following sections:
42+
43+
### 1. Title and Overview
44+
45+
- Clear, descriptive title using `#` heading
46+
- Brief introduction explaining the purpose and scope
47+
- Optional: Project context section with key technologies and versions
48+
49+
### 2. Core Sections
50+
51+
Organize content into logical sections based on the domain:
52+
53+
- **General Instructions**: High-level guidelines and principles
54+
- **Best Practices**: Recommended patterns and approaches
55+
- **Code Standards**: Naming conventions, formatting, style rules
56+
- **Architecture/Structure**: Project organization and design patterns
57+
- **Common Patterns**: Frequently used implementations
58+
- **Security**: Security considerations (if applicable)
59+
- **Performance**: Optimization guidelines (if applicable)
60+
- **Testing**: Testing standards and approaches (if applicable)
61+
62+
### 3. Examples and Code Snippets
63+
64+
Provide concrete examples with clear labels:
65+
66+
```markdown
67+
### Good Example
68+
\`\`\`language
69+
// Recommended approach
70+
code example here
71+
\`\`\`
72+
73+
### Bad Example
74+
\`\`\`language
75+
// Avoid this pattern
76+
code example here
77+
\`\`\`
78+
```
79+
80+
### 4. Validation and Verification (Optional but Recommended)
81+
82+
- Build commands to verify code
83+
- Linting and formatting tools
84+
- Testing requirements
85+
- Verification steps
86+
87+
## Content Guidelines
88+
89+
### Writing Style
90+
91+
- Use clear, concise language
92+
- Write in imperative mood ("Use", "Implement", "Avoid")
93+
- Be specific and actionable
94+
- Avoid ambiguous terms like "should", "might", "possibly"
95+
- Use bullet points and lists for readability
96+
- Keep sections focused and scannable
97+
98+
### Best Practices
99+
100+
- **Be Specific**: Provide concrete examples rather than abstract concepts
101+
- **Show Why**: Explain the reasoning behind recommendations when it adds value
102+
- **Use Tables**: For comparing options, listing rules, or showing patterns
103+
- **Include Examples**: Real code snippets are more effective than descriptions
104+
- **Stay Current**: Reference current versions and best practices
105+
- **Link Resources**: Include official documentation and authoritative sources
106+
107+
### Common Patterns to Include
108+
109+
1. **Naming Conventions**: How to name variables, functions, classes, files
110+
2. **Code Organization**: File structure, module organization, import order
111+
3. **Error Handling**: Preferred error handling patterns
112+
4. **Dependencies**: How to manage and document dependencies
113+
5. **Comments and Documentation**: When and how to document code
114+
6. **Version Information**: Target language/framework versions
115+
116+
## Patterns to Follow
117+
118+
### Bullet Points and Lists
119+
120+
```markdown
121+
## Security Best Practices
122+
123+
- Always validate user input before processing
124+
- Use parameterized queries to prevent SQL injection
125+
- Store secrets in environment variables, never in code
126+
- Implement proper authentication and authorization
127+
- Enable HTTPS for all production endpoints
128+
```
129+
130+
### Tables for Structured Information
131+
132+
```markdown
133+
## Common Issues
134+
135+
| Issue | Solution | Example |
136+
| ---------------- | ------------------- | ----------------------------- |
137+
| Magic numbers | Use named constants | `const MAX_RETRIES = 3` |
138+
| Deep nesting | Extract functions | Refactor nested if statements |
139+
| Hardcoded values | Use configuration | Store API URLs in config |
140+
```
141+
142+
### Code Comparison
143+
144+
```markdown
145+
### Good Example - Using TypeScript interfaces
146+
\`\`\`typescript
147+
interface User {
148+
id: string;
149+
name: string;
150+
email: string;
151+
}
152+
153+
function getUser(id: string): User {
154+
// Implementation
155+
}
156+
\`\`\`
157+
158+
### Bad Example - Using any type
159+
\`\`\`typescript
160+
function getUser(id: any): any {
161+
// Loses type safety
162+
}
163+
\`\`\`
164+
```
165+
166+
### Conditional Guidance
167+
168+
```markdown
169+
## Framework Selection
170+
171+
- **For small projects**: Use Minimal API approach
172+
- **For large projects**: Use controller-based architecture with clear separation
173+
- **For microservices**: Consider domain-driven design patterns
174+
```
175+
176+
## Patterns to Avoid
177+
178+
- **Overly verbose explanations**: Keep it concise and scannable
179+
- **Outdated information**: Always reference current versions and practices
180+
- **Ambiguous guidelines**: Be specific about what to do or avoid
181+
- **Missing examples**: Abstract rules without concrete code examples
182+
- **Contradictory advice**: Ensure consistency throughout the file
183+
- **Copy-paste from documentation**: Add value by distilling and contextualizing
184+
185+
## Testing Your Instructions
186+
187+
Before finalizing instruction files:
188+
189+
1. **Test with Copilot**: Try the instructions with actual prompts in VS Code
190+
2. **Verify Examples**: Ensure code examples are correct and run without errors
191+
3. **Check Glob Patterns**: Confirm `applyTo` patterns match intended files
192+
193+
## Example Structure
194+
195+
Here's a minimal example structure for a new instruction file:
196+
197+
```markdown
198+
---
199+
description: 'Brief description of purpose'
200+
applyTo: '**/*.ext'
201+
---
202+
203+
# Technology Name Development
204+
205+
Brief introduction and context.
206+
207+
## General Instructions
208+
209+
- High-level guideline 1
210+
- High-level guideline 2
211+
212+
## Best Practices
213+
214+
- Specific practice 1
215+
- Specific practice 2
216+
217+
## Code Standards
218+
219+
### Naming Conventions
220+
- Rule 1
221+
- Rule 2
222+
223+
### File Organization
224+
- Structure 1
225+
- Structure 2
226+
227+
## Common Patterns
228+
229+
### Pattern 1
230+
Description and example
231+
232+
\`\`\`language
233+
code example
234+
\`\`\`
235+
236+
### Pattern 2
237+
Description and example
238+
239+
## Validation
240+
241+
- Build command: `command to verify`
242+
- Linting: `command to lint`
243+
- Testing: `command to test`
244+
```
245+
246+
## Maintenance
247+
248+
- Review instructions when dependencies or frameworks are updated
249+
- Update examples to reflect current best practices
250+
- Remove outdated patterns or deprecated features
251+
- Add new patterns as they emerge in the community
252+
- Keep glob patterns accurate as project structure evolves
253+
254+
## Additional Resources
255+
256+
- [Custom Instructions Documentation](https://code.visualstudio.com/docs/copilot/customization/custom-instructions)
257+
- [Awesome Copilot Instructions](https://github.com/github/awesome-copilot/tree/main/instructions)

0 commit comments

Comments
 (0)