notes

What one shim costs: the measurement §170 asked for

(For §170 (how a foreign program is told what to do), which gates milestone 205 (how a foreign program is told what to do). Measured 2026-09-25 by lane lane/argv-shim-measure. This page's stem is provisional, per the naming tenet; calef names things. It measures and does not rule.)

§170 is decided (calef, 2026-09-26). It took the argv of option A, carried the way this page's fourth reading describes. The argv is plain bytes in one page. Authority is carried separately, by the directories the line grants and by what the program's manifest says a resolved word may be. A vouched program's manifest may ask for a named file read-only, read-write, or as its directory, and may ask to create a name that does not yet resolve. An unvouched program gets named files read-only unless the word carries a mark. The per-program tables of option B, and option C, were refused for the reasons measured below. Milestone 205 built the transport on 2026-09-26 in the layout this page's prototype used, with slot 8 and 0x1400_0000 for "where"; partsfoundry/program_argument_contract is the codec and design/roadmap/0672-the-argument-page-layout.md is the proposal that brings it to calef.

§170 set the test in one sentence. If a shim is per-program work, option A (a POSIX argv) wins. If it is a library written once, options B and C stay open. This page answers that with counts from the tree, from ripgrep 14.1.1 and gitoxide 0.59.0 source, and from a host-tested prototype.

The answer

A shim is two jobs, and they answer the question differently.

  1. Transport: getting bytes into std::env::args(). This is a library, written once, and every option needs it. Nothing else reaches an unmodified program, because both programs measured here read their arguments from std::env::args_os() and from nowhere else.
  2. Designation: deciding which of those bytes name something, so the launcher can grant it as a capability. This is per-program work. Only the program knows its grammar, and the grammar is large and changes by release.

So option A costs the transport alone. Option B, in the token-by-token form §170 describes, costs the transport plus a per-program table. Option C cannot carry ripgrep's pattern at all without first adding the transport.

Transport, measured by writing it

The prototype is a length-prefixed block and the std file that reads it. It was written and host-tested in a scratch crate and is not in this tree, because its layout is the irreversible part and belongs to the ruling.

piece size shape it copies
the layout codec (build and parse) 39 lines of code, 4 host tests passing the environment_contract package
sys/args/nife.rs in the std overlay 11 lines of code std's own sys/args/xous.rs, 19 lines
xtask std-src dispatch 2 anchors, 1 generated-module job the sys/env/mod.rs arm in xtask/src/farm.rs
the spawner's half one read-only mapping and one grant_at slot 7, the config page, in system_tests/src/user/std_service.rs

The layout: an 8-byte magic, a u32 count, a u32 total length, then each argument as a u32 length and its bytes. Length-prefixed so an argument may hold any byte, including the 0xff the round-trip test puts in a regex. A zeroed or truncated block reads as no arguments, the same default-honest shape environment_contract uses.

The second anchor exists because std compiles sys/args/common.rs only for a listed set of platforms. Adding nife to that list lets the nife file reuse std's Args type, as Xous and Motor do. The alternative is a self-contained Args, as zkvm has in 94 lines.

It costs nothing in the system call surface: no new system call number and no new method. It rides PageFrame and MAP_INTO, which slots 5 and 7 already use. There is a cheaper wire still: std's _start receives three entry registers and ignores all three (patches/std-nife/overlay/std/src/sys/pal/nife/mod.rs), so the block's address and length could arrive there with no slot at all.

Designation, measured per program

ripgrep 14.1.1

ripgrep parses with its own lexopt-based code and reads std::env::args_os().skip(1) (parse_low in crates/core/flags/parse.rs). Counted from crates/core/flags/defs.rs:

count
flags 104
switches 69
flags taking a value 35
flags with a short letter 41
value flags that designate a file 2: --file, --ignore-file
value flags that name a program to run 2: --pre, --hostname-bin

The rest are inert data: numbers, globs, separators, encodings, type names, and the pattern itself. Positionals follow a rule no table expresses: the first is the pattern unless -e or -f was given, and every other positional is a path.

A per-program binder for ripgrep therefore needs all 104 arities. Without them it cannot find the positionals: in rg -g foo bar, only the table says foo belongs to -g. It also needs one hand-written rule for the pattern. The generic half is getopt's conventions (bundled short flags, attached values, --flag=value, --). lexopt 0.3.0 is 571 lines of code for exactly that.

gitoxide 0.59.0, the second program

Milestone 99 (git on nife) chose gitoxide. Its gix binary parses with clap derive and reads gix::env::args_os(), which is std::env::args_os() with optional Unicode precomposition (args_os in gix-0.74.1/src/env.rs). So the same transport serves it with no program-specific work.

Its designation table is larger. src/plumbing/options/ and src/porcelain/options.rs declare 260 argument fields across nested subcommands. Of these, 32 are PathBuf and 57 are BString, which carry pathspecs and ref names. A binder would need that tree, per release.

clap can report part of it. Arg::get_value_hint answers AnyPath for any PathBuf argument (get_value_hint in clap_builder-4.6.7/src/builder/arg.rs), so a build step could derive the path flags of a clap program. That covers neither ripgrep, which does not use clap, nor gitoxide's pathspecs.

The result for §170's test

The transport is one library and serves both programs unchanged. The designation table is per-program: 104 flags plus a custom rule for one, 260 fields for the other, and neither is derivable in general.

Option C cannot say rg pattern

grant_plan::Endowment carries arg: u64 and flags: u64. The shell parses the argument with parse_u64 (crates/grant_plan/src/lexing.rs) and refuses anything else as ProgramArgumentRequired. A regex is not a u64, and ripgrep's 104 flags do not fit a 64-bit mask. C as written needs a string channel first, which is the transport above.

C is per-program by construction beyond that. Program is a closed enum of 16 programs with their manifests compiled into grant_plan, so each foreign program is a new variant and a new manifest. None of the 16 is a std program today.

The three options, priced

transport per-program work system call surface runs unmodified rg
A: argv about 50 lines in std and a layout crate, plus about 10 in the spawner none nothing new yes
B: token-grained the same a table per program and release (rg 104 flags and a rule, gix 260 fields), plus a generic binder of lexopt's size nothing new yes, while the table matches the release
C: grant_plan only must be added first a Program variant and manifest per program, plus B's table nothing new no, until a string field exists

There is a fourth reading of B that §170 does not list, and every system in the prior art below uses it. Arguments travel as inert bytes, and authority travels separately as a namespace: the directories a program was handed. That costs what A costs. A path string can then reach only what the namespace holds. ripgrep already behaves this way here: it resolves names under slot 4, and the std PAL refuses .. and absolute paths before they reach the wire.

What A asks two programs to agree on

This is the irreversible list, the part a ruling fixes:

The page as built

partsfoundry/program_argument_contract is that layout, built. Its rules beyond the table:

Prior art, read from source

None of the four delivers arguments as capabilities. All four deliver bytes and keep authority in a separate channel.

BUGS