Each project's own Agda¶
Open several Agda projects that depend on different Agdas and different libraries, in VS Code or in Emacs, and check any file of any of them, with no Agda switched by hand and no setting touched once you trust your own checkouts. That is Milestone 9 of the plan, added on 2026-11-07, and this page says what it builds, how, and what is done.
The problem¶
An editor starts one Agda for every file it is given: agda2-mode in Emacs
runs the program agda2-program-name names, and agda-mode-vscode the last
entry of its agdaMode.connection.paths. That works while every file you
open belongs to projects on the same Agda with the same libraries. It
stops working the day you have two, and the errors read as broken code
rather than as the wrong Agda. Both of the following were met on
2026-11-07 (#97):
-
A file of formal-ledger-specifications (Agda 2.8.0, five libraries), opened while the editor's Agda was agda-algebras' (Agda 2.9.0, the standard library alone):
error: [LibraryError] Library 'standard-library-classes' not found. -
A file of formal-ledger-specifications checked by an Agda built by hand from an earlier lock than the checkout's:
NotInScopeinside a dependency, because the checkout's lock had moved past the pin.
The usual fixes do not last. A hand-built Agda matches one lock and goes stale in silence when the lock moves; a table of projects in the editor's configuration must be kept by hand for every checkout and every worktree; and switching Agdas before each file is the chore this milestone ends.
The idea¶
A project worth checking usually pins its Agda and its libraries already,
in a Nix flake whose flake.lock names every input by hash. So the answer
to "which Agda for this file" is written down, and a program can read it.
The resolver, agda-for-project, is a program an editor runs where it
would run agda. It finds the file's project and the project's flake,
decides which Agda the flake names, builds it the first time, and then
runs it with every argument the editor passed, so the editor cannot tell
it from agda.
How it decides¶
- The project is the directory of the nearest
.agda-libat or above the file, as Agda itself finds a file's library. The flake is the nearestflake.nixat or above the project, without leaving its repository. - An attribute the host names wins:
AGDA_FLAKE_ATTRin the environment, or--flake-attrfirst on the command line. It is the interface of agda-native-air's launcher foragda-mcp, so a registration written for that launcher works here. - A choice you made for the project comes next.
agda-for-project --candidateslists what can run it (trusting the flake, its environments and dev shells, the Agdas already built on this machine,agdaon PATH), and--choose IDremembers one, in your state directory and never in the checkout, for every worktree of the repository. - The flake's one Agda environment: a package named
default, or withagdain its name, that is anagda.withPackages, when you trust the flake (below). The resolver evaluates the candidates rather than trusting their names: formal-ledger-specifications has four packages withagdain the name, and one environment among them. - The flake's default dev shell, when entering it puts an
agdaof its own on PATH, as agda-algebras' downstream projects (such as agda-lattices) do, and you trust the flake. - Trust: running a flake's Agda runs the flake's code as you, since an
environment's
agdais whatever program the flake builds and a dev shell's hook runs when it is entered. So the resolver runs what it finds only for a flake you trust: one line in~/.config/agda-for-project/trustedfor the directory you keep your own checkouts in (agda-for-project --choose trust:$HOME/gitwrites it), or the first entry of an editor's chooser, which trusts the file's repository and every worktree of it. A choice for the project is consent too, and a repository cloned anywhere else is never run unasked. - Otherwise nothing is decided: the resolver says so on one line and exits 69 without running any Agda. It never runs some other Agda instead.
The environment is tried before the dev shell because evaluating a package runs nothing and builds only Agda and its libraries, while entering a dev shell runs the project's hook and builds every tool its developers use.
Building once, and only when it matters¶
The first time a project's Agda is needed, the resolver builds it with
nix build (usually a download from a cache) and keeps the result under
~/.cache/agda-for-project/. Later starts reuse it until the key
changes: a hash of every file of the checkout that Nix reads, which is
every tracked file except Agda sources. So a moved lock or an edited
flake.nix gets its own build, and editing proofs never triggers one;
worktrees on the same lock share a build, and a worktree on another lock
gets its own.
An Agda environment cannot contain the project's own library, and a
project may depend on another library in the same checkout
(formal-ledger-specifications' test library depends on its main library).
When the project needs a library the environment does not provide, the
resolver writes a libraries file of the environment's entries and the
checkout's .agda-lib files that provide the missing names, and passes it
to Agda.
In the editors¶
- Emacs (#98): a package makes agda2-mode start each buffer's project's Agda through the resolver, restart it when you move to a buffer of another project, and accept the version the resolved Agda reports, so that Agda 2.8.0 and 2.9.0 both load under one agda2-mode. agda2-mode keeps one Agda process, so a switch of project restarts it, and the other buffer needs a load again. In Emacs says how to install it.
- VS Code (#99): agda-mode-vscode and the companion's lanes run each project's Agda through the resolver. agda-mode-vscode runs one Agda for the whole window, so the companion names the resolver as the mode's one path, tells it which project is active, and restarts the mode when the active file moves to a project on another Agda. A status-bar item names the active project's Agda and how it was decided, and a quick pick offers the candidates when nothing decides. In VS Code says how to install it.
- agda-mcp, agda-native-air's tool server for agents, can name the resolver as its Agda, so an agent checks a file with the same Agda the editor does.
What is done, and what is not¶
All three parts were merged on 2026-11-09: the resolver in #101, Emacs in #104 and VS Code in #102.
-
The resolver is written and tested, with its design record, ADR 0004, and its note, from which the account above is drawn. Its interface (the program in place of
agda, exit 69,--explain,--candidatesand--choose) is what the editors build on. -
Emacs's run: one
emacs --batchsession with the real agda2-mode (Doom's, GNU Emacs 29.3) loaded five files in turn, each withC-c C-l, on 2026-11-08, with the resolver's cache warm, as follows:File Agda Libraries Resolved Load formal-ledger-specifications, Axiom/Set/Map/Extra.agda2.8.0 6qscaqml…-libraries0.18 s 9.0 s a worktree of it on an older lock, the same file 2.8.0 xza7nddh…-libraries0.22 s 9.4 s agda-algebras, Setoid/Operations.lagda.md2.9.0 v81rfymb…-libraries0.19 s 1.0 s agda-lattices, Lattices/Bounded/Covers.lagda.md2.9.0 its dev shell's 0.07 s 2.3 s formal-ledger-specifications again 2.8.0 6qscaqml…-libraries0.18 s 9.8 s Every load ended
*All Done*, each under its own project's Agda and libraries, read from the running process; the worktree got a build of its own, and agda-lattices was chosen once, through the chooser, and remembered. "Load" runs fromC-c C-lto Agda's verdict and includes the restart. The figures are the run's record,emacs-2026-11-08.json, and the Emacs note has the rest of it. -
VS Code's run: on 2026-11-08, one VS Code window (1.141.0, with agda-mode-vscode 0.10.4) held agda-algebras and formal-ledger-specifications, with the resolver as the mode's one path and no setting changed. A file of agda-algebras loaded under its flake's Agda 2.9.0; a file of formal-ledger-specifications under its Agda 2.8.0, after the mode restarted on the switch (8.6 s, a fresh Agda reading the project's interfaces); and agda-algebras again under 2.9.0. The figures are the run's record,
vscode-project-agda-2026-11-08.json. Its three screenshots are not on this page yet: the repository commits no binaries, and they wait for a home that is pinned by hash, as every file the site serves is. -
Not shown yet: the milestone's exit criterion asks the VS Code window to hold agda-lattices as well, and a worktree on a moved lock, which its run did not. Both runs also came before the resolver asked for trust in every flake (2026-11-09): there, only a dev shell needed it, which is why agda-lattices went through the chooser.