agentleFS
MicrosoftKnown publishermicrosoft/go-sqlcmd/.github/copilot-instructions.md

go-sqlcmd

Copilot instructions602 starsChanged 6 months agoMITView on GitHub

This document provides guidance for GitHub Copilot when working with the go-sqlcmd repository. go-sqlcmd is a Go-based command line tool (sqlcmd) for working with Microsoft SQL Server, Azure SQL Database, and Azure Synapse. The project aims to be a complete port of the original ODBC sqlcmd to Go, utilizing the go-mssqldb driver. The project uses Go modules. Run go mod download to fetch dependencies. Tests may require the following environment variables for database connectivity: - SQLCMDSERVER - SQL Server hostname…

  • Installs packages
  • Commits and pushes

The file

Show its rules and text

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

53 rules. About 0 are common, 35 are distinctive, and 18 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈35

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 18

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Follow standard Go conventions and idioms

    line 90
  2. Very specific:

    Use gofmt for formatting

    line 91
  3. Very specific:

    Use tabs for indentation (as specified in .editorconfig)

    line 92
  4. Distinctive:

    Follow effective Go guidelines: https://go.dev/doc/effective_go

    line 93
  5. Distinctive:

    All Go files should include the following copyright header:

    line 97
  6. Distinctive:

    Use the standard Go error handling patterns

    line 109
  7. Distinctive:

    Use camelCase for unexported identifiers

    line 115
  8. Distinctive:

    Use PascalCase for exported identifiers

    line 116
  9. Distinctive:

    When adding new commands:

    line 135
  10. Very specific:

    Create the command in cmd/modern/root/

    line 136
  11. Very specific:

    Follow the existing pattern for subcommands (see query.go, start.go, stop.go)

    line 137
  12. Very specific:

    Add corresponding tests with _test.go suffix

    line 138
  13. Very specific:

    Use the internal/config package for configuration management

    line 143
  14. Very specific:

    Use the internal/localizer package for localized messages

    line 155
  15. Very specific:

    When adding user-facing strings to the code, use the localizer package:

    line 160
  16. Distinctive:

    After adding new localizable strings, you must regenerate the translation catalog files before committing.

    line 176
  17. Distinctive:

    Run the following commands manually:

    line 192
  18. Distinctive:

    Always run the build script after adding new user-facing strings

    line 204
  19. Distinctive:

    Check the build output for "conflicting localizable strings" warnings and resolve them

    line 205
  20. Distinctive:

    Test your changes with different language settings to ensure proper localization

    line 207
  21. Distinctive:

    Never commit secrets or credentials

    line 217
  22. Distinctive:

    Use environment variables or secure credential stores for sensitive data

    line 218
  23. Distinctive:

    Follow the Microsoft Security Development Lifecycle (SDL)

    line 219
  24. Distinctive:

    Ensure all tests pass locally

    line 224
  25. Distinctive:

    Follow the existing code style

    line 225
  26. Distinctive:

    Update documentation if adding new features

    line 226
  27. Distinctive:

    Add tests for new functionality

    line 227
  28. Distinctive:

    Keep commits focused and well-described

    line 228
  29. Distinctive:

    ALWAYS: use conventional commit format for PR titles and commit messages:

    line 236
  30. Distinctive:

    Write code for the maintenance programmer: Write clear, concise code that is easy to read and understand.

    line 284
  31. Distinctive:

    No filler phrases: "This ensures that...", "In order to...", "It's worth noting..."

    line 291
  32. Distinctive:

    No over-commenting obvious code (comments that restate what the code does)

    line 292
  33. Distinctive:

    No bloated docstrings with "Validates:" bullet lists or "Note:" paragraphs

    line 293
  34. Distinctive:

    No redundant inner docstrings on helpers inside tests

    line 294
  35. Very specific:

    No redundant logic (e.g., strings.ToLower() inside strings.EqualFold())

    line 297
  36. Distinctive:

    No duplicate validation (checking the same condition twice)

    line 298
  37. Distinctive:

    No excessive blank lines or formatting

    line 299
  38. Distinctive:

    No stale examples in docstrings that don't match the actual API

    line 300
  39. Distinctive:

    Before git push, always run the repo-specific checks.

    line 304
  40. Distinctive:

    Run full test suite

    line 309
  41. Very specific:

    If repo has .github/copilot-instructions.md, follow its build/test/lint instructions instead.

    line 312
  42. Distinctive:

    Test behavior, not implementation

    line 318
  43. Distinctive:

    When in doubt: would a senior engineer roll their eyes at this?

    line 322
  44. Very specific:

    Create a new file in cmd/modern/root/ (e.g., mycommand.go)

    line 330
  45. Very specific:

    Add corresponding tests in mycommand_test.go

    line 334
  46. Very specific:

    Update the config struct in internal/config/config.go

    line 360
  47. Distinctive:

    Add validation if needed

    line 361
  48. Very specific:

    Update the Viper bindings in internal/config/viper.go

    line 362
  49. Very specific:

    Add new fields to the SQLCmdArguments struct in cmd/sqlcmd/sqlcmd.go

    line 369
  50. Very specific:

    Add validation logic in the Validate method if needed

    line 371
  51. Very specific:

    Update setVars or setConnect functions to use the new arguments

    line 373
  52. Distinctive:

    Update README.md to show example usage

    line 376
  53. Very specific:

    Use pkg/sqlcmd for SQL connection management

    line 380

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

