agentleFS
naviktnavikt/copilot/.github/copilot-instructions.md

copilot

Copilot instructions54 starsChanged 3 months agoMITView on GitHub

Monorepo containing Nav's GitHub Copilot ecosystem tools: All applications deployed on NAIS platform with environment-specific configurations. Security architecture: See SECURITY.md for trust zones, auth flow, and secret isolation. These standards apply across Nav projects. Project-specific guidelines follow below. When fixing a bug or implementing a feature, change only what is necessary. Do not rename variables, restructure working code, or refactor beyond the task at hand. Keep diffs small and focused so they are easy to review. Based on GitHub's analysis…

The file

Show its rules and text

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

14 rules. About 0 are common, 8 are distinctive, and 6 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.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All applications deployed on NAIS platform with environment-specific configurations.

    line 13
  2. Distinctive:

    When fixing a bug or implementing a feature, change only what is necessary.

    line 42
  3. Distinctive:

    CRITICAL: Always use Aksel spacing tokens, never Tailwind padding/margin

    line 53
  4. Distinctive:

    Commands early: Put executable commands near the top, not buried at the bottom

    line 105
  5. Distinctive:

    CRITICAL: Always use Nav DS spacing tokens, never Tailwind padding/margin utilities.

    line 186
  6. Very specific:

    Run: pnpm test in apps/my-copilot

    line 211
  7. Distinctive:

    Error responses: never leak upstream error details to clients

    line 270
  8. Very specific:

    Use {{domain_internal}} and {{domain_external}} in allowlist.json for environment-specific URLs:

    line 416
  9. Distinctive:

    When working across applications:

    line 437
  10. Very specific:

    Change directory: Use cd apps/{app-name} before running commands

    line 440
  11. Very specific:

    Use mise tasks: All apps support mise commands (preferred)

    line 441
  12. Very specific:

    Verify changes: Always run mise check after making changes

    line 442
  13. Distinctive:

    Reference paths: Use workspace-relative paths from repo root

    line 443
  14. Very specific:

    IMPORTANT: After making any code or documentation changes, run mise all from the repository root to build and verify all applications:

    line 465

≈ “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 navikt/copilot

Repository Overview

Monorepo containing Nav's GitHub Copilot ecosystem tools:

  • my-copilot - Self-service portal for managing Copilot subscriptions (Next.js 16)
  • copilot-api - Backend API for Copilot data and seat management (Go)
  • copilot-metrics - Naisjob that populates BigQuery with daily Copilot usage metrics (Go)
  • mcp-onboarding - Reference MCP server with GitHub OAuth (Go)
  • mcp-registry - Public registry for Nav-approved MCP servers (Go)

All applications deployed on NAIS platform with environment-specific configurations.

Security architecture: See SECURITY.md for trust zones, auth flow, and secret isolation.


Nav Development Standards

These standards apply across Nav projects. Project-specific guidelines follow below.

Nav Principles

  • Team First: Autonomous teams with circles of autonomy, supported by Architecture Advice Process
  • Product Development: Continuous development and product-organized reuse over ad hoc approaches
  • Essential Complexity: Focus on essential complexity, avoid accidental complexity
  • DORA Metrics: Measure and improve team performance using DevOps Research and Assessment metrics

Nav Tech Stack

  • Backend: Kotlin with Ktor, PostgreSQL, Apache Kafka
  • Frontend: Next.js 16+, React, TypeScript, Aksel Design System
  • Platform: Nais (Kubernetes on Google Cloud Platform)
  • Auth: Azure AD, TokenX, ID-porten, Maskinporten
  • Observability: Prometheus, Grafana Loki, Tempo (OpenTelemetry)

Nav Code Standards

Minimal Editing

When fixing a bug or implementing a feature, change only what is necessary. Do not rename variables, restructure working code, or refactor beyond the task at hand. Keep diffs small and focused so they are easy to review.

Kotlin/Ktor Patterns

  • ApplicationBuilder pattern for bootstrapping
  • Sealed classes for environment configuration (Dev/Prod/Local)
  • Kotliquery with HikariCP for database access
  • Rapids & Rivers pattern for Kafka event handling

