copilot-instructions.md · git:20261111.85f77f5 · 2026-11-11 · sha256 96b96f7b11fc9b7e

copilot-instructions.md git:20261111.85f77f5A

Immutable. This exact content never changes and is served at /api/v1/blob/96b96f7b11fc9b7e.

# GitHub Copilot for Azure — Repository Instructions

This repo contains Azure agent skills (markdown-based knowledge packages) organized into per-plugin sources under `plugins/`, plus a standalone .NET telemetry reporter under `telemetry-reporter/`. The plugin build produces versioned output in `output/`, with shared hooks built at the top level. The telemetry reporter has its own solution and build process.

## Repository Layout

```
plugins/                  # Plugin sources
  <plugin-dirname>/       # Individual plugin package
    .plugin/              # GitHub Copilot plugin manifest
    .cursor-plugin/       # Cursor plugin manifest
    .claude-plugin/       # Claude plugin manifest
    skills/<name>/        # Individual skill directories
      SKILL.md            # Skill definition (required)
      version.json        # NBGV per-skill version config
      references/         # On-demand reference docs
    .mcp.json             # MCP server declarations
    version.json          # NBGV plugin-level version config
hooks/                    # Shared hook sources, built at the output top level

telemetry-reporter/       # Standalone .NET 10 telemetry reporting executable
  src/                    # Console application and telemetry library
  tests/                  # .NET unit tests
  eng/scripts/            # Opt-in cross-platform Native AOT packaging
  ghcfa-telem.slnx        # .NET solution
  version.json            # NBGV version rooted at 0.1

output/                   # Build output (git-ignored) — stamped, ready to deploy
  <plugin-dirname>/       # Built plugin output
  hooks/                  # Built shared hooks
scripts/                  # Dev tooling: token analysis, frontmatter/reference validators
evals/                    # Vally test suites
tests/                    # Code related to testing
.github/
  instructions/           # Copilot instruction files for skill authoring
  skills/                 # Repo-local agent skills (not shipped in plugin)
  workflows/              # CI/CD workflows
docs/                     # Documentation (versioning, specs, diagrams)
eng/                      # Engineering scripts (test subscription cleanup)
gulpfile.ts               # Build pipeline
.token-limits.json        # Token budget config
.vally.yaml                # Vally eval framework config
```

## Building

### Skills and Hooks

```bash
npm install          # Install root + scripts deps (postinstall handles scripts/)
npm run build        # Builds plugins/ and shared hooks into output/, stamps NBGV versions, generates CHANGELOG.md
```

### Telemetry Reporter

Run .NET commands from `telemetry-reporter/` so the nested `global.json` settings are applied:

```powershell
cd telemetry-reporter
dotnet build .\ghcfa-telem.slnx --configuration Release
```

The telemetry reporter is independent of the root npm build. Do not add it to existing build or CI systems unless explicitly requested.

## Versioning Rules

This repo uses **Nerdbank.GitVersioning (NBGV)**. Versions are computed automatically from git commit history.

- **Never manually edit version numbers** in plugin manifests or SKILL.md frontmatter under `plugins/`
- Source files must always use `"0.0.0-placeholder"` — the build stamps real versions
- Each skill has its own `version.json` with `pathFilters: ["."]`; only commits touching that skill's directory increment its version
- For skills outside `plugins/` (e.g., `.github/skills/`), set a real semver version and bump it in the same PR that modifies the skill
- `telemetry-reporter/version.json` starts at `0.1` and uses `pathFilters: ["."]`; the NBGV NuGet package stamps its .NET assemblies and packages
- Do not add hard-coded `<Version>` properties to telemetry reporter projects; use NBGV's `GetBuildVersion` target when scripts need the computed version
- Use conventional commit-style PR titles (e.g. `feat:`, `fix:`, `feature:`) — the build generates `CHANGELOG.md` from these

## Validating Changes

### Token and Structure Validators (from repo root)