This document provides guidance for GitHub Copilot when working with the go-sqlcmd repository.

Project Overview

go-sqlcmd is a Go-based command line tool (sqlcmd) for working with Microsoft SQL Server, Azure SQL Database, and Azure Synapse. The project aims to be a complete port of the original ODBC sqlcmd to Go, utilizing the go-mssqldb driver.

Repository Structure

/
├── cmd/                    # Entry points for the application
│   ├── modern/             # Modern CLI entry point (Cobra-based)
│   │   ├── root/           # Root command and subcommands
│   │   └── sqlconfig/      # SQL configuration management
│   └── sqlcmd/             # Legacy CLI entry point (Kong-based)
├── pkg/                    # Public packages consumable by other hosts
│   └── sqlcmd/             # Core sqlcmd functionality
├── internal/               # Internal packages (not for external use)
│   ├── buffer/             # Buffer management
│   ├── cmdparser/          # Command parsing utilities
│   ├── color/              # Console coloring
│   ├── config/             # Configuration management
│   ├── container/          # Docker/Podman container management
│   ├── credman/            # Credential management
│   ├── http/               # HTTP utilities
│   ├── io/                 # I/O utilities
│   ├── localizer/          # Localization support
│   ├── net/                # Network utilities
│   ├── output/             # Output formatting
│   ├── pal/                # Platform abstraction layer
│   ├── secret/             # Secret/credential management
│   ├── sql/                # SQL-related utilities
│   ├── test/               # Test utilities
│   ├── tools/              # Development tools
│   └── translations/       # Localized string translations
├── build/                  # Build scripts and templates
├── testdata/               # Test data files
├── release/                # Release-related files
└── .github/                # GitHub workflows and configurations

Building the Project

Build Commands

# Build the sqlcmd executable
./build/build.sh       # Linux/macOS
.\build\build.cmd      # Windows

# Or build directly with Go
go build -o sqlcmd ./cmd/modern

Dependencies

The project uses Go modules. Run go mod download to fetch dependencies.

Testing

Running Tests

# Run all tests
go test ./...

# Run tests with verbose output
go test -v ./...

# Run tests for a specific package
go test -v ./pkg/sqlcmd/...
go test -v ./internal/config/...

Test Environment Variables

Tests may require the following environment variables for database connectivity:

  • SQLCMDSERVER - SQL Server hostname
  • SQLCMDPORT - SQL Server port (default: 1433)
  • SQLCMDUSER - Username (e.g., sa)
  • SQLCMDPASSWORD - Password
  • SQLCMDDATABASE - Database name

Code Style and Conventions

Go Standards

  • Follow standard Go conventions and idioms
  • Use gofmt for formatting
  • Use tabs for indentation (as specified in .editorconfig)
  • Follow effective Go guidelines: https://go.dev/doc/effective_go

File Headers

All Go files should include the following copyright header:

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

Package Documentation

Each package should have a doc.go file with package-level documentation.

Error Handling

  • Use the standard Go error handling patterns
  • For user-facing errors, prefer localized error messages via the internal/localizer package
  • Wrap errors with context when propagating

Naming Conventions

  • Use camelCase for unexported identifiers
  • Use PascalCase for exported identifiers
  • Acronyms should be all uppercase (e.g., SQL, URL, HTTP)
  • Package names should be lowercase, single-word if possible

CLI Architecture

Modern CLI (Cobra-based)

