agentleFS
MicrosoftKnown publishermicrosoft/arc-switch/copilot-instructions.md

arc-switch

Copilot instructions6 starsChanged 8 months agoMITView on GitHub

This file provides guidelines for GitHub Copilot and other AI assistants when helping with this repository. All tools must output data in JSON format with standardized fields for consistency and interoperability. Every parser tool must use this exact structure for all output records: Every tool output must include these four required fields: All parser-specific data must be contained within the message field as a JSON object. This provides: - Consistent top-level structure across all parsers - Clear separation between metadata…

The file

Show its rules and text

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

88 rules. About 0 are common, 66 are distinctive, and 22 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈66

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 22

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow the Go Code Review Comments for style guidance

    line 9
  2. Very specific:

    Use gofmt or goimports for consistent formatting

    line 11
  3. Very specific:

    Follow package structure: package main for executables, descriptive names for libraries

    line 13
  4. Distinctive:

    Place interfaces near where they're used, not in separate files

    line 14
  5. Distinctive:

    Use custom error types for specific error conditions

    line 20
  6. Very specific:

    Use errors.Is() and errors.As() for error checking when appropriate

    line 21
  7. Very specific:

    Prefer fmt.Errorf("...%w", err) for wrapping errors

    line 22
  8. Distinctive:

    Use short, concise variable names in small scopes

    line 26
  9. Distinctive:

    Use descriptive names for exported functions, types, and variables

    line 27
  10. Distinctive:

    Use camelCase for private and PascalCase for exported identifiers

    line 28
  11. Distinctive:

    Prefer single-letter variables for indices and short loops

    line 29
  12. Very specific:

    Write table-driven tests using testing.T

    line 33
  13. Very specific:

    Use t.Parallel() for tests that can run in parallel

    line 34
  14. Distinctive:

    Test both expected successes and failures

    line 35
  15. Distinctive:

    Avoid global variables in tests

    line 36
  16. Distinctive:

    Use buffered I/O for file operations

    line 41
  17. Distinctive:

    Use efficient data structures (maps for lookups, slices for iteration)

    line 43
  18. Distinctive:

    Consider sync.Pool for frequently allocated objects

    line 44
  19. Distinctive:

    Use channels to communicate between goroutines, not shared memory

    line 49
  20. Distinctive:

    Use context for cancellation and timing

    line 50
  21. Distinctive:

    Use sync.Mutex for simple state protection

    line 52
  22. Distinctive:

    Consider sync.WaitGroup for waiting on multiple goroutines

    line 53
  23. Distinctive:

    Use JSON struct tags consistently

    line 59
  24. Distinctive:

    Document all configuration options

    line 60
  25. Distinctive:

    Follow separation of concerns between:

    line 63
  26. Distinctive:

    All tools must output data in JSON format with standardized fields for consistency and interoperability.

    line 71
  27. Distinctive:

    Every parser tool must use this exact structure for all output records:

    line 75
  28. Distinctive:

    Every tool output must include these four required fields:

    line 90
  29. Very specific:

    All parser-specific data must be contained within the message field as a JSON object.

    line 99
  30. Very specific:

    All parsers should be designed to work with the standardized syslogwriter library located in src/SyslogTools/syslogwriter/.

    line 185
  31. Distinctive:

    When creating new parsers, ensure:

    line 223
  32. Distinctive:

    Structure Compliance: Always use the four required fields (data_type, timestamp, date, message)

    line 225
  33. Distinctive:

    Message Content: All parser-specific data goes in the message field only

    line 227
  34. Distinctive:

    JSON Validity: Ensure output is valid JSON and can be parsed

    line 228
  35. Distinctive:

    Syslog Compatibility: Test integration with the syslogwriter library

    line 229
  36. Very specific:

    Use consistent data_type naming: vendor_device_data_type (e.g., "cisco_nexus_mac_table")

    line 233
  37. Distinctive:

    Document all message field structures in the parser's README

    line 236
  38. Distinctive:

    Write unit tests that validate JSON structure compliance

    line 238
  39. Very specific:

    Test parser output with the validation script: Use ./validate-parser-output.sh to verify compliance with the standardized JSON structure

    line 239
  40. Very specific:

    Keep main.go small and focused on setup and coordination

    line 267
  41. Distinctive:

    Use separate packages for specialized functionality

    line 268
  42. Distinctive:

    Place most logic in importable packages for testing

    line 269
  43. Distinctive:

    Use appropriate directory structure:

    line 270
  44. Distinctive:

    Use Go modules for dependency management

    line 280
  45. Distinctive:

    Use specific versions in go.mod, not master branch

    line 282
  46. Distinctive:

    Follow these guidelines to ensure all markdown files comply with linting rules and GitHub best practices.

    line 286
  47. Very specific:

    Start every markdown file with a single H1 header (#)

    line 290
  48. Distinctive:

    Use proper heading hierarchy (H1 → H2 → H3, don't skip levels)

    line 291
  49. Distinctive:

    Use consistent heading case (prefer title case for main sections)

    line 294
  50. Distinctive:

    Always specify language for fenced code blocks:

    line 298
  51. Very specific:

    Use backticks for inline code: variable_name, function()

    line 309
  52. Distinctive:

    Use triple backticks for multi-line code blocks

    line 310
  53. Very specific:

    Use - (hyphen) for unordered lists consistently

    line 315
  54. Very specific:

    Use 1. for ordered lists (let markdown auto-number)

    line 316
  55. Distinctive:

    Add blank lines around lists for proper spacing

    line 317
  56. Distinctive:

    Use bold for emphasis, *italic* for subtle emphasis

    line 319
  57. Very specific:

    Use inline code for technical terms, commands, and filenames

    line 320
  58. Distinctive:

    Use descriptive link text, avoid "click here" or bare URLs

    line 324
  59. Distinctive:

    Prefer reference-style links for readability in long documents:

    line 325
  60. Distinctive:

    Use relative paths for internal repository links

    line 331
  61. Distinctive:

    Ensure all links are valid and accessible

    line 332
  62. Distinctive:

    Use proper table formatting with aligned columns

    line 336
  63. Distinctive:

    Don't break lines in the middle of inline code or links

    line 350
  64. Distinctive:

    Use soft line breaks (don't force hard wraps unless necessary)

    line 351
  65. Very specific:

    Use descriptive filenames with hyphens: installation-guide.md

    line 355
  66. Distinctive:

    Use table of contents for longer documents (>10 sections)

    line 358
  67. Distinctive:

    Ensure compliance with these key rules:

    line 362
  68. Very specific:

    MD003: Use consistent heading style (ATX-style with #)

    line 365
  69. Very specific:

    MD004: Use consistent unordered list style (hyphens -)

    line 366
  70. Distinctive:

    MD009: No trailing spaces at end of lines

    line 368
  71. Distinctive:

    MD010: No hard tabs, use spaces only

    line 369
  72. Distinctive:

    MD012: No multiple consecutive blank lines

    line 370
  73. Very specific:

    MD018: No space after # in headings

    line 372
  74. Distinctive:

    MD025: Only one H1 heading per document

    line 374
  75. Distinctive:

    MD026: No trailing punctuation in headings

    line 375
  76. Distinctive:

    Use GitHub Flavored Markdown (GFM) features appropriately

    line 384
  77. Distinctive:

    Test rendering in GitHub's preview before committing

    line 385
  78. Very specific:

    Use task lists for TODO items: - [ ] Task name

    line 386
  79. Distinctive:

    Use GitHub's alert syntax for important information:

    line 387
  80. Very specific:

    Use proper emoji codes when appropriate: :rocket: → 🚀

    line 396
  81. Distinctive:

    Write in clear, concise language

    line 400
  82. Distinctive:

    Use active voice when possible

    line 401
  83. Distinctive:

    Document prerequisites and assumptions

    line 403
  84. Distinctive:

    Keep documentation up-to-date with code changes

    line 405
  85. Distinctive:

    Use consistent terminology throughout the project

    line 406
  86. Distinctive:

    Every tool/project should include a README.md with:

    line 410
  87. Distinctive:

    Use markdownlint or similar tools to validate markdown files

    line 423
  88. Distinctive:

    Test documentation rendering in GitHub preview mode

    line 426

≈ “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 arc-switch Go Projects

This file provides guidelines for GitHub Copilot and other AI assistants when helping with this repository.

Golang Best Practices

Code Style and Organization

  • Follow the Go Code Review Comments for style guidance
  • Respect Go's Effective Go principles
  • Use gofmt or goimports for consistent formatting
  • Organize imports in three groups: standard library, external packages, internal packages
  • Follow package structure: package main for executables, descriptive names for libraries
  • Place interfaces near where they're used, not in separate files

Error Handling

  • Return errors explicitly; avoid panic except for unrecoverable situations
  • Handle errors immediately; don't defer checks
  • Use custom error types for specific error conditions
  • Use errors.Is() and errors.As() for error checking when appropriate
  • Prefer fmt.Errorf("...%w", err) for wrapping errors

Variable Naming

  • Use short, concise variable names in small scopes
  • Use descriptive names for exported functions, types, and variables
  • Use camelCase for private and PascalCase for exported identifiers
  • Prefer single-letter variables for indices and short loops

Testing

  • Write table-driven tests using testing.T
  • Use t.Parallel() for tests that can run in parallel
  • Test both expected successes and failures
  • Avoid global variables in tests
  • Name test files as *_test.go

Performance

  • Use buffered I/O for file operations
  • Preallocate slices when size is known
  • Use efficient data structures (maps for lookups, slices for iteration)
  • Consider sync.Pool for frequently allocated objects
  • Profile before optimizing

Concurrency

  • Use channels to communicate between goroutines, not shared memory
  • Use context for cancellation and timing
  • Be careful with goroutine leaks
  • Use sync.Mutex for simple state protection
  • Consider sync.WaitGroup for waiting on multiple goroutines

SNMP Project Specifics

  • Log errors with context (device info, OIDs)
  • Handle SNMP timeouts gracefully
  • Use JSON struct tags consistently
  • Document all configuration options
  • Include retry logic for transient failures
  • Validate input configurations
  • Follow separation of concerns between:
    • SNMP operations
    • MIB handling
    • Configuration management
    • Output formatting

JSON Output Format

All tools must output data in JSON format with standardized fields for consistency and interoperability.

Standardized JSON Structure

Every parser tool must use this exact structure for all output records:

{
  "data_type": "",
  "timestamp": "",
  "date": "",
  "message": {
    // Parser-specific JSON data goes here
  }
}

Required Fields

Every tool output must include these four required fields:

  • data_type: String identifying the type of data (e.g., "interface_counters", "cisco_nexus_mac_table", "lldp_neighbors")
  • timestamp: Full timestamp in ISO 8601 format (e.g., "2024-01-15T10:30:00Z") for machine parsing
  • date: Date in ISO format (YYYY-MM-DD) for easy filtering and sorting
  • message: JSON object containing all parser-specific data fields

Message Field Structure

All parser-specific data must be contained within the message field as a JSON object. This provides:

  • Consistent top-level structure across all parsers
  • Clear separation between metadata and data
  • Compatibility with the syslogwriter library
  • Easier processing and validation

Example: Cisco Nexus MAC Table Parser

{
  "data_type": "cisco_nexus_mac_table",
  "timestamp": "2024-06-23T17:05:01Z",
  "date": "2024-06-23",
  "message": {
    "primary_entry": true,
    "gateway_mac": false,
    "routed_mac": false,
    "overlay_mac": false,
    "vlan": "7",
    "mac_address": "02ec.a004.0000",
    "type": "dynamic",
    "age": "NA",
    "secure": "F",
    "ntfy": "F",
    "port": "Eth1/1",
    "vpc_peer_link": false
  }
}

Message Fields for MAC Table Parser:

  • primary_entry: Boolean indicating if this is a primary entry
  • gateway_mac: Boolean indicating if this is a gateway MAC
  • routed_mac: Boolean indicating if this is a routed MAC
  • overlay_mac: Boolean indicating if this is an overlay MAC
  • vlan: VLAN ID as string
  • mac_address: MAC address in Cisco format (xxxx.xxxx.xxxx)
  • type: Entry type (e.g., "dynamic", "static")
  • age: Age information or "NA"
  • secure: Security flag ("F" or "T")
  • ntfy: Notification flag ("F" or "T")
  • port: Port identifier
  • vpc_peer_link: Boolean, only present when true for vPC peer-link entries

Example: Interface Counters Parser

{
  "data_type": "interface_counters",
  "timestamp": "2024-01-15T10:30:00Z",
  "date": "2024-01-15",
  "message": {
    "interface_name": "Eth1/1",
    "interface_type": "ethernet",
    "in_octets": 205027653248,
    "in_ucast_pkts": 650373664,
    "in_mcast_pkts": 2262324,
    "in_bcast_pkts": 68097,
    "out_octets": 3195383643785,
    "out_ucast_pkts": 2314463086,
    "out_mcast_pkts": 365931965,
    "out_bcast_pkts": 53571839,
    "has_ingress_data": true,
    "has_egress_data": true
  }
}

Message Fields for Interface Counters Parser:

  • interface_name: Interface identifier (e.g., "Eth1/1", "Po50", "Vlan1")
  • interface_type: Type category ("ethernet", "port-channel", "vlan", "management", "tunnel")
  • in_octets: Ingress octets counter (-1 if unavailable)
  • in_ucast_pkts: Ingress unicast packets counter (-1 if unavailable)
  • in_mcast_pkts: Ingress multicast packets counter (-1 if unavailable)
  • in_bcast_pkts: Ingress broadcast packets counter (-1 if unavailable)
  • out_octets: Egress octets counter (-1 if unavailable)
  • out_ucast_pkts: Egress unicast packets counter (-1 if unavailable)
  • out_mcast_pkts: Egress multicast packets counter (-1 if unavailable)
  • out_bcast_pkts: Egress broadcast packets counter (-1 if unavailable)
  • has_ingress_data: Boolean indicating if ingress counters are available
  • has_egress_data: Boolean indicating if egress counters are available

Integration with SyslogWriter

All parsers should be designed to work with the standardized syslogwriter library located in src/SyslogTools/syslogwriter/. This library expects the exact JSON structure defined above:

import "github.com/arc-switch/syslogwriter"

// Initialize syslog writer
writer, err := syslogwriter.NewWithDefaults("parser-name")
if err != nil {
    log.Fatal(err)
}
defer writer.Close()

// Create standardized JSON structure
entry := map[string]interface{}{
    "data_type": "your_parser_type",
    "timestamp": time.Now().Format(time.RFC3339),
    "date": time.Now().Format("2006-01-02"),
    "message": map[string]interface{}{
        // Your parser-specific fields here
        "field1": "value1",
        "field2": 12345,
    },
}

// Convert to JSON and write to syslog
jsonData, err := json.Marshal(entry)
if err != nil {
    log.Printf("Failed to marshal entry: %v", err)
    return
}

if err := writer.WriteEntry(string(jsonData)); err != nil {
    log.Printf("Failed to write to syslog: %v", err)
}

Validation Requirements

When creating new parsers, ensure:

  1. Structure Compliance: Always use the four required fields (data_type, timestamp, date, message)
  2. Field Validation: Validate that all required fields are present and non-empty
  3. Message Content: All parser-specific data goes in the message field only
  4. JSON Validity: Ensure output is valid JSON and can be parsed
  5. Syslog Compatibility: Test integration with the syslogwriter library

Parser Development Guidelines

  • Use consistent data_type naming: vendor_device_data_type (e.g., "cisco_nexus_mac_table")
  • Include comprehensive error handling for malformed input
  • Provide verbose output options for debugging
  • Document all message field structures in the parser's README
  • Include sample input and output files for testing
  • Write unit tests that validate JSON structure compliance
  • Test parser output with the validation script: Use ./validate-parser-output.sh to verify compliance with the standardized JSON structure

Output Validation

The project includes a validation script at the root level (validate-parser-output.sh) that verifies parser outputs conform to the standardized JSON structure. This script supports multiple JSON formats:

  • Single JSON object (compact or pretty-printed)
  • JSON array containing multiple objects
  • Concatenated JSON objects (newline-separated)
  • Live parser output via stdin

Usage examples:

# Validate a parser output file
./validate-parser-output.sh parser-output.json

# Validate live parser output
./parser -input data.txt | ./validate-parser-output.sh

# Test your parser's compliance
cd src/SwitchOutput/Cisco/Nexus/10/ip_arp_parser
./ip_arp_parser -input ../show-ip-arp.txt | /workspaces/arc-switch2/validate-parser-output.sh

Always run the validation script on your parser output before committing code.

Project Structure

  • Keep main.go small and focused on setup and coordination
  • Use separate packages for specialized functionality
  • Place most logic in importable packages for testing
  • Use appropriate directory structure:
    • /cmd - Main applications
    • /pkg - Library code
    • /internal - Private application code
    • /api - API definitions
    • /configs - Configuration file templates

Dependencies

  • Minimize external dependencies
  • Use Go modules for dependency management
  • Vendor dependencies for reproducible builds
  • Use specific versions in go.mod, not master branch

Markdown Best Practices

Follow these guidelines to ensure all markdown files comply with linting rules and GitHub best practices.

Document Structure

  • Start every markdown file with a single H1 header (#)
  • Use proper heading hierarchy (H1 → H2 → H3, don't skip levels)
  • Include a blank line after each heading
  • End files with a single blank line
  • Use consistent heading case (prefer title case for main sections)

Code Blocks and Syntax Highlighting

  • Always specify language for fenced code blocks:

    # Good
    ./command --help
    # For plain text output
    Interface Status: UP
  • Use backticks for inline code: variable_name, function()
  • Use triple backticks for multi-line code blocks
  • Specify appropriate language identifiers: bash, go, json, yaml, text, markdown

Lists and Formatting

  • Use - (hyphen) for unordered lists consistently
  • Use 1. for ordered lists (let markdown auto-number)
  • Add blank lines around lists for proper spacing
  • Indent nested list items with 2 spaces
  • Use bold for emphasis, italic for subtle emphasis
  • Use inline code for technical terms, commands, and filenames

Links and References

  • Use descriptive link text, avoid "click here" or bare URLs
  • Prefer reference-style links for readability in long documents:
    See the [Go documentation][go-docs] for more details.
    
    [go-docs]: https://golang.org/doc/
  • Use relative paths for internal repository links
  • Ensure all links are valid and accessible

Tables

  • Use proper table formatting with aligned columns
  • Include header separators with at least 3 dashes
  • Align text content left, numbers right:
    | Tool Name        | Type     | Status |
    |------------------|----------|--------|
    | mac_parser       | CLI      | Active |
    | interface_parser | CLI      | Active |

Line Length and Wrapping

  • Aim for 80-120 character line length for readability
  • Break long lines at natural points (after punctuation, before conjunctions)
  • Don't break lines in the middle of inline code or links
  • Use soft line breaks (don't force hard wraps unless necessary)

File Organization

  • Use descriptive filenames with hyphens: installation-guide.md
  • Include a brief description at the top of each document
  • Organize content with clear sections and subsections
  • Use table of contents for longer documents (>10 sections)

Common Markdown Linting Rules (markdownlint)

Ensure compliance with these key rules:

  • MD001: Heading levels should only increment by one level at a time
  • MD003: Use consistent heading style (ATX-style with #)
  • MD004: Use consistent unordered list style (hyphens -)
  • MD007: Unordered list indentation should be 2 spaces
  • MD009: No trailing spaces at end of lines
  • MD010: No hard tabs, use spaces only
  • MD012: No multiple consecutive blank lines
  • MD013: Line length should be reasonable (80-120 chars)
  • MD018: No space after # in headings
  • MD022: Headings should be surrounded by blank lines
  • MD025: Only one H1 heading per document
  • MD026: No trailing punctuation in headings
  • MD030: Spaces after list markers (1 space for unordered, 2 for ordered)
  • MD032: Lists should be surrounded by blank lines
  • MD040: Fenced code blocks should have a language specified
  • MD041: First line in file should be a top-level heading
  • MD047: Files should end with a single newline character

GitHub-Specific Considerations

  • Use GitHub Flavored Markdown (GFM) features appropriately
  • Test rendering in GitHub's preview before committing
  • Use task lists for TODO items: - [ ] Task name
  • Use GitHub's alert syntax for important information:
    > [!NOTE]
    > This is a note
    
    > [!WARNING]
    > This is a warning
  • Include shields/badges consistently at the top of README files
  • Use proper emoji codes when appropriate: :rocket: → 🚀

Documentation Standards

  • Write in clear, concise language
  • Use active voice when possible
  • Include examples for all instructions
  • Document prerequisites and assumptions
  • Provide troubleshooting sections for complex procedures
  • Keep documentation up-to-date with code changes
  • Use consistent terminology throughout the project

README File Requirements

Every tool/project should include a README.md with:

  1. Title and Description: Clear project name and purpose
  2. Installation Instructions: How to build/install the tool
  3. Usage Examples: Command-line examples with expected output
  4. Configuration: Available options and settings
  5. Input/Output Formats: Expected data formats and schemas
  6. Examples: Sample input/output files
  7. Contributing: How to contribute to the project
  8. License: License information or reference

Validation and Tools

  • Use markdownlint or similar tools to validate markdown files
  • Set up pre-commit hooks to check markdown formatting
  • Configure editor extensions for real-time markdown linting
  • Test documentation rendering in GitHub preview mode
  • Validate all external links regularly

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.