```bash
npm run tokens check          # Check token limits against .token-limits.json
npm run tokens compare        # Compare token counts vs main
```

### Frontmatter and Reference Validation (from scripts/)

```bash
cd scripts
npm run frontmatter           # Validate skill YAML frontmatter against agentskills.io spec
npm run references            # Validate markdown links stay within skill directories
```

### Unit and Trigger Tests (from tests/)

```bash
cd tests
npm install
npm test                                    # Run unit tests
npm run typecheck                            # TypeScript type checking
npm run lint                                 # ESLint
```

### Integration Tests

Integration tests are authored as vally eval suites. Read `vally-eval` skill to see how to author integration tests for skills.

### Telemetry Reporter

Run the .NET tests from the telemetry reporter directory:

```powershell
cd telemetry-reporter
dotnet test .\ghcfa-telem.slnx --configuration Release
```

The executable must preserve the Azure MCP `server plugin-telemetry` JSON responses, allowlist validation, and telemetry properties. All three allowlist paths (`--allowed-skills`, `--allowed-references`, and `--allowed-tools`) are required; there are no embedded lists. Plugin builds supply these files under `hooks/allowlists/`. Update compatibility metadata and tests when synchronizing runtime behavior with a new Azure MCP source revision.

## Adding a New Skill

> ⚠️ The char-count budget for skill descriptions is close to the Copilot CLI limit. Adding new skills risks truncation. Consider extending an existing skill first.

### Steps

1. **Create the skill directory**: `plugins/<plugin-name>/skills/<your-skill-name>/`

2. **Add `version.json`**:
   ```json
   {
     "version": "1.1",
     "pathFilters": ["."]
   }
   ```

3. **Write `SKILL.md`** with required frontmatter:
   ```yaml
   ---
   name: your-skill-name
   description: "What the skill does and when to use it. Include trigger phrases."
   license: MIT
   metadata:
     author: Microsoft
     version: "0.0.0-placeholder"
   ---
   ```
   - `name` must match the directory name (lowercase, hyphens only, 1-64 chars)
   - `version` must be `"0.0.0-placeholder"` — NBGV stamps the real version at build time
   - `description` must be 1-1024 chars, explaining WHAT and WHEN with trigger phrases

4. **Move detailed content** to `references/` subdirectory — keep SKILL.md under 500 tokens (soft limit)

5. **Add to `tests/skills.json`**: Add your skill name to the `skills` array and assign it to an integration test schedule slot

6. **Scaffold tests**: Copy `tests/_template` to `tests/<your-skill-name>/` and update `SKILL_NAME` in each test file

7. **Validate**:
   ```bash
   npm run build                              # Verify version stamping works
   cd scripts && npm run frontmatter          # Validate frontmatter
   cd scripts && npm run references           # Validate markdown links
   cd tests && npm test                       # Run skill unit tests
   ```

### Token Limits

| File Pattern           | Soft Limit | Notes                            |
|------------------------|------------|----------------------------------|
| `SKILL.md`             | 500 tokens | Move detail to `references/`     |
| `references/**/*.md`   | 1000 tokens| Split large references           |
| `*.md` (other)         | 2000 tokens| General markdown                 |

Token estimation: ~4 characters ≈ 1 token. Limits are configured in `.token-limits.json`.

### Skill Authoring Guidelines