The modern CLI is located in cmd/modern/ and uses the Cobra library. Key points:

  • Root command is in cmd/modern/root.go
  • Subcommands are in cmd/modern/root/ directory
  • Uses dependency injection for testability

Legacy CLI (Kong-based)

The legacy CLI is in cmd/sqlcmd/ and maintains backward compatibility with the original ODBC sqlcmd.

Command Structure

When adding new commands:

  1. Create the command in cmd/modern/root/
  2. Follow the existing pattern for subcommands (see query.go, start.go, stop.go)
  3. Add corresponding tests with _test.go suffix

Configuration

  • Configuration files are stored in ~/.sqlcmd/sqlconfig
  • Use the internal/config package for configuration management
  • Viper is used for configuration parsing (internal/config/viper.go)

Container Support

The project supports creating SQL Server instances using Docker or Podman:

  • Container management is in internal/container/
  • Supports SQL Server images

Localization

  • Localized strings are in internal/translations/
  • Use the internal/localizer package for localized messages
  • Supported languages: Chinese (Simplified/Traditional), English, French, German, Italian, Japanese, Korean, Portuguese (Brazil), Russian, Spanish

Adding Localizable Strings

When adding user-facing strings to the code, use the localizer package:

import "github.com/microsoft/go-sqlcmd/internal/localizer"

// Use localizer.Sprintf for formatted strings
message := localizer.Sprintf("This is a localizable message with %s", value)

// Use localizer.Errorf for localized errors
err := localizer.Errorf("Error: %s failed", operation)

Constants that are not user-facing (like environment variable names, command names) should be placed in internal/localizer/constants.go and do not need localization.

Generating Localization Files

After adding new localizable strings, you must regenerate the translation catalog files before committing. The build scripts handle this automatically.

On Windows

build\build.cmd

This script:

  • Installs gotext if not already installed
  • Runs go generate which executes the gotext command defined in internal/translations/translations.go
  • Generates/updates the translation catalog in internal/translations/catalog.go
  • Reports any conflicting localizable strings that need to be fixed

On Linux/macOS

Run the following commands manually:

# Install gotext if not already installed
go install golang.org/x/text/cmd/gotext@latest

# Generate translation files
go generate ./...

Important Notes

  • Always run the build script after adding new user-facing strings
  • Check the build output for "conflicting localizable strings" warnings and resolve them
  • The SQLCMD_LANG environment variable controls the runtime language (e.g., de-de, fr-fr)
  • Test your changes with different language settings to ensure proper localization

Azure Authentication

  • Azure AD authentication is supported via the azidentity package
  • Authentication code is in pkg/sqlcmd/azure_auth.go
  • Supports multiple authentication methods: DefaultAzureCredential, Password, Interactive, ManagedIdentity, ServicePrincipal

Security Considerations

  • Never commit secrets or credentials
  • Use environment variables or secure credential stores for sensitive data
  • Follow the Microsoft Security Development Lifecycle (SDL)
  • Report security vulnerabilities via SECURITY.md

Pull Request Guidelines

  1. Ensure all tests pass locally
  2. Follow the existing code style
  3. Update documentation if adding new features
  4. Add tests for new functionality
  5. Keep commits focused and well-described

Commit Message Format

This project uses Conventional Commits for automated version management and changelog generation via Release Please.

Required Format

ALWAYS use conventional commit format for PR titles and commit messages:

<type>: <description>

[optional body]

[optional footer]

Commit Types and Version Bumps

TypeVersion BumpWhen to UseExample
feat:Minor (X.Y.0)New features or functionalityfeat: add support for SQL Server 2025
fix:Patch (X.Y.Z)Bug fixesfix: resolve timeout issue in query parsing
feat!: or BREAKING CHANGE:Major (X.0.0)Breaking changesfeat!: change CLI flag behavior
docs:No bumpDocumentation only changesdocs: update README with examples
chore:No bumpMaintenance taskschore: update dependencies
deps:No bumpDependency updatesdeps: bump go-mssqldb to v1.10.0
ci:No bumpCI/CD changesci: update GitHub Actions workflow
test:No bumpTest additions or fixestest: add coverage for edge cases
refactor:No bumpCode refactoring without behavior changerefactor: simplify command parsing
perf:Patch (X.Y.Z)Performance improvementsperf: optimize batch processing

Examples

Good commit messages:

feat: add --server-name flag for tunneled connections
fix: help flags preprocessing for -h and -help
deps: bump go-mssqldb to v1.9.8
ci: add release-please workflow

Bad commit messages:

