TdsLib
Copilot instructions25 starsChanged 2 months agoMITView on GitHub
This repository contains an open implementation of the TDS protocol (version 7.4) in managed C# code. It is focused on the login steps and TDS connection diagnostics.
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
19 rules. About 0 are common, 8 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Limitations: Does not support normal data streams or T-SQL commands
- Very specific: line 87
Use XML documentation comments for all public APIs with <summary>, <param>, and <returns> tags
- Distinctive: line 88
Use file-scoped license headers:
- Very specific: line 93
Use ConfigureAwait(false) on all awaited calls in library code
- Distinctive: line 94
Prefer expression-bodied members for simple properties:
- Very specific: line 101
Always use ConfigureAwait(false) to avoid deadlocks:
- Very specific: line 114
Use InvalidOperationException for unsupported operations
- Very specific: line 119
Create token class inheriting from Token in Tokens/{TokenName}/
- Very specific: line 126
Create payload class inheriting from Payload in Payloads/{PayloadName}/
- Very specific: line 128
Use ByteBuffer for all binary data manipulation
- Very specific: line 141
Use [Fact] for single test cases
- Very specific: line 142
Use descriptive method names: CreatePacketWithNullBuffer, TestStatusResetConnectionIgnore
- Distinctive: line 143
Test both success and failure cases
- Very specific: line 144
Use Assert.Throws<T>() for exception testing:
- Distinctive: line 188
Add XML documentation for all public members
- Very specific: line 189
Use ConfigureAwait(false) on async calls
- Distinctive: line 191
Write unit tests for new functionality
- Distinctive: line 192
Follow existing patterns in the codebase
- Distinctive: line 205
Use clear, descriptive commit messages:
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Instructions for TdsLib
This repository contains an open implementation of the TDS protocol (version 7.4) in managed C# code. It is focused on the login steps and TDS connection diagnostics.
Project Overview
- Purpose: A .NET library for probing and diagnosing TDS (Tabular Data Stream) connections to SQL Server
- Use cases: Connection diagnostics, TDS probing, mocking TDS clients
- Limitations: Does not support normal data streams or T-SQL commands
Documentation
- README.md - Main documentation with usage examples
- TDS Protocol Specification - Microsoft TDS protocol documentation
Tech Stack
- Language: C# (.NET Standard 2.0)
- Test Framework: xUnit with Moq for mocking
- Target Framework: netstandard2.0 (library), net6.0 (tests)
- Build Tool: dotnet CLI / MSBuild
Repository Structure
src/
Microsoft.Data.Tools.TdsLib/ # Main library code
Buffer/ # ByteBuffer for low-level byte operations
Exceptions/ # Custom exceptions (ConnectionClosedException)
IO/ # Connection and stream handling
Connection/ # IConnection interface and implementations
Tcp/ # TCP-specific connection classes
Messages/ # Message format and handling
Packets/ # TDS packet classes
Payloads/ # Message payloads (PreLogin, Login7, etc.)
Login7/ # Login7 payload and authentication
Auth/ # Fed Auth implementations
PreLogin/ # PreLogin payload options
Tokens/ # TDS response tokens
Done/ # Done token types
EnvChange/ # Environment change tokens
Error/ # Error tokens
FedAuthInfo/ # Federation auth info tokens
FeatureExtAck/ # Feature extension ack tokens
Info/ # Info tokens
LoginAck/ # Login acknowledgment tokens
ReturnStatus/ # Return status tokens
test/
Microsoft.Data.Tools.TdsLib.UnitTest/ # Unit tests
Microsoft.Data.Tools.TdsLib.IntegrationTest/ # Integration testsArchitectural Layers
| Layer | Location | Purpose |
| Client | TdsClient.cs | Main entry point, orchestrates message/token handling |
| Messages | Messages/ | High-level message abstraction, splits into packets |
| Packets | Packets/ | TDS packet format with headers and data |
| Payloads | Payloads/ | Message content (PreLogin, Login7, etc.) |
| Tokens | Tokens/ | Response parsing from SQL Server |
| Connection | IO/Connection/ | Low-level connection management |
| Buffer | Buffer/ | Byte manipulation utilities |
Coding Guidelines
Naming Conventions
- Classes/Types: PascalCase (e.g.,
TdsClient,PreLoginPayload) - Methods: PascalCase (e.g.,
SendMessage,ReceiveTokensAsync) - Properties: PascalCase (e.g.,
MessageHandler,TokenStreamHandler) - Private fields: camelCase with no prefix (e.g.,
buffer,connection) - Parameters: camelCase (e.g.,
tokenStreamHandler,packetSize) - Constants: PascalCase (e.g.,
DefaultPacketId,HeaderLength) - Enums: PascalCase for both type and members (e.g.,
PacketType.SqlBatch)
File Organization
- One public class per file, named after the class
- Internal classes may be in the same file if closely related
- Token parsers are
internaland follow pattern:{TokenName}TokenParser.cs - Tests mirror source structure in test project
Code Style
- Use XML documentation comments for all public APIs with
<summary>,<param>, and<returns>tags - Use file-scoped license headers:
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - Use
ConfigureAwait(false)on all awaited calls in library code - Prefer expression-bodied members for simple properties:
public override TokenType Type => TokenType.Done;
Async Patterns
Always use ConfigureAwait(false) to avoid deadlocks:
await tokenStreamHandler.ReadUInt16LE().ConfigureAwait(false);Error Handling
- Throw
ArgumentNullExceptionfor null arguments withnameof():Connection = connection ?? throw new ArgumentNullException(nameof(connection)); - Throw
ArgumentExceptionfor invalid argument values - Use
InvalidOperationExceptionfor unsupported operations - Custom exceptions inherit from appropriate base (e.g.,
ConnectionClosedException : IOException)
Implementing New Tokens
- Create token class inheriting from
TokeninTokens/{TokenName}/ - Override
Typeproperty returning appropriateTokenType - Create internal
{TokenName}TokenParser : TokenParser - Register parser in
TokenStreamHandler
Implementing New Payloads
- Create payload class inheriting from
PayloadinPayloads/{PayloadName}/ - Override
BuildBufferInternal()to construct theBufferproperty - Use
ByteBufferfor all binary data manipulation
Testing Requirements
Framework and Structure
- Framework: xUnit
- Mocking: Moq
- Test location:
test/Microsoft.Data.Tools.TdsLib.UnitTest/ - Naming:
{ClassName}Test.cs(e.g.,PacketTest.cs,TdsClientTest.cs)
Test Patterns
- Use
[Fact]for single test cases - Use descriptive method names:
CreatePacketWithNullBuffer,TestStatusResetConnectionIgnore - Test both success and failure cases
- Use
Assert.Throws<T>()for exception testing:[Fact] public void CreateTdsClientWithNullConnection() { Assert.Throws<ArgumentNullException>(() => { IConnection connection = default; new TdsClient(connection); }); }
Running Tests
dotnet test # Run all tests
dotnet test --filter "FullyQualifiedName~UnitTest" # Run unit tests onlyBuild and Development
Prerequisites
- .NET 6.0 SDK or later
- Visual Studio 2022 or VS Code with C# extension
Build Commands
dotnet restore # Restore NuGet packages
dotnet build # Build solution
dotnet test # Run tests
dotnet pack # Create NuGet package (uses tdslib.nuspec)Solution Structure
Open TdsLib.sln in Visual Studio or use dotnet CLI.
Best Practices
Always Do
- Add XML documentation for all public members
- Use
ConfigureAwait(false)on async calls - Implement
IDisposablefor classes managing resources - Write unit tests for new functionality
- Follow existing patterns in the codebase
- Use
ByteBufferfor all binary data manipulation
Never Do
- Block on async code (no
.Resultor.Wait()) - Forget
ConfigureAwait(false)in library code - Store credentials or connection strings in code
- Skip null checks for public API parameters
- Break backward compatibility without discussion
Git Commit Messages
Use clear, descriptive commit messages:
Add support for new token type XYZ
- Implement XyzToken and XyzTokenParser
- Register parser in TokenStreamHandler
- Add unit tests for token parsingDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

