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

SdnDiagnostics

Copilot instructions35 starsChanged 5 years agoMITView on GitHub

The file

Show its rules and text

We split this copilot-instructions.md into the rules it gives an agent

26 rules. About 0 are common, 12 are distinctive, and 14 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow PowerShell best practices and the PowerShell Practice and Style Guide

    line 9
  2. Distinctive:

    Use approved verbs for function names (Get-, Set-, New-, Remove-, etc.)

    line 10
  3. Distinctive:

    Use PascalCase for function names and parameters

    line 11
  4. Distinctive:

    Use camelCase for local variables

    line 12
  5. Very specific:

    Always include [CmdletBinding()] attribute for advanced functions

    line 16
  6. Distinctive:

    Use parameter sets when functions have mutually exclusive parameters

    line 17
  7. Very specific:

    Use ShouldProcess pattern for functions that make changes (with -Confirm and -WhatIf support)

    line 19
  8. Distinctive:

    Always include proper error handling with try/catch blocks

    line 20
  9. Very specific:

    Use Trace-Output for logging instead of Write-Host or Write-Verbose

    line 23
  10. Very specific:

    Always include both Trace-Exception and Write-Error in catch blocks

    line 25
  11. Distinctive:

    Use Trace-Output function for all logging with appropriate -Level parameter

    line 40
  12. Distinctive:

    Place role-specific functions in appropriate module files:

    line 49
  13. Very specific:

    Use New-PSRemotingSession for creating remote sessions

    line 58
  14. Very specific:

    Use Invoke-PSRemoteCommand for executing commands remotely.

    line 59
  15. Very specific:

    Always pass $Credential parameter for remote operations

    line 60
  16. Very specific:

    Use Invoke-RestMethodWithRetry or Invoke-WebRequestWithRetry for Network Controller REST API calls

    line 63
  17. Very specific:

    Always include parameter sets for RestCertificate and RestCredential

    line 65
  18. Very specific:

    Use @ncRestParams splatting pattern for REST parameters

    line 66
  19. Very specific:

    Use Initialize-DataCollection to prepare output directories and validate disk space

    line 69
  20. Very specific:

    Use Export-ObjectToFile to save results with consistent formatting

    line 70
  21. Distinctive:

    Use proper markdown formatting in comment-based help

    line 89
  22. Distinctive:

    Document any prerequisites or dependencies

    line 90
  23. Very specific:

    All tests are offline (mock-based) in tests/offline/.

    line 111
  24. Distinctive:

    Never log credentials or secrets

    line 125
  25. Distinctive:

    Use SecureString for password parameters

    line 126
  26. Very specific:

    Check for admin privileges when required using Confirm-IsAdmin

    line 128

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

GitHub Copilot Instructions for SdnDiagnostics

Project Overview

SdnDiagnostics is a PowerShell module for diagnosing and troubleshooting Software Defined Networking (SDN) infrastructure in Microsoft environments, including Azure Stack HCI and Windows Server deployments.

Code Style and Conventions

PowerShell Standards

  • Follow PowerShell best practices and the PowerShell Practice and Style Guide
  • Use approved verbs for function names (Get-, Set-, New-, Remove-, etc.)
  • Use PascalCase for function names and parameters
  • Use camelCase for local variables
  • Include comprehensive comment-based help for all exported functions

Function Structure

  • Always include [CmdletBinding()] attribute for advanced functions
  • Use parameter sets when functions have mutually exclusive parameters
  • Include proper parameter validation attributes (Mandatory, ValidateSet, ValidateScript, etc.)
  • Use ShouldProcess pattern for functions that make changes (with -Confirm and -WhatIf support)
  • Always include proper error handling with try/catch blocks

Error Handling

  • Use Trace-Output for logging instead of Write-Host or Write-Verbose
  • Pipe exceptions to Trace-Exception in catch blocks
  • Always include both Trace-Exception and Write-Error in catch blocks
  • Return meaningful error messages to users