Next.js/Aksel Requirements

  • CRITICAL: Always use Aksel spacing tokens, never Tailwind padding/margin
  • Mobile-first with responsive props: xs, sm, md, lg, xl
  • Norwegian number formatting with space separators

Nais Deployment

  • Manifests in .nais/ directory
  • Required endpoints: /isalive, /isready, /metrics
  • OpenTelemetry auto-instrumentation for observability

Writing Effective Agents

Based on GitHub's analysis of 2,500+ repositories, follow these patterns when creating or updating agents in .github/agents/:

Structure (in order):

  1. Frontmatter - Name and description in YAML
  2. Persona - One sentence: who you are and what you specialize in
  3. Commands - Executable commands early, with flags and expected output
  4. Related Agents - Table of agents to delegate to
  5. Core Content - Code examples over explanations (show, don't tell)
  6. Boundaries - Three-tier system at the end

Six Core Areas to Cover:

  • Commands (with flags and options)
  • Testing patterns
  • Project structure
  • Code style (✅ Good / ❌ Bad examples)
  • Git workflow
  • Boundaries

Three-Tier Boundaries:

## Boundaries

### ✅ Always
- Run `mise check` after changes
- Use parameterized queries

### ⚠️ Ask First
- Modifying production configs
- Changing auth mechanisms

### 🚫 Never
- Commit secrets to git
- Skip input validation

Key Principles:

  • Commands early: Put executable commands near the top, not buried at the bottom
  • Code over prose: Show real code examples, not descriptions of what code should do
  • Specific stack: Include versions (Next.js 16, Go 1.26, Kotlin 2.0)
  • Actionable boundaries: "Never commit secrets" not "I cannot access secrets"

Application-Specific Guidelines

apps/my-copilot (Next.js + TypeScript)

Self-service portal for managing GitHub Copilot subscriptions. Next.js 16 app with Azure AD authentication.

Commands

Working directory: apps/my-copilot

Run after all changes: mise check

Available tasks:

  • mise check - Run all checks (ESLint, TypeScript, Prettier, Knip, Vitest)
  • mise test - Run Vitest tests
  • mise dev - Start Next.js dev server (http://localhost:3000)

Tech Stack

  • Next.js 16 with App Router
  • TypeScript strict mode
  • Nav Design System (@navikt/ds-react)
  • Tailwind CSS v4.1
  • Octokit for GitHub API
  • BigQuery for usage analytics (via @google-cloud/bigquery)
  • Vitest for testing

File Structure

apps/my-copilot/src/
├── app/              # Next.js App Router pages
│   ├── api/         # API routes for Copilot data
│   ├── usage/       # Analytics dashboard
│   └── overview/    # License management
├── components/       # Reusable React components
└── lib/             # Utilities and business logic
    ├── auth.ts      # Azure AD JWT validation
    ├── github.ts    # GitHub API client (Octokit)
    ├── bigquery.ts  # BigQuery client for usage metrics
    ├── cached-bigquery.ts # Cached BigQuery queries
    └── data-utils.ts # Data aggregation

Key Patterns

Authentication:

const user = await getUser(); // redirects if not auth
const user = await getUser(false); // returns null if not auth

API Routes:

// ✅ Explicit error handling
export async function GET() {
  const { usage, error } = await getCachedBigQueryUsage();
  if (error) return NextResponse.json({ error }, { status: 500 });
  return NextResponse.json(usage);
}

Number Formatting:

import { formatNumber } from "@/lib/format";
formatNumber(151354); // "151 354" (Norwegian locale)

Spacing Rules - Mobile-First Design

CRITICAL: Always use Nav DS spacing tokens, never Tailwind padding/margin utilities.

// ✅ Good - Nav DS Box with responsive padding
<main className="max-w-7xl mx-auto">
  <Box
    paddingBlock={{ xs: "space-16", md: "space-24" }}
    paddingInline={{ xs: "space-16", md: "space-40" }}
  >
    {children}
  </Box>
</main>

// ❌ Bad - Tailwind utilities
<main className="p-4 mx-4">

Responsive breakpoints: xs (0px), sm (480px), md (768px), lg (1024px), xl (1280px)

Common spacing tokens: space-8, space-16, space-24, space-32, space-40

Testing

  • Framework: Vitest with TypeScript
  • Location: *.test.ts files next to source
  • Run: pnpm test in apps/my-copilot
  • Focus on lib/ utilities

Boundaries

✅ Always: Use Nav DS spacing tokens, run mise check after all changes, TypeScript strict mode ⚠️ Ask first: Auth changes, GitHub API modifications, data aggregation changes 🚫 Never: Tailwind p-/m- utilities, commit secrets, skip type checking


apps/copilot-api (Go + Backend API)

Backend API that holds all external service credentials (GitHub App, BigQuery). See SECURITY.md for the full security architecture.

Commands

Working directory: apps/copilot-api

Run after all changes: mise check

Available tasks:

  • mise check - Run all checks (fmt, vet, staticcheck, lint, test)
  • mise test - Run tests with verbose output
  • mise dev - Run with DEBUG logging (http://localhost:8080)

Tech Stack

  • Go with standard library
  • Azure AD JWT validation (JWKS + azp)
  • BigQuery client for usage analytics
  • GitHub App authentication (installation tokens)
  • Prometheus metrics (background collection)

Architecture

my-copilot (BFF) → OBO token → copilot-api → GitHub API / BigQuery

Key Files

  • auth.go — Azure AD JWT validation, JWKS cache, azp check, auth middleware
  • github.go — GitHub App auth, installation tokens, billing/seat/SAML
  • github_handlers.go — HTTP handlers for seat management
  • bigquery.go — BigQuery queries + cached wrapper
  • bigquery_handlers.go — HTTP handlers for BigQuery data
  • handlers.go — Router, middleware chain, RFC 7807 errors
  • main.go — Server setup, graceful shutdown
  • metrics.go — Prometheus metrics with background collection
  • config.go — Environment config
  • cache.go — In-memory TTL cache

Security Boundaries

  • All /api/v1/ routes require Azure AD OBO token with valid azp
  • /health, /ready, /metrics are public (pod-level, not exposed via ingress)
  • Input validation uses regex for GitHub usernames, MaxBytesReader for request bodies
  • Error responses never leak upstream error details to clients
  • Secrets come from Nais Secrets (envFrom), never hardcoded

Boundaries

✅ Always: Validate azp claim, parameterize queries, log mutations with actor, run mise check ⚠️ Ask first: Auth mechanism changes, network policy changes, new outbound rules 🚫 Never: Log PII at INFO+, forward raw errors to clients, bypass azp validation


apps/mcp-onboarding (Go + MCP)

Reference MCP server demonstrating GitHub OAuth authentication for VS Code integration.

Commands

Working directory: apps/mcp-onboarding

Run after all changes: mise check

Available tasks:

  • mise check - Run all checks (fmt, vet, staticcheck, lint, test)
  • mise test - Run tests with verbose output
  • mise dev - Run with DEBUG logging (http://localhost:8080)

Tech Stack

  • Go with standard library
  • OAuth 2.1 with PKCE
  • MCP JSON-RPC protocol
  • Streamable HTTP transport

Architecture

VS Code (MCP Client) ←→ mcp-onboarding (OAuth + MCP Server) ←→ GitHub OAuth

Flow:

  1. VS Code discovers OAuth metadata via /.well-known/oauth-authorization-server
  2. User authenticates via GitHub
  3. Server validates org membership and issues access token
  4. VS Code uses token to call MCP tools

Available MCP Tools

  • hello_world - Returns greeting with authenticated GitHub username
  • greet - Personalized greeting message
  • whoami - Authenticated user information
  • echo - Echo back message
  • get_time - Current server time

Configuration

VariableDescriptionDefault
PORTServer port8080
BASE_URLPublic URL for OAuth redirectshttp://localhost:8080
GITHUB_CLIENT_IDGitHub OAuth App client ID(required)
GITHUB_CLIENT_SECRETGitHub OAuth App client secret(required)
ALLOWED_ORGANIZATIONRequired GitHub org membershipnavikt
LOG_LEVELLog levelINFO

Key Files

  • main.go - Application entry point
  • oauth.go - OAuth 2.1 + PKCE implementation
  • mcp.go - MCP JSON-RPC protocol handlers
  • github.go - GitHub API integration

Boundaries

✅ Always: Run mise check after all changes, validate OAuth flow, test org membership ⚠️ Ask first: OAuth implementation changes, MCP protocol updates 🚫 Never: Commit secrets, skip security validation, bypass org checks


apps/mcp-registry (Go + Public API)

Public registry service for Nav-approved MCP servers, implementing MCP Registry v0.1 specification.

Commands

Working directory: apps/mcp-registry

Run after all changes: mise check

Available tasks:

  • mise check - Run all checks (fmt, vet, staticcheck, lint, test)
  • mise test - Run tests with verbose output
  • mise validate - Validate allowlist.json by starting server
  • mise dev - Run with DEBUG logging (http://localhost:8080)

Tech Stack

  • Go with standard library
  • MCP Registry v0.1 specification
  • JSON Schema validation
  • Prometheus metrics

Configuration

VariableDescriptionDefault
PORTServer port8080
LOG_LEVELLog levelINFO
LOGGED_ENDPOINTSEndpoints to log/,/v0.1/servers
DOMAIN_INTERNALInternal domain for templatesintern.dev.nav.no
DOMAIN_EXTERNALExternal domain for templatesekstern.dev.nav.no

API Endpoints

EndpointDescription
GET /Service information
GET /v0.1/serversList all MCP servers
GET /v0.1/servers/{name}/versions/{version}Get specific server
GET /v0.1/servers/{name}/versions/latestGet latest server version
GET /healthHealth check
GET /readyReadiness check
GET /metricsPrometheus metrics

Note: Server names with / must be URL-encoded (e.g., io.github.navikt/github-mcp → io.github.navikt%2Fgithub-mcp)

Key Files

  • main.go - Application entry point and routing
  • handlers.go - HTTP request handlers
  • config.go - Configuration and environment loading
  • validation.go - allowlist.json validation
  • types.go - Data structures
  • allowlist.json - Registry data (MCP Server JSON Schema)

Server Name Format

Reverse-DNS with exactly one /:

  • Format: {namespace}/{name} (e.g., io.github.navikt/github-mcp)
  • Pattern: ^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]/[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]$

Domain Templates

Use {{domain_internal}} and {{domain_external}} in allowlist.json for environment-specific URLs:

{
  "remotes": [{
    "type": "streamable-http",
    "url": "https://my-server.{{domain_internal}}/mcp"
  }]
}

Boundaries

✅ Always: Validate allowlist.json with mise validate, run mise check after all changes, follow MCP spec ⚠️ Ask first: Registry format changes, validation rules, API endpoints 🚫 Never: Bypass security validation, skip schema validation, modify spec compliance


Monorepo Navigation

When working across applications:

  1. Check context: Determine which app the request relates to
  2. Change directory: Use cd apps/{app-name} before running commands
  3. Use mise tasks: All apps support mise commands (preferred)
  4. Verify changes: Always run mise check after making changes
  5. Reference paths: Use workspace-relative paths from repo root

Example workflow:

# Working on my-copilot
cd apps/my-copilot
mise check

# Working on mcp-registry
cd apps/mcp-registry
mise validate       # validate allowlist.json
mise check

# Back to root
cd ../..

Build and Verify

IMPORTANT: After making any code or documentation changes, run mise all from the repository root to build and verify all applications:

mise all

This runs all checks across all applications to ensure nothing is broken.

Running the nav-pilot binary

nav-pilot writes to ~/.copilot/, ~/.nav-pilot/ and the repository you are standing in. Never run it — or a test that calls run() — against a real home directory. Set HOME to a temporary directory (nav-pilot does not read COPILOT_HOME), along with NAV_PILOT_CONFIG and XDG_CONFIG_HOME, and check ~/.copilot and ~/.nav-pilot afterwards for changes you did not intend. In Go tests, use isolatedConfig(t).

Isolation that is set up wrong looks exactly like isolation until someone checks.

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.