AGENTS.md · git:20261117.32c5613 · 2026-11-17 · sha256 643e213d82b5affe

AGENTS.md git:20261117.32c5613A

Immutable. This exact content never changes and is served at /api/v1/blob/643e213d82b5affe.

# AGENTS.md for navikt/copilot

Minimal guide for agents working in this repository.

## What this repo is

Monorepo for Nav's Copilot ecosystem:

- `apps/my-copilot` (Next.js/TypeScript web app)
- `apps/copilot-api` (Go backend API)
- `apps/copilot-cli` (Go CLI gateway for `nav-pilot`)
- `apps/copilot-survey` (Go survey backend)
- `apps/copilot-metrics` (Go metrics job)
- `apps/copilot-adoption` (Go adoption scan job)
- `apps/mcp-onboarding` (Go MCP reference server)
- `apps/mcp-registry` (Go MCP registry API)
- `cli/nav-pilot` (Go developer CLI)

`SECURITY.md` has the security model and trust boundaries.

## Efficiency rule

Keep tool output small. Run targeted commands, do not dump whole files or full build logs into context, and reach for deterministic tools (`rg`, `git`, `gh`) before asking the model to guess.

`rtk` is an optional CLI proxy that filters terminal output before it reaches the model. Use it if you want to (`rtk git status`). Nothing here requires or assumes it, and public controlled measurement has not reproduced its advertised savings ([JetBrains study](https://blog.jetbrains.com/ai/2026/07/rtk-claude-code-token-savings/)).

## Standard commands

From repo root:

```bash
mise check
mise test
mise build
mise all
```

After editing an app, run `mise check` in that app's directory. Run `mise all` when the change reaches across the repo.

## Conventions

- PR bodies may be in Norwegian, but issue-closing references must use GitHub's
  English keywords: `Closes #NNN` / `Fixes #NNN`. `Lukker #NNN` does not link or
  auto-close anything, and three months of shipped-but-open issues in this repo
  trace back to exactly that. Verify with the PR's `closingIssuesReferences`
  when it matters.

- Issue titles use `<scope>: <short description>` (`nav-pilot:`, `my-copilot:`,
  `copilot-api:`, `copilot-survey:`, `copilot-metrics:`, `copilot-adoption:`,
  `mcp-onboarding:`, `mcp-registry:`, `fleet-gateway:`, `kostnadsinnsikt:`,
  `verdi:`, `dispatch:`, `benchmark:`, `harness:`, `skills:`, `observability:`, `security:`, or
  `PRD:`). Leave Conventional Commit prefixes (`feat:`, `fix:`, `chore:`) for
  commits and PRs; issue type belongs in labels. Write issues in Norwegian
  (following `apps/my-copilot/ORDBOK.md`) or English, and do not mix languages
  within the same issue.

- Artifact language: body text in instructions and skills is English; metadata
  in the YAML frontmatter stays Norwegian (#179). The rule governs every
  artifact in this repo and was only recorded in a changelog entry, which is not
  where an author looks before editing a skill (#679).

- Text a human reads gets a språkvask and unslop pass before it ships: docs,
  READMEs, issue and PR bodies, user-facing CLI strings and error messages,
  Norwegian and English alike. Cut filler and AI tells, keep every command,
  flag and value verbatim. Recorded after the 2026-09-13 pass over navikt/apt
  and nais/pilot#3, where a denial message an engineer meets mid-task had to
  be cut down to what is wrong and what to run.

- Editing `agents/`, `prompts/`, `skills/`, or `instructions/` requires running
  `mise run generate` so `copilot-manifest.json` and `docs/README.*.md` stay in
  sync, and verifying with `mise check` rather than only `nav-pilot:check` (#769).
- Verify framework APIs and Nav platform config against repo skills (`skills/`),
  Nav MCP servers (`io.github.navikt/aksel-mcp`), or official docs
  (`doc.nais.io`, `aksel.nav.no`, `sikkerhet.nav.no`) before writing code (#152).
- Start with the smallest safe change and keep diffs task-focused.
- Reuse existing patterns before adding new abstractions.
- In `my-copilot`, use Aksel spacing tokens, not Tailwind `p-*/m-*` utilities.
- `/cplt` in `my-copilot` is the external landing page for the cplt open-source
  project: keep it in English (`lang="en"`) and keep its dark design. Don't
  translate it or restyle it to the ki-utvikling/Aksel look; fix bugs only.
- Do not commit secrets.
- Do not push unless explicitly asked.

## Merging a stacked pull request

This repository uses a merge queue, and pull requests are sometimes registered
as a GitHub *stack* (`GET /repos/{owner}/{repo}/pulls/{n}` shows a `stack`
object). A stacked PR refuses every ordinary merge route, each with a different
error, so it is easy to spend a long time concluding the wrong thing:

- `gh pr merge --auto` reports `Auto-merge is not supported for stacked pull requests`.
- GraphQL `enqueuePullRequest` refuses and points at the async REST API.
- `PUT /pulls/{n}/merge` refuses stacked PRs outright.
- `PATCH /pulls/{n}` cannot change the base while the PR is in a stack.
- `gh stack merge` (gh-stack v0.2.1) sends `merge_action: direct_merge` and fails
  with `Changes must be made through the merge queue`. Its merge-queue detection
  queries `mergeQueue` and `ref.rules{type}` together, the `rules` part errors on
  this repository, and the extension then falls back to a direct merge.

The route that works is the asynchronous one:

```sh
gh api -X PUT repos/OWNER/REPO/pulls/N/merge-async -f merge_action=merge_queue
```

Pass the top PR of the stack; every PR below it is enqueued with it.

**Do not pass `merge_method`.** The merge queue sets it, and supplying one makes
the request fail with `Custom merge params are not supported when merging via a
merge queue`.

**Poll the result.** The endpoint returns `{"status":"pending"}` with a `uuid`
whether or not the request will succeed. The failure only appears here:

```sh
gh api repos/OWNER/REPO/pulls/N/merge-async/UUID
```

That returns `enqueued`, or `failed` with the actual reason: a rejected merge
param, checks still owing results, and so on. Treating the `pending` response as
success means retrying a request that has already failed, silently.

## Running the nav-pilot binary in tests or verification

`nav-pilot` writes to the developer's own environment: `~/.copilot/`,
`~/.nav-pilot/` and the repository you are standing in. A verification that runs
the real binary without isolation changes a real setup, and it has: an install
run during testing pointed a user scope at a temporary worktree and left 23 of 52
files in conflict, which `sync` then silently skipped. Nothing had been edited by
hand.

Whenever you run the binary — directly, or through a test that calls `run()`:

- Set `HOME` to a temporary directory. That is the one that matters, because
  everything resolves through `os.UserHomeDir`. `nav-pilot` does **not** read
  `COPILOT_HOME`. Also set `NAV_PILOT_CONFIG` (relocates
  `~/.nav-pilot/config.toml`, see `internal/cli/config.go`) and
  `XDG_CONFIG_HOME` (honoured on the opencode export path, see
  `internal/provider/opencode_launch.go`). In Go tests, `isolatedConfig(t)` does
  this for you — use it.
- Every Go test package in `cli/nav-pilot` has a `TestMain` that calls
  `testhome.Run` (`internal/testhome`). It points `HOME`, the XDG directories
  and `NAV_PILOT_CONFIG` at a temporary directory for the whole test binary and
  fails the run if the test binary opened nav-pilot's files in the real home
  (Go's test log shows it). A change in those files that the binary did not
  open is a warning locally, since a real nav-pilot may be running, and a
  failure in CI. A new test
  package needs the same `TestMain`; `TestEveryTestPackageCallsRun`
  fails without it. A test that sets `HOME` itself must also set
  `NAV_PILOT_CONFIG`, or it uses the config `testhome.Run` chose.
  `isolatedConfig(t)` sets both.
- Do not assume a command only reads. `install`, `sync`, `config` and the launch
  paths all write.
- Hash `~/.copilot` and `~/.nav-pilot` before and after, and report any
  difference. Isolation that is set up wrong looks exactly like isolation until
  someone checks.
- Say so loudly if you did touch something. A silent change to a developer's
  setup is worse than a failed test.