- Follow the [agentskills.io specification](https://agentskills.io/specification)
- See `.github/instructions/skill-files.instructions.md` for detailed formatting rules
- See `.github/skills/skill-authoring/SKILL.md` for the full authoring guide
- Prefer Azure MCP tools over direct CLI commands when available
- Use progressive disclosure: frontmatter → SKILL.md → references
- Descriptions over 200 chars in frontmatter must use folded YAML (`>-`)
- Markdown links must not escape the skill directory (validated by `npm run references`)

## Authoring Scripts in Skills

Some skills ship helper scripts (under a skill's `scripts/` or `references/**/scripts/` directory). These guidelines help avoid common problems in the scripts.

### General Guidelines

- **Always ship both `.sh` (bash) and `.ps1` (PowerShell) versions** of a script. Keep their behavior, options, output format, and exit codes in sync.
- **Document exit codes in a header comment** and keep it accurate: the convention is `0` = success/all passed, `1` = a check failed, `2` = usage/argument error. Update the comment whenever the code changes, and keep both scripts' headers consistent.
- **Provide both bash and PowerShell invocation examples** wherever a script is referenced in docs — never show only one shell.
- **Make `--dry-run`/preview output match what actually runs.** If a pipe or step is conditional (e.g. only pipe to `tcpdump` when it's installed), the previewed command must reflect the same condition.
- **Don't double-report results.** Pick one source of truth (inline per-step lines *or* a final summary table), not both. Remove dead/unused variables and helpers.
- **Treat errors as errors.** For critical checks (especially pre-provision scans), a read error, missing file, or failed CLI call must produce a non-zero exit — never silently fall through to a misleading "not applicable" / "already configured" / "fix required" verdict.

### PowerShell Scripts

- **Do not set `$ErrorActionPreference = 'Stop'` at script scope.** It makes `Write-Error` terminating and can bypass your explicit `exit` codes. Leave the default (`Continue`) and, where you need a hard stop, use `-ErrorAction Stop` on the specific call inside a `try/catch`. Also don't add a redundant `$ErrorActionPreference = 'Continue'` line — that's already the default.
- **Check `$LASTEXITCODE` after native commands** (`az`, `kubectl`, `terraform`, etc.). Non-zero exits from native executables do *not* raise PowerShell errors, so capture output and test `$LASTEXITCODE` explicitly instead of assuming success.
- **Avoid `[Parameter(Mandatory)]`.** In non-interactive scenarios PowerShell will block prompting for the value. Instead, check the parameter explicitly (e.g. `[string]::IsNullOrWhiteSpace(...)`) and exit `2` with a clear message.
- **Stay compatible with Windows PowerShell 5.1**, not just PowerShell 7. Avoid 7-only features/parameters such as `Invoke-WebRequest -SkipHttpErrorCheck`; read HTTP status from the caught exception's `Response.StatusCode` instead.
- Prefer `Write-Error` (stderr) over `Write-Host` for genuine error conditions so failures surface in CI/log collectors, while still exiting non-zero.

### Bash Scripts

- **Target Bash 3.2** (macOS default) — do not assume Bash 4+. Avoid `declare -A` (associative arrays), `mapfile`, and similar. Use portable alternatives like `while IFS= read -r` loops and small `grep`/`sed` helpers. Use `#!/usr/bin/env bash`.
- **Mark every shebang-bearing `.sh` script executable in Git** with `git update-index --chmod=+x <path-to-script>`.
- **Never use `eval`** to run a command string (injection risk + brittle quoting). Pass the command as arguments and invoke via `"$@"`, or pass a function name.
- **With `set -e`, capture command output via command substitution** (`OUT=$(cmd ...)`), not process substitution (`done < <(cmd ...)`), so a failing command reliably aborts instead of producing a misleading downstream error.
- **Use fixed-string grep (`grep -F`/`-Fq`) for literal matches** and handle grep's read-error exit code (`2`) explicitly — don't let it be treated as "no match".
- **Guard argument parsing.** For value-consuming options, verify a value is present before `shift 2` — otherwise, under `set -euo pipefail`, a missing value causes an unbound-variable/`shift count` error or an infinite loop. Reject unknown/mistyped `--options` with usage instead of silently treating them as positional args. Validate expected types (e.g. `--tail` must be a positive integer) and exit `2` with a clear message on bad input.
- **`usage()`/`--help` should exit `0`** (asking for help is not an error); reserve non-zero exits for actual argument errors.
- **`set -o pipefail` is not inherited by a new Bash process** (e.g. a pipeline run inside `bash -c "..."`). Re-declare it inside that process so a failing command in the pipeline is still surfaced.
- **Don't hold large command output in a variable on success** (e.g. `terraform plan`). Redirect to a temp file and only read it back on failure.
- **Exclude the shebang from `--help` output.** A `usage()` that prints lines starting with `#` will echo `#!/usr/bin/env bash`; filter it (e.g. `grep -v '^#!'`) or stop at the first non-comment line.
- **Don't swallow failures of critical steps with `|| true`** (e.g. `az account set`). Record an explicit PASS/FAIL so a failed step fails the overall run.

### Deterministic CLI Parsing

- **Don't parse CLI JSON with `grep`/`sed`.** Use the tool's own query support (e.g. `az account show --query name -o tsv`) and key decisions off the command's exit code.
- **Keep CLI install hints in the repo's standard call form**, e.g. `mcp_azure_mcp_extension_cli_install(cli-type: "az")`, so they match the rest of the skill and stay copy/pasteable.

### Referencing Scripts from Markdown

- **Use Markdown links** to the script files, not bare text or bare command names.
- **Don't present a script as if it were on `PATH`** (e.g. `run-ig ...`). Reference the explicit path (`scripts/run-ig.sh` / `scripts/run-ig.ps1`).
- **State the working directory** any relative path assumes. Prefer skill-root-relative paths (`./scripts/...`) and note that commands run from the skill root.
- **Note that PowerShell parameter names differ** (PascalCase, e.g. `-Gadget`, `-Namespace`) so readers don't copy bash `--flag` syntax into `.ps1` calls.
- Markdown links still must not escape the skill directory.

## CI Checks on Pull Requests

PRs against `main` must pass these checks — run the corresponding local commands before pushing:

| CI Job | What it validates | Local equivalent |
|--------|-------------------|------------------|
| ESLint | Linting + typechecking `scripts/` and `tests/` | `cd tests && npm run lint && npm run typecheck` |
| Token Analysis | Token counts and limits for markdown files | `npm run tokens check` |
| Skill Structure | Frontmatter, `tests/skills.json` sync, markdown references | `npm run build && cd scripts && npm run frontmatter && npm run references` |
| Plugin Version Check | `plugin.json` versions remain `0.0.0-placeholder` | Ensure you never edit version fields |
| Skill Tests | Unit and trigger tests for changed skills | `cd tests && npm test` |
| Shell Scripts | Shebang-bearing `.sh` files are executable in Git | `npm run check:shell-scripts` |
| Line Endings | Tracked text files are committed with LF line endings | `npm run check:line-endings` |

The telemetry reporter is not currently included in these CI jobs. Build and test it locally for changes under `telemetry-reporter/`, and do not modify CI configuration unless explicitly requested.

## Commit and PR Conventions

- Use conventional commit-style PR titles: `feat:`, `fix:`, `feature:` (these populate the auto-generated changelog)
- If modifying skill descriptions, verify routing correctness with integration tests
- For skills under `plugins/`, never bump the frontmatter version — it uses `0.0.0-placeholder`
- For skills under `.github/skills/`, bump the frontmatter version in the same PR

## Available Agent Skills

The repo includes agent skills under `.github/skills/` that can help with development tasks:

| Skill | When to invoke |
|-------|----------------|
| `skill-authoring` | Creating or modifying SKILL.md files |
| `skill-reviewer` | Reviewing skill PRs for compliance |
| `markdown-token-optimizer` | Reducing token count in markdown files |
| `sensei` | Iteratively improving skill frontmatter compliance |
| `analyze-test-run` | Investigating GitHub Actions test run failures |
| `file-test-bug` | Filing GitHub issues for test failures |

## GitHub Agent workflow

When compiling agent workflows in .github/workflows/*.md. Make sure to always pass `--gh-aw-ref {hash-of-the-gh-aw-version}`. By default, gh aw doesn't pin the gh aw setup action to its hash, which violates ur branch policy requiring all actions to be pined to their hash.