Update README
Bug fix
Added new feature
Bump go directive to go 1.25.9

Code Quality Standards

  • Simplicity first: Make every change as simple as possible. Minimal code impact. Maximum modularity.
  • No laziness: Find root causes. No temporary fixes. Senior developer standards.
  • Minimal impact: Changes should only touch what's necessary. Avoid introducing bugs.
  • Write code for the maintenance programmer: Write clear, concise code that is easy to read and understand.

No AI Slop

Applies to all output: code, tests, docstrings, comments, PR descriptions, commit messages.

Prose and comments:

  • No filler phrases: "This ensures that...", "In order to...", "It's worth noting..."
  • No over-commenting obvious code (comments that restate what the code does)
  • No bloated docstrings with "Validates:" bullet lists or "Note:" paragraphs
  • No redundant inner docstrings on helpers inside tests

Code:

  • No redundant logic (e.g., strings.ToLower() inside strings.EqualFold())
  • No duplicate validation (checking the same condition twice)
  • No excessive blank lines or formatting
  • No stale examples in docstrings that don't match the actual API

Pre-Push Checklist

Before git push, always run the repo-specific checks. Default:

  • git fetch upstream && git rebase upstream/main (avoid "out-of-date with base branch")
  • Review your own diff (git diff upstream/main) -- check for AI slop, stale docstrings, weak assertions, anti-patterns. Read every changed line as a reviewer, not the author.
  • Build
  • Run full test suite
  • Run linter

If repo has .github/copilot-instructions.md, follow its build/test/lint instructions instead.

Rule: Review means reading every changed line as a hostile reviewer, not the author. For each addition, ask: (1) Is this used? grep for it. (2) Is this consistent with parallel code? Check sibling maps/lists. (3) Does the docstring match the code? Compare them line by line. (4) Would a senior engineer flag this? If you can't articulate why each line is correct, you haven't reviewed it.

Tests:

  • DAMP over DRY: tests should be Descriptive And Meaningful Phrases, each readable top-to-bottom as a self-contained story
  • Test behavior, not implementation
  • Assertions must match claims: if the test says "all types", check all of them
  • Cover what motivated the fix: the case that caused the bug is the most important assertion

When in doubt: would a senior engineer roll their eyes at this?

Common Tasks

Adding a New Command (Modern CLI)

For new commands related to context management, container operations, or configuration:

  1. Create a new file in cmd/modern/root/ (e.g., mycommand.go)
  2. Define a command struct that embeds cmdparser.Cmd
  3. Implement the DefineCommand method to set up command options, flags, and examples
  4. Implement the run method with the command logic
  5. Add corresponding tests in mycommand_test.go

Example structure:

type MyCommand struct {
    cmdparser.Cmd
    // flags
}

func (c *MyCommand) DefineCommand(...cmdparser.CommandOptions) {
    options := cmdparser.CommandOptions{
        Use:   "mycommand",
        Short: localizer.Sprintf("Description"),
        Run:   c.run,
    }
    c.Cmd.DefineCommand(options)
    // Add flags
}

func (c *MyCommand) run() {
    // Command logic
}

Adding a New Configuration Option (Modern CLI)

  1. Update the config struct in internal/config/config.go
  2. Add validation if needed
  3. Update the Viper bindings in internal/config/viper.go
  4. Add tests

Adding Features (Legacy CLI)

For new features related to querying SQL Server and displaying query results, add them to the legacy CLI:

  1. Add new fields to the SQLCmdArguments struct in cmd/sqlcmd/sqlcmd.go
  2. Register new flags in the setFlags function
  3. Add validation logic in the Validate method if needed
  4. Determine from existing patterns whether to add a SQLCMD variable to support it
  5. Update setVars or setConnect functions to use the new arguments
  6. Implement the feature logic in the run function or related functions
  7. Add corresponding tests in cmd/sqlcmd/sqlcmd_test.go
  8. Update README.md to show example usage

Working with SQL Connections

  • Use pkg/sqlcmd for SQL connection management
  • Connection options are defined in pkg/sqlcmd/connect.go
  • Support for various transports: TCP, named pipes, shared memory

CI/CD

  • GitHub Actions workflows are in .github/workflows/
  • golangci-lint.yml - Linting with golangci-lint
  • pr-validation.yml - Build and test validation for PRs
  • Azure Pipelines configurations are in .pipelines/

Linting

The project uses golangci-lint. To run locally:

golangci-lint run

Useful Resources

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.