notes

Adding a user program

Task-oriented: what to do, in order. A program is declared in one place, and in four if the shell can spawn it (five if it answers in a register). Only the first two of those are places you have to remember: the build or a host test sends you to each of the rest.

A program is a [[bin]] in one of two packages, running at EL0, linked against user_mode_runtime.

Which package: components/ or fixtures/?

Decide this first, because it picks the directory and the Cargo.toml every later step edits. Milestone 175 split user/ on 2026-09-13, and the question it answers is would a distribution ship this because somebody wants its function?

"Who calls it" is not the test, and getting that wrong is the easy mistake: nearly everything here is reached only from a kernel test, disk_partitioner and timetable included, because this system has one user. What separates them is what the program is.

One program does one thing

A behavior is a program, not a role. The tempting shortcut, when a fixture already exists that is nearly what you want, is to add an arm to its match on x0 and select the new behavior with a number. Do not. calef, 2026-09-14: "Part of the beauty of Unix that I think we want to retain is small programs with specific functions", and, on the binary that had accumulated thirty-one arms, "31 role binary is not the right shape."

The cost is not aesthetic. A role is dispatched on a word the kernel puts in x0, so it is a value the kernel's wiring and the program agree on that nothing checks. Its name lives in a const two files apart rather than in the archive. The binary links everything every role needs, so a fixture spawned to prove one system call drags in an ELF parser. And the program's name has to describe all of them at once, which it stops doing at about the third.

Milestones 291 and 405 are the worked example. One fixture, hello, reached thirty-one roles one convenient arm at a time over two months. Seven of them were an exact duplicate of components/src/block_driver.rs, kept alive only because one archive table did not pack it; the other twenty-four became programs. See 291 and 405.

The exception is allowed and has to say so (AGENTS.md's ladder, rung four's rule). If two behaviors genuinely are one program, write down in the module doc why, where a reader meets it.

The steps

1. The source

components/src/<name>.rs or fixtures/src/<name>.rs, snake_case (DECISIONS §39, and the convention table in naming.md). no_std, against user_mode_runtime.

2. A provenance block in its module doc

//! Name: unrecorded. Introduced 2026-08-14 for <what it does>.

script/lint fails without one, via script/names --check. Three states: ratified (calef ruled, with the date and what was refused), recorded (the tree argues the name somewhere, with a citation), unrecorded (nothing outside this block says why). The gate checks presence, never ratified, so an unratified name never blocks a build and unrecorded is a truthful answer.

The name is an architect's (AGENTS.md, "calef names the crates, the programs, and the shared modules"). Ship a provisional one, say so in your report, expect it to change.

Write provisional when you expect the name to change, which is AGENTS.md's word and, since §89 (2026-08-16), the gate's too. Four states:

Name: ratified 2026-08-04 (calef, milestone 63). Refused `x` (why).
Name: recorded (milestone 46). <what the tree already argues, and where>
Name: provisional. <what you called it and why you expect it to change>
Name: unrecorded. <what the history does and does not say>

provisional is a claim about intent (you expect this to change); the other three are claims about the record. A settled name can be unrecorded (nobody wrote down why hello is called hello, and nobody needs to), so the two are not the same word for the same thing.

script/names --provisional lists them and they sort first in --unratified, because a name its own author called wrong is the shortest conversation an architect can have. This page told newcomers the opposite until §89 (provisional): run 2 of the stranger test wrote the word AGENTS.md asked for and got a red gate, raising the decision.

3. A [[bin]] block in that package's Cargo.toml

[[bin]]
name = "your_program"
path = "src/your_program.rs"
test = false
bench = false

test and bench off are mandatory, not tidiness: the default libtest harness needs extern crate test, which does not exist for a bare-metal target.

That block is the whole of step 3, and of packing. xtask reads the [[bin]] blocks of both packages (declared_programs()) and packs every one into all three archives, aarch64, riscv64 and x86_64, under its own name. There is no packing table and no per-architecture filter; why-it-works-this-way.md says why. You do not touch the measurement table either: xtask hashes every entry of the archive it just packed and writes the table the progenitor measures against from that (write_measure_manifest).

The reader is strict on purpose. A key it does not know inside a [[bin]] block (required-features, say) stops the pack with the key named, rather than packing an archive with that program silently missing.

