agentleFS
MicrosoftKnown publishermicrosoft/TdsLib/.github/copilot-instructions.md

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
  1. Distinctive:

    Limitations: Does not support normal data streams or T-SQL commands

    line 9
  2. Very specific:

    Use XML documentation comments for all public APIs with <summary>, <param>, and <returns> tags

    line 87
  3. Distinctive:

    Use file-scoped license headers:

    line 88
  4. Very specific:

    Use ConfigureAwait(false) on all awaited calls in library code

    line 93
  5. Distinctive:

    Prefer expression-bodied members for simple properties:

    line 94
  6. Very specific:

    Always use ConfigureAwait(false) to avoid deadlocks:

    line 101
  7. Very specific:

    Use InvalidOperationException for unsupported operations

    line 114
  8. Very specific:

    Create token class inheriting from Token in Tokens/{TokenName}/

    line 119
  9. Very specific:

    Create payload class inheriting from Payload in Payloads/{PayloadName}/

    line 126
  10. Very specific:

    Use ByteBuffer for all binary data manipulation

    line 128
  11. Very specific:

    Use [Fact] for single test cases

    line 141
  12. Very specific:

    Use descriptive method names: CreatePacketWithNullBuffer, TestStatusResetConnectionIgnore

    line 142
  13. Distinctive:

    Test both success and failure cases

    line 143
  14. Very specific:

    Use Assert.Throws<T>() for exception testing:

    line 144
  15. Distinctive:

    Add XML documentation for all public members

    line 188
  16. Very specific:

    Use ConfigureAwait(false) on async calls

    line 189
  17. Distinctive:

    Write unit tests for new functionality

    line 191
  18. Distinctive:

    Follow existing patterns in the codebase

    line 192
  19. Distinctive:

    Use clear, descriptive commit messages:

    line 205

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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

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 tests

Architectural Layers

LayerLocationPurpose
ClientTdsClient.csMain entry point, orchestrates message/token handling
MessagesMessages/High-level message abstraction, splits into packets
PacketsPackets/TDS packet format with headers and data
PayloadsPayloads/Message content (PreLogin, Login7, etc.)
TokensTokens/Response parsing from SQL Server
ConnectionIO/Connection/Low-level connection management
BufferBuffer/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 internal and 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 ArgumentNullException for null arguments with nameof():
    Connection = connection ?? throw new ArgumentNullException(nameof(connection));
  • Throw ArgumentException for invalid argument values
  • Use InvalidOperationException for unsupported operations
  • Custom exceptions inherit from appropriate base (e.g., ConnectionClosedException : IOException)

Implementing New Tokens

  1. Create token class inheriting from Token in Tokens/{TokenName}/
  2. Override Type property returning appropriate TokenType
  3. Create internal {TokenName}TokenParser : TokenParser
  4. Register parser in TokenStreamHandler

Implementing New Payloads

  1. Create payload class inheriting from Payload in Payloads/{PayloadName}/
  2. Override BuildBufferInternal() to construct the Buffer property
  3. Use ByteBuffer for 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 only

Build 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 IDisposable for classes managing resources
  • Write unit tests for new functionality
  • Follow existing patterns in the codebase
  • Use ByteBuffer for all binary data manipulation

Never Do

  • Block on async code (no .Result or .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 parsing

Download now (ZIP)

Does 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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.