Skip to content

Commit 6ab3301

Browse files
jennyf19bgavrilMS
andauthored
add ai assist rules (#5312)
* add ai assist rules * updates * Update .clinerules/csharp-guidelines.md * Update .clinerules/csharp-guidelines.md --------- Co-authored-by: Bogdan Gavril <[email protected]>
1 parent e1a5998 commit 6ab3301

File tree

5 files changed

+214
-0
lines changed

5 files changed

+214
-0
lines changed

.clinerules/ai-guidelines.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Development Guidelines
2+
3+
This directory contains guidelines for AI assistants:
4+
5+
* [Cline AI Assistant Guidelines](cline-instructions.md) - Guidelines specific to using Cline AI assistant
6+
* [C# Development Guidelines](csharp-guidelines.md) - C# coding standards and best practices
7+
* [MSAL.NET Guidelines](msal-guidelines.md) - Guidelines for working with MSAL.NET components and ecosystem
8+
9+
The guidelines are split into separate files to organize different concerns:
10+
- Cline-specific capabilities and workflows
11+
- C# language-specific standards and practices
12+
- MSAL.NET -specific development guidelines and best practices

.clinerules/cline-instructions.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Cline AI Assistant Guidelines
2+
3+
## Core Principles
4+
5+
* Make changes incrementally and verify each step
6+
* Always analyze existing code patterns before making changes
7+
* Prioritize built-in tools over shell commands
8+
* Follow existing project patterns and conventions
9+
* Maintain comprehensive test coverage
10+
11+
## Tool Usage
12+
13+
### File Operations
14+
* Use `read_file` for examining file contents instead of shell commands like `cat`
15+
* Use `replace_in_file` for targeted, specific changes to existing files
16+
* Use `write_to_file` only for new files or complete file rewrites
17+
* Use `list_files` to explore directory structures
18+
* Use `search_files` with precise regex patterns to find code patterns
19+
* Use `list_code_definition_names` to understand code structure before modifications
20+
21+
### Command Execution
22+
* Use `execute_command` sparingly, preferring built-in file operation tools when possible
23+
* Always provide clear explanations for any executed commands
24+
* Set `requires_approval` to true for potentially impactful operations
25+
26+
## Development Workflow
27+
28+
### Planning Phase (PLAN MODE)
29+
* Begin complex tasks in PLAN mode to discuss approach
30+
* Analyze existing codebase patterns using search tools
31+
* Review related test files to understand testing patterns
32+
* Present clear implementation steps for approval
33+
* Ask clarifying questions early to avoid rework
34+
35+
### Implementation Phase (ACT MODE)
36+
* Make changes incrementally, one file at a time
37+
* Verify each change before proceeding
38+
* Follow patterns discovered during planning phase
39+
* Focus on maintaining test coverage
40+
* Use error messages and linter feedback to guide fixes
41+
42+
## Code Modifications
43+
44+
### General Guidelines
45+
* Follow .editorconfig rules strictly
46+
* Preserve file headers and license information
47+
* Maintain consistent XML documentation
48+
* Respect existing error handling patterns
49+
* Keep line endings consistent with existing files
50+
51+
### Quality Checks
52+
* Verify changes match existing code style
53+
* Ensure test coverage for new code
54+
* Validate changes against project conventions
55+
* Check for proper error handling
56+
* Maintain nullable reference type annotations
57+
58+
## MCP Server Integration
59+
60+
* Use appropriate MCP tools when available for specialized tasks
61+
* Access MCP resources efficiently using proper URIs
62+
* Handle MCP operation results appropriately
63+
* Follow server-specific authentication and usage patterns
64+
65+
## Error Handling
66+
67+
* Provide clear error messages and suggestions
68+
* Handle tool operation failures gracefully
69+
* Suggest alternative approaches when primary approach fails
70+
* Roll back changes if necessary to maintain stability

.clinerules/csharp-guidelines.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# C# Development Guidelines
2+
3+
## General
4+
5+
* Always use the latest version C#, currently C# 13 features
6+
* Never change global.json unless explicitly asked to
7+
* Never change package.json or package-lock.json files unless explicitly asked to
8+
* Never change NuGet.config files unless explicitly asked to
9+
10+
## Formatting
11+
12+
* Apply code-formatting style defined in `.editorconfig`
13+
* Prefer file-scoped namespace declarations and single-line using directives
14+
* Insert a newline before the opening curly brace of any code block (e.g., after `if`, `for`, `while`, `foreach`, `using`, `try`, etc.)
15+
* Ensure that the final return statement of a method is on its own line
16+
* Use pattern matching and switch expressions wherever possible
17+
* Use `nameof` instead of string literals when referring to member names
18+
* Ensure that XML doc comments are created for any public APIs. When applicable, include `<example>` and `<code>` documentation in the comments
19+
20+
### Nullable Reference Types
21+
22+
* Declare variables non-nullable, and check for `null` at entry points
23+
* Always use `is null` or `is not null` instead of `== null` or `!= null`
24+
* Trust the C# null annotations and don't add null checks when the type system says a value cannot be null
25+
26+
### Testing
27+
28+
* We use mstest SDK v3 for tests
29+
* Emit "Act", "Arrange" or "Assert" comments
30+
* Use NSubstitute for mocking in tests
31+
* Copy existing style in nearby files for test method names and capitalization
32+
33+
## Running tests
34+
35+
* To build and run tests in the repo, run `dotnet test`, you need one solution open, or specify the solution

.clinerules/msal-guidelines.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# MSAL.NET Guidelines
2+
3+
## Overview
4+
5+
Microsoft Authentication Library (MSAL) for .NET is a highly scalable authentication library that enables applications to authenticate with the Microsoft identity platform. For confidential client scenarios (server-side applications), the library provides:
6+
7+
- Token acquisition for service-to-service calls
8+
- Flexible token caching with distributed cache support
9+
- Managed identity integration for Azure workloads
10+
- On-behalf-of flow for service-to-service delegated access
11+
12+
Through its comprehensive feature set and proven reliability, MSAL.NET simplifies the implementation of secure authentication in server-side applications while maintaining optimal performance and security.
13+
14+
## Repository Structure
15+
16+
### Core Directories
17+
- `/src/client/Microsoft.Identity.Client` - Core MSAL functionality
18+
- `ConfidentialClientApplication.cs` - Primary confidential client implementation
19+
- `ApiConfig/` - API configuration and builders
20+
- `Cache/` - Token cache implementations
21+
- `ManagedIdentity/` - Azure managed identity support
22+
- `OAuth2/` - OAuth protocol implementations
23+
- `Internal/` - Internal components and utilities
24+
- `/tests` - Unit tests and integration tests
25+
- `/benchmark` - Performance benchmarking infrastructure
26+
- `/tools` - Development and configuration tools
27+
28+
## Core Components
29+
30+
### Confidential Client Features
31+
- Microsoft.Identity.Client - Main MSAL library with confidential client support
32+
- Token cache implementations with extensible serialization
33+
- Managed identity integration for Azure environments
34+
35+
### Authentication Components
36+
- IConfidentialClientApplication - Primary interface for confidential clients
37+
- Token cache providers and serialization extensibility
38+
- Client credential builders and configurations
39+
- Custom assertion providers (certificates, managed identity)
40+
41+
## Development Guidelines
42+
43+
### Core Development Principles
44+
- Follow .editorconfig rules strictly
45+
- Maintain backward compatibility due to widespread usage
46+
- Implement proper error handling and retry logic
47+
- Keep dependencies minimal and well-justified
48+
- Document security considerations thoroughly
49+
50+
### Authentication Best Practices
51+
- Use certificate-based authentication over client secrets when possible
52+
- Implement token caching for optimal performance
53+
- Handle token expiration and refresh scenarios
54+
- Configure appropriate token lifetimes
55+
- Use managed identities in Azure environments when available
56+
57+
### Performance Requirements
58+
- Implement distributed token caching for scale-out scenarios
59+
- Optimize token acquisition patterns
60+
- Use asynchronous APIs consistently
61+
- Configure appropriate retry policies
62+
- Benchmark token operations in high-throughput scenarios
63+
64+
### Security Guidelines
65+
- Secure storage of client secrets and certificates
66+
- Implement proper token validation
67+
- Follow least-privilege principle for scopes
68+
- Handle sensitive data appropriately
69+
- Implement proper logging (avoiding sensitive data)
70+
71+
### Testing Requirements
72+
- Maintain comprehensive test coverage
73+
- Include integration tests with actual identity endpoints
74+
- Test token cache implementations thoroughly
75+
- Verify managed identity scenarios
76+
- Include performance benchmarks for token operations
77+
78+
### Public API Changes
79+
- The project uses Microsoft.CodeAnalysis.PublicApiAnalyzers
80+
- For any public API changes:
81+
1. Update PublicAPI.Unshipped.txt in the package directory
82+
2. Include complete API signatures
83+
3. Consider backward compatibility impacts
84+
4. Document breaking changes clearly
85+
86+
Example format:
87+
```diff
88+
// Adding new API
89+
+Microsoft.Identity.Client.ConfidentialClientApplication.AcquireTokenForClient() -> Task<AuthenticationResult>
90+
+Microsoft.Identity.Client.IConfidentialClientApplication.GetAccounts() -> Task<IEnumerable<IAccount>>
91+
92+
// Removing API (requires careful consideration)
93+
-Microsoft.Identity.Client.ConfidentialClientApplication.ObsoleteMethod() -> void
94+
```
95+
96+
The analyzer enforces documentation of all public API changes in PublicAPI.Unshipped.txt and will fail the build if changes are not properly reflected.

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Carefully review all markdown documents in the ../.clinerules folder. Those are your custom instructions.

0 commit comments

Comments
 (0)