A new program or crate also needs an entry in a packages/*.package.toml file, provisional like a name, or script/lint fails (package boundaries).

4. Keep the name under 32 bytes

nifefs caps NAME_LEN at 32, raised from 24 so os_primitives_benchmarker would fit. Raising it again costs directory entries per block, so do not let a name spend it.

There is also a ceiling on how many programs an archive holds, nifefs::MAXIMUM_FILES, 178 at DIR_BLOCKS = 14. The kernel suite's x86_64 archive holds 128 where cargo xtask basalt-fetch ran, so the headroom is about fifty. It fails loudly: write_image returns TooManyFiles and each initial_ramdisk_* function prints the error, the file count and the size.

5. If the shell should be able to spawn it

Three edits, and after the first the machine names each of the others.

  1. A row in programs! in crates/program_table/src/program.rs, with its doc comment:

    /// Triples its integer argument (milestone N, `components/src/triple.rs`).
    Triple { id: 13, name: "triple" },
    

    name is the [[bin]] name. id is the stable wire id: the shell sends it and the progenitor decodes it, so it is a thing two programs agree on and changing it later is a flag day. Take the next unused number; never reuse a removed program's id (the build refuses a duplicate, and the_wire_ids_already_shipped_never_move refuses reuse of any id shipped before milestone 150). The enum, name(), id(), from_id(), from_name(), Program::ALL and PROGRAM_COUNT are all generated from the row.

  2. Its manifest() arm, which the compiler asks for (E0004 in grant_plan). This carries all of the actual meaning: see "What you declare" below.

  3. A row in the swish-check script: in the topic file under xtask/src/swish_check/script/ whose subject the line belongs to (each file's module doc says what it holds), a line(...) or keys(...) element of that file's LINES. The topic slices concatenate, in table order, into SWISH_CHECK_SCRIPT in script.rs. The host test every_spawnable_program_has_a_swish_check_line fails until the row exists, and names the one exception it allows (a program a transcript cannot drive, listed with the reason).

And a fourth only if your manifest says output: OutputDeclaration::Words, meaning the answer is a number in a register rather than a stream: an arm in write_outcome in crates/swish/src/sentences.rs that renders it. every_program_that_answers_in_words_renders_its_answer fails without one. A byte-stream program needs nothing there.

xtask refuses to pack an archive when a programs! row names a program no [[bin]] builds, so getting the name wrong in step 1 is a build failure rather than a program that cannot be spawned.

What you declare: the manifest

The manifest is the program's endowment, and the shell checks it at the prompt, before a child exists. A mismatch is a legible refusal on the line you typed rather than a hang deep inside a program that assumed a slot was full. See grant-expression.md and program-manifest.md.

The manifest declares the direction; the command line designates the file. Whether a program writes is a fixed, publishable property of it. Which file it touches is the caller's business. So wc report.txt reads and tee report.txt writes, and nobody types a mode.

A manifest is as much about refusal as need. date's row is Forbidden throughout, so a memory grant aimed at a clock reader stops at the prompt.

Removing a program

Delete its source file and its [[bin]] block. It leaves all three archives at once.

If the shell could spawn it, also delete its programs! row. The compiler then points at its manifest() arm and any write_outcome arm that named it; delete those, and its SWISH_CHECK_SCRIPT lines, which nothing on the host flags (see BUGS) and which script/swish-check answers with no such program. Leave its id unused. The table's holes are expected: PROGRAM_COUNT is one past the highest id, not the number of programs.

What catches a removal you did not mean to make: xtask's host test every_program_the_tree_loads_by_name_is_declared fails when the kernel or the progenitor still looks the program up by a string literal (program("name"), .read("name")), naming the file that does. Before milestone 150 such a test would skip!() with "no such program in this archive" and nobody would hear about it.

Check your work

script/lint          # the name block, the conventions, and every host test named above
script/swish-check   # if the shell spawns it: both ISAs, and much faster than the suite
script/test          # all three architectures

cargo xtask build packs the aarch64 archive only, whatever the name suggests; has_initial_ramdisk_riscv64() and has_initial_ramdisk_x86() are called by test and swish-check. That no longer hides a packing mistake, because all three archives pack one list, but it is still not a check of the other two builds.

Run swish-check once with a deliberately wrong expectation. A green harness only proves the harness did not complain; a red one proves your program was really loaded from the archive, measured, granted its endpoint and run at EL0. Verbatim from a run of this page on 2026-08-18:

$ triple 21
  a process at EL0 computed 21*3 = 63
--- swish-check (aarch64) FAILED ---
  `triple 21` answered "a process at EL0 computed 21*3 = 63", wanted "21*3 = 64"

Why it works this way

Milestone 150 (2026-09-19) made the [[bin]] blocks the archive list and the shell's program table one macro_rules! declaration. It replaced a pinned program count with three host tests, and turned write_outcome's exhaustive match into a wildcard. The block is design/roadmap/0150-program-declaration-data.md, and DECISIONS §158 (a program is declared once) is the record. What was considered and refused for each choice is in why-it-works-this-way.md.

BUGS