# AGENTS.md -- how work happens in this tree Makronix is a NetBSD, built and shaped on purpose. Read this before changing anything; the rules are few and they are binding. Read in this order, every time: `GOAL.md` (what Makronix is and when a part is done), this file, `docs/BUILD-CONTRACT.md` (the one way to build). Every directory below the root carries its own `AGENTS.md`: what lives there, what may be changed, what may not. Read the one in the directory you work in before you touch it. Where this file and a measurement disagree, the measurement wins and this file is wrong: fix the file, name the log line that settled it. The old measurements and narratives (media sizes, the CDE/MCDE build-host story, what was measured when) are in `docs/reference/agents-history-2026-11-13.txt`; they are history, not rules. ## The rule before all others **Read the documentation first, every time, and save what you read.** In this order: the docs in the tree (`AGENTS.md`, `src/BUILDING`, man pages, the comment at the top of the file), then the project's own upstream documentation. Keep a copy under `docs/reference/.txt` with source and date so the next session does not start over. Quote the sentence that settles a question -- with its location -- before acting on it. "The docs say" without having opened them is the failure this rule exists to prevent; it has cost this project days. ## The one rule **NetBSD first, in this order:** read the documentation in the tree (`AGENTS.md`, `src/BUILDING`, `src/share/misc/style`, `src/distrib/sets/README`, `src/etc/rc.subr`); look for the pattern already in the tree with `git grep`; use the building block that exists. Only then write code -- and the comment says which NetBSD pattern it follows. A patch that breaks a NetBSD convention is a finding for the report, never a quiet change in the tree. ## Licence What Makronix wrote itself is under the CNCL (Could Not Care Less License 1.0, `LICENSE` at the root; files carry the line `License: CNCL 1.0 ...`). What comes from elsewhere keeps its own licence: `src/` (NetBSD, BSD), `xsrc/`, `pkgsrc/`, `refs/*`, the imported trees under `ext/` (MCDE is CDE: LGPL 2.0 or later) and their changes to files that already had a licence. A new file in a fork gets the CNCL line; a changed upstream file keeps the notice it has. ## What belongs where - `src/` is **Makronix's NetBSD tree**, tracked here. It began as the upstream commit in `src/BASE` and is edited directly: no patches, no overlay. `refs/netbsd/src` is upstream trunk, shallow and read-only -- look there, never build from it. - `xsrc/` is **Makronix's X tree** (since 2026-11-13 again), tracked the same way: the upstream commit in `xsrc/BASE`, built by `build.sh -x -X xsrc` into the X sets; pkgsrc uses it (`X11_TYPE=native`). - `mobile/` is the Linux tree for the phones: kernel from `refs/linux/7.0.14`, our changes as `mobile/kernel/patches/`. The imported tree is read-only. - `ext/` holds third-party sources Makronix ships and changes (MCDE, afpfs-ng, ...): `ext/src//` the tree, `.../pkgsrc/` its recipe, `IMPORT` where it came from. First commit of a tree is the upstream archive unchanged; every change after it is a visible diff (`ext/AGENTS.md`). - `pkgsrc/` and `refs/*` are their own repositories, pinned. Moving a pin is a decision; editing inside them is not allowed. - `distfiles/` is part of the repository (Konrad, 2026-11-19: everything the build needs lives in the repository -- today the source archives and the binary packages, later the sources of what now comes as a binary). ## Building Everything builds from the root `Makefile`. It is NetBSD make (Konrad, 2026-11-19): `make` on Makronix, `bmake` on a Linux host; GNU make does not read it. The interface is meant to stay this small -- **do not add targets**: make the build (sets) make release the release: sets, kernels, ramdisks, media make install over a running Makronix, idempotent, incremental make mobile the phones (wanted; not there yet -- mobile/Makefile has its own targets, mobile/AGENTS.md) The other targets that exist (`iso`, `usb`, `compress`, `sourcesets`, `isosrc`, `userland`, `binaries`, `test`, `cdtest`) package or check what `release` built; `docs/BUILD-CONTRACT.md` says in which order. **Cross and native are one build** (decided 2026-11-13). The build host may be NetBSD (native) or anything else (cross); the build detects which at the start and sets the toolchain up once. A package that builds only on one of them is broken, and the fix is in our recipe (`ext/`), in `tools/pkgsrc-cross.mk.conf` (host tools such as `CC_FOR_BUILD`), or in the source -- never "build it in a VM". `pkgsrc/` itself is not patched. **The VM is for testing only**: installations from the media, upgrades, smoke tests. Nothing is built in it. Rules for a build: - `make release` is the whole release: sets, kernels, the signed source set, the ISO and the USB image, in one lock (since 2026-11-18). `make iso` and `make usb` alone only repackage what the last release built: they check the stamp (`build-stamp.sh -c`) and stop without removing anything. - Long builds: start the one named target in the background with its output in `build/logs/-.log` and end the turn. The status is the last line, `make exit=N`, not the wrapper's. No transient units. - One build at a time in one tree: the root Makefile takes `tools/build-lock.sh`; a second build is refused with the holder's pid (t0286, `METALOG.sanitised` and the CD staging). The lock is re-entrant (`BUILD_LOCK_HELD`), so `make cdtest` holds it across release, iso and the VM test; `make mcde-linux` and `make mcde-host` take it too. Tools that write `build/obj` or `releasedir` (`build-stamp.sh`, `cd2.sh`, `cd3.sh`, `cd-source.sh`, `images.sh`, `srctree-stage.sh`, `userland.sh`, `mcde-linux.sh`, `mcde-host.sh`, `mcde-debian.sh`) refuse to run outside it; start them through make or `tools/build-lock.sh '...'`. The tests (`test.sh`, `mediacheck.sh`, `install-simple.sh`, `install-cgd.sh`, `mcde-tests.sh`) call `build-lock.sh --check` and refuse to start beside a build; `make test` and `make cdtest` hold the lock while they run. - The gate on a build is `checkflist`, run the way NetBSD runs it (`cd src/distrib/sets && DESTDIR=build/obj/destdir.amd64 MACHINE=amd64 MACHINE_ARCH=x86_64 build/obj/tooldir.*/bin/nbmake-amd64 checkflist`). Extra or missing files fail the build. Do not hand-roll its environment. - A boot message `WARNING: 1 module failed to load` for `cd9660` is not a defect (the INSTALL kernel has it built in). ## Third-party packages (pkgsrc) pkgsrc builds FOR the target with this tree's toolchain (`tools/pkgsrc-cross.mk.conf` is the whole configuration, `--prefer-native=yes` is not optional). Packages are installed into the sysroot's `/usr/pkg` and belong to one set, `makronix`, which is **generated**: `tools/makronix-set.sh` reads the installed tree back and writes `src/distrib/sets/lists/makronix/mi` and the METALOG records; since 2026-11-15 `packages.list` also knows the art `bin` (vim, git-base, sysupgrade, flex, ksh93, tcl; commit 51c89ff23a), so `makronix-set.sh` starts from `set`+`bin` and removes every other registered package from the sysroot with pkg_delete (x11-links, osabi stay; commit 909271b3d7). sysinst installs it (`SET_MAKRONIX` in `defs.h`, `util.c`, every `msg.mi.*`). Removing a package means removing its list entries and marking them `obsolete`. The target's `pkg_install` comes from the distribution, not from pkgsrc. A fork from `ext/` is built from an archive `git archive` makes of its last commit (`tools/ext-dist.sh`, `tools/mcde-dist.sh`), its recipe is copied into pkgsrc by `tools/ext-sync.sh`. Where pkgsrc's cross mode stops on a Linux host (`awk:run`, xbase looked up on the host, host-only tools) is a finding for the report and a setting in our configuration; see the history file for the details measured so far. ## Definition of done A change is done when its test is green and it is committed. A build is done when `checkflist` reports no missing and no extra files. A medium is done when an install from it reaches a login prompt and shuts down cleanly -- with the log kept in the tree. No claim without a measurement: file and line, exit code, log excerpt. ## Forbidden Enforced by the build gate `tools/claude-build-gate.sh` where a harness hook can see it, binding everywhere else: - building through `systemd-run` or any transient unit; `make -C build`, `cd build && make`, hand-chained `build.sh` operations. - writing, moving or deleting anything under `build/obj/releasedir/**` by hand. (The hook is textual: a command that names `releasedir` and contains `rm `, `mv `, `cp `, `touch `, `chmod `, `sed -i` or `>` is refused, a `2>&1` included. Read without redirections, or in a script under `tools/`.) - `git reset --hard`, `git checkout -- .`, `git clean -fdx` in the root. Undo with `git restore ` after looking at what it is. - deleting `src/distrib/sets/lists/**` to make `checkflist` pass. - unattended loops: cron jobs, timers, "tick" scripts that start builds or tests or hand work to an agent. ## How to work - Plan before acting on anything non-trivial: say which command you will run and what you expect, run it, compare. - Every claim carries `file:line` or a log line. A sentence without one is a guess. - Do not trust a status document, a commit message or an old log over a measurement you can repeat. Repeat it. - `tools/` is POSIX `sh`: no Python, no bashisms (`dash -n`, `checkbashisms`). - Commit with explicit paths in one command (`git commit -m ... -- `); a second agent works in `mobile/` in the same repository. - Each directory has its own `AGENTS.md` (what it is for, what is in it, what may change, what must not be touched); when a directory gains a purpose, a rule or a hazard, its file changes in the same commit. Not below the top-level directories of `src/`, `pkgsrc/` or the reference trees.