Example:

try {
    # Function logic
}
catch {
    $_ | Trace-Exception
    $_ | Write-Error
}

Logging and Tracing

  • Use Trace-Output function for all logging with appropriate -Level parameter
    • Level:Verbose for detailed debug information
    • Level:Information for general information (default)
    • Level:Warning for warnings
    • Level:Error for errors
    • Level:Exception for exceptions (handled by Trace-Exception)
    • Level:Success for successful operations

Module Organization

Place role-specific functions in appropriate module files:

  • SdnDiag.Common.psm1 - Functions common to all roles
  • SdnDiag.Gateway.psm1 - Gateway-specific functions
  • SdnDiag.LoadBalancerMux.psm1 - Load balancer MUX functions
  • SdnDiag.NetworkController.psm1 - Network Controller functions
  • SdnDiag.Server.psm1 - Server/host-specific functions
  • SdnDiag.Utilities.psm1 - Utility helper functions

Remote Execution

  • Use New-PSRemotingSession for creating remote sessions
  • Use Invoke-PSRemoteCommand for executing commands remotely. This function should handle session management and error handling.
  • Always pass $Credential parameter for remote operations

REST API Interactions

  • Use Invoke-RestMethodWithRetry or Invoke-WebRequestWithRetry for Network Controller REST API calls
  • Support both certificate and credential-based authentication
  • Always include parameter sets for RestCertificate and RestCredential
  • Use @ncRestParams splatting pattern for REST parameters

Data Collection

  • Use Initialize-DataCollection to prepare output directories and validate disk space
  • Use Export-ObjectToFile to save results with consistent formatting
  • Support -OutputDirectory parameter for all data collection functions
  • Include time range parameters (-FromDate, -ToDate) where applicable

Credential Handling

  • Use [System.Management.Automation.PSCredential] type
  • Default to [System.Management.Automation.PSCredential]::Empty
  • Include [System.Management.Automation.Credential()] attribute

Example:

[Parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = [System.Management.Automation.PSCredential]::Empty

Documentation

  • Include synopsis, description, parameter descriptions, and examples
  • Use proper markdown formatting in comment-based help
  • Document any prerequisites or dependencies
  • Include related links where applicable

Common Patterns

Network Controller REST Parameter Pattern

$ncRestParams = @{
    NcUri = $NcUri
    ErrorAction = 'Stop'
}

switch ($PSCmdlet.ParameterSetName) {
    'RestCertificate' { $ncRestParams.Add('NcRestCertificate', $NcRestCertificate) }
    'RestCredential' { $ncRestParams.Add('NcRestCredential', $NcRestCredential) }
}

$result = Get-SdnResource @ncRestParams -ResourceRef $resourceRef

Pester Testing

All tests are offline (mock-based) in tests/offline/. See .github/instructions/pester-tests.instructions.md for the full authoring guide.

When adding a new function, always add corresponding Pester tests:

  • Pure utility functions (Format-, Confirm-, Convert-*) → Pattern A (InModuleScope, no mocking)
  • Functions calling NC REST API → Pattern B (mock Invoke-RestMethodWithRetry inside InModuleScope SdnDiag.NetworkController)
  • Functions calling remote commands → Pattern C (mock Invoke-PSRemoteCommand inside the nested module scope)

Test file convention: Named after the source module (e.g., SdnDiag.Utilities.psm1 → Utilities.Tests.ps1)

Mock data: Uses DVLAB prefix naming. JSON files in tests/offline/data/SdnApiResources/ auto-load into $Global:PesterOfflineTests.SdnApiResources.

Running: Build the module first (.\build.ps1), then .\tests\offline\RunTests.ps1

Security Best Practices

  • Never log credentials or secrets
  • Use SecureString for password parameters
  • Validate user input with appropriate attributes
  • Check for admin privileges when required using Confirm-IsAdmin

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.