interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

Comparing 4ed98366d73a435e1f8477da6902b3f6411bdba4 ... a64d48239e0204bf7585620b2bc9b7078550d1ab

17 files changed, +2945 -0

ipl/.gitignore+1-0
ipl/CONTRACT.md+227-0
ipl/DESIGN.md+100-0
ipl/PIN+7-0
ipl/README.md+37-0
ipl/build.sh+20-0
ipl/ipl+907-0
ipl/om/landrec.om+466-0
ipl/reviews/4658e80a-codex.md+75-0
ipl/reviews/6560f9ab-codex.md+40-0
ipl/reviews/810c802a-codex.md+54-0
ipl/reviews/9ed74e8f-codex.md+71-0
ipl/reviews/d56cf19a-codex.md+46-0
ipl/tests/import-identity.sh+83-0
ipl/tests/run.sh+641-0
ipl/tools/import-radicle.sh+67-0
ipl/tools/receipt.sh+103-0

ipl/.gitignore

new file mode 100644
@@ -0,0 +1 @@
1+bin/

ipl/CONTRACT.md

new file mode 100644
@@ -0,0 +1,227 @@
1+# Interplane native store: the contract for consumers (version 0, trial)
2+
3+Status: IMPLEMENTED and EXERCISED on the Spark host (the gate in `tests/run.sh`, and a trial import).
4+Not installed, not serving anything, not the publishing route. Under the standing rule the route
5+"exists" only after its gates on a fresh clone, an other-provider MERGE and a receipt. Consumers may
6+build against this contract; they may not publish through it yet.
7+
8+Operator intent (Drake, 2026-11-13): "take everything radicle did and replicate it into interplane
9+and leave out all the bullshit ... designed around agent workflows and agent coding", and to the
10+HardenOS lane: "take radicle out and build this directly on to of git".
11+
12+## Where things are
13+
14+One store root. Where a trial store stands, and with which trial key, is named in the receipt of the head that made it.
15+
16+```
17+ROOT/catalog.tsv generated, never typed
18+ROOT/projects/NAME/repo.git ordinary bare Git repository
19+ROOT/projects/NAME/chain.tsv the record chain
20+ROOT/projects/NAME/records/N the exact payload bytes record N commits to
21+ROOT/projects/NAME/owner.pub the owner's public key
22+ROOT/projects/NAME/staging/ landings in progress. A finished request removes its own files; an abandoned one leaves its files here until that same request is finished
23+```
24+
25+`catalog.tsv` has one line per project, five tab-separated fields:
26+`name id default-branch head visibility` (`head` is `none` before the first recorded head).
27+It is rewritten on every change the store commits (init, import, land), from each project's own
28+line, so it follows a landing without anyone running anything. `ipl catalog` re-derives every line
29+from full verification, drops a project that does not verify, and then exits 3. Readers take the
30+catalog as the list of projects; they do not scan the folder. A project folder or `repo.git` that is
31+a link is not a project.
32+
33+## Identity
34+
35+- A project's **id** is the SHA-256 of record 1's payload (`records/1`): 64 lowercase hex digits. That
36+ payload is signed and holds a random 128-bit `nonce` made at creation, so the id cannot be changed
37+ without the owner's key, and projects created separately get different ids (by chance, not by a
38+ registry). A copy of a project keeps its id.
39+- A project's **name** is its folder name and is written in record 1: letters, digits,
40+ `.`, `_`, `-`, starting with a letter or digit, not ending in a dot. Two names that differ only in
41+ case cannot both exist. A project folder copied under another name does not verify.
42+- The **owner** starts as one Ed25519 SSH key, named in record 1 by its fingerprint (`SHA256:` and
43+ 43 characters). Other key types are refused. A later `SUCCESSOR` record, signed by the then-current
44+ key, names a new owner key (its public key blob and fingerprint). The current owner is the last
45+ such successor, or the key in record 1 if there has been none. `owner.pub` stays the key record 1
46+ names; swapping it for the successor is not how a handover is recorded, and a project whose
47+ `owner.pub` is not the key record 1 names does not verify.
48+- The old Radicle id is kept in record 1 as `alias` (`rad:z...` or `-`), for looking up history only.
49+- Receipt identity for gate tools: `git:` followed by the project id.
50+
51+## Records
52+
53+The chain is the forge's `chain/chain.om` format: one line per record, seven tab-separated fields
54+`seq utc kind actor subject payload prev`; `payload` is the SHA-256 of the bytes in `records/SEQ`;
55+`prev` commits to the line before. `actor` is the fingerprint of the owner key that was current
56+when the record was written (the key in record 1, until a `SUCCESSOR` is signed, and the successor
57+key after that).
58+
59+| Kind | Subject | Payload (`records/N`) |
60+|---|---|---|
61+| `PROJECT` | the name | `interplane-project 1`, then `project`, `branch`, `visibility`, `owner`, `alias`, `nonce` lines. Always record 1. |
62+| `IMPORT` | the branch | a land payload whose `old` is 40 zeros: a head taken over from the old store, not gated or reviewed here. Once per branch, before any landing on it. |
63+| `LAND` | the branch | `interplane-land 1`, then `project`, `branch`, `old`, `new`, `receipt`, `verdict`, `request` lines. `old` is the head the chain recorded for that branch before (40 zeros for a new branch). |
64+| `SUCCESSOR` | the new key's fingerprint | `interplane-successor 1`, then `project`, `old`, `new`, `pub`, `reason` lines. `old` is the then-current owner's fingerprint, `new` is the successor's, `pub` is the 68-character `ssh-ed25519` blob of that successor (no comment), and `reason` is `-` or the same bytes a request id may use. The successor must differ from every key that has already been an owner of the project (the key in record 1, and every earlier `SUCCESSOR` `new`). |
65+| `SIG` | the seq it signs | an SSH signature, namespace `interplane`, by the owner key that was current when the signed record was written |
66+
67+A name or branch longer than 128 bytes is written in the subject field as `sha256:` and the digest of
68+its bytes; the payload always holds it in full.
69+
70+Every `PROJECT`, `IMPORT`, `LAND` and `SUCCESSOR` record is immediately followed by its `SIG` record. The signed
71+message is six lines: `interplane-sig 1`, then `kind`, `actor`, `subject`, `payload`, `prev`, each
72+followed by that field of the record it signs. So a signature fixes what the record says, who wrote
73+it, and, through `prev`, every record before it. It does not cover the record's `seq` and `utc`
74+fields or the SIG line itself; those are fixed by the next signed record's `prev`, and for the last
75+record of a chain by nothing. So the times in a chain are not signed facts: do not rely on the time of
76+the last record, and treat the others as fixed only by what was signed after them.
77+
78+`receipt` and `verdict` are the SHA-256 of the receipt file and of the review verdict file. Version 0
79+commits to those files; it does not read them. Checking that the verdict comes from a different key
80+and provider than the author is step 3.
81+
82+Field rules and the canonical bytes are decided in one place, `om/landrec.om` (seeded Omega). No
83+field can hold a space, a tab or a line feed. No field has a length chosen by this store. The chain
84+format's subject field holds 128 bytes, which is why longer names and branches go there as a digest.
85+What is refused for length is only what the machine cannot hold: a name longer than a file name on
86+the store's file system, a branch part longer than that less the five bytes of git's `.lock`, a
87+branch path past the file system's path limit, and an argument longer than Linux passes to a
88+program (131071 bytes). The numbers are read from the file system when the call is made.
89+
90+## Actions
91+
92+```
93+ipl init ROOT NAME BRANCH VISIBILITY ALIAS KEY record 1 for an existing repo.git
94+ipl import ROOT NAME BRANCH EVIDENCE_FILE NOTE_FILE REQUEST KEY
95+ipl land ROOT NAME BRANCH NEW SOURCE RECEIPT_FILE VERDICT_FILE REQUEST KEY [--expect-owner FP]
96+ipl handover ROOT NAME|--all OLD_KEY NEW_PUBKEY [REASON] signed succession to a new owner key
97+ipl verify ROOT NAME [--expect-owner FP] prints: OK NAME ID BRANCH HEAD VISIBILITY CURRENT SEQ CHAINHEAD
98+ipl catalog ROOT [--expect-owner FP]
99+```
100+
101+SOURCE is the absolute path of a local repository that holds NEW, or `-` when the store already has
102+it. Nothing else is accepted there.
103+
104+The `OK` line from `verify`, `land`, `import`, `init` and `handover` is
105+`OK NAME ID BRANCH HEAD VISIBILITY CURRENT SEQ CHAINHEAD`. `CURRENT` is the current owner
106+fingerprint, `SEQ` is the last record number, and `CHAINHEAD` is the SHA-256 of the last chain line
107+with no line feed (the `prev` a next record would commit to). `catalog.tsv` stays five fields
108+(`name`, `id`, `default-branch`, `head`, `visibility`) and does not include these extra columns.
109+
110+The current owner is pinned outside the store, in
111+`${IPL_OWNER_PINS:-$HOME/.config/interplane/owner-pins}`. Each line is `NAME SHA256:<43>` or
112+`* SHA256:<43>` (every project). Blank lines and `#` comments are allowed. The file must exist, be
113+mode 0600 (no group or world bits), and resolve outside ROOT. `verify`, `land`, `import`,
114+`handover` and `catalog` load it automatically and fail closed, exit 3, if it is missing, has bad
115+permissions, is inside ROOT, or names a different key than the walk ends on. `catalog` leaves a
116+mismatching project out and exits 3. `--expect-owner FP` may also be passed to those commands; if
117+it disagrees with the file, that is exit 3.
118+
119+The pin is the out-of-band channel the leaked key cannot sign for. Its value is written by hand,
120+from the current owner key's `.pub` on the machine that holds that key — never copied from a store.
121+After `ipl handover` appends a signed `SUCCESSOR`, it updates the local pin file (only then, never
122+on a no-op). A single-project handover rewrites or appends that project's `NAME` line and prints
123+`ipl: pin: NAME SHA256:...`. `handover --all` rewrites the `NAME` line of every project rotated in
124+that run, rewrites `*` only if it named the old key (and appends `* NEW` if there was no `*` line),
125+and prints `ipl: pin: * SHA256:...`. Install a `* SHA256:...` line by hand on the forge serving
126+host, on the machine that runs `tools/receipt.sh`, and on each mirror. `receipt.sh` points
127+`IPL_OWNER_PINS` at a pin file outside the trial ROOT. If handover records the SUCCESSOR but then
128+exits 5 because the pin file could not be updated, write the printed line into the pin file by
129+hand; a rerun will not repair a stale pin, because the current key has already switched.
130+
131+Do not install the pin on the live forge host from this change alone. When it is time, on the
132+machine that holds the current owner key:
133+
134+```
135+install -d -m 0700 ~/.config/interplane
136+printf '* %s\n' "$(ssh-keygen -lf /path/to/current-owner.pub | awk '{print $2}')" > ~/.config/interplane/owner-pins
137+chmod 600 ~/.config/interplane/owner-pins
138+```
139+
140+Use the same path (or set `IPL_OWNER_PINS`) on the forge, receipt, and mirror hosts, with the
141+fingerprint taken from that key's `.pub`, not from any store. After a rotation, replace the file
142+with the `ipl: pin: * SHA256:...` line the handover printed.
143+
144+`ipl handover --all` prechecks every project before writing any record. If any project cannot be
145+handed over (including one whose current owner is not the given old key, or whose successor was
146+already an owner), nothing is recorded and the run exits 2, naming every project that failed.
147+
148+| Exit | Meaning | State afterwards |
149+|---|---|---|
150+| 0 | done | recorded, signed, branch in place |
151+| 1 | usage | unchanged |
152+| 2 | an argument, file or key was refused (stderr says which) | unchanged |
153+| 3 | the project does not verify, or has an unfinished request that is not this one | unchanged |
154+| 4 | not a fast-forward, the head is already there, not a commit the store can find, the branch name collides with an existing one, or the request id was already used for something else | unchanged |
155+| 5 | a tool failed part-way | possibly unfinished: run the same request again; it finishes or refuses |
156+
157+"Unchanged" means the chain, the records and the branches, with two exceptions that are said here
158+rather than hidden. A refused landing may already have copied Git objects from SOURCE into
159+`repo.git`; no branch points at them. And on a call by the owner, leftovers of an interruption are
160+put right before the request is looked at, and that repair stays even if the request is then
161+refused; `ipl` says so on stderr (`ipl: repaired: ...`).
162+
163+- A landing checks every argument, then that the key signs as the project's owner, then puts right
164+ what an interruption left, then that the project verifies. Only after that is anything appended.
165+ The branch moves last, and only forward.
166+- `init` with the same terms by the owner is safe to repeat: it finishes an init that was
167+ interrupted, and on a complete project it publishes the catalog line again and answers. With
168+ other terms or another key it is exit 2.
169+- The same REQUEST never lands twice. A request is the same only if kind, branch, head, receipt and
170+ verdict are all the same; then it is answered with the project's present state (the same `OK` line
171+ `ipl verify` prints now, not a copy of the first answer) and nothing moves. Used again for
172+ anything else it is exit 4.
173+- An interruption can leave: a torn last line in the chain (never a record), an empty chain file, a
174+ record whose payload is still in staging, `PENDING_SIG` (recorded, not signed yet) or `PENDING_REF`
175+ (signed, branch not moved yet). `ipl verify` exits 3 and names the state. The first three are put
176+ right, and the two pending states finished, only on a call by the owner's key, and a pending
177+ request only by that same request. Until then nothing else can be recorded on the project.
178+ Anything else that does not verify is refused whole; this tool does not repair it.
179+- What the gate has exercised of this, said exactly. A real landing is stopped at five points: after
180+ staging (nothing is recorded yet: the project verifies and the request id is still free), between
181+ the chain line and its payload file, after the record, after the signature (these three do not
182+ verify, are closed to other requests and to other keys, and are finished by the same request), and
183+ after the branch moved (the project verifies; the same request publishes the catalog line that
184+ was missing). A real init is stopped at the first four of those points, since an init moves no
185+ branch; each is refused to another key and to other terms and finished by the same init. Not
186+ exercised: a write the kernel never completed, and loss of power.
187+- Before anything is changed for a caller, including finishing or repairing, the caller's key must
188+ sign a fresh message that verifies against the current owner key (`owner.pub` until a `SUCCESSOR`
189+ is signed, and the successor key after that). Having a public key file is not enough.
190+- Only the current owner key can record in version 0. `ipl land` signs with that key and refuses any
191+ other, including a retired owner key. `ipl handover` appends a `SUCCESSOR` record signed by the
192+ current key and is a no-op if that successor is already current. It refuses a successor that has
193+ already been an owner of the project; `ipl verify` also refuses a chain that hands a retired key
194+ back. Agent keys with a scope and an end date are step 3.
195+
196+## What verify proves, and what it does not
197+
198+It proves: the chain is intact from record 1; every payload file is the one its record commits to
199+and is in canonical form; record 1 is this project's `PROJECT` record under this folder's name;
200+`owner.pub` is the Ed25519 key record 1 names; every record was written by the owner key that was
201+current at that point in the chain, and every `PROJECT`, `IMPORT`, `LAND` and `SUCCESSOR` record
202+carries a valid signature by that same key; a `SUCCESSOR` names a new Ed25519 key, different from every key that has already been an owner,
203+whose fingerprint matches the `pub` blob, and after that record's signature the current key is only
204+the successor (a later record signed by a retired key does not verify, and a successor that returns
205+to a prior owner does not verify);
206+every landing starts from the head the chain recorded before it and is a fast-forward of it, and its
207+head is a commit the store holds; no request id appears twice; and every branch the chain has a head
208+for is, in `repo.git`, exactly at that head. Sequential handovers are followed in order. A store
209+with no `SUCCESSOR` records verifies as it did before this rule existed. Anything ambiguous about
210+which key is current, or a handover not signed by the then-current key, fails closed.
211+
212+It does not prove: that a receipt or verdict is any good; anything about branches and tags the chain
213+has no record of; that a copy of the store is the newest one (an older or forked pre-handover copy
214+also verifies if the operator pin still names that copy's current key; with the pin file, or
215+`--expect-owner`, naming the successor, it does not); or that Git objects are intact beyond what Git
216+itself checks on use.
217+
218+Outside this version's trust boundary: anyone who can write files in the store directly, and the
219+`git` and `ssh-keygen` programs on the host. `ipl` runs git with no user or system configuration, no
220+hooks, no replace objects and only the local file transport.
221+
222+## Not in version 0
223+
224+Agent grants and their withdrawal, the HTTP form of these actions, proposals and issues, mirrors and
225+freshness, serving, private-project access rules beyond "not served", events. `ipl` itself is shell
226+around the Omega record rules, the Omega chain, git and ssh-keygen; its decisions move into Omega
227+before the route is offered for publishing.

ipl/DESIGN.md

new file mode 100644
@@ -0,0 +1,100 @@
1+# Interplane without Radicle: what replaces it
2+
3+Status: step 1 is IMPLEMENTED and EXERCISED on the Spark host in a trial store (see README.md and CONTRACT.md); steps 2 to 6 are PROPOSED. Written 2026-11-13 by the omp session in `~/tmp` on the Spark.
4+
5+## Intent (Drake, 2026-11-13, verbatim)
6+
7+> "we are cutting out radicle"
8+> "Staying on interplane, it's just being built without radicle now"
9+> "I want you to take everything radicle did and replicate it into interplane and leave out all the bullshit and part that no nody likes. Maek this intended and designed around agent workflows and agent coding"
10+
11+In one line: Interplane itself keeps, proves, copies and reviews our code, with an agent as the normal user, and nothing of Radicle underneath.
12+
13+## What was observed (2026-11-13, Spark)
14+
15+- 106 public repositories of ours and 1 private one live in Radicle storage (`rad ls --all`, node database).
16+- Our tools call `rad` in 18 different ways. By count in `~/handoffs/radicle/tools`, `~/work/sitehub`, `~/.local/bin`: inspect 53, node 19, sync 17, self 10, init 10, patch 9, id 6, auth 6, config 5, seed 4, clone 4, checkout 3, unseed 2, follow 2, cob 2, ls 1, issue 1, fork 1.
17+- 20 landing and record tools read Radicle storage directly (desk-publish, land-hooks, hub-sync, pin-follow, rids-gen, record, publish, the gates).
18+- The forge web server `forged` (seeded Omega, 69,536 lines of `.om`) reads Radicle in 45 units across 14 folders.
19+- Replication measured the same day: updates did not reach outside seeds that could not dial our node. 477 outside copies were behind our head (node database); two public seeds confirmed it for one project over their own web API.
20+- The interplane.io site redeploys when a ref changes inside Radicle storage (an `aien-onchange` watch on that folder). The rules installer and the SI front door clone from Radicle storage.
21+
22+## What Radicle did for us, and what Interplane does instead
23+
24+| Job | Radicle's way | Interplane's way | Why |
25+|---|---|---|---|
26+| Keep code and history | Git objects inside a per-node store, one copy of every branch per peer | One plain repository per project in one known folder, one `main` | No per-peer copies to reconcile. "Which head is real" has one answer. |
27+| Say which head is real | Each peer signs its own list of refs; a rule picks the canonical one from delegates | One signed landing record per change, in an append-only chain per project | The record already exists in our work as the receipt. It becomes the protocol instead of a side file. |
28+| Who may publish | Identity document, delegates, thresholds | Owner key per project. The owner grants an agent key a scope (which project, land or propose only) and an end date | Radicle has no idea of an agent working for a person. This is the centre of the new design. |
29+| Proposed changes | Patches as collaborative objects with revisions | A proposal is one request: the exact head, its gate output, its review verdict. States READY, REVIEWED, LANDED, REFUSED | This is the READY, verdict, receipt flow the lanes already follow by hand. |
30+| Issues | Collaborative objects | Plain signed records in the same chain | One mechanism, not two. |
31+| Copy projects between machines | Always-on node, gossip, seeding policies, inbound connections | A mirror pulls the signed chain and the objects over ordinary HTTPS from any other mirror and checks every signature | Nothing has to dial into a home network. A mirror cannot alter a project, because the chain is checked. A mirror can still serve an older copy that verifies, so "is this the newest" needs a signed checkpoint the puller can compare; pulling makes an update reachable, it does not by itself prove freshness. |
32+| Find a project | Network routing table | The list of mirrors is itself a signed record of the project | No separate discovery layer. |
33+| Private projects | Allow-lists enforced by the node | A private project is not served and not mirrored | Simple, and fails closed. |
34+
35+## What is left out on purpose
36+
37+- The node program and its network protocol, port 8776, peer addresses, gossip.
38+- Per-peer copies of every branch and the rules for choosing among them.
39+- Seeding policies and scopes.
40+- Delegate thresholds and identity documents as a separate object type.
41+- The `rad` program as something a person or agent must install, the key passphrase and agent dance.
42+- The vocabulary: RID, NID, DID, delegate, seed, sigrefs, COB. Old Radicle IDs stay as a lookup alias in the developer view so old links and receipts still resolve.
43+
44+## Designed for agents first
45+
46+- Every action is one request to a stable address with plain inputs, and answers in a machine-readable form, including refusals. A refusal names the rule that refused and what would satisfy it.
47+- Every write accepts a dry run that returns exactly what would be recorded.
48+- Every write carries a request ID, so a retried request never lands twice.
49+- An agent never holds the owner's key. It holds its own key and a grant with a scope and an end date. A grant can be withdrawn with one record.
50+- A landing is refused by the server itself unless the proposal carries gate output from a fresh clone and a verdict from a reviewer whose key differs from the author's. The rule stops being something agents are asked to remember.
51+- Changes are announced as events a reader subscribes to. Nothing polls.
52+- The site's agent file lists each action only once it works.
53+- People get the same actions as pages, from the same handlers.
54+
55+## Order of work
56+
57+1. Store and chain. A tool that creates a project, records a landing as a signed link in the chain, and verifies a chain from its first record: the record rules in Omega first, the orchestration in shell until it is moved into Omega too. Import the public repositories with their history. Acceptance: every imported head equals the head in Radicle storage; a chain with one altered byte is refused. How many projects a given head imported, and which it refused, is in that head's receipt (`READY.json`, written by `tools/receipt.sh`), not here. One exclusion is known and stated: `.github`, a profile repository left over from GitHub, is refused by the name rule.
58+2. `forged` reads the store. Browse, download and project pages served from the store. Acceptance: the same pages byte-for-byte for a sample of projects, with Radicle storage unmounted in the test.
59+3. Agent requests. Propose, review, land, grant, withdraw, with dry run and request IDs. Acceptance: a landing without a second-key verdict is refused; a replayed request does not land twice.
60+4. Mirrors. Pull and verify over HTTPS; the hub Pi becomes the first mirror. Acceptance: a mirror that serves an altered chain is refused by the puller.
61+5. Our own tools move over: landing tools, hooks, pin following, the rules installer, the site deploy trigger, the SI front door. Acceptance: one real landing end to end with no `rad` call (checked by running with `rad` absent from the path).
62+6. Issues and events. Then the Radicle nodes can be switched off, which is Drake's call.
63+
64+Step 1 is built in trial form. Until step 5 passes, work waits as READY under the standing rule.
65+
66+## Owner-key succession
67+
68+Swapping `owner.pub` alone would break verify for history, because every earlier signature was made
69+by the key record 1 names. The store records a handover explicitly: `ipl handover` appends a
70+`SUCCESSOR` record (canonical bytes from `om/landrec.om`) naming the new public key and its SHA-256
71+fingerprint, then a `SIG` by the then-current owner key, in the same record and signature style as
72+a landing. After that signature, only the successor key is current. Records before the handover
73+still verify against the old key; a later record signed by a retired key does not verify.
74+`owner.pub` stays the key named in record 1. Sequential handovers are followed in order. A rerun
75+that names a successor already current is a no-op. A successor may not be a key that has already
76+been an owner of the project; verify fails closed on a chain that hands a retired key back.
77+`ipl handover --all` prechecks every project and writes nothing unless every project can be handed
78+over. `ipl verify` prints the current owner fingerprint and the chain head (seq and hash of the last
79+line). The current owner is pinned in `${IPL_OWNER_PINS:-$HOME/.config/interplane/owner-pins}`,
80+outside the store (mode 0600). `verify`, `land`, `import`, `handover` and `catalog` apply it
81+automatically and fail closed if the file is missing, inside ROOT, group- or world-accessible, or
82+mismatched; `--expect-owner FP` that disagrees with the file also fails. After a signed `SUCCESSOR`
83+is recorded, `handover` updates that pin (a single handover rewrites the NAME line and prints
84+`ipl: pin: NAME SHA256:...`; `--all` rewrites every rotated NAME line, and `*` only if it named
85+the old key, and prints `ipl: pin: * SHA256:...`) for the forge, gates
86+and mirrors, which must be updated by hand from the new key's `.pub` — never from a store. The pin
87+is checked before `mend` touches files. `ipl handover --all` holds every project's lock from
88+preflight through write. The
89+`load_current` walk used by `prove_owner` checks each record's `prev` link (GENESIS for record 1)
90+before `mend` is allowed to change files. Signing and signature checks stay with
91+`ssh-keygen -Y` (Omega has no Ed25519 unit yet; the same gap is noted below). The walk that decides
92+which key is current, and the handover orchestration, stay in `ipl` until those decisions move into
93+Omega with the rest of the tool.
94+
95+## Not yet established
96+
97+- Settled while building step 1: `forged` has no Ed25519 of its own, it runs `ssh-keygen -Y verify`; step 1 signs and verifies the same way. An Ed25519 unit in Omega beside `om/tls` is still to be written.
98+- Settled by Drake's words to the HardenOS lane ("build this directly on to of git"): Git stays the storage format.
99+- How the first landing of this system itself is reviewed and installed, since it is the thing that makes landings possible. The HardenOS lane proposed: run the candidate only as a test artifact from a fresh clone until its gates and an other-provider MERGE exist, then use the route to record its own reviewed head, then install from that. Not settled; it may need Drake's word.
100+- Drake's own owner key. The trial uses a throwaway key. The real one is made and kept on his machine.

ipl/PIN

new file mode 100644
@@ -0,0 +1,7 @@
1+omega-mv 2ee0a70d1830581b706f288e722f3329d51f3583
2+omc-sha256 26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991
3+sha2-om-sha256 5cf0f98116def6917d3a373f2bd4c3932d46e3ff84d9567bbae9e720366fdb33
4+forge 4ed98366d73a435e1f8477da6902b3f6411bdba4
5+chain-om-sha256 fe2a99a0ab95b86a7bc1548024c997d23048d89dcce89b85bb39da7bd7e41bb9
6+snapshot a82c85048040b7bbd10ca14e64c8879707fdd25c
7+snapshot-om-sha256 8b0781f3a86267bb596bebb3261814a2a7318ac6d52b9a91181f7b1b8c2f506d

ipl/README.md

new file mode 100644
@@ -0,0 +1,37 @@
1+# interplane-native
2+
3+Interplane's own project store: the code in ordinary Git, and a signed record chain that says which
4+head is real. Step 1 of the design in `DESIGN.md`. What consumers may rely on is `CONTRACT.md`.
5+
6+Status: IMPLEMENTED, EXERCISED on the Spark host (the gate, and a trial import of the public projects
7+from the old store). Not installed, not serving, not the publishing route.
8+
9+| File | What it is |
10+|---|---|
11+| `om/landrec.om` | seeded Omega: every record field rule and the canonical record bytes, including `SUCCESSOR` |
12+| `ipl` | shell around `landrec`, the forge's `chain/chain.om`, git and ssh-keygen (`init`, `import`, `land`, `handover`, `verify`, `catalog`). The current owner is pinned in `$IPL_OWNER_PINS` or `~/.config/interplane/owner-pins` (outside the store, mode 0600). Unfinished migration: its decisions move into Omega |
13+| `build.sh` | builds `bin/landrec` and `bin/chain` from the pinned compiler and sources |
14+| `tests/run.sh` | the gate: record rules, one project's life, crafted arguments, tamper and forged-signature controls, and a real landing stopped at five chosen points and a real init at four (not at every write, and not by cutting power). It prints the versions of git, ssh, bash, coreutils and util-linux it ran with |
15+| `tools/import-radicle.sh` | one-time migration instrument: old store to a store root |
16+| `tools/receipt.sh` | from a clean clone: build, gate, wrong-compiler control, import, full verification, head comparison, and a `READY.json` written from what was measured, never over an earlier one |
17+| `PIN` | the compiler, `sha2.om`, `chain.om` and snapshot tool this was built and run with |
18+| `reviews/` | review verdicts for exact heads, with the author's reply to each finding |
19+
20+Build and gate (Linux AArch64): take `seed/out/omc` and `om/tls/sha2.om` from omega-mv at PIN's commit and
21+`chain/chain.om` from the forge at PIN's commit, then
22+
23+```
24+./build.sh OMC SHA2_OM CHAIN_OM [SNAPSHOT_OM] # writes bin/landrec, bin/chain (and bin/snapshot for the import) and bin/BUILD.sha256
25+tests/run.sh OMC SHA2_OM CHAIN_OM # builds its own copies in scratch; ends GATE PASS cases=N
26+```
27+
28+Both refuse any other compiler or source file.
29+
30+Host programs on the path of this version: bash, git, ssh-keygen, awk, sed, cmp (diffutils), getconf
31+(libc), flock (util-linux), and from coreutils sha256sum, sync, realpath, od, env, mktemp, cut, tr,
32+head, tail, wc, cp, mv, rm, mkdir, chmod, cat, basename, dirname.
33+Their versions are whatever the host has; the gate prints the ones it ran with, so the number is in
34+the gate's output and not typed here. ssh-keygen does the Ed25519 signing and checking because Omega
35+has no Ed25519 yet (the forge's sign-in uses the same `-Y verify`). Omega replacement, in order: the
36+decisions in `ipl`, then an Ed25519 unit beside `om/tls`. Git stays: storage on Git is the operator's
37+decision.

ipl/build.sh

new file mode 100755
@@ -0,0 +1,20 @@
1+#!/bin/sh
2+# build.sh OMC SHA2_OM CHAIN_OM [SNAPSHOT_OM]: build bin/landrec and bin/chain, and bin/snapshot when
3+# its source is given (the import instrument needs it), with the pinned compiler and sources.
4+# Refuses any compiler or source file whose sha256 is not PIN's. Writes bin/BUILD.sha256, the digests
5+# of what it built, which tools/import-radicle.sh checks before it runs anything. Invocation glue only.
6+set -u
7+cd "$(dirname "$0")" || exit 2
8+ck() { [ "$(sha256sum "$1" | cut -d' ' -f1)" = "$(sed -n "s/^$2 //p" PIN)" ] || { echo "build: $1 is not PIN's $2" >&2; exit 2; }; }
9+ck "${1:?OMC}" omc-sha256; ck "${2:?SHA2_OM}" sha2-om-sha256; ck "${3:?CHAIN_OM}" chain-om-sha256
10+mkdir -p bin && "$1" < om/landrec.om > bin/landrec.new && { printf 'om2\n'; cat "$2" "$3"; } | "$1" > bin/chain.new || { echo "build: compile failed" >&2; exit 2; }
11+chmod +x bin/landrec.new bin/chain.new && mv bin/landrec.new bin/landrec && mv bin/chain.new bin/chain || exit 2
12+set -- "$1" "$2" "$3" "${4:-}"
13+if [ -n "$4" ]; then
14+ ck "$4" snapshot-om-sha256
15+ "$1" < "$4" > bin/snapshot.new && chmod +x bin/snapshot.new && mv bin/snapshot.new bin/snapshot || { echo "build: snapshot did not compile" >&2; exit 2; }
16+ ( cd bin && sha256sum landrec chain snapshot > BUILD.sha256 )
17+else
18+ rm -f bin/snapshot; ( cd bin && sha256sum landrec chain > BUILD.sha256 )
19+fi
20+cat bin/BUILD.sha256

ipl/ipl

new file mode 100755
@@ -0,0 +1,907 @@
1+#!/bin/bash
2+# ipl: Interplane's own project store. Step 1 of DESIGN.md; the contract for consumers is CONTRACT.md.
3+#
4+# ipl init ROOT NAME BRANCH VISIBILITY ALIAS KEY
5+# ipl import ROOT NAME BRANCH EVIDENCE_FILE NOTE_FILE REQUEST KEY
6+# ipl land ROOT NAME BRANCH NEW SOURCE RECEIPT_FILE VERDICT_FILE REQUEST KEY
7+# ipl handover ROOT NAME|--all OLD_KEY NEW_PUBKEY [REASON]
8+# ipl verify ROOT NAME [--expect-owner FP]
9+# ipl land ... [--expect-owner FP]
10+# ipl catalog ROOT [--expect-owner FP]
11+#
12+# The current owner is pinned outside the store, at
13+# ${IPL_OWNER_PINS:-$HOME/.config/interplane/owner-pins}: lines of `NAME SHA256:<43>`
14+# or `* SHA256:<43>` for every project. The file must exist, be mode 0600 (no group or
15+# world bits), and resolve outside ROOT; otherwise verify, land, import, handover and
16+# catalog fail closed (exit 3). That is the out-of-band pin: the value is written by
17+# hand from the owner key's .pub on the machine that holds it, never copied from a
18+# store. After a handover writes a signed SUCCESSOR, ipl updates the local pin file
19+# (a single handover rewrites that NAME line and prints `ipl: pin: NAME SHA256:...`;
20+# --all rewrites every rotated NAME line, and the `*` line only if it named the old
21+# key, and prints `ipl: pin: * SHA256:...`) so other hosts can be updated by hand.
22+# --expect-owner FP may also be passed; if it disagrees with the file, or the
23+# current key is not the pin, the command fails closed (exit 3).
24+#
25+# Who decides what:
26+# bin/landrec (om/landrec.om, seeded Omega) what a record may say: field rules, canonical bytes
27+# bin/chain (forge chain/chain.om) the chain: append and its own verification
28+# git storage, ancestry, ref rules
29+# ssh-keygen -Y sign / verify Ed25519 signatures (as the forge's sign-in)
30+# this file the order of those calls and the refusals between them
31+# This file is shell: unfinished migration, not the destination. Its decisions (what verifies, replay,
32+# fast-forward, the order of a landing and its recovery) move into Omega before the route is offered
33+# for publishing. Host tools: bash, git, ssh-keygen, awk, sed, cmp (diffutils), getconf (libc), flock
34+# (util-linux), and from coreutils sha256sum, sync, realpath, od, env, mktemp, cut, tr, head, tail,
35+# wc, cp, mv, rm, mkdir, chmod, cat, basename, dirname. The gate prints the versions it ran with. The
36+# two rule programs are the ones beside this file; no setting replaces them.
37+#
38+# A landing, in order: every argument is checked; the key is shown to sign as the project's owner;
39+# what an interruption left is put right; the project must verify; the payload and the owner's
40+# signature over it are written to staging, synced, and the signature is verified; only then the
41+# record and its SIG record are appended and the branch is moved forward. What an interruption can
42+# leave, and what happens then (always: only for the owner's key, said on stderr as "repaired:", and
43+# only the same request finishes an unfinished one):
44+# a torn last line of the chain (never a record) -> cut off
45+# an empty chain file from an init that never wrote -> removed, init goes on
46+# a record whose payload is still only in staging -> the payload is put in place
47+# PENDING_SIG the last record has no SIG yet -> it is signed, then the branch moves
48+# PENDING_REF the last landing is signed, the branch still at its old head -> the branch moves
49+# Anything else that does not verify is refused whole; this tool does not repair it.
50+# Exit 0 done; 1 usage; 2 an argument, file or key was refused; 3 the project does not verify, or has
51+# an unfinished request that is not this one; 4 refused: not a fast-forward, head already there, not
52+# a commit the store can find, branch name taken, or the request id was already used for something
53+# else; 5 a tool failed part-way: run the same request again, it finishes or refuses. On 1 to 4
54+# nothing of the request is in the chain, the records or the branches; a repair made first for the
55+# owner stays, and a refused landing may have copied Git objects no branch points at.
56+# IPL_TEST_STOP=after-stage|mid-record|after-record|after-sig|after-ref makes a landing stop there
57+# with exit 9 (an init has the first four points; it moves no branch). It exists for the gate's
58+# interruption cases and can only stop the program early.
59+set -u
60+here=$(cd "$(dirname "$0")" && pwd)
61+CHAIN=$here/bin/chain
62+LANDREC=$here/bin/landrec
63+ZERO=0000000000000000000000000000000000000000
64+PATH=/usr/bin:/bin
65+die() { echo "ipl: $2" >&2; exit "$1"; }
66+[ -x "$CHAIN" ] && [ -x "$LANDREC" ] || die 5 "bin/chain and bin/landrec are not built (build.sh)"
67+# git sees no caller environment, no user or system configuration, no hooks, no replace objects,
68+# and only the local file transport
69+g() {
70+ env -i PATH=/usr/bin:/bin HOME=/nonexistent GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_NOSYSTEM=1 \
71+ GIT_NO_REPLACE_OBJECTS=1 GIT_TERMINAL_PROMPT=0 git -c core.hooksPath=/dev/null -c protocol.allow=never -c protocol.file.allow=always \
72+ --git-dir="$P/repo.git" "$@"
73+}
74+sha() { sha256sum < "$1" | cut -c1-64; }
75+pfield() { sed -n "s/^$1 //p" "$2"; }
76+stop_at() { [ "${IPL_TEST_STOP:-}" != "$1" ] || exit 9; }
77+sigmsg() { printf 'interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n' "$1" "$2" "$3" "$4" "$5"; }
78+# the message the signature of chain line $1 must cover: everything but seq and time; prev fixes the position
79+linemsg() { local s u k a sj p pv; IFS=$'\t' read -r s u k a sj p pv <<< "$1"; sigmsg "$k" "$a" "$sj" "$p" "$pv"; }
80+sigok() { # MSG_FILE SIG_FILE [PUB_FILE]: a valid signature by that public key (owner.pub if omitted), purpose interplane
81+ local al rc pub=${3:-$P/owner.pub}
82+ al=$(mktemp) || return 1
83+ printf 'owner %s\n' "$(cut -d' ' -f1,2 "$pub")" > "$al"
84+ ssh-keygen -q -Y verify -f "$al" -I owner -n interplane -s "$2" < "$1" >/dev/null 2>&1; rc=$?
85+ rm -f "$al"; return $rc
86+}
87+pubblob() { # PUB_FILE: the ssh-ed25519 blob (field 2), or fail
88+ local t b; t=$(head -n 1 "$1")
89+ [ "${t%% *}" = ssh-ed25519 ] || return 1
90+ b=${t#ssh-ed25519 }; b=${b%% *}
91+ [ ${#b} = 68 ] || return 1
92+ printf '%s' "$b"
93+}
94+write_ssh_pub() { # DEST BLOB: one ssh-ed25519 public key line, no comment
95+ printf 'ssh-ed25519 %s\n' "$2" > "$1"
96+}
97+ensure_vcurpub() {
98+ if [ -z "${VCURPUB:-}" ] || [ ! -e "$VCURPUB" ]; then
99+ VCURPUB=$(mktemp) || return 1
100+ fi
101+}
102+cleanup_temps() { rm -f "${VCURPUB:-}" "${VCURPUB:-}.pending"; }
103+trap cleanup_temps EXIT
104+reset_owners() { declare -gA OWNERS=(); }
105+note_owner() { OWNERS[$1]=1; }
106+is_prior_owner() { [ -n "${OWNERS[$1]:-}" ]; }
107+# apply_successor PAYLOAD DEST: PAYLOAD is a canonical SUCCESSOR for $NAME whose old key is $CURRENT.
108+# Writes the successor public key to DEST and sets PENDING_NEW to its fingerprint.
109+apply_successor() {
110+ local f=$1 dest=$2 old new blob reason np fp
111+ old=$(pfield old "$f"); new=$(pfield new "$f"); blob=$(pfield pub "$f"); reason=$(pfield reason "$f")
112+ [ -n "$reason" ] || reason=-
113+ "$LANDREC" successor "$(pfield project "$f")" "$old" "$new" "$blob" "$reason" 2>/dev/null | cmp -s - "$f" || return 1
114+ [ "$(pfield project "$f")" = "$NAME" ] || return 1
115+ [ "$old" = "$CURRENT" ] && [ "$new" != "$old" ] || return 1
116+ is_prior_owner "$new" && return 1
117+ np=$(mktemp) || return 1
118+ write_ssh_pub "$np" "$blob" || { rm -f "$np"; return 1; }
119+ fp=$(ed25519_fp "$np") || { rm -f "$np"; return 1; }
120+ [ "$fp" = "$new" ] || { rm -f "$np"; return 1; }
121+ mv "$np" "$dest" || return 1
122+ PENDING_NEW=$new
123+ return 0
124+}
125+# payload_for SEQ: records/SEQ, or a staging file whose digest is the one the chain line commits to
126+payload_for() {
127+ local i=$1 want f
128+ if [ -f "$P/records/$i" ]; then printf '%s' "$P/records/$i"; return 0; fi
129+ want=$(sed -n "${i}p" "$P/chain.tsv" | cut -f6)
130+ [ -n "$want" ] || return 1
131+ for f in "$P"/staging/*; do
132+ if [ -f "$f" ] && [ "$(sha "$f")" = "$want" ]; then printf '%s' "$f"; return 0; fi
133+ done
134+ return 1
135+}
136+# load_current: set CURRENT and VCURPUB from owner.pub and every complete SUCCESSOR+SIG pair.
137+# A torn last line is ignored (it was never a record). Fails closed if the current key is ambiguous.
138+# Each line's prev must commit to the line before it (GENESIS for record 1), so prove_owner/mend
139+# do not run on a spliced chain.
140+load_current() {
141+ local lines nl i s u k a sj p pv f pend="" tmp want
142+ CURRENT=""
143+ reset_owners
144+ ensure_vcurpub || { VMSG="mktemp"; return 1; }
145+ rm -f "$VCURPUB.pending"
146+ [ -f "$P/owner.pub" ] || { VMSG="no owner.pub"; return 1; }
147+ CURRENT=$(ed25519_fp "$P/owner.pub") || { VMSG="owner.pub is not one Ed25519 public key"; return 1; }
148+ cp "$P/owner.pub" "$VCURPUB" || { VMSG="cannot read owner.pub"; return 1; }
149+ note_owner "$CURRENT"
150+ [ -s "$P/chain.tsv" ] || return 0
151+ mapfile -t lines < "$P/chain.tsv" || { VMSG="cannot read the chain"; return 1; }
152+ # a torn last line (no terminating line feed) was never a record
153+ if [ "$(tail -c 1 "$P/chain.tsv" | od -An -tx1 | tr -d ' ')" != 0a ] && [ ${#lines[@]} -gt 0 ]; then
154+ unset "lines[$((${#lines[@]} - 1))]"
155+ fi
156+ nl=${#lines[@]}
157+ if [ -f "$P/records/1" ]; then
158+ [ "$(pfield owner "$P/records/1")" = "$CURRENT" ] || { VMSG="owner.pub is not the Ed25519 key record 1 names"; return 1; }
159+ fi
160+ for ((i = 1; i <= nl; i++)); do
161+ IFS=$'\t' read -r s u k a sj p pv <<< "${lines[i - 1]}"
162+ if [ "$i" = 1 ]; then
163+ [ "$pv" = GENESIS ] || { VMSG="record 1 prev is not GENESIS"; return 1; }
164+ else
165+ want=$(printf '%s' "${lines[i - 2]}" | sha256sum | cut -c1-64)
166+ [ "$pv" = "$want" ] || { VMSG="record $i does not follow the line before it"; return 1; }
167+ fi
168+ [ "$a" = "$CURRENT" ] || { VMSG="record $i was written by $a, not the current owner"; return 1; }
169+ # only SUCCESSOR records are followed here; PROJECT/IMPORT/LAND signatures are
170+ # checked by vcore. A SUCCESSOR not followed by SIG (except as the last record) is ambiguous.
171+ if [ -n "$pend" ] && [ "$k" != SIG ]; then VMSG="record $pend is not followed by its signature"; return 1; fi
172+ case $k in
173+ SUCCESSOR)
174+ [ "$i" != 1 ] || { VMSG="SUCCESSOR record $i is out of place"; return 1; }
175+ pend=$i
176+ if [ "$i" = "$nl" ]; then continue; fi
177+ f=$(payload_for "$i") || { VMSG="payload of record $i is missing"; return 1; }
178+ if is_prior_owner "$(pfield new "$f")"; then VMSG="record $i names a key that was already an owner"; return 1; fi
179+ apply_successor "$f" "$VCURPUB.pending" || { VMSG="record $i is not a canonical successor from the current key"; return 1; }
180+ [ "$sj" = "$(subj "$PENDING_NEW")" ] || { VMSG="record $i does not name its successor in the subject"; return 1; }
181+ ;;
182+ SIG)
183+ if [ -n "$pend" ]; then
184+ [ "$pend" = $((i - 1)) ] || { VMSG="record $i signs nothing"; return 1; }
185+ if [ -f "$VCURPUB.pending" ]; then
186+ f=$(payload_for "$i") || { VMSG="payload of record $i is missing"; return 1; }
187+ tmp=$(mktemp) || { VMSG="mktemp"; return 1; }
188+ linemsg "${lines[i - 2]}" > "$tmp"
189+ if ! sigok "$tmp" "$f" "$VCURPUB"; then rm -f "$tmp"; VMSG="the signature in record $i does not verify for record $pend"; return 1; fi
190+ rm -f "$tmp"
191+ CURRENT=$PENDING_NEW
192+ note_owner "$CURRENT"
193+ mv "$VCURPUB.pending" "$VCURPUB" || return 1
194+ fi
195+ pend=""
196+ fi
197+ ;;
198+ esac
199+ done
200+ rm -f "$VCURPUB.pending"
201+ return 0
202+}
203+ed25519_fp() { # PUB_FILE: prints the fingerprint only for one Ed25519 key
204+ local l; l=$(ssh-keygen -lf "$1" 2>/dev/null) || return 1
205+ [ "$(printf '%s\n' "$l" | wc -l)" = 1 ] && [[ $l == *"(ED25519)" ]] && [[ $(head -c 12 "$1") == "ssh-ed25519 " ]] || return 1
206+ printf '%s' "$l" | awk '{print $2}'
207+}
208+export LC_ALL=C
209+# subj: the chain's subject field holds at most 128 bytes (a cap of the chain format); a longer name or
210+# branch is written there as the digest of its bytes, so this store adds no length rule of its own
211+subj() { if [ "${#1}" -le 128 ]; then printf '%s' "$1"; else printf 'sha256:%s' "$(printf '%s' "$1" | sha256sum | cut -c1-64)"; fi; }
212+admit() { # sets P; a project folder and its repository are real directories, not links
213+ P=$PR/$NAME
214+ "$LANDREC" check name "$NAME" && [ -d "$P" ] && [ ! -L "$P" ] && [ -d "$P/repo.git" ] && [ ! -L "$P/repo.git" ]
215+}
216+open_project() { # ROOT NAME: nothing outside ROOT/projects
217+ "$LANDREC" check name "$2" || die 2 "REFUSED name"
218+ PR=$(realpath -e -- "$1/projects" 2>/dev/null) || die 2 "no store at $1"
219+ ROOT=${PR%/projects}; NAME=$2
220+ [ "${#NAME}" -le "$(getconf NAME_MAX "$PR")" ] || die 2 "REFUSED name: longer than a file name can be on this file system ($(getconf NAME_MAX "$PR") bytes)"
221+ admit || die 2 "no project $2 in the store"
222+}
223+key_actor() { # KEY: ACTOR is the fingerprint of an Ed25519 key pair that is present
224+ [ -f "$1" ] && [ -f "$1.pub" ] || die 2 "key $1 (and $1.pub) not found"
225+ ACTOR=$(ed25519_fp "$1.pub") || die 2 "$1.pub is not one Ed25519 public key"
226+}
227+# prove_owner KEY: the private key signs, here and now, as the project's current owner key
228+# (owner.pub, or the successor named by the last complete SUCCESSOR+SIG pair). Nothing is changed
229+# for a caller who cannot do that.
230+prove_owner() {
231+ local d rc
232+ load_current || die 3 "cannot determine the current owner key: $VMSG"
233+ [ "$ACTOR" = "$CURRENT" ] || die 2 "key $ACTOR is not this project's current owner (agent grants are step 3)"
234+ d=$(mktemp -d) || die 5 mktemp
235+ printf 'interplane-proof 1\n%s\n' "$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')" > "$d/m"
236+ ssh-keygen -q -Y sign -n interplane -f "$1" "$d/m" >/dev/null 2>&1 && sigok "$d/m" "$d/m.sig" "$VCURPUB"; rc=$?
237+ rm -rf "$d"
238+ [ "$rc" = 0 ] || die 2 "that key does not sign as the project's current owner"
239+}
240+# lock_fd: fd 9, or ALL_LOCK_FD when --all is holding every project's lock across preflight and write
241+lock_fd() { if [ -n "${ALL_LOCK_FD:-}" ]; then printf '%s' "$ALL_LOCK_FD"; else printf 9; fi; }
242+lock() {
243+ local fd; fd=$(lock_fd)
244+ if [ -z "${ALL_LOCK_FD:-}" ]; then
245+ exec 9>> "$P/lock" || die 5 "lock"
246+ fi
247+ flock "$1" "$fd" || die 5 "lock"
248+}
249+unlock() { flock -u "$(lock_fd)"; }
250+durable() { sync "$@" || die 5 "sync failed: $*"; }
251+# vcore: 0 verifies; 10 PENDING_SIG; 11 PENDING_REF; 3 does not verify (VMSG says why).
252+# Sets N, LINES, OWNER, DEFBR, VIS, HEADS[branch], REQAT[request]=seq, TAILOLD.
253+vcore() {
254+ local out i s u k a sj p pv pend="" f br old new req t ref mism=0 mbr=""
255+ VMSG=""; N=0; declare -gA HEADS=() REQAT=(); TAILOLD=""; TAILBR=""
256+ [ -s "$P/chain.tsv" ] || { VMSG="no chain"; return 3; }
257+ out=$("$CHAIN" verify "$P/chain.tsv" 2>&1) || { VMSG="chain: $out"; return 3; }
258+ mapfile -t LINES < "$P/chain.tsv"; N=${#LINES[@]}
259+ f=$P/records/1
260+ [ -f "$f" ] && [ "$(sha "$f")" = "$(cut -f6 <<< "${LINES[0]}")" ] || { VMSG="payload of record 1 is missing or not the one committed"; return 3; }
261+ "$LANDREC" project "$(pfield project "$f")" "$(pfield branch "$f")" "$(pfield visibility "$f")" "$(pfield owner "$f")" "$(pfield alias "$f")" "$(pfield nonce "$f")" 2>/dev/null | cmp -s - "$f" ||
262+ { VMSG="record 1 is not a canonical project record"; return 3; }
263+ OWNER=$(pfield owner "$f"); DEFBR=$(pfield branch "$f"); VIS=$(pfield visibility "$f")
264+ [ "$(pfield project "$f")" = "$NAME" ] || { VMSG="record 1 is for project $(pfield project "$f"), not $NAME"; return 3; }
265+ [ -f "$P/owner.pub" ] && [ "$(ed25519_fp "$P/owner.pub")" = "$OWNER" ] || { VMSG="owner.pub is not the Ed25519 key record 1 names"; return 3; }
266+ CURRENT=$OWNER
267+ reset_owners
268+ note_owner "$CURRENT"
269+ ensure_vcurpub || { VMSG="mktemp"; return 3; }
270+ cp "$P/owner.pub" "$VCURPUB" || { VMSG="cannot read owner.pub"; return 3; }
271+ rm -f "$VCURPUB.pending"
272+ t=$(mktemp) || { VMSG="mktemp"; return 3; }
273+ for ((i = 1; i <= N; i++)); do
274+ IFS=$'\t' read -r s u k a sj p pv <<< "${LINES[i - 1]}"; f=$P/records/$i
275+ [ -f "$f" ] && [ "$(sha "$f")" = "$p" ] || { VMSG="payload of record $i is missing or not the one committed"; rm -f "$t" "$VCURPUB.pending"; return 3; }
276+ [ "$a" = "$CURRENT" ] || { VMSG="record $i was written by $a, not the current owner"; rm -f "$t" "$VCURPUB.pending"; return 3; }
277+ if [ -n "$pend" ] && [ "$k" != SIG ]; then VMSG="record $pend is not followed by its signature"; rm -f "$t" "$VCURPUB.pending"; return 3; fi
278+ case $k in
279+ PROJECT)
280+ [ "$i" = 1 ] && [ "$sj" = "$(subj "$NAME")" ] || { VMSG="PROJECT record $i is out of place"; rm -f "$t" "$VCURPUB.pending"; return 3; }
281+ pend=$i ;;
282+ SUCCESSOR)
283+ [ "$i" != 1 ] || { VMSG="SUCCESSOR record $i is out of place"; rm -f "$t" "$VCURPUB.pending"; return 3; }
284+ if is_prior_owner "$(pfield new "$f")"; then VMSG="record $i names a key that was already an owner"; rm -f "$t" "$VCURPUB.pending"; return 3; fi
285+ apply_successor "$f" "$VCURPUB.pending" || { VMSG="record $i is not a canonical successor from the current key"; rm -f "$t" "$VCURPUB.pending"; return 3; }
286+ [ "$sj" = "$(subj "$PENDING_NEW")" ] || { VMSG="record $i does not name its successor in the subject"; rm -f "$t" "$VCURPUB.pending"; return 3; }
287+ pend=$i ;;
288+ IMPORT | LAND)
289+ br=$(pfield branch "$f"); old=$(pfield old "$f"); new=$(pfield new "$f"); req=$(pfield request "$f")
290+ "$LANDREC" land "$(pfield project "$f")" "$br" "$old" "$new" "$(pfield receipt "$f")" "$(pfield verdict "$f")" "$req" 2>/dev/null | cmp -s - "$f" ||
291+ { VMSG="record $i is not a canonical land record"; rm -f "$t"; return 3; }
292+ [ "$(pfield project "$f")" = "$NAME" ] && [ "$sj" = "$(subj "$br")" ] || { VMSG="record $i does not belong to $NAME $br"; rm -f "$t"; return 3; }
293+ [ -z "${REQAT[$req]:-}" ] || { VMSG="request $req is recorded twice ($((REQAT[$req])) and $i)"; rm -f "$t"; return 3; }
294+ [ "$old" = "${HEADS[$br]:-$ZERO}" ] && [ "$new" != "$old" ] || { VMSG="record $i does not start from the recorded head of $br"; rm -f "$t"; return 3; }
295+ [ "$k" = LAND ] || [ "$old" = $ZERO ] || { VMSG="IMPORT record $i on a branch that already has a head"; rm -f "$t"; return 3; }
296+ [ "$(g cat-file -t "$new" 2>/dev/null)" = commit ] || { VMSG="record $i names a head that is not a commit the store holds"; rm -f "$t"; return 3; }
297+ [ "$old" = $ZERO ] || g merge-base --is-ancestor "$old" "$new" 2>/dev/null || { VMSG="record $i is not a fast-forward of the head before it"; rm -f "$t"; return 3; }
298+ REQAT[$req]=$i; HEADS[$br]=$new; pend=$i; TAILOLD=$old; TAILBR=$br ;;
299+ SIG)
300+ [ -n "$pend" ] && [ "$pend" = $((i - 1)) ] && [ "$sj" = "$pend" ] || { VMSG="record $i signs nothing"; rm -f "$t" "$VCURPUB.pending"; return 3; }
301+ linemsg "${LINES[i - 2]}" > "$t"
302+ sigok "$t" "$f" "$VCURPUB" || { VMSG="the signature in record $i does not verify for record $pend"; rm -f "$t" "$VCURPUB.pending"; return 3; }
303+ if [ -f "$VCURPUB.pending" ]; then
304+ CURRENT=$PENDING_NEW
305+ note_owner "$CURRENT"
306+ mv "$VCURPUB.pending" "$VCURPUB" || { rm -f "$t"; return 3; }
307+ fi
308+ pend="" ;;
309+ *) VMSG="record $i has unknown kind $k"; rm -f "$t" "$VCURPUB.pending"; return 3 ;;
310+ esac
311+ done
312+ rm -f "$t"
313+ for br in "${!HEADS[@]}"; do
314+ ref=$(g rev-parse -q --verify "refs/heads/$br" 2>/dev/null) || ref=$ZERO
315+ [ "$ref" = "${HEADS[$br]}" ] || { mism=$((mism + 1)); mbr=$br; }
316+ done
317+ IFS=$'\t' read -r s u k a sj p pv <<< "${LINES[N - 1]}"
318+ if [ -n "$pend" ]; then
319+ # an unsigned last record: its own branch has not moved yet, every other branch is in place
320+ if [ "$k" = PROJECT ] && [ "$mism" = 0 ]; then VMSG="PENDING_SIG record $N (PROJECT) is not signed yet"; return 10; fi
321+ if [ "$k" = SUCCESSOR ] && [ "$mism" = 0 ]; then VMSG="PENDING_SIG record $N (SUCCESSOR) is not signed yet"; return 10; fi
322+ ref=$(g rev-parse -q --verify "refs/heads/${TAILBR:-}" 2>/dev/null) || ref=$ZERO
323+ if [ "$k" = LAND ] && [ "$mism" = 1 ] && [ "$mbr" = "$TAILBR" ] && [ "$ref" = "$TAILOLD" ]; then VMSG="PENDING_SIG record $N (LAND $TAILBR) is not signed yet"; return 10; fi
324+ if [ "$k" = IMPORT ] && [ "$mism" = 0 ]; then VMSG="PENDING_SIG record $N (IMPORT $TAILBR) is not signed yet"; return 10; fi
325+ VMSG="record $N is not signed and the branches are not where the chain says"; return 3
326+ fi
327+ [ "$mism" = 0 ] && return 0
328+ if [ "$N" -ge 2 ]; then
329+ IFS=$'\t' read -r s u k a sj p pv <<< "${LINES[N - 2]}"
330+ ref=$(g rev-parse -q --verify "refs/heads/${TAILBR:-}" 2>/dev/null) || ref=$ZERO
331+ if [ "$k" = LAND ] && [ "$mism" = 1 ] && [ "$mbr" = "$TAILBR" ] && [ "$ref" = "$TAILOLD" ]; then VMSG="PENDING_REF $TAILBR is still at ${TAILOLD}, the chain says ${HEADS[$TAILBR]}"; return 11; fi
332+ fi
333+ VMSG="refs/heads/$mbr is not where the chain says (${HEADS[$mbr]})"; return 3
334+}
335+# chain_head: SHA-256 of the last chain line with no line feed (the prev a next record would commit to)
336+chain_head() { printf '%s' "${LINES[N - 1]}" | sha256sum | cut -c1-64; }
337+# OK NAME ID BRANCH HEAD VISIBILITY CURRENT_OWNER SEQ CHAIN_HEAD
338+okline() { echo "OK $NAME $(sha "$P/records/1") $DEFBR ${HEADS[$DEFBR]:-none} $VIS $CURRENT $N $(chain_head)"; }
339+# The operator pin lives outside the store. load_owner_pins requires ROOT, fails closed
340+# (exit 3) if the file is missing, inside ROOT, or group-/world-accessible, and parses
341+# NAME FP and * FP lines. pin_for NAME sets PIN_FP.
342+load_owner_pins() {
343+ local raw path mode root_abs pin_abs given line name fp rest
344+ raw=${IPL_OWNER_PINS:-"$HOME/.config/interplane/owner-pins"}
345+ [ -n "${ROOT:-}" ] || die 5 "owner pin: store root is not set"
346+ [ -e "$raw" ] || die 3 "owner pin file not found: $raw"
347+ pin_abs=$(realpath -e -- "$raw") || die 3 "owner pin file not found: $raw"
348+ [ -f "$pin_abs" ] || die 3 "owner pin file is not a regular file: $raw"
349+ root_abs=$(realpath -e -- "$ROOT") || die 2 "no store at $ROOT"
350+ given=$(realpath -s -- "$raw" 2>/dev/null || printf '%s' "$pin_abs")
351+ case $pin_abs in "$root_abs"|"$root_abs"/*) die 3 "owner pin file is inside the store: $pin_abs" ;; esac
352+ case $given in "$root_abs"|"$root_abs"/*) die 3 "owner pin file is inside the store: $given" ;; esac
353+ mode=$(stat -c '%a' "$pin_abs") || die 3 "cannot stat owner pin file"
354+ case $mode in
355+ 600|400) ;;
356+ *) die 3 "owner pin file must be mode 0600 (not group- or world-accessible): $pin_abs is $mode" ;;
357+ esac
358+ [ "$(stat -c '%u' "$pin_abs")" = "$(id -u)" ] || die 3 "owner pin file is not owned by this user"
359+ local parent pmode
360+ parent=$(dirname "$pin_abs")
361+ pmode=$(stat -c '%a' "$parent") || die 3 "cannot stat owner pin directory"
362+ if [ $((8#$pmode & 8#022)) -ne 0 ]; then
363+ die 3 "owner pin directory must not be group- or world-writable: $parent is $pmode"
364+ fi
365+ PIN_PATH=$pin_abs
366+ PIN_STAR=""
367+ declare -gA PIN_BY_NAME=()
368+ while IFS= read -r line || [ -n "$line" ]; do
369+ [[ $line =~ ^[[:space:]]*$ || $line =~ ^[[:space:]]*# ]] && continue
370+ read -r name fp rest <<< "$line"
371+ [ -n "$name" ] && [ -n "$fp" ] && [ -z "$rest" ] || die 3 "owner pin file has a malformed line"
372+ "$LANDREC" check owner "$fp" || die 3 "owner pin file names a fingerprint that is not an owner key"
373+ if [ "$name" = '*' ]; then
374+ [ -z "$PIN_STAR" ] || die 3 "owner pin file names * more than once"
375+ PIN_STAR=$fp
376+ else
377+ "$LANDREC" check name "$name" || die 3 "owner pin file names a project that is not a name"
378+ [ -z "${PIN_BY_NAME[$name]:-}" ] || die 3 "owner pin file names $name more than once"
379+ PIN_BY_NAME[$name]=$fp
380+ fi
381+ done < "$pin_abs"
382+ [ -n "$PIN_STAR" ] || [ ${#PIN_BY_NAME[@]} -gt 0 ] || die 3 "owner pin file is empty"
383+}
384+pin_for() {
385+ if [ -n "${PIN_BY_NAME[$1]:-}" ]; then PIN_FP=${PIN_BY_NAME[$1]}; return 0; fi
386+ if [ -n "${PIN_STAR:-}" ]; then PIN_FP=$PIN_STAR; return 0; fi
387+ return 1
388+}
389+require_expect_owner() {
390+ pin_for "$NAME" || die 3 "owner pin file has no line for $NAME"
391+ if [ -n "${EXPECT_OWNER:-}" ] && [ "$EXPECT_OWNER" != "$PIN_FP" ]; then
392+ die 3 "current owner pin is $PIN_FP, not $EXPECT_OWNER"
393+ fi
394+ [ "$CURRENT" = "$PIN_FP" ] || die 3 "current owner is $CURRENT, not $PIN_FP"
395+}
396+# announce_pin / update_owner_pin: after a signed SUCCESSOR is on the chain. Never on a no-op,
397+# and never from a fingerprint read out of the store: NEWFP is the key the operator just signed over.
398+announce_pin() { echo "ipl: pin: $1 $2" >&2; }
399+# update_owner_pin NAME NEWFP: rewrite or append the NAME line only. Does not touch *.
400+# update_owner_pin_all OLDFP NEWFP names...: rewrite each named project's line to NEWFP;
401+# rewrite * only if it named OLDFP; if there is no * line, append * NEWFP.
402+update_owner_pin() {
403+ local name=$1 fp=$2 tmp dir line nname nfp rest found=0
404+ dir=$(dirname "$PIN_PATH")
405+ tmp=$(mktemp "$dir/owner-pins.XXXXXX") || die 5 "cannot update owner pin"
406+ chmod 600 "$tmp" || { rm -f "$tmp"; die 5 "cannot update owner pin"; }
407+ while IFS= read -r line || [ -n "$line" ]; do
408+ if [[ $line =~ ^[[:space:]]*$ || $line =~ ^[[:space:]]*# ]]; then
409+ printf '%s\n' "$line" >> "$tmp"
410+ continue
411+ fi
412+ read -r nname nfp rest <<< "$line"
413+ if [ "$nname" = "$name" ]; then
414+ printf '%s %s\n' "$name" "$fp" >> "$tmp"; found=1
415+ else
416+ printf '%s\n' "$line" >> "$tmp"
417+ fi
418+ done < "$PIN_PATH"
419+ if [ "$found" = 0 ]; then
420+ printf '%s %s\n' "$name" "$fp" >> "$tmp"
421+ fi
422+ sync "$tmp" && mv -f "$tmp" "$PIN_PATH" && chmod 600 "$PIN_PATH" && sync "$dir" || { rm -f "$tmp"; die 5 "recorded, but the owner pin could not be updated"; }
423+}
424+update_owner_pin_all() {
425+ local oldfp=$1 newfp=$2 tmp dir line nname nfp rest star=0
426+ shift 2
427+ local -A rotate=() seen=()
428+ local n
429+ for n in "$@"; do rotate[$n]=1; done
430+ dir=$(dirname "$PIN_PATH")
431+ tmp=$(mktemp "$dir/owner-pins.XXXXXX") || die 5 "cannot update owner pin"
432+ chmod 600 "$tmp" || { rm -f "$tmp"; die 5 "cannot update owner pin"; }
433+ while IFS= read -r line || [ -n "$line" ]; do
434+ if [[ $line =~ ^[[:space:]]*$ || $line =~ ^[[:space:]]*# ]]; then
435+ printf '%s\n' "$line" >> "$tmp"
436+ continue
437+ fi
438+ read -r nname nfp rest <<< "$line"
439+ if [ "$nname" = '*' ]; then
440+ if [ "$nfp" = "$oldfp" ]; then
441+ printf '* %s\n' "$newfp" >> "$tmp"
442+ else
443+ printf '%s\n' "$line" >> "$tmp"
444+ fi
445+ star=1
446+ elif [ -n "${rotate[$nname]:-}" ]; then
447+ printf '%s %s\n' "$nname" "$newfp" >> "$tmp"
448+ seen[$nname]=1
449+ else
450+ printf '%s\n' "$line" >> "$tmp"
451+ fi
452+ done < "$PIN_PATH"
453+ for n in "$@"; do
454+ [ -n "${seen[$n]:-}" ] || printf '%s %s\n' "$n" "$newfp" >> "$tmp"
455+ done
456+ if [ "$star" = 0 ]; then
457+ printf '* %s\n' "$newfp" >> "$tmp"
458+ fi
459+ sync "$tmp" && mv -f "$tmp" "$PIN_PATH" && chmod 600 "$PIN_PATH" && sync "$dir" || { rm -f "$tmp"; die 5 "recorded, but the owner pin could not be updated"; }
460+}
461+finish_handover_pin() { # NEWFP: after this process appended a signed SUCCESSOR (not a no-op)
462+ announce_pin "$NAME" "$1"
463+ if [ -z "${HANDOVER_DEFER_PIN:-}" ]; then
464+ update_owner_pin "$NAME" "$1"
465+ fi
466+}
467+
468+# mend: called only after prove_owner. Cuts a torn last line (bytes after the last line feed were
469+# never a record) and puts a staged payload in place for a record that lacks its file.
470+mend() {
471+ local n i want f keep
472+ [ -f "$P/chain.tsv" ] || return 0
473+ if [ -s "$P/chain.tsv" ] && [ "$(tail -c 1 "$P/chain.tsv" | od -An -tx1 | tr -d ' ')" != 0a ]; then
474+ keep=$(wc -l < "$P/chain.tsv")
475+ head -n "$keep" "$P/chain.tsv" > "$P/chain.tsv.mend" && durable "$P/chain.tsv.mend" && mv "$P/chain.tsv.mend" "$P/chain.tsv" && durable "$P" || die 5 "cannot cut the torn line"
476+ echo "ipl: repaired: cut a torn last line off the chain" >&2
477+ fi
478+ n=$(wc -l < "$P/chain.tsv")
479+ for ((i = n; i >= 1 && i > n - 2; i--)); do
480+ [ -f "$P/records/$i" ] && continue
481+ want=$(sed -n "${i}p" "$P/chain.tsv" | cut -f6)
482+ for f in "$P"/staging/*; do
483+ if [ -f "$f" ] && [ "$(sha "$f")" = "$want" ]; then
484+ cp "$f" "$P/records/$i.tmp" && mv "$P/records/$i.tmp" "$P/records/$i" || die 5 "cannot restore payload $i"
485+ durable "$P/records/$i" "$P/records"; echo "ipl: repaired: put the staged payload of record $i in place" >&2; break
486+ fi
487+ done
488+ done
489+}
490+# add KIND SUBJECT STAGED_FILE: append one record whose payload is already durable in staging
491+add() {
492+ local out seq
493+ out=$("$CHAIN" add "$P/chain.tsv" "$1" "$ACTOR" "$2" < "$3") || die 5 "chain add failed: $out"
494+ seq=$(cut -f2 <<< "$out"); [[ $seq =~ ^[1-9][0-9]*$ ]] || die 5 "chain add answered: $out"
495+ [ "$seq" != 1 ] || durable "$P"
496+ [ "$1" = SIG ] || stop_at mid-record
497+ cp "$3" "$P/records/$seq.tmp" && mv "$P/records/$seq.tmp" "$P/records/$seq" || die 5 "cannot keep payload $seq"
498+ durable "$P/records/$seq" "$P/records"
499+ SEQ=$seq
500+}
501+# sign_tail KEY TAG: sign the unsigned last record and append its SIG
502+sign_tail() {
503+ local m=$P/staging/$2.msg
504+ mapfile -t LINES < "$P/chain.tsv"; N=${#LINES[@]}
505+ linemsg "${LINES[N - 1]}" > "$m" || die 5 "staging"
506+ rm -f "$m.sig"; ssh-keygen -q -Y sign -n interplane -f "$1" "$m" >/dev/null 2>&1 || die 2 "signing with $1 failed"
507+ sigok "$m" "$m.sig" "${VCURPUB:-$P/owner.pub}" || { rm -f "$m" "$m.sig"; die 2 "that key does not sign as the project's current owner"; }
508+ durable "$m.sig" "$P/staging"
509+ add SIG "$N" "$m.sig"
510+ rm -f "$m" "$m.sig"
511+}
512+move_ref() { # BRANCH NEW OLD
513+ if [ "$3" = $ZERO ]; then g update-ref "refs/heads/$1" "$2" "" || die 5 "ref update"; else g update-ref "refs/heads/$1" "$2" "$3" || die 5 "ref update"; fi
514+}
515+ref_free() { # BRANCH: no existing ref is a parent or a child of the new name
516+ local b=$1 pre
517+ [ -z "$(g for-each-ref --count=1 "refs/heads/$b/")" ] || return 1
518+ pre=$b
519+ while [[ $pre == */* ]]; do pre=${pre%/*}; g show-ref --verify -q "refs/heads/$pre" && return 1; done
520+ return 0
521+}
522+# publish_row: this project's catalog line, then the catalog from every project's line. Derived on
523+# every committed change; `ipl catalog` re-derives all of it from full verification.
524+publish_row() {
525+ put_row || die 5 "recorded, but the catalog line could not be written"
526+ join_catalog || die 5 "recorded, but the catalog could not be published"
527+}
528+put_row() { # under the project lock: this project's line, written whole or not at all
529+ local r; r=$(mktemp "$P/catalog.row.XXXXXX") || return 1
530+ # catalog stays five fields (name, id, branch, head, visibility); the extra OK fields are for verify
531+ printf '%s\t%s\t%s\t%s\t%s\n' "$NAME" "$(sha "$P/records/1")" "$DEFBR" "${HEADS[$DEFBR]:-none}" "$VIS" > "$r" && chmod 644 "$r" && sync "$r" && mv -f "$r" "$P/catalog.row" && sync "$P" || { rm -f "$r"; return 1; }
532+}
533+join_catalog() {
534+ local new d
535+ ( flock -x 7 || exit 1
536+ new=$(mktemp "$ROOT/catalog.tsv.XXXXXX") || exit 1
537+ for d in "$PR"/*/; do [ -f "$d/catalog.row" ] && [ ! -L "${d%/}" ] && cat "$d/catalog.row"; done > "$new"
538+ chmod 644 "$new" && sync "$new" && mv -f "$new" "$ROOT/catalog.tsv" && sync "$ROOT" || { rm -f "$new"; exit 1; }
539+ ) 7>> "$ROOT/catalog.lock"
540+}
541+# record KIND BRANCH NEW RECEIPT_FILE VERDICT_FILE REQUEST KEY SOURCE (NEW is empty for IMPORT)
542+record() {
543+ local kind=$1 br=$2 new=$3 rf=$4 vf=$5 req=$6 key=$7 src=$8 st old j f pay rd vd prev tag
544+ "$LANDREC" check branch "$br" && g check-ref-format "refs/heads/$br" || die 2 "REFUSED branch"
545+ branch_fits "$br" || die 2 "REFUSED branch: longer than this file system can hold as a branch"
546+ "$LANDREC" check request "$req" || die 2 "REFUSED request"
547+ [ "$kind" = IMPORT ] || [[ $new =~ ^[0-9a-f]{40}$ ]] || die 2 "REFUSED new"
548+ [ -f "$rf" ] && [ -f "$vf" ] || die 2 "receipt or verdict file not found"
549+ if [ "$src" != - ]; then [[ $src == /* ]] && [ -d "$src" ] || die 2 "REFUSED source: an absolute path of a local repository, or -"; fi
550+ lock -x
551+ load_current || die 3 "cannot determine the current owner key: $VMSG"
552+ require_expect_owner
553+ prove_owner "$key"; mend; vcore; st=$?
554+ [ "$st" != 3 ] || die 3 "$VMSG"
555+ [ "$ACTOR" = "$CURRENT" ] || die 2 "key $ACTOR is not this project's current owner"
556+ rd=$(sha "$rf"); vd=$(sha "$vf"); tag=req-$(printf '%s' "$req" | sha256sum | cut -c1-64); mkdir -p "$P/staging" || die 5 "staging"
557+ j=${REQAT[$req]:-}
558+ if [ -n "$j" ]; then
559+ f=$P/records/$j
560+ [ "$kind" != IMPORT ] || new=$(pfield new "$f")
561+ [ "$(cut -f3 <<< "${LINES[j - 1]}")" = "$kind" ] && [ "$(pfield branch "$f")" = "$br" ] && [ "$(pfield new "$f")" = "$new" ] &&
562+ [ "$(pfield receipt "$f")" = "$rd" ] && [ "$(pfield verdict "$f")" = "$vd" ] || die 4 "request $req was already used for something else"
563+ if [ "$st" = 10 ] && [ "$j" = "$N" ]; then sign_tail "$key" "$tag"; stop_at after-sig; [ "$kind" = IMPORT ] || move_ref "$br" "$new" "$(pfield old "$f")"
564+ elif [ "$st" = 11 ] && [ "$j" = $((N - 1)) ]; then move_ref "$br" "$new" "$(pfield old "$f")"
565+ elif [ "$st" != 0 ]; then die 3 "$VMSG"; fi
566+ rm -f "$P/staging/$tag".*
567+ vcore || die 3 "$VMSG"; publish_row; okline; return 0
568+ fi
569+ [ "$st" = 0 ] || die 3 "$VMSG"
570+ old=${HEADS[$br]:-$ZERO}
571+ if [ "$kind" = IMPORT ]; then
572+ [ "$old" = $ZERO ] || die 4 "import: $br already has a recorded head"
573+ new=$(g rev-parse -q --verify "refs/heads/$br" 2>/dev/null) || die 4 "import: no refs/heads/$br in the store"
574+ [ "$(g cat-file -t "$new" 2>/dev/null)" = commit ] || die 4 "import: refs/heads/$br is not a commit"
575+ else
576+ [ "$src" = - ] || g fetch -q --no-tags --no-write-fetch-head --end-of-options "file://$src" "$new" 2>/dev/null || die 4 "cannot fetch $new from $src"
577+ [ "$(g cat-file -t "$new" 2>/dev/null)" = commit ] || die 4 "$new is not a commit in the store"
578+ [ "$old" != "$new" ] || die 4 "$new is already the head"
579+ if [ "$old" = $ZERO ]; then
580+ g show-ref --verify -q "refs/heads/$br" && die 4 "refs/heads/$br exists but has no recorded head; import it"
581+ ref_free "$br" || die 4 "branch name $br collides with an existing branch"
582+ else g merge-base --is-ancestor "$old" "$new" || die 4 "not a fast-forward: $old is not an ancestor of $new"; fi
583+ fi
584+ pay=$P/staging/$tag.payload
585+ "$LANDREC" land "$NAME" "$br" "$old" "$new" "$rd" "$vd" "$req" > "$pay" || { rm -f "$pay"; die 2 "record refused"; }
586+ prev=$(tail -n 1 "$P/chain.tsv" | tr -d '\n' | sha256sum | cut -c1-64)
587+ sigmsg "$kind" "$ACTOR" "$(subj "$br")" "$(sha "$pay")" "$prev" > "$P/staging/$tag.msg"
588+ rm -f "$P/staging/$tag.msg.sig"; ssh-keygen -q -Y sign -n interplane -f "$key" "$P/staging/$tag.msg" >/dev/null 2>&1 || { rm -f "$P/staging/$tag".*; die 2 "signing with $key failed"; }
589+ sigok "$P/staging/$tag.msg" "$P/staging/$tag.msg.sig" "${VCURPUB:-$P/owner.pub}" || { rm -f "$P/staging/$tag".*; die 2 "that key does not sign as the project's current owner"; }
590+ durable "$pay" "$P/staging/$tag.msg.sig" "$P/staging"
591+ stop_at after-stage
592+ add "$kind" "$(subj "$br")" "$pay"
593+ stop_at after-record
594+ add SIG "$SEQ" "$P/staging/$tag.msg.sig"
595+ stop_at after-sig
596+ [ "$kind" = IMPORT ] || move_ref "$br" "$new" "$old"
597+ stop_at after-ref
598+ rm -f "$P/staging/$tag".*
599+ vcore || die 5 "recorded, but the project does not verify: $VMSG"
600+ publish_row; okline
601+}
602+# branch_fits BRANCH: what this file system can hold. Git keeps a branch as the file
603+# repo.git/refs/heads/BRANCH and writes BRANCH.lock beside it while updating, so the last part
604+# needs room for five more bytes, the parts before it are folders, and the whole path must fit.
605+branch_fits() {
606+ local nm pm parts i last
607+ nm=$(getconf NAME_MAX "$P/repo.git") && pm=$(getconf PATH_MAX "$P/repo.git") || return 1
608+ IFS=/ read -ra parts <<< "$1"; last=$((${#parts[@]} - 1))
609+ for ((i = 0; i < last; i++)); do [ "${#parts[i]}" -le "$nm" ] || return 1; done
610+ [ "${#parts[last]}" -le $((nm - 5)) ] || return 1
611+ local path=$P/repo.git/refs/heads/$1.lock
612+ [ "${#path}" -lt "$pm" ]
613+}
614+handover_noop_finish() {
615+ local st
616+ vcore; st=$?
617+ [ "$st" = 0 ] || die 3 "$VMSG"
618+ require_expect_owner
619+ rm -f "$P/staging"/handover.*
620+ okline
621+}
622+
623+# do_handover KEY NEW_PUB REASON: one project, already opened as $NAME at $P. KEY is the
624+# private key named as old-key. A rerun whose new public key is already current is a no-op.
625+# owner.pub is never replaced: it stays the key record 1 names. A successor that was ever
626+# an owner of this project (record 1, or any earlier SUCCESSOR new) is refused.
627+do_handover() {
628+ local key=$1 newpub=$2 reason=$3 blob newfp st f pay prev tag
629+ key_actor "$key"
630+ [ -f "$newpub" ] || die 2 "public key $newpub not found"
631+ blob=$(pubblob "$newpub") || die 2 "$newpub is not one ssh-ed25519 public key"
632+ newfp=$(ed25519_fp "$newpub") || die 2 "$newpub is not one Ed25519 public key"
633+ "$LANDREC" check reason "$reason" || die 2 "REFUSED reason"
634+ lock -s
635+ load_current || die 3 "cannot determine the current owner key: $VMSG"
636+ require_expect_owner
637+ if [ "$newfp" = "$CURRENT" ]; then
638+ # already the current key: nothing is recorded (a pending unsigned SUCCESSOR has
639+ # not switched yet, so it is finished in the branch below, not here)
640+ handover_noop_finish
641+ return 0
642+ fi
643+ unlock
644+ lock -x
645+ load_current || die 3 "cannot determine the current owner key: $VMSG"
646+ require_expect_owner
647+ if [ "$newfp" = "$CURRENT" ]; then
648+ handover_noop_finish
649+ return 0
650+ fi
651+ is_prior_owner "$newfp" && die 2 "REFUSED new: $newfp was already an owner of this project"
652+ prove_owner "$key"
653+ mend
654+ vcore; st=$?
655+ [ "$st" != 3 ] || die 3 "$VMSG"
656+ [ "$ACTOR" = "$CURRENT" ] || die 2 "key $ACTOR is not this project's current owner"
657+ is_prior_owner "$newfp" && die 2 "REFUSED new: $newfp was already an owner of this project"
658+ if [ "$st" = 10 ]; then
659+ IFS=$'\t' read -r s u k a sj p pv <<< "${LINES[N - 1]}"
660+ if [ "$k" = SUCCESSOR ]; then
661+ f=$P/records/$N
662+ [ "$(pfield new "$f")" = "$newfp" ] && [ "$(pfield old "$f")" = "$ACTOR" ] && [ "$(pfield reason "$f")" = "$reason" ] || die 3 "$VMSG"
663+ mkdir -p "$P/staging" || die 5 "staging"
664+ sign_tail "$key" handover
665+ finish_handover_pin "$newfp"
666+ stop_at after-sig
667+ rm -f "$P"/staging/handover.*
668+ vcore || die 5 "recorded, but the project does not verify: $VMSG"
669+ publish_row; okline
670+ return 0
671+ fi
672+ die 3 "$VMSG"
673+ fi
674+ [ "$st" = 0 ] || die 3 "$VMSG"
675+ [ "$newfp" != "$CURRENT" ] || die 2 "REFUSED new: already the current owner"
676+ mkdir -p "$P/staging" || die 5 "staging"
677+ tag=handover
678+ pay=$P/staging/$tag.payload
679+ "$LANDREC" successor "$NAME" "$CURRENT" "$newfp" "$blob" "$reason" > "$pay" || { rm -f "$pay"; die 2 "record refused"; }
680+ prev=$(tail -n 1 "$P/chain.tsv" | tr -d '\n' | sha256sum | cut -c1-64)
681+ sigmsg SUCCESSOR "$ACTOR" "$(subj "$newfp")" "$(sha "$pay")" "$prev" > "$P/staging/$tag.msg"
682+ rm -f "$P/staging/$tag.msg.sig"
683+ ssh-keygen -q -Y sign -n interplane -f "$key" "$P/staging/$tag.msg" >/dev/null 2>&1 || { rm -f "$P/staging/$tag".*; die 2 "signing with $key failed"; }
684+ sigok "$P/staging/$tag.msg" "$P/staging/$tag.msg.sig" "$VCURPUB" || { rm -f "$P/staging/$tag".*; die 2 "that key does not sign as the project's current owner"; }
685+ durable "$pay" "$P/staging/$tag.msg.sig" "$P/staging"
686+ stop_at after-stage
687+ add SUCCESSOR "$(subj "$newfp")" "$pay"
688+ stop_at after-record
689+ add SIG "$SEQ" "$P/staging/$tag.msg.sig"
690+ finish_handover_pin "$newfp"
691+ stop_at after-sig
692+ rm -f "$P/staging/$tag".*
693+ vcore || die 5 "recorded, but the project does not verify: $VMSG"
694+ publish_row; okline
695+}
696+
697+# --expect-owner FP may appear anywhere; --all stays a positional handover argument
698+EXPECT_OWNER=""
699+args=()
700+while [ $# -gt 0 ]; do
701+ case $1 in
702+ --expect-owner)
703+ [ -n "${2:-}" ] || die 1 "usage: --expect-owner FP"
704+ EXPECT_OWNER=$2
705+ shift 2 ;;
706+ --expect-owner=*)
707+ EXPECT_OWNER=${1#--expect-owner=}
708+ shift ;;
709+ --all)
710+ # --all is a positional handover argument, not a flag
711+ args+=("$1"); shift ;;
712+ *)
713+ args+=("$1"); shift ;;
714+ esac
715+done
716+set -- "${args[@]}"
717+if [ -n "$EXPECT_OWNER" ]; then
718+ "$LANDREC" check owner "$EXPECT_OWNER" || die 2 "REFUSED expect-owner"
719+fi
720+
721+# preflight_handover KEY NEWFP: read-only check that this project can be handed to NEWFP (or is already).
722+# Prints a reason on stderr and returns 1 on failure; does not write.
723+preflight_handover() {
724+ local key=$1 newfp=$2 st k
725+ lock -s
726+ if ! load_current; then echo "ipl: $NAME: cannot determine the current owner key: $VMSG" >&2; return 1; fi
727+ if ! pin_for "$NAME"; then echo "ipl: $NAME: owner pin file has no line for $NAME" >&2; return 1; fi
728+ if [ -n "${EXPECT_OWNER:-}" ] && [ "$EXPECT_OWNER" != "$PIN_FP" ]; then
729+ echo "ipl: $NAME: current owner pin is $PIN_FP, not $EXPECT_OWNER" >&2
730+ return 1
731+ fi
732+ if [ "$CURRENT" != "$PIN_FP" ]; then
733+ echo "ipl: $NAME: current owner is $CURRENT, not $PIN_FP" >&2
734+ return 1
735+ fi
736+ if [ "$newfp" = "$CURRENT" ]; then
737+ vcore >/dev/null || { echo "ipl: $NAME: does not verify: $VMSG" >&2; return 1; }
738+ return 0
739+ fi
740+ if is_prior_owner "$newfp"; then
741+ echo "ipl: $NAME: REFUSED new: $newfp was already an owner of this project" >&2
742+ return 1
743+ fi
744+ if [ "$ACTOR" != "$CURRENT" ]; then
745+ echo "ipl: $NAME: current owner is $CURRENT, not $ACTOR" >&2
746+ return 1
747+ fi
748+ if ! ( prove_owner "$key" ); then
749+ echo "ipl: $NAME: that key does not sign as the project's current owner" >&2
750+ return 1
751+ fi
752+ vcore >/dev/null; st=$?
753+ if [ "$st" = 10 ]; then
754+ IFS=$'\t' read -r s u k a sj p pv <<< "${LINES[N - 1]}"
755+ if [ "$k" = SUCCESSOR ] && [ "$(pfield new "$P/records/$N")" = "$newfp" ]; then
756+ return 0
757+ fi
758+ echo "ipl: $NAME: $VMSG" >&2
759+ return 1
760+ fi
761+ if [ "$st" != 0 ]; then echo "ipl: $NAME: $VMSG" >&2; return 1; fi
762+ return 0
763+}
764+
765+case ${1:-} in
766+init)
767+ [ -z "$EXPECT_OWNER" ] || die 1 "--expect-owner is for verify, land, import, handover, and catalog"
768+ [ $# = 7 ] || die 1 "usage: ipl init ROOT NAME BRANCH VISIBILITY ALIAS KEY"
769+ open_project "$2" "$3"; key_actor "$7"
770+ t=$(mktemp) || die 5 mktemp
771+ "$LANDREC" project "$NAME" "$4" "$5" "$ACTOR" "$6" "$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')" > "$t" && g check-ref-format "refs/heads/$4" || { rm -f "$t"; die 2 "record refused"; }
772+ branch_fits "$4" || { rm -f "$t"; die 2 "REFUSED branch: longer than this file system can hold as a branch"; }
773+ exec 8>> "$ROOT/init.lock" && flock -x 8 || die 5 "lock"
774+ lock -x
775+ for d in "$PR"/*/; do
776+ o=$(basename "$d"); [ "$o" = "$NAME" ] || [ "${o,,}" != "${NAME,,}" ] || { rm -f "$t"; die 2 "$NAME differs from the existing project $o only in case"; }
777+ done
778+ # an earlier init left its owner key here: only that owner goes on, whatever state it reached
779+ had_owner=0
780+ if [ -e "$P/owner.pub" ]; then had_owner=1; prove_owner "$7"; mend; fi
781+ if [ -e "$P/chain.tsv" ] && [ ! -s "$P/chain.tsv" ]; then rm -f "$P/chain.tsv"; echo "ipl: repaired: removed an empty chain file" >&2; fi
782+ if [ -e "$P/chain.tsv" ]; then
783+ # the same terms by the owner: finish an init that stopped before its signature, or, for a
784+ # project that is already complete, publish its catalog line again and answer
785+ rm -f "$t"; [ "$had_owner" = 1 ] || die 3 "a chain with no owner key beside it"
786+ vcore; st=$?
787+ [ "$st" != 3 ] || die 3 "$VMSG"
788+ [ "$DEFBR" = "$4" ] && [ "$VIS" = "$5" ] && [ "$(pfield alias "$P/records/1")" = "$6" ] || die 2 "$NAME already exists with other terms"
789+ if [ "$st" = 10 ] && [ "$N" = 1 ]; then mkdir -p "$P/staging"; sign_tail "$7" init
790+ elif [ "$st" != 0 ]; then die 3 "$VMSG"; fi
791+ else
792+ sp=$P/staging/init.payload
793+ if [ "$had_owner" = 1 ] && [ -f "$sp" ]; then
794+ # an earlier attempt staged its record: the same terms go on with it, other terms are refused
795+ [ "$(pfield branch "$sp")" = "$4" ] && [ "$(pfield visibility "$sp")" = "$5" ] && [ "$(pfield alias "$sp")" = "$6" ] && [ "$(pfield owner "$sp")" = "$ACTOR" ] ||
796+ { rm -f "$t"; die 2 "$NAME was started with other terms"; }
797+ rm -f "$t"
798+ else
799+ mkdir -p "$P/records" "$P/staging" && cp "$t" "$sp" || { rm -f "$t"; die 5 "cannot write $P"; }
800+ rm -f "$t"
801+ [ "$had_owner" = 1 ] || { cp "$7.pub" "$P/owner.pub.tmp" && mv "$P/owner.pub.tmp" "$P/owner.pub"; } || die 5 "cannot write $P"
802+ fi
803+ sigmsg PROJECT "$ACTOR" "$(subj "$NAME")" "$(sha "$sp")" GENESIS > "$P/staging/init.msg"
804+ rm -f "$P/staging/init.msg.sig"
805+ if ! { ssh-keygen -q -Y sign -n interplane -f "$7" "$P/staging/init.msg" >/dev/null 2>&1 && sigok "$P/staging/init.msg" "$P/staging/init.msg.sig"; }; then
806+ # a key that was only just put here goes again; an owner who was here before stays
807+ rm -f "$P/staging/init.msg" "$P/staging/init.msg.sig"; [ "$had_owner" = 1 ] || rm -f "$sp" "$P/owner.pub"
808+ die 2 "the key pair $7 does not sign and verify"
809+ fi
810+ durable "$sp" "$P/staging/init.msg.sig" "$P/owner.pub" "$P/staging" "$P"
811+ stop_at after-stage
812+ add PROJECT "$(subj "$NAME")" "$sp"
813+ stop_at after-record
814+ add SIG "$SEQ" "$P/staging/init.msg.sig"
815+ stop_at after-sig
816+ fi
817+ rm -f "$P"/staging/init.*
818+ vcore || die 5 "recorded, but the project does not verify: $VMSG"
819+ publish_row; okline ;;
820+import)
821+ [ $# = 8 ] || die 1 "usage: ipl import ROOT NAME BRANCH EVIDENCE_FILE NOTE_FILE REQUEST KEY"
822+ open_project "$2" "$3"; load_owner_pins; key_actor "$8"
823+ record IMPORT "$4" "" "$5" "$6" "$7" "$8" - ;;
824+land)
825+ [ $# = 10 ] || die 1 "usage: ipl land ROOT NAME BRANCH NEW SOURCE RECEIPT_FILE VERDICT_FILE REQUEST KEY [--expect-owner FP]"
826+ open_project "$2" "$3"; load_owner_pins; key_actor "${10}"
827+ record LAND "$4" "$5" "$7" "$8" "$9" "${10}" "$6" ;;
828+verify)
829+ [ $# = 3 ] || die 1 "usage: ipl verify ROOT NAME [--expect-owner FP]"
830+ open_project "$2" "$3"; load_owner_pins; lock -s
831+ vcore || die 3 "$VMSG"
832+ require_expect_owner
833+ okline ;;
834+catalog)
835+ [ $# = 2 ] || die 1 "usage: ipl catalog ROOT [--expect-owner FP]"
836+ PR=$(realpath -e -- "$2/projects" 2>/dev/null) || die 2 "no store at $2"; ROOT=${PR%/projects}; rc=0
837+ load_owner_pins
838+ for d in "$PR"/*/; do
839+ NAME=$(basename "$d")
840+ if ! admit; then echo "ipl: $NAME is not a project of this store; left out" >&2; [ -L "$PR/$NAME" ] || [ ! -d "$PR/$NAME" ] || rm -f "$PR/$NAME/catalog.row"; rc=3; continue; fi
841+ lock -s
842+ if ! vcore; then
843+ echo "ipl: $NAME does not verify; left out of the catalog" >&2
844+ rm -f "$P/catalog.row"; rc=3; continue
845+ fi
846+ if ! pin_for "$NAME"; then
847+ echo "ipl: $NAME: owner pin file has no line for $NAME; left out of the catalog" >&2
848+ rm -f "$P/catalog.row"; rc=3; continue
849+ fi
850+ if [ -n "${EXPECT_OWNER:-}" ] && [ "$EXPECT_OWNER" != "$PIN_FP" ]; then
851+ echo "ipl: $NAME: current owner pin is $PIN_FP, not $EXPECT_OWNER; left out of the catalog" >&2
852+ rm -f "$P/catalog.row"; rc=3; continue
853+ fi
854+ if [ "$CURRENT" != "$PIN_FP" ]; then
855+ echo "ipl: $NAME: current owner is $CURRENT, not $PIN_FP; left out of the catalog" >&2
856+ rm -f "$P/catalog.row"; rc=3; continue
857+ fi
858+ put_row || { echo "ipl: $NAME: catalog line could not be written; left out" >&2; rc=3; continue; }
859+ done
860+ join_catalog || die 5 "cannot publish the catalog"
861+ wc -l < "$ROOT/catalog.tsv"; exit $rc ;;
862+handover)
863+ reason=-
864+ if [ $# = 6 ]; then reason=$6
865+ elif [ $# != 5 ]; then die 1 "usage: ipl handover ROOT NAME|--all OLD_KEY NEW_PUBKEY [REASON]"
866+ fi
867+ [ -f "$5" ] || die 2 "public key $5 not found"
868+ if [ "$3" = --all ]; then
869+ PR=$(realpath -e -- "$2/projects" 2>/dev/null) || die 2 "no store at $2"; ROOT=${PR%/projects}
870+ load_owner_pins
871+ key_actor "$4"
872+ newfp=$(ed25519_fp "$5") || die 2 "$5 is not one Ed25519 public key"
873+ found=0; bad=0; names=(); fds=()
874+ for d in "$PR"/*/; do
875+ NAME=$(basename "$d")
876+ admit || continue
877+ found=1
878+ names+=("$NAME")
879+ exec {lockfd}>>"$P/lock" || die 5 "lock"
880+ flock -s "$lockfd" || die 5 "lock"
881+ fds+=("$lockfd")
882+ ALL_LOCK_FD=$lockfd preflight_handover "$4" "$newfp" || bad=1
883+ done
884+ [ "$found" = 1 ] || die 2 "no project in the store"
885+ if [ "$bad" = 1 ]; then
886+ for fd in "${fds[@]}"; do flock -u "$fd" 2>/dev/null || true; eval "exec ${fd}>&-"; done
887+ echo "ipl: --all preflight failed; nothing was recorded" >&2
888+ exit 2
889+ fi
890+ HANDOVER_DEFER_PIN=1
891+ i=0
892+ for NAME in "${names[@]}"; do
893+ admit || die 5 "project $NAME vanished during --all"
894+ ALL_LOCK_FD=${fds[$i]} do_handover "$4" "$5" "$reason"
895+ i=$((i + 1))
896+ done
897+ for fd in "${fds[@]}"; do flock -u "$fd" 2>/dev/null || true; eval "exec ${fd}>&-"; done
898+ announce_pin '*' "$newfp"
899+ update_owner_pin_all "$ACTOR" "$newfp" "${names[@]}"
900+ else
901+ open_project "$2" "$3"
902+ load_owner_pins
903+ do_handover "$4" "$5" "$reason"
904+ fi
905+ ;;
906+*) die 1 "usage: ipl init|import|land|verify|catalog|handover ..." ;;
907+esac

ipl/om/landrec.om

new file mode 100644
@@ -0,0 +1,466 @@
1+om2
2+note landrec.om: the one place that decides what a native Interplane record may say.
3+note landrec project NAME BRANCH VISIBILITY OWNER ALIAS NONCE
4+note landrec land NAME BRANCH OLD NEW RECEIPT VERDICT REQUEST
5+note landrec successor NAME OLD NEW PUB REASON
6+note landrec check name|branch|request|owner|pub|reason VALUE exit 0 when VALUE satisfies that rule, else 1
7+note project and land check every field and print the canonical payload (the exact bytes a chain
8+note record commits to) on stdout, exit 0. A field that breaks its rule prints "REFUSED <field>" on
9+note stderr, exit 1, and nothing on stdout. Wrong word or argument count: usage on stderr, exit 2.
10+note Field rules. NAME: one or more bytes of letters digits . _ - starting with a letter or digit, never
11+note ending in a dot (two names that differ only in case are refused by the store, not here).
12+note BRANCH: one or more bytes of letters digits . _ - / ; no leading - . / ; no trailing . / ; no ".."
13+note "//" or "/." inside; no part ending in ".lock" (git refuses those). OLD, NEW: 40 lowercase hex
14+note digits (a commit; OLD is 40 zeros when the branch has no head yet). RECEIPT, VERDICT: 64
15+note lowercase hex digits (SHA-256 of the file). REQUEST: one or more bytes of letters digits . _ -
16+note (the caller's own id; the same id never lands twice). NONCE: 32 lowercase hex digits, random,
17+note made once when the project is created, so that projects created separately get, by chance, different ids.
18+note VISIBILITY: public or private. OWNER, and successor OLD and NEW: an SSH key fingerprint, SHA256:
19+note and 43 base64 characters. PUB: 68 characters of base64 (A-Za-z0-9+/), the blob of one ssh-ed25519
20+note public key with no comment (51 decoded bytes, no padding). REASON: - or the same bytes as REQUEST.
21+note ALIAS: - or the project's old id, rad:z and 20..60 letters and digits (history lookups only).
22+note No field can hold a space, a tab or a line feed, so a payload line is never ambiguous.
23+note Sizes. No field has a length chosen here. (The store writes a name or branch longer than the
24+note chain format's 128-byte subject field into that field as a digest, and refuses only what the
25+note file system cannot hold as a folder or a branch.)
26+note Nothing else has a size chosen here. ab holds one argument and is 131072 bytes, the most Linux
27+note lets one argument be (MAX_ARG_STRLEN, terminator included), so no argument a process can be
28+note started with is cut or refused for its length. ob holds one payload. The longest is a land
29+note record whose name, branch and request are each the longest argument, 131071 bytes: 18 for the
30+note first line, 131080 + 131079 + 131080 for those three lines, 45 + 45 for old and new, 73 + 73 for
31+note receipt and verdict, 393493 bytes in all; ob is 400000. The loop bounds 200000 and 2000000 are
32+note above those sizes. (A run-time pool would say this more directly, but at this compiler pin
33+note argread refuses a pool as its buffer, error 7.)
34+global ab uchar 131072
35+global ob uchar 400000
36+global ol ulong 1
37+text tland "land"
38+text tproj "project"
39+text tcheck "check"
40+text tname "name"
41+text tbr "branch"
42+text trq "request"
43+text hland "interplane-land 1\n"
44+text hproj "interplane-project 1\n"
45+text kproj "project "
46+text kbranch "branch "
47+text kold "old "
48+text knew "new "
49+text krec "receipt "
50+text kver "verdict "
51+text kreq "request "
52+text kvis "visibility "
53+text kown "owner "
54+text kali "alias "
55+text knon "nonce "
56+text tref "REFUSED "
57+text tnl "\n"
58+text tpub "public"
59+text tpriv "private"
60+text tsha "SHA256:"
61+text trad "rad:z"
62+text tsucc "successor"
63+text hsucc "interplane-successor 1\n"
64+text kpub "pub "
65+text kreason "reason "
66+text tpubk "pub"
67+text treason "reason"
68+text town "owner"
69+text tusage "usage: landrec project NAME BRANCH VISIBILITY OWNER ALIAS NONCE | landrec land NAME BRANCH OLD NEW RECEIPT VERDICT REQUEST | landrec successor NAME OLD NEW PUB REASON | landrec check name|branch|request|owner|pub|reason VALUE\n"
70+fn islow c uchar to bool
71+ret and ge c 97 le c 122
72+end
73+fn isup c uchar to bool
74+ret and ge c 65 le c 90
75+end
76+fn isdig c uchar to bool
77+ret and ge c 48 le c 57
78+end
79+fn isaln c uchar to bool
80+ret or (islow c) (or (isup c) (isdig c))
81+end
82+fn nope b bool to bool
83+if b
84+ret false
85+end
86+ret true
87+end
88+note loada: argument i into ab; the length, or a negative host error
89+fn loada i ulong to long
90+ret argread i ab 0 131072
91+end
92+note same: ab[0,n) equals the text t
93+fn same t view uchar * n ulong to bool
94+if ne n len t
95+ret false
96+end
97+j = ulong 0
98+while lt j n bound 256
99+if ne get ab j get t j
100+ret false
101+end
102+j = add j 1
103+end
104+ret true
105+end
106+fn hexn n ulong want ulong to bool
107+if ne n want
108+ret false
109+end
110+j = ulong 0
111+while lt j n bound 256
112+c = get ab j
113+if nope or (isdig c) (and ge c 97 le c 102)
114+ret false
115+end
116+j = add j 1
117+end
118+ret true
119+end
120+fn namec c uchar to bool
121+ret or (isaln c) (or eq c 46 (or eq c 95 eq c 45))
122+end
123+fn isname n ulong to bool
124+if eq n 0
125+ret false
126+end
127+f = get ab 0
128+if nope and (isaln f) (ne get ab sub n 1 46)
129+ret false
130+end
131+j = ulong 0
132+while lt j n bound 200000
133+if nope namec get ab j
134+ret false
135+end
136+j = add j 1
137+end
138+ret true
139+end
140+fn refc c uchar to bool
141+ret or (isaln c) (or eq c 46 (or eq c 95 (or eq c 45 eq c 47)))
142+end
143+note lockat: ab[e-5,e) is ".lock"
144+fn lockat e ulong to bool
145+if lt e 5
146+ret false
147+end
148+s = sub e 5
149+if ne get ab s 46
150+ret false
151+end
152+if ne get ab add s 1 108
153+ret false
154+end
155+if ne get ab add s 2 111
156+ret false
157+end
158+if ne get ab add s 3 99
159+ret false
160+end
161+ret eq get ab add s 4 107
162+end
163+fn isref n ulong to bool
164+if eq n 0
165+ret false
166+end
167+f = get ab 0
168+if or eq f 45 or eq f 46 eq f 47
169+ret false
170+end
171+l = get ab sub n 1
172+if or eq l 46 eq l 47
173+ret false
174+end
175+p = uchar 0
176+j = ulong 0
177+while lt j n bound 200000
178+c = get ab j
179+if nope refc c
180+ret false
181+end
182+if and eq c 46 or eq p 46 eq p 47
183+ret false
184+end
185+if and eq c 47 eq p 47
186+ret false
187+end
188+if and eq c 47 (lockat j)
189+ret false
190+end
191+p = c
192+j = add j 1
193+end
194+ret nope lockat n
195+end
196+fn isreq n ulong to bool
197+if eq n 0
198+ret false
199+end
200+j = ulong 0
201+while lt j n bound 200000
202+if nope namec get ab j
203+ret false
204+end
205+j = add j 1
206+end
207+ret true
208+end
209+fn isfp n ulong to bool
210+if ne n 50
211+ret false
212+end
213+j = ulong 0
214+while lt j 7 bound 8
215+if ne get ab j get tsha j
216+ret false
217+end
218+j = add j 1
219+end
220+while lt j 50 bound 64
221+c = get ab j
222+if nope or (isaln c) (or eq c 43 eq c 47)
223+ret false
224+end
225+j = add j 1
226+end
227+ret true
228+end
229+fn isalias n ulong to bool
230+if eq n 0
231+ret false
232+end
233+if and eq n 1 eq get ab 0 45
234+ret true
235+end
236+if or lt n 25 gt n 65
237+ret false
238+end
239+j = ulong 0
240+while lt j 5 bound 8
241+if ne get ab j get trad j
242+ret false
243+end
244+j = add j 1
245+end
246+while lt j n bound 256
247+if nope isaln get ab j
248+ret false
249+end
250+j = add j 1
251+end
252+ret true
253+end
254+fn isb64c c uchar to bool
255+ret or (isaln c) (or eq c 43 eq c 47)
256+end
257+note ispub: the 68-character ssh-ed25519 public-key blob, no padding, no comment
258+fn ispub n ulong to bool
259+if ne n 68
260+ret false
261+end
262+j = ulong 0
263+while lt j n bound 128
264+if nope isb64c get ab j
265+ret false
266+end
267+j = add j 1
268+end
269+ret true
270+end
271+fn isreason n ulong to bool
272+if and eq n 1 eq get ab 0 45
273+ret true
274+end
275+ret isreq n
276+end
277+note valid: field rule k for ab[0,n)
278+fn valid k ulong n ulong to bool
279+if eq k 1
280+ret isname n
281+end
282+if eq k 2
283+ret isref n
284+end
285+if eq k 3
286+ret hexn n 40
287+end
288+if eq k 4
289+ret hexn n 64
290+end
291+if eq k 5
292+ret isreq n
293+end
294+if eq k 6
295+ret isfp n
296+end
297+if eq k 7
298+ret or (same tpub n) (same tpriv n)
299+end
300+if eq k 8
301+ret isalias n
302+end
303+if eq k 9
304+ret hexn n 32
305+end
306+if eq k 10
307+ret ispub n
308+end
309+if eq k 11
310+ret isreason n
311+end
312+ret false
313+end
314+note room: a payload never needs more than ob; exit 91 says this note is wrong
315+fn room n ulong to void
316+if gt n 400000
317+exit 91
318+end
319+end
320+fn emit t view uchar * to void
321+o = get ol 0
322+m = len t
323+room add o m
324+j = ulong 0
325+while lt j m bound 4096
326+put ob add o j get t j
327+j = add j 1
328+end
329+put ol 0 add o m
330+end
331+fn emita n ulong to void
332+o = get ol 0
333+room add o n
334+j = ulong 0
335+while lt j n bound 200000
336+put ob add o j get ab j
337+j = add j 1
338+end
339+put ol 0 add o n
340+end
341+fn errw t view uchar * to void
342+k = write 2 t 0 len t
343+end
344+note putf: argument i must satisfy rule k; append "key value\n" to the payload, or refuse
345+fn putf i ulong key view uchar * k ulong to void
346+r = loada i
347+if lt r 0
348+errw tref
349+errw key
350+errw tnl
351+exit 1
352+end
353+n = ulong r
354+if nope valid k n
355+errw tref
356+errw key
357+errw tnl
358+exit 1
359+end
360+emit key
361+emita n
362+emit tnl
363+end
364+fn flush to void
365+e = get ol 0
366+p = ulong 0
367+while lt p e bound 2000000
368+k = write 1 ob p sub e p
369+if le k 0
370+exit 90
371+end
372+p = add p ulong k
373+end
374+end
375+note docheck: landrec check RULE VALUE
376+fn docheck to int
377+r = loada 2
378+if lt r 0
379+ret 2
380+end
381+m = ulong r
382+k = ulong 0
383+if same tname m
384+k = 1
385+end
386+if same tbr m
387+k = 2
388+end
389+if same trq m
390+k = 5
391+end
392+if same town m
393+k = 6
394+end
395+if same tpubk m
396+k = 10
397+end
398+if same treason m
399+k = 11
400+end
401+if eq k 0
402+ret 2
403+end
404+v = loada 3
405+if lt v 0
406+ret 1
407+end
408+if valid k ulong v
409+ret 0
410+end
411+ret 1
412+end
413+fn main to int
414+put ol 0 0
415+c = argcnt
416+if lt c 2
417+errw tusage
418+ret 2
419+end
420+r = loada 1
421+if lt r 0
422+errw tusage
423+ret 2
424+end
425+m = ulong r
426+isl = same tland m
427+isp = same tproj m
428+if and (same tcheck m) eq c 4
429+ret docheck
430+end
431+if and isl eq c 9
432+emit hland
433+putf 2 kproj 1
434+putf 3 kbranch 2
435+putf 4 kold 3
436+putf 5 knew 3
437+putf 6 krec 4
438+putf 7 kver 4
439+putf 8 kreq 5
440+flush
441+ret 0
442+end
443+if and isp eq c 8
444+emit hproj
445+putf 2 kproj 1
446+putf 3 kbranch 2
447+putf 4 kvis 7
448+putf 5 kown 6
449+putf 6 kali 8
450+putf 7 knon 9
451+flush
452+ret 0
453+end
454+if and (same tsucc m) eq c 7
455+emit hsucc
456+putf 2 kproj 1
457+putf 3 kold 6
458+putf 4 knew 6
459+putf 5 kpub 10
460+putf 6 kreason 11
461+flush
462+ret 0
463+end
464+errw tusage
465+ret 2
466+end

ipl/reviews/4658e80a-codex.md

new file mode 100644
@@ -0,0 +1,75 @@
1+# Review of 4658e80a2ee0d004a86583691a2a0c463ea08bd6
2+
3+Reviewer: omp consultant (consult-codex), model openai-codex/gpt-6-astra, as it stated. Read-only
4+source review, nothing executed by the reviewer. Author: omp, anthropic/claude-fable-5-2.
5+Verdict: MERGE_AFTER_FIX (for the trial implementation, not for publication or installation).
6+
7+A second review of 9ed74e8f by the omp `reviewer` agent ran on anthropic/claude-fable-5-2, the
8+author's own provider, and said so itself: it does not count as the independent review. Its findings
9+(REJECT, with executed proofs under /tmp/ipl-review.6vUQY3) overlap the Codex ones; two were new and
10+are answered at the end.
11+
12+Author's reply. "Gate" is tests/run.sh; case names are in its output.
13+
14+Earlier findings the reviewer said were still open:
15+1. Pending-ref recovery trusted the public key file. FIXED: before anything is changed for a caller
16+ (landing, finishing, repairing) the key must sign a fresh message that verifies against owner.pub
17+ (`prove_owner`). Gate: pending-ref-not-for-mixed-pair, pending-ref-mixed-untouched.
18+3. Historical IMPORT replay, and "answers as the first time". FIXED: an import request is looked up
19+ before the present branch head is read; the contract now says a repeated request is answered with
20+ the project's present state. Gate: import-replay-after-landings, import-replay-added-nothing.
21+7. Recovery claim wider than the code. FIXED and narrowed: sync failures stop the landing (exit 5); an
22+ empty chain file lets init start over; a torn last line is cut on the owner's next call; the contract
23+ lists exactly these five leftovers and says everything else is refused whole. The gate now stops a
24+ real landing at each write boundary (IPL_TEST_STOP, which can only end the program early) instead
25+ of only constructing the states. Gate: stop-after-stage/-record/-sig (seen, closed to others, not
26+ for another key, finished, result, catalog follows), init-stop-*, torn-*, empty-chain-init.
27+ ANSWERED, not fixed: a short write inside the chain program itself is simulated by appending a
28+ partial line; the chain program's own write path was not fault-injected.
29+9. "reads the chain once" was wrong in my reply: verify reads it through the chain program and again
30+ with mapfile, both under the project's shared lock. The wording is withdrawn; the lock is what
31+ makes the two reads agree.
32+12. Request cap. FIXED: the request id has no size chosen by this store. landrec's argument buffer is
33+ 131072 bytes, the most Linux allows one argument to be, and staging names come from a digest of the
34+ request. Gate: rec-request-longest, rec-request-longest-whole, no-request-bad-byte-late. The first
35+ attempt used a run-time pool; at this compiler pin `argread` refuses a pool as its buffer (error 7),
36+ which is recorded in landrec.om and is a gap for the compiler lane. Name and branch stay at 128
37+ because that is the chain format's subject field: an inherited cap in our own software, now
38+ described as such in CONTRACT.md, not as a boundary.
39+
40+New findings:
41+F1. see 1 above.
42+F2. Annotated tag object as a head. FIXED: the object itself must be of type commit, when landing and
43+ when verifying. Gate: no-tag-object, tag-added-nothing, tag-commit-control.
44+F3. see 7 above.
45+F4. heal changed files before authentication. FIXED: restoring a staged payload and cutting a torn
46+ line happen only after `prove_owner`. Gate: staged-not-restored-for-other-key, staged-still-staged,
47+ torn-not-cut-for-other-key, torn-still-there.
48+F5. see 3 above.
49+F6. Project id depended on an unsigned time. FIXED: the id is the digest of record 1's payload, which
50+ is signed and now carries a random nonce. Gate: id-is-payload-digest, no-nonce-*. The contract says
51+ plainly that times in a chain are not signed facts.
52+F7. Catalog stale after a landing; admitted what verify refuses. FIXED: every committed change rewrites
53+ the project's catalog line and the catalog; the catalog and verify share one admission check.
54+ Gate: stop-*-catalog-follows, no-linked-repository, catalog-leaves-out-linked, catalog-race-whole
55+ (which caught a real race in my first version of this fix: two catalog runs shared one temporary
56+ row file; rows are now written under the project lock with unique names, and the gate passed 6 of
57+ 6 runs afterwards).
58+F8. see 12 above.
59+
60+Other points:
61+- "Unchanged" exits: ANSWERED in CONTRACT.md: unchanged means chain, records and branches; a refused
62+ landing may have copied objects that no branch points at. FETCH_HEAD is no longer written.
63+- Dependency versions: FIXED, the gate prints git, ssh, bash, coreutils and util-linux versions.
64+- Snapshot provenance: FIXED, PIN names the snapshot source digest, build.sh builds it and writes
65+ bin/BUILD.sha256, and the import refuses to run unless bin/ matches that file.
66+- Import completeness: FIXED, a project the old store cannot be asked about is a failure of the run.
67+- Receipts: see READY.json in the lane's handoff folder, named in the board line for this head.
68+- DESIGN line 57 "An Omega tool": ANSWERED in the status line and README: the record rules are Omega,
69+ the orchestration is shell and labelled unfinished migration.
70+- Git environment: FIXED, git runs under `env -i` with an explicit environment. Gate: env-not-inherited.
71+
72+From the same-provider review of 9ed74e8f, not already covered:
73+- IPL_CHAIN / IPL_LANDREC let the rule programs be replaced. FIXED: removed; ipl uses only the two
74+ programs beside it, and the gate runs a copy of ipl beside the binaries it built.
75+- Two copies of DESIGN.md. FIXED: the handoff folder now holds a pointer to this repository's file.

ipl/reviews/6560f9ab-codex.md

new file mode 100644
@@ -0,0 +1,40 @@
1+# Review of 6560f9ab4dad516c49000d851cc970c0e1c77bdb
2+
3+Reviewer: omp consultant (consult-codex), model openai-codex/gpt-6-astra, as it stated. Read-only
4+source review of a clean clone at that head; nothing executed by the reviewer. Author: omp,
5+anthropic/claude-fable-5-2. Verdict: MERGE_AFTER_FIX for the local-trial claim; all eight findings
6+of the fourth review closed in source.
7+
8+Author's reply. "Gate" is tests/run.sh.
9+
10+Must fix for the trial claim:
11+1. The receipt called the expected refusals "the operator's stated exclusions". FIXED: they are the
12+ runner's expectation and the receipt says so (`refusals_the_runner_expected`). Drake has said
13+ nothing about `.github`; leaving it out is the consequence of the name rule and is reported to
14+ him as an open point, not presented as his decision.
15+2. Host-program lists incomplete. FIXED: the header of ipl and README name awk, sed, cmp, getconf and
16+ the coreutils programs used; the gate prints the versions of git, ssh, bash, coreutils,
17+ util-linux, awk, sed, diffutils and libc's getconf.
18+3. The receipt must finish. DONE for 6560f9ab: receipt-6560f9ab4dad/READY.json, result "every step
19+ below did what it should" (gate 247 cases, import 105 OK, 1 left out on purpose, 1 refused as
20+ expected, 105 heads the same as the old store). A receipt for the head that carries this reply is
21+ written the same way.
22+4. Test the removal of a key this call put there. DONE. Gate: no-fresh-init-with-mixed-pair,
23+ mixed-init-left-nothing.
24+5. Wrong-compiler control with a real other compiler. DONE: the receipt refuses to start unless
25+ WRONG_OMC is an executable whose digest differs from PIN's.
26+6. A FAILED READY.json when inputs are missing. DONE: counts default to 0 and the files are created
27+ empty so that the receipt is still written, with `result` FAILED.
28+7. Receipt header overstated. FIXED: "every project of the old store that this node signed".
29+ Also added: the verified catalog and the import's OK lines are compared by name, not only by count.
30+8. One trial root per head. DONE in practice and in the text: CONTRACT.md no longer types a path, the
31+ receipt names the trial root, and the run for each head uses a root of its own.
32+
33+Leftovers named under F1 to F7: the receipt's own invocation is now the first line of commands.txt;
34+the ipl header says an init has four stop points; the nonce note in landrec.om says "by chance".
35+
36+Before this could become the publishing route: ACCEPTED as written, with two additions from this
37+review to the work list: an init's staged payload is synced only together with the owner key (a
38+power loss between the two writes is not covered), and the 131072-byte argument size is Linux's on
39+4 KiB pages, which is what this host has; on other page sizes the buffer must be sized from the
40+running kernel, or be a run-time pool once the compiler lets argread fill one.

ipl/reviews/810c802a-codex.md

new file mode 100644
@@ -0,0 +1,54 @@
1+# Review of 810c802ae2ad0caec934a387e0c6abb4fd9f9697
2+
3+Reviewer: omp consultant (consult-codex), model openai-codex/gpt-6-astra, as it stated. Read-only
4+source review of a fresh clone at that head; nothing executed by the reviewer. Author: omp,
5+anthropic/claude-fable-5-2. Verdict: MERGE_AFTER_FIX for the trial implementation.
6+
7+Author's reply. "Gate" is tests/run.sh; case names are in its output.
8+
9+R1 HIGH. A linked project folder made `ipl catalog` delete a file behind the link. FIXED: nothing is
10+ removed behind a link. Gate: linked-folder-untouched.
11+R2 MEDIUM. An init stopped before its first record could be taken over by another key. FIXED: once an
12+ init has put an owner key in the folder, only that key goes on, in every state. Gate, for each of
13+ four stop points: init-stop-*-not-other-key, init-stop-*-owner-kept, init-stop-*-finished.
14+R3 MEDIUM. A completed init could not be repeated to finish its catalog line. FIXED: init with the same
15+ terms by the owner is safe to repeat; on a complete project it publishes the line and answers,
16+ appending nothing. Gate: init-stop-after-sig-finished, init-stop-*-in-catalog, init-again-same-terms,
17+ init-again-adds-nothing, init-again-other-terms, init-again-other-key.
18+R4 MEDIUM. "Unchanged" exits could follow a repair. ANSWERED by making the repair an explicit outcome
19+ rather than by reordering it: a request cannot be judged before the leftovers of an interruption
20+ are put right, so on the owner's call the repair happens first, is said on stderr, and CONTRACT.md
21+ states that it stays even when the request is then refused. Gate: torn-then-altered-request,
22+ repair-was-announced.
23+R5 MEDIUM. Interruption coverage and durability overstated. FIXED in wording and extended in coverage:
24+ README and CONTRACT say five chosen stop points, not every write, not a power cut. New stop points
25+ between the chain line and its payload file (mid-record) and after the branch moved (after-ref), and
26+ after-sig for init. Catalog line, catalog file and a new chain's folder are now synced after their
27+ renames. Gate: stop-mid-record-*, stop-after-ref-*, init-stop-mid-record-*, init-stop-after-sig-*.
28+ NOT DONE and said so: a short write inside the chain program, and loss of power.
29+R6 MEDIUM. Import completeness. FIXED for discovery: a missing old store or an unreadable repository is
30+ a failure of the run, an empty store is an error, and every repository this node signed gets a line
31+ in import.tsv. ANSWERED for `.github`: it is refused by the name rule (leading dot), DESIGN.md now
32+ says the import is 105 of 106, and the receipt lists it under `refused`. Taking it in under another
33+ name would be a decision about that project, not a property of the tool.
34+R7 MEDIUM. No complete receipt. FIXED: tools/receipt.sh runs build, gate, wrong-compiler control,
35+ import, full catalog verification and an independent head comparison from a clean clone of the
36+ exact head and writes READY.json from what it measured. The earlier evidence folder for 810c802a
37+ held only the two gate logs; the trial store standing at that time was not made by that head alone
38+ (I changed binaries under a running import, which is why that run reported eight refusals), and no
39+ claim rests on it.
40+R8 MEDIUM. Inherited 128-byte caps on name and branch. FIXED in this store: landrec has no length rule
41+ for them; a name or branch longer than the chain format's subject field is written there as its
42+ digest and in full in the signed payload; only what the file system cannot hold is refused, with
43+ the number read from the file system. Gate: rec-name-129, rec-branch-129, long-name-init,
44+ long-name-subject-is-digest, long-name-verify, no-name-longer-than-file-names, long-branch-lands,
45+ long-branch-verifies, no-branch-part-too-long. The chain format's own 128 (and its 1,023-byte line)
46+ remains a cap in the forge's chain.om; this store no longer passes it on to users.
47+R9 LOW. "Never share an id". FIXED in CONTRACT.md: different by chance, and a copy keeps its id.
48+
49+Other points:
50+- Staging "empty otherwise": FIXED in CONTRACT.md.
51+- Order of checks in the prose: FIXED in CONTRACT.md (arguments, owner proof, repair, verification).
52+- Import uses rad and jq: FIXED, the import prints their versions; its git calls on the old store run
53+ with a clean environment.
54+- Earlier finding 12 and F8: see R8.

ipl/reviews/9ed74e8f-codex.md

new file mode 100644
@@ -0,0 +1,71 @@
1+# Review of 9ed74e8f5d115d74a58be28fc8800fb969492d45
2+
3+Reviewer: omp consultant (consult-codex), model openai-codex/gpt-6-astra, as it stated. Read-only
4+source review, nothing executed by the reviewer. Author: omp, anthropic/claude-fable-5-2.
5+Verdict: REJECT. Full text: agent output Step1Codex of the authoring session, findings summarised here.
6+
7+Author's reply, finding by finding. "Gate" is tests/run.sh; case names are in its output.
8+
9+1. HIGH replay moved refs before authenticating caller or request. FIXED. A request is looked up only
10+ among records of a project that verifies (or is in one of two named pending states), after the
11+ caller's key is shown to be the owner's. Gate: pending-ref-not-for-other-key, pending-sig-not-for-other-key,
12+ pending-sig-not-for-mixed-pair, pending-sig-untouched, payload-gone-refused, payload-gone-untouched.
13+2. HIGH request ids with a line feed matched other requests. FIXED. Name, branch and request are checked
14+ by landrec before any lookup or path use. Gate: check-request-newline, no-request-newline.
15+3. MEDIUM altered retries accepted; old retries failed. FIXED. A request is the same only with the same
16+ kind, branch, head, receipt and verdict; a completed one answers and moves nothing. Gate:
17+ replay-other-verdict, replay-as-import, replay-historical, replay-historical-moved-nothing.
18+4. HIGH project names escaped the store. FIXED. The name is checked first; the project path is resolved
19+ under ROOT/projects and symlinks are refused; init validates everything before writing. Gate:
20+ no-traversal-verify, no-traversal-land, no-symlink-project, no-bad-init-name, rsa-init-wrote-nothing.
21+5. HIGH SOURCE could be an option or a transport. FIXED. Only `-` or an absolute local directory; git is
22+ called with --end-of-options, a file:// URL, every transport but file disabled, no user or system
23+ configuration, no hooks, no replace objects. Gate: no-source-option, no-source-remote, no-source-ext,
24+ source-ran-nothing.
25+6. HIGH signing failure could leave records; ref moved before the signature was checked. FIXED. The
26+ signature is made over a message known before anything is appended (kind, actor, subject, payload
27+ digest, previous line digest), verified against the owner's key, and only then are the record and
28+ its SIG appended; the branch moves last. Append failures are checked. Gate: no-mismatched-key-pair,
29+ crafted-add-nothing, no-other-key.
30+7. HIGH crash recovery covered only the ref window. FIXED for the windows this version can leave:
31+ payload staged and synced before the chain append; PENDING_SIG and PENDING_REF are named states that
32+ only the same request by the owner finishes; a payload that did not reach records/ is restored from
33+ staging; one that is gone refuses the project whole. Gate: the "interruptions" section (pending-*,
34+ payload-lost-*, payload-gone-*, half-init-*). ANSWERED, not claimed: these states are constructed in
35+ the gate, not produced by killing the process at each write; fault injection inside the Omega
36+ version is the place for that.
37+8. HIGH branch names git cannot update; namespace conflicts. FIXED. landrec refuses parts ending in
38+ .lock; ipl also asks git check-ref-format and refuses a new branch that is a parent or child of an
39+ existing one, before recording. Gate: no-branch-lock, no-branch-lock-part, no-branch-lock-land,
40+ no-branch-under-existing, race-topic-child-refused.
41+9. HIGH init, readers and catalog outside the locking. FIXED. init takes a store-wide init lock and the
42+ project lock; verify takes the project lock shared and reads the chain once; catalog takes its own
43+ lock, writes a uniquely named file, and checks the rename. Gate: catalog-race-whole, half-init-*.
44+10. MEDIUM verify authenticated bytes, not schema or binding. FIXED. verify re-derives every payload
45+ through landrec and compares bytes; binds project name to the folder, subject to the payload, actor
46+ to the owner on every record; checks each landing starts from the recorded head and is a
47+ fast-forward; refuses a request id used twice; checks every recorded branch. Gate:
48+ tamper-signed-but-malformed, tamper-copied-under-other-name, tamper-last-actor,
49+ tamper-second-branch-removed.
50+11. MEDIUM Ed25519 not enforced. FIXED. Gate: no-rsa-owner.
51+12. MEDIUM hard caps. ANSWERED and reported, per the no-caps rule. Name, branch and request are bounded
52+ at 128 bytes because name and branch are written as the subject field of a chain record and the
53+ forge's chain format holds a subject of at most 128 bytes (chain.om, BAD code 8). That bound
54+ belongs to the chain format, another lane's source; this store does not add a smaller one any more
55+ (it had 64 and 100). The cap itself (128, and the chain's 1,023-byte line) is reported to the
56+ chain's owner as a cap to remove or justify. Gate: rec-name-128, no-name-129.
57+
58+Claims and gaps:
59+- CONTRACT exit 3 after changes: FIXED, the exit table now has a state column and exit 5 is the only
60+ "possibly unfinished" one.
61+- DESIGN freshness overclaim: FIXED in DESIGN.md and stated in CONTRACT ("does not prove").
62+- DESIGN status lines stale: FIXED.
63+- README build left no binaries: FIXED, build.sh.
64+- Dependency versions absent: ANSWERED. Versions are facts of the host, so the gate prints the ones it
65+ ran with instead of a typed list.
66+- Import "ours" filter: FIXED, the sole delegate must be this node's key.
67+- Import lost the snapshot exit status: FIXED.
68+- No filed gate or trial receipts: FIXED, see the READY record for this lane.
69+
70+Not fixed by intent: `ipl` is still shell. It is labelled unfinished migration in the file, README and
71+CONTRACT; moving its decisions into Omega is the next piece of work on this step.

ipl/reviews/d56cf19a-codex.md

new file mode 100644
@@ -0,0 +1,46 @@
1+# Review of d56cf19a226e9911c293f737c0bc7a86e95619ff
2+
3+Reviewer: omp consultant (consult-codex), model openai-codex/gpt-6-astra, as it stated. Read-only
4+source review of a clean clone at that head; nothing executed by the reviewer. Author: omp,
5+anthropic/claude-fable-5-2. Verdict: MERGE_AFTER_FIX for the local-trial claim.
6+
7+Author's reply. "Gate" is tests/run.sh; case names are in its output.
8+
9+Must fix for the trial claim:
10+F1 HIGH. Receipt success ignored the import and a failed write. FIXED: the receipt passes only if every
11+ step has the exit it should, the inventory adds up (every line is OK, left out on purpose, or
12+ refused; the verified catalog holds every OK project and nothing else), the refusals are exactly
13+ the ones named on the command line, and READY.json was written. READY.json carries `result`, which
14+ says FAILED when any of that is not so.
15+F2 HIGH. Receipt files could be overwritten; placeholders instead of commands; "throwaway key" asserted.
16+ FIXED: the receipt folder and the trial store must not exist (mkdir without -p; refusal otherwise);
17+ commands.txt holds each command as run; the trial key is made by the run itself and its
18+ fingerprint is in the receipt.
19+F3 MEDIUM. A failed signing on an init retry removed an established owner. FIXED: only an owner key
20+ that this same call put there is taken away again. Gate: init-stop-*-not-mixed-pair,
21+ init-stop-*-owner-still-kept.
22+F4 MEDIUM. A staged init could be retried with other terms; a torn first line needed two calls. FIXED:
23+ a staged init record is kept and its terms compared; a torn first line is cut and the init
24+ completes in the same call, and removing an empty chain file is announced. Gate:
25+ init-stop-*-not-other-terms (all four stop points), torn-first-line-finished,
26+ torn-first-line-two-records.
27+F5 MEDIUM. Import inventory incomplete. FIXED: an empty or unreadable store is an error (nullglob, a
28+ checked for-each-ref instead of show-ref), a project this node signed but does not solely own
29+ gets a SKIP line with that reason, and the delegate is compared exactly.
30+F6 MEDIUM. Aggregate payload cap; file-system checks. FIXED: landrec's payload buffer holds the longest
31+ payload three longest arguments can make (393493 bytes, the sum is in the source and the gate
32+ measures it); branch length is checked in one place, applied at init, import and land, with
33+ folder parts allowed the full file-name length, the last part five bytes less for git's .lock,
34+ and the real path compared with the path limit. Gate: rec-all-longest, rec-all-longest-whole,
35+ long-branch-folder-part, no-default-branch-too-long, long-default-refusal-wrote-nothing.
36+F7 LOW. Coverage and staging wording. FIXED: CONTRACT.md lists the five landing stops and four init
37+ stops and what each one shows, separately; staging is described per request; the header of ipl
38+ and the nonce note in landrec.om are corrected.
39+F8 LOW. "105 of 106" typed in DESIGN.md. FIXED: the count is only in the receipt of the head it was
40+ measured at; DESIGN.md names the one known exclusion and points at the receipt.
41+
42+Before this could become the publishing route (the reviewer's list, none of it claimed here):
43+evidence admission (reading receipts and verdicts, exact-head binding, reviewer identity); the
44+decisions out of shell into Omega; durability under power loss and short writes; owner anchoring,
45+grants, revocation, serving, mirror checkpoints; keeping the evidence itself retrievable, not only
46+its digests. ACCEPTED as the work list for steps 1b to 4; not attempted in this head.

ipl/tests/import-identity.sh

new file mode 100755
@@ -0,0 +1,83 @@
1+#!/bin/bash
2+# tests/import-identity.sh REFERENCE_ROOT OLD_STORAGE NID RID...: the import that reads the identity
3+# document with git (no `rad` program) must give what the earlier `rad inspect` route gave.
4+# REFERENCE_ROOT is a store made by the old route (the 2026-11-13 trial store). For each RID, a scratch
5+# old store holds only that repository (a symlink into OLD_STORAGE, read only), tools/import-radicle.sh
6+# runs with IMPORT_NID=NID and a scratch key, and the test compares with the reference:
7+# - the import.tsv line, byte for byte;
8+# - for an imported project: record 1 with only the owner and nonce lines removed (they name the
9+# signing key and a fresh random nonce); the evidence file's digests of every migration file that
10+# holds no path; the files that do hold paths (every *.argv, the snapshot's argument vectors as
11+# u16le argc then u16le length and bytes per argument, and clone.stderr) decoded, with the old
12+# repository's path replaced by OLDSTORE and the store root by ROOT, since those two paths differ
13+# between the runs by construction; the note's first line without its date; the catalog line
14+# without its id (a digest over record 1); every ref of repo.git; and `ipl verify`.
15+# A RID whose head moved in OLD_STORAGE after the reference was made cannot be compared and is refused
16+# as an argument (exit 2). Needs bin/ built by build.sh with the snapshot source.
17+# Negative controls: a reference line with one field changed, and a decoded argv with one argument
18+# changed, must not compare equal.
19+# Prints PASS/FAIL per check, ends "IDENTITY PASS checks=N" (exit 0) or "IDENTITY FAIL ..." (exit 1).
20+set -u
21+cd "$(dirname "$0")/.." || exit 2
22+REF=${1:?REFERENCE_ROOT} OLDS=${2:?OLD_STORAGE} NID=${3:?NID}; shift 3
23+[ $# -gt 0 ] || { echo "usage: tests/import-identity.sh REFERENCE_ROOT OLD_STORAGE NID RID..." >&2; exit 2; }
24+T=$(mktemp -d /tmp/ipl-identity.XXXXXX) || exit 2; trap 'rm -rf "$T"' EXIT
25+ssh-keygen -q -t ed25519 -N "" -C "import-identity test key" -f "$T/key" || exit 2
26+printf '* %s\n' "$(ssh-keygen -lf "$T/key.pub" | awk '{print $2}')" > "$T/owner-pins"
27+chmod 600 "$T/owner-pins"
28+export IPL_OWNER_PINS="$T/owner-pins"
29+pass=0; fail=0
30+ok() { pass=$((pass + 1)); echo "PASS $1"; }
31+no() { fail=$((fail + 1)); echo "FAIL $1"; }
32+same() { if cmp -s "$2" "$3"; then ok "$1"; else no "$1: $(diff "$2" "$3" | head -4 | tr '\n' ' ')"; fi; }
33+og() { env -i PATH=/usr/bin:/bin HOME=/nonexistent GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null git "$@"; }
34+# argv FILE: one argument per line; "BAD" when the file is not exactly argc and that many arguments
35+argv() { od -An -v -tu1 "$1" | LC_ALL=C awk '{ for (i = 1; i <= NF; i++) b[n++] = $i }
36+ END { if (n < 2) { print "BAD"; exit } argc = b[0] + 256 * b[1]; p = 2
37+ for (a = 0; a < argc; a++) { if (p + 2 > n) { print "BAD"; exit } l = b[p] + 256 * b[p + 1]; p += 2
38+ if (p + l > n) { print "BAD"; exit } s = ""; for (j = 0; j < l; j++) s = s sprintf("%c", b[p + j]); p += l; print s }
39+ if (p != n) print "BAD" }'; }
40+# paths DIR OLDREPO OLDREPO_RESOLVED ROOT: every path-holding migration file of DIR, decoded, both paths
41+# replaced (the snapshot names the old repository both as given and resolved through the symlink)
42+paths() { local f; for f in "$1"/repo.git.migration/*.argv; do
43+ echo "== ${f##*/}"; argv "$f" | awk -v o="$2" -v o2="$3" -v r="$4/" '$0 == o || $0 == o2 { print "OLDSTORE"; next } index($0, r) == 1 { print "ROOT/" substr($0, length(r) + 1); next } { print }'
44+ done
45+ echo "== clone.stderr"; awk -v r="$4/" '{ while ((i = index($0, r)) > 0) $0 = substr($0, 1, i - 1) "ROOT/" substr($0, i + length(r)); print }' "$1/repo.git.migration/clone.stderr"; }
46+pathfree() { grep -v '\.argv$\|/clone\.stderr$' "$1"; }
47+for rid in "$@"; do
48+ refrow=$(awk -F'\t' -v r="rad:$rid" '$2 == r' "$REF/import.tsv")
49+ [ -n "$refrow" ] || { echo "identity: rad:$rid has no line in $REF/import.tsv" >&2; exit 2; }
50+ name=$(printf '%s' "$refrow" | cut -f1) br=$(printf '%s' "$refrow" | cut -f3) refhead=$(printf '%s' "$refrow" | cut -f4)
51+ if [ "$refhead" != - ] && [ "$(og --git-dir="$OLDS/$rid" rev-parse -q --verify "refs/heads/$br")" != "$refhead" ]; then
52+ echo "identity: rad:$rid moved after the reference was made; pick another" >&2; exit 2
53+ fi
54+ H=$T/$rid; mkdir -p "$H/old/storage" || exit 2; ln -s "$OLDS/$rid" "$H/old/storage/$rid" || exit 2
55+ RAD_HOME=$H/old IMPORT_NID=$NID PATH=/usr/bin:/bin tools/import-radicle.sh "$H/root" "$T/key" > "$H/import.out" 2>&1
56+ echo " import exit $? for rad:$rid: $(head -1 "$H/import.out")"
57+ printf '%s\n' "$refrow" > "$H/want.tsv"
58+ same "row rad:$rid" "$H/want.tsv" "$H/root/import.tsv"
59+ printf '%s\n' "$refrow" | awk -F'\t' -v OFS='\t' '{$3 = $3 "x"} 1' > "$H/bad.tsv"
60+ if cmp -s "$H/bad.tsv" "$H/root/import.tsv"; then no "control-row rad:$rid: an altered line compared equal"; else ok "control-row rad:$rid"; fi
61+ case $(printf '%s' "$refrow" | cut -f6) in OK) ;; *) continue ;; esac
62+ P=$H/root/projects/$name R=$REF/projects/$name
63+ grep -v '^owner \|^nonce ' "$R/records/1" > "$H/r1.want"; grep -v '^owner \|^nonce ' "$P/records/1" > "$H/r1.got"
64+ same "record-1 $name" "$H/r1.want" "$H/r1.got"
65+ pathfree "$REF/import-notes/$name.evidence" > "$H/e.want"; pathfree "$H/root/import-notes/$name.evidence" > "$H/e.got"
66+ same "evidence-pathfree $name ($(wc -l < "$H/e.got") files)" "$H/e.want" "$H/e.got"
67+ paths "$R" "$HOME/.radicle/storage/$rid" "$HOME/.radicle/storage/$rid" "$REF" > "$H/p.want"
68+ paths "$P" "$H/old/storage/$rid" "$(realpath "$H/old/storage/$rid")" "$H/root" > "$H/p.got"
69+ if grep -q '^BAD$' "$H/p.want" "$H/p.got"; then no "evidence-paths $name: an argv file did not decode"
70+ else same "evidence-paths $name ($(grep -c '^== ' "$H/p.got") files)" "$H/p.want" "$H/p.got"; fi
71+ awk '!d && $0 == "--mirror" { $0 = "--bare"; d = 1 } 1' "$H/p.got" > "$H/p.bad"
72+ if cmp -s "$H/p.want" "$H/p.bad"; then no "control-argv $name: an altered argument compared equal"; else ok "control-argv $name"; fi
73+ head -1 "$REF/import-notes/$name.note" | sed 's/ on [0-9-]* by / on DATE by /' > "$H/n.want"
74+ head -1 "$H/root/import-notes/$name.note" | sed 's/ on [0-9-]* by / on DATE by /' > "$H/n.got"
75+ same "note $name" "$H/n.want" "$H/n.got"
76+ cut -f1,3- "$R/catalog.row" > "$H/c.want"; cut -f1,3- "$P/catalog.row" > "$H/c.got"
77+ same "catalog $name" "$H/c.want" "$H/c.got"
78+ og --git-dir="$R/repo.git" for-each-ref --format='%(refname) %(objectname)' > "$H/refs.want"
79+ og --git-dir="$P/repo.git" for-each-ref --format='%(refname) %(objectname)' > "$H/refs.got"
80+ same "refs $name" "$H/refs.want" "$H/refs.got"
81+ if ./ipl verify "$H/root" "$name" > "$H/verify.out" 2>&1; then ok "verify $name"; else no "verify $name: $(head -1 "$H/verify.out")"; fi
82+done
83+if [ "$fail" = 0 ]; then echo "IDENTITY PASS checks=$pass"; else echo "IDENTITY FAIL failed=$fail passed=$pass"; exit 1; fi

ipl/tests/run.sh

new file mode 100755
@@ -0,0 +1,641 @@
1+#!/bin/bash
2+# tests/run.sh OMC SHA2_OM CHAIN_OM: the step 1 gate. Builds bin/landrec and bin/chain with OMC (its
3+# sha256 must be PIN's), then checks the record rules, a full project life and every tamper control.
4+# Prints PASS/FAIL per case and ends "GATE PASS cases=N" (exit 0) or "GATE FAIL ..." (exit 1);
5+# exit 2 on a pin or build error. Scratch files only; no network, no old store.
6+set -u
7+cd "$(dirname "$0")/.." || exit 2
8+omc=${1:?OMC}; sha2=${2:?SHA2_OM}; chainom=${3:?CHAIN_OM}
9+want=$(sed -n 's/^omc-sha256 //p' PIN); got=$(sha256sum "$omc" | cut -d' ' -f1)
10+[ "$got" = "$want" ] || { echo "GATE FAIL omc sha256 $got, PIN wants $want" >&2; exit 2; }
11+[ "$(sha256sum "$sha2" | cut -d' ' -f1)" = "$(sed -n 's/^sha2-om-sha256 //p' PIN)" ] || { echo "GATE FAIL sha2.om is not PIN's" >&2; exit 2; }
12+[ "$(sha256sum "$chainom" | cut -d' ' -f1)" = "$(sed -n 's/^chain-om-sha256 //p' PIN)" ] || { echo "GATE FAIL chain.om is not PIN's" >&2; exit 2; }
13+T=$(mktemp -d /tmp/ipl-gate.XXXXXX) || exit 2; trap 'rm -rf "$T"' EXIT
14+mkdir "$T/bin"; cp ipl "$T/ipl" || exit 2
15+"$omc" < om/landrec.om > "$T/bin/landrec" || { echo "GATE FAIL landrec.om did not compile" >&2; exit 2; }
16+{ printf 'om2\n'; cat "$sha2" "$chainom"; } | "$omc" > "$T/bin/chain" || { echo "GATE FAIL chain did not compile" >&2; exit 2; }
17+chmod +x "$T/bin/landrec" "$T/bin/chain" "$T/ipl"; cp "$T/bin/chain" "$T/chain"
18+L=$T/bin/landrec; pass=0; fail=0; NC=0123456789abcdef0123456789abcdef
19+t() { # NAME WANT_EXIT cmd...
20+ local name=$1 want=$2 rc; shift 2; "$@" > "$T/out" 2> "$T/err"; rc=$?
21+ if [ "$rc" = "$want" ]; then pass=$((pass + 1)); echo "PASS $name"; else fail=$((fail + 1)); echo "FAIL $name: exit $rc, want $want: $(head -c 200 "$T/err")"; fi
22+}
23+Z=0000000000000000000000000000000000000000; A=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
24+H=$(printf x | sha256sum | cut -c1-64); FP="SHA256:bBVPM9xU/+oMCeKoeBrBmyI4XkGmp3YeBKYF/0hvArU"
25+# ---- record rules
26+t rec-land 0 $L land a main $Z $A $H $H r
27+t rec-land-branch 0 $L land AienOS-nv feature/x-1.2 $Z $A $H $H r
28+t rec-project 0 $L project interplane.io main private "$FP" - $NC
29+t rec-project-alias 0 $L project a main public "$FP" rad:z6do9WDBhuSnvopDkgFdFr1yWA62 $NC
30+t no-nonce-short 1 $L project a main public "$FP" - ${NC%?}
31+t no-nonce-upper 1 $L project a main public "$FP" - ${NC%f}F
32+t usage-project-no-nonce 2 $L project a main public "$FP" -
33+printf 'interplane-land 1\nproject a\nbranch main\nold %s\nnew %s\nreceipt %s\nverdict %s\nrequest r\n' $Z $A $H $H > "$T/want"
34+$L land a main $Z $A $H $H r > "$T/gotp" 2>/dev/null; t rec-canonical-bytes 0 cmp -s "$T/want" "$T/gotp"
35+t no-name-dot 1 $L land .a main $Z $A $H $H r
36+t no-name-enddot 1 $L land a. main $Z $A $H $H r
37+t no-name-space 1 $L land "a b" main $Z $A $H $H r
38+t no-name-newline 1 $L land "$(printf 'a\nb')" main $Z $A $H $H r
39+t no-name-empty 1 $L land "" main $Z $A $H $H r
40+t no-name-slash 1 $L land a/b main $Z $A $H $H r
41+t no-branch-dash 1 $L land a -main $Z $A $H $H r
42+t no-branch-dotdot 1 $L land a a..b $Z $A $H $H r
43+t no-branch-slashes 1 $L land a a//b $Z $A $H $H r
44+t no-branch-dotpart 1 $L land a a/.b $Z $A $H $H r
45+t no-branch-trail 1 $L land a main/ $Z $A $H $H r
46+t no-old-long 1 $L land a main ${Z}0 $A $H $H r
47+t no-new-upper 1 $L land a main $Z ${A%a}A $H $H r
48+t no-new-short 1 $L land a main $Z ${A%a} $H $H r
49+t no-receipt-short 1 $L land a main $Z $A ${H%?} $H r
50+t no-verdict-nonhex 1 $L land a main $Z $A $H ${H%?}g r
51+t no-request-space 1 $L land a main $Z $A $H $H "r 1"
52+t no-request-tab 1 $L land a main $Z $A $H $H "$(printf 'r\tx')"
53+t no-visibility 1 $L project a main secret "$FP" - $NC
54+t no-owner-short 1 $L project a main public SHA256:short - $NC
55+t no-owner-kind 1 $L project a main public "MD5:bBVPM9xU/+oMCeKoeBrBmyI4XkGmp3YeBKYF/0hvArUab" - $NC
56+t no-alias 1 $L project a main public "$FP" rad:x6do9WDBhuSnvopDkgFdFr1yWA62 $NC
57+t no-alias-dashes 1 $L project a main public "$FP" -- $NC
58+t usage-few 2 $L land a main $Z $A $H $H
59+t usage-many 2 $L land a main $Z $A $H $H r extra
60+t usage-word 2 $L nothing
61+$L land .a main $Z $A $H $H r > "$T/gotp" 2>/dev/null; t refusal-prints-nothing 0 test ! -s "$T/gotp"
62+t no-branch-lock 1 $L land a feature.lock $Z $A $H $H r
63+t no-branch-lock-part 1 $L land a a.lock/b $Z $A $H $H r
64+t rec-branch-lockish 0 $L land a a.locked/blocks $Z $A $H $H r
65+N128=$(head -c 128 /dev/zero | tr '\0' a)
66+t rec-name-128 0 $L land "$N128" main $Z $A $H $H r
67+t rec-name-129 0 $L land "${N128}a" main $Z $A $H $H r
68+t rec-branch-129 0 $L land a "${N128}a" $Z $A $H $H r
69+# a request id has no size chosen here: the longest argument Linux allows passes and comes back whole
70+BIG=$(head -c 131071 /dev/zero | tr '\0' r)
71+t rec-request-longest 0 $L land a main $Z $A $H $H "$BIG"
72+$L land a main $Z $A $H $H "$BIG" 2>/dev/null | tail -n 1 > "$T/gotp"; t rec-request-longest-whole 0 test "$(wc -c < "$T/gotp")" = 131080
73+t no-request-bad-byte-late 1 $L land a main $Z $A $H $H "${BIG%r}!"
74+t check-name 0 $L check name interplane.io
75+t check-name-traversal 1 $L check name ../demo
76+t check-name-slash 1 $L check name a/b
77+t check-branch 0 $L check branch feature/x
78+t check-request-newline 1 $L check request "$(printf 'x\nrequest req-1')"
79+t check-unknown-rule 2 $L check colour red
80+PUB68=$(head -c 68 /dev/zero | tr '\0' A)
81+FP2=SHA256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
82+t rec-successor 0 $L successor a "$FP" "$FP2" "$PUB68" rotate-1
83+printf 'interplane-successor 1\nproject a\nold %s\nnew %s\npub %s\nreason rotate-1\n' "$FP" "$FP2" "$PUB68" > "$T/want"
84+$L successor a "$FP" "$FP2" "$PUB68" rotate-1 > "$T/gotp" 2>/dev/null; t rec-successor-canonical-bytes 0 cmp -s "$T/want" "$T/gotp"
85+t rec-successor-dash-reason 0 $L successor a "$FP" "$FP2" "$PUB68" -
86+t no-successor-pub-short 1 $L successor a "$FP" "$FP2" "${PUB68%A}" rotate-1
87+t no-successor-reason-space 1 $L successor a "$FP" "$FP2" "$PUB68" "rotate 1"
88+t no-successor-old-short 1 $L successor a SHA256:short "$FP2" "$PUB68" rotate-1
89+t no-successor-new-kind 1 $L successor a "$FP" "MD5:bBVPM9xU/+oMCeKoeBrBmyI4XkGmp3YeBKYF/0hvArUab" "$PUB68" -
90+t check-pub 0 $L check pub "$PUB68"
91+t check-pub-short 1 $L check pub "${PUB68%A}"
92+t check-owner 0 $L check owner "$FP"
93+t check-reason 0 $L check reason rotate-1
94+t check-reason-dash 0 $L check reason -
95+t check-reason-space 1 $L check reason "a b"
96+t usage-successor-few 2 $L successor a "$FP" "$FP2" "$PUB68"
97+t usage-successor-many 2 $L successor a "$FP" "$FP2" "$PUB68" - extra
98+# ---- one project's life
99+export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid
100+R=$T/root; P=$R/projects/demo; mkdir -p "$P"
101+ssh-keygen -q -t ed25519 -N "" -C gate -f "$T/key"; ssh-keygen -q -t ed25519 -N "" -C other -f "$T/key2"
102+FPK=$(ssh-keygen -lf "$T/key.pub" | awk '{print $2}')
103+printf '* %s\n' "$FPK" > "$T/owner-pins"
104+chmod 600 "$T/owner-pins"
105+export IPL_OWNER_PINS="$T/owner-pins"
106+git init -q -b main "$T/work"; cd "$T/work" || exit 2
107+echo a > f; git add f; git commit -q -m one; C1=$(git rev-parse HEAD)
108+echo b >> f; git commit -q -am two; C2=$(git rev-parse HEAD)
109+echo c >> f; git commit -q -am three; C4=$(git rev-parse HEAD)
110+git checkout -q -b side "$C1"; echo z > g; git add g; git commit -q -m side; C3=$(git rev-parse HEAD)
111+cd - >/dev/null || exit 2
112+git init -q --bare "$P/repo.git"; git --git-dir="$P/repo.git" fetch -q "$T/work" "$C1"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C1"
113+echo ev > "$T/ev"; echo note > "$T/note"; echo rc > "$T/rc"; echo vd > "$T/vd"
114+I=$T/ipl
115+t init 0 $I init "$R" demo main public - "$T/key"
116+n=$(wc -l < "$P/chain.tsv")
117+t init-again-same-terms 0 $I init "$R" demo main public - "$T/key"
118+t init-again-adds-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n"
119+t init-again-other-terms 2 $I init "$R" demo main private - "$T/key"
120+t init-again-other-key 2 $I init "$R" demo main public - "$T/key2"
121+# a name or branch longer than the chain's subject field goes in as a digest; only the file system says no
122+N200=$(head -c 200 /dev/zero | tr '\0' n); mkdir -p "$R/projects/$N200"; git init -q --bare "$R/projects/$N200/repo.git"
123+t long-name-init 0 $I init "$R" "$N200" main public - "$T/key"
124+t long-name-subject-is-digest 0 grep -q " PROJECT [^ ]* sha256:[0-9a-f]\{64\} " "$R/projects/$N200/chain.tsv"
125+t long-name-verify 0 $I verify "$R" "$N200"; rm -rf "$R/projects/$N200"
126+t no-name-longer-than-file-names 2 $I verify "$R" "$(head -c 300 /dev/zero | tr '\0' n)"
127+mkdir -p "$R/projects/Demo"; git init -q --bare "$R/projects/Demo/repo.git"
128+t init-case-collision 2 $I init "$R" Demo main public - "$T/key"; rm -rf "$R/projects/Demo"
129+t import 0 $I import "$R" demo main "$T/ev" "$T/note" import-1 "$T/key"
130+t import-twice-new-request 4 $I import "$R" demo main "$T/ev" "$T/note" import-2 "$T/key"
131+t land 0 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key"
132+n=$(wc -l < "$P/chain.tsv")
133+t replay-same 0 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key"
134+t replay-adds-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n"
135+t replay-other-head 4 $I land "$R" demo main "$C3" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key"
136+t no-non-fast-forward 4 $I land "$R" demo main "$C3" "$T/work" "$T/rc" "$T/vd" req-2 "$T/key"
137+t no-same-head 4 $I land "$R" demo main "$C2" - "$T/rc" "$T/vd" req-3 "$T/key"
138+t no-unknown-commit 4 $I land "$R" demo main 1111111111111111111111111111111111111111 - "$T/rc" "$T/vd" req-4 "$T/key"
139+t no-bad-request 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" "bad req" "$T/key"
140+t no-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-5 "$T/key2"
141+t no-missing-verdict 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/absent" req-6 "$T/key"
142+t refusals-add-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n"
143+t verify 0 $I verify "$R" demo
144+# ---- crafted arguments: refused before anything is read or written outside the project
145+n=$(wc -l < "$P/chain.tsv"); h=$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)
146+mkdir -p "$T/outside"; cp -a "$P" "$T/outside/demo"
147+t no-traversal-verify 2 $I verify "$R" ../../outside/demo
148+t no-traversal-land 2 $I land "$R" ../../outside/demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-t "$T/key"
149+ln -s "$T/outside/demo" "$R/projects/linked"; t no-symlink-project 2 $I verify "$R" linked; rm "$R/projects/linked"
150+t no-request-newline 2 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" "$(printf 'x\nrequest req-1')" "$T/key"
151+t no-source-option 2 $I land "$R" demo main "$C4" "--upload-pack=touch $T/pwned" "$T/rc" "$T/vd" req-o "$T/key"
152+t no-source-remote 2 $I land "$R" demo main "$C4" "ssh://example.invalid/x" "$T/rc" "$T/vd" req-o "$T/key"
153+t no-source-ext 2 $I land "$R" demo main "$C4" "ext::sh -c touch% $T/pwned" "$T/rc" "$T/vd" req-o "$T/key"
154+t source-ran-nothing 0 test ! -e "$T/pwned"
155+t no-branch-lock-land 2 $I land "$R" demo x.lock "$C4" "$T/work" "$T/rc" "$T/vd" req-l "$T/key"
156+t no-branch-under-existing 4 $I land "$R" demo main/sub "$C4" "$T/work" "$T/rc" "$T/vd" req-d "$T/key"
157+ssh-keygen -q -t rsa -b 2048 -N "" -C rsa -f "$T/rsa"
158+mkdir -p "$R/projects/rsaproj"; git init -q --bare "$R/projects/rsaproj/repo.git"
159+t no-rsa-owner 2 $I init "$R" rsaproj main public - "$T/rsa"
160+t rsa-init-wrote-nothing 0 test ! -e "$R/projects/rsaproj/chain.tsv" -a ! -e "$R/projects/rsaproj/owner.pub"
161+t no-bad-init-name 2 $I init "$R" "bad name" main public - "$T/key"
162+# the owner's public key beside another private key: refused before anything is appended
163+cp "$T/key2" "$T/mixed"; cp "$T/key.pub" "$T/mixed.pub"
164+t no-mismatched-key-pair 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-m "$T/mixed"
165+t crafted-add-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n" -a "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$h"
166+# the same request with other evidence is not the same request
167+echo other > "$T/vd2"; t replay-other-verdict 4 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd2" req-1 "$T/key"
168+t replay-as-import 4 $I import "$R" demo main "$T/rc" "$T/vd" req-1 "$T/key"
169+# a second branch, and landings racing on one request id: one record, both answer the same
170+t land-new-branch 0 $I land "$R" demo topic "$C3" "$T/work" "$T/rc" "$T/vd" req-b "$T/key"
171+( $I land "$R" demo topic/x "$C3" - "$T/rc" "$T/vd" req-c "$T/key" >/dev/null 2>&1; echo $? > "$T/r1" ) &
172+( $I land "$R" demo topic/x "$C3" - "$T/rc" "$T/vd" req-c "$T/key" >/dev/null 2>&1; echo $? > "$T/r2" ) & wait
173+t race-topic-child-refused 0 test "$(cat "$T/r1")$(cat "$T/r2")" = 44
174+git --git-dir="$P/repo.git" update-ref -d refs/heads/topic; t tamper-second-branch-removed 3 $I verify "$R" demo
175+git --git-dir="$P/repo.git" update-ref refs/heads/topic "$C3"; t second-branch-back 0 $I verify "$R" demo
176+# ---- tamper controls: each starts from the good copy
177+cp -a "$P" "$T/good"; fresh() { rm -rf "$P"; cp -a "$T/good" "$P"; }
178+sed -i '3s/main/maim/' "$P/chain.tsv"; t tamper-chain-byte 3 $I verify "$R" demo; fresh
179+sed -i '5d' "$P/chain.tsv"; t tamper-record-removed 3 $I verify "$R" demo; fresh
180+echo x >> "$P/records/3"; t tamper-payload 3 $I verify "$R" demo; fresh
181+rm "$P/records/5"; t tamper-payload-missing 3 $I verify "$R" demo; fresh
182+git --git-dir="$P/repo.git" update-ref refs/heads/main "$C1"; t tamper-ref-behind 3 $I verify "$R" demo; fresh
183+git --git-dir="$P/repo.git" fetch -q "$T/work" "$C3"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C3"; t tamper-ref-elsewhere 3 $I verify "$R" demo; fresh
184+cp "$T/key2.pub" "$P/owner.pub"; t tamper-owner-key 3 $I verify "$R" demo; fresh
185+head -n 5 "$T/good/chain.tsv" > "$P/chain.tsv"; t tamper-signature-dropped 3 $I verify "$R" demo; fresh
186+# a valid signature moved to stand for another record must not verify (records 2 and 6 are both SIG)
187+cp "$P/records/2" "$T/sig2"; cp "$T/sig2" "$P/records/6"; t tamper-signature-swapped 3 $I verify "$R" demo; fresh
188+# a well-formed record 6 whose signature is over other bytes, by another key or for another purpose
189+FPK=$(ssh-keygen -lf "$T/key.pub" | awk '{print $2}')
190+lmsg() { awk -F'\t' -v n="$1" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$T/good/chain.tsv"; }
191+forge() { head -n 5 "$T/good/chain.tsv" > "$P/chain.tsv"; "$T/chain" add "$P/chain.tsv" SIG "$FPK" 5 < "$1" >/dev/null; cp "$1" "$P/records/6"; }
192+printf 'deadbeef\n' > "$T/m1"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m1" 2>/dev/null
193+forge "$T/m1.sig"; t tamper-signature-over-other-bytes 3 $I verify "$R" demo; fresh
194+lmsg 3 > "$T/m0"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m0" 2>/dev/null
195+forge "$T/m0.sig"; t tamper-signature-of-another-record 3 $I verify "$R" demo; fresh
196+lmsg 5 > "$T/m2"; ssh-keygen -q -Y sign -n interplane -f "$T/key2" "$T/m2" 2>/dev/null
197+forge "$T/m2.sig"; t tamper-signature-by-other-key 3 $I verify "$R" demo; fresh
198+lmsg 5 > "$T/m3"; ssh-keygen -q -Y sign -n other-purpose -f "$T/key" "$T/m3" 2>/dev/null
199+forge "$T/m3.sig"; t tamper-signature-for-other-purpose 3 $I verify "$R" demo; fresh
200+lmsg 5 > "$T/m4"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m4" 2>/dev/null
201+forge "$T/m4.sig"; t control-honest-resigned-record-verifies 0 $I verify "$R" demo; fresh
202+# the last line is not covered by a later record: its actor is checked on its own
203+sed -i "\$s#$FPK#SHA256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA#" "$P/chain.tsv"; t tamper-last-actor 3 $I verify "$R" demo; fresh
204+# an owner-signed record that is not canonical (no new head) must not verify
205+printf 'interplane-land 1\nproject demo\nbranch main\nold %s\nreceipt %s\nverdict %s\nrequest bad\n' "$C2" $H $H > "$T/badpay"
206+head -n 6 "$T/good/chain.tsv" > "$P/chain.tsv"; "$T/chain" add "$P/chain.tsv" LAND "$FPK" main < "$T/badpay" >/dev/null; cp "$T/badpay" "$P/records/7"
207+awk -F'\t' 'NR==7 {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$P/chain.tsv" > "$T/m5"; ssh-keygen -q -Y sign -n interplane -f "$T/key" "$T/m5" 2>/dev/null
208+"$T/chain" add "$P/chain.tsv" SIG "$FPK" 7 < "$T/m5.sig" >/dev/null; cp "$T/m5.sig" "$P/records/8"
209+t tamper-signed-but-malformed 3 $I verify "$R" demo; fresh
210+# a whole project copied under another name is not that project
211+cp -a "$T/good" "$R/projects/demo2"; t tamper-copied-under-other-name 3 $I verify "$R" demo2; rm -rf "$R/projects/demo2"
212+# ---- interruptions: only the same request, by the owner, finishes one; nothing else gets in
213+t land-2 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key"
214+n=$(wc -l < "$P/chain.tsv"); cp -a "$P" "$T/done"; redo() { rm -rf "$P"; cp -a "$T/done" "$P"; }
215+# (a) signed, branch not moved yet
216+git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2"
217+t pending-ref-seen 3 $I verify "$R" demo
218+t pending-ref-blocks-other 3 $I land "$R" demo main "$C4" - "$T/rc" "$T/vd" req-8 "$T/key"
219+t pending-ref-not-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2"
220+t pending-ref-still-behind 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C2"
221+t pending-ref-finished 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key"
222+t finish-adds-nothing 0 test "$(wc -l < "$P/chain.tsv")" = "$n"
223+# (b) recorded, not signed yet, branch not moved
224+redo; sed -i '$d' "$P/chain.tsv"; rm "$P/records/$n"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2"
225+t pending-sig-seen 3 $I verify "$R" demo
226+t pending-sig-blocks-other 3 $I land "$R" demo main "$C4" - "$T/rc" "$T/vd" req-8 "$T/key"
227+t pending-sig-not-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2"
228+t pending-sig-not-for-mixed-pair 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/mixed"
229+t pending-sig-untouched 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C2" -a "$(wc -l < "$P/chain.tsv")" = "$((n - 1))"
230+t pending-sig-finished 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key"
231+t pending-sig-result 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C4" -a "$(wc -l < "$P/chain.tsv")" = "$n"
232+# (c) recorded, the payload file did not reach records/ but is still in staging
233+redo; mkdir -p "$P/staging"; mv "$P/records/$((n - 1))" "$P/staging/req-req-7.payload"
234+t payload-lost-seen 3 $I verify "$R" demo
235+t payload-lost-healed 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key"
236+# (d) recorded, the payload is gone for good: refused whole, nothing moves
237+redo; rm "$P/records/$((n - 1))"; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2"
238+t payload-gone-refused 3 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key"
239+t payload-gone-untouched 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C2"
240+# an old request repeated after later landings answers and moves nothing
241+redo; t replay-historical 0 $I land "$R" demo main "$C2" "$T/work" "$T/rc" "$T/vd" req-1 "$T/key"
242+t replay-historical-moved-nothing 0 test "$(git --git-dir="$P/repo.git" rev-parse refs/heads/main)" = "$C4" -a "$(wc -l < "$P/chain.tsv")" = "$n"
243+# init interrupted before its signature is finished by the same init, not by another key
244+mkdir -p "$R/projects/half"; git init -q --bare "$R/projects/half/repo.git"
245+t half-init 0 $I init "$R" half main private - "$T/key"
246+sed -i '$d' "$R/projects/half/chain.tsv"; rm "$R/projects/half/records/2"
247+t half-init-seen 3 $I verify "$R" half
248+t half-init-not-other-key 2 $I init "$R" half main private - "$T/key2"
249+t half-init-not-other-terms 2 $I init "$R" half main public - "$T/key"
250+t half-init-finished 0 $I init "$R" half main private - "$T/key"
251+# ---- second review round
252+ref() { git --git-dir="$P/repo.git" rev-parse -q --verify "refs/heads/$1" 2>/dev/null; }
253+lines() { wc -l < "$P/chain.tsv"; }
254+# PENDING_REF is not finished by the owner's public key beside another private key
255+redo; git --git-dir="$P/repo.git" update-ref refs/heads/main "$C2"
256+t pending-ref-not-for-mixed-pair 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/mixed"
257+t pending-ref-mixed-untouched 0 test "$(ref main)" = "$C2"
258+# an annotated tag is not a commit, even though it leads to one
259+redo; TAG=$(cd "$T/work" && git tag -a -m t vt "$C3" && git rev-parse vt); n=$(lines)
260+t no-tag-object 4 $I land "$R" demo tagbr "$TAG" "$T/work" "$T/rc" "$T/vd" req-tag "$T/key"
261+t tag-added-nothing 0 test "$(lines)" = "$n" -a -z "$(ref tagbr)"
262+t tag-commit-control 0 $I land "$R" demo tagbr "$C3" "$T/work" "$T/rc" "$T/vd" req-tag2 "$T/key"
263+# a landing stopped at each write boundary: seen, closed to others, finished by the same request
264+C5=$(cd "$T/work" && git checkout -q main && echo d >> f && git commit -q -am four && git rev-parse HEAD)
265+for s in after-stage mid-record after-record after-sig; do
266+ redo; n=$(lines)
267+ IPL_TEST_STOP=$s t "stop-$s" 9 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key"
268+ t "stop-$s-branch-not-moved" 0 test "$(ref main)" = "$C4"
269+ if [ $s = after-stage ]; then t "stop-$s-nothing-recorded" 0 $I verify "$R" demo
270+ else
271+ t "stop-$s-seen" 3 $I verify "$R" demo
272+ t "stop-$s-closed-to-others" 3 $I land "$R" demo topic "$C4" "$T/work" "$T/rc" "$T/vd" req-g "$T/key"
273+ t "stop-$s-not-for-other-key" 2 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key2"
274+ fi
275+ t "stop-$s-finished" 0 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key"
276+ t "stop-$s-result" 0 test "$(ref main)" = "$C5" -a "$(lines)" = "$((n + 2))" -a -z "$(ls "$P/staging")"
277+ t "stop-$s-catalog-follows" 0 grep -q "^demo [0-9a-f]\{64\} main $C5 public$" "$R/catalog.tsv"
278+done
279+# stopped after the branch moved, before the catalog: the project verifies, the same request publishes
280+redo; n=$(lines); $I catalog "$R" >/dev/null 2>&1
281+IPL_TEST_STOP=after-ref t stop-after-ref 9 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key"
282+t stop-after-ref-verifies 0 $I verify "$R" demo
283+t stop-after-ref-catalog-behind 1 grep -q "^demo [0-9a-f]\{64\} main $C5 public$" "$R/catalog.tsv"
284+t stop-after-ref-finished 0 $I land "$R" demo main "$C5" "$T/work" "$T/rc" "$T/vd" req-f "$T/key"
285+t stop-after-ref-result 0 test "$(lines)" = "$((n + 2))" -a -z "$(ls "$P/staging")"
286+t stop-after-ref-catalog-follows 0 grep -q "^demo [0-9a-f]\{64\} main $C5 public$" "$R/catalog.tsv"
287+# a longer branch part than the chain's subject field lands; one the file system cannot hold is refused
288+redo; B200=$(head -c 200 /dev/zero | tr '\0' b)
289+t long-branch-lands 0 $I land "$R" demo "x/$B200" "$C3" "$T/work" "$T/rc" "$T/vd" req-lb "$T/key"
290+t long-branch-verifies 0 $I verify "$R" demo
291+t no-branch-part-too-long 2 $I land "$R" demo "y/$(head -c 252 /dev/zero | tr '\0' b)" "$C3" "$T/work" "$T/rc" "$T/vd" req-lb2 "$T/key"
292+# a folder part may be as long as a file name; only the last part needs room for git's .lock
293+t long-branch-folder-part 0 $I land "$R" demo "$(head -c 255 /dev/zero | tr '\0' f)/x" "$C3" "$T/work" "$T/rc" "$T/vd" req-lb3 "$T/key"
294+mkdir -p "$R/projects/lb"; git init -q --bare "$R/projects/lb/repo.git"
295+t no-default-branch-too-long 2 $I init "$R" lb "$(head -c 252 /dev/zero | tr '\0' b)" public - "$T/key"
296+t long-default-refusal-wrote-nothing 0 test ! -e "$R/projects/lb/owner.pub" -a ! -e "$R/projects/lb/chain.tsv"; rm -rf "$R/projects/lb"
297+# name, branch and request all as long as an argument can be: the payload holds them whole
298+t rec-all-longest 0 $L land "$BIG" "$BIG" $Z $A $H $H "$BIG"
299+$L land "$BIG" "$BIG" $Z $A $H $H "$BIG" 2>/dev/null > "$T/gotp"; t rec-all-longest-whole 0 test "$(wc -c < "$T/gotp")" = 393493
300+# init stopped at each point: only the key that started it goes on
301+for s in after-stage mid-record after-record after-sig; do
302+ Q=$R/projects/i-$s; mkdir -p "$Q"; git init -q --bare "$Q/repo.git"
303+ IPL_TEST_STOP=$s t "init-stop-$s" 9 $I init "$R" "i-$s" main public - "$T/key"
304+ cp "$Q/owner.pub" "$T/owner.before"
305+ t "init-stop-$s-not-other-key" 2 $I init "$R" "i-$s" main public - "$T/key2"
306+ t "init-stop-$s-owner-kept" 0 cmp -s "$T/owner.before" "$Q/owner.pub"
307+ t "init-stop-$s-not-mixed-pair" 2 $I init "$R" "i-$s" main public - "$T/mixed"
308+ t "init-stop-$s-owner-still-kept" 0 cmp -s "$T/owner.before" "$Q/owner.pub"
309+ t "init-stop-$s-not-other-terms" 2 $I init "$R" "i-$s" main private - "$T/key"
310+ t "init-stop-$s-finished" 0 $I init "$R" "i-$s" main public - "$T/key"
311+ t "init-stop-$s-two-records" 0 test "$(wc -l < "$Q/chain.tsv")" = 2
312+ t "init-stop-$s-in-catalog" 0 grep -q "^i-$s " "$R/catalog.tsv"
313+ rm -rf "$Q"
314+done
315+# a first init with someone's public key beside another private key: refused, and nothing is left behind
316+Q=$R/projects/mix1; mkdir -p "$Q"; git init -q --bare "$Q/repo.git"
317+t no-fresh-init-with-mixed-pair 2 $I init "$R" mix1 main public - "$T/mixed"
318+t mixed-init-left-nothing 0 test ! -e "$Q/owner.pub" -a ! -e "$Q/staging/init.payload" -a ! -e "$Q/chain.tsv"; rm -rf "$Q"
319+# a first chain line that was never finished: the owner's same init cuts it and completes, in one call
320+Q=$R/projects/torn1; mkdir -p "$Q"; git init -q --bare "$Q/repo.git"
321+IPL_TEST_STOP=after-stage t torn-first-setup 9 $I init "$R" torn1 main public - "$T/key"
322+printf '1\t2026' > "$Q/chain.tsv"
323+t torn-first-line-finished 0 $I init "$R" torn1 main public - "$T/key"
324+t torn-first-line-two-records 0 test "$(wc -l < "$Q/chain.tsv")" = 2; rm -rf "$Q"
325+# a repair on the owner's call is said out loud, even when the request itself is then refused
326+redo; printf '99\tgarbage' >> "$P/chain.tsv"
327+t torn-then-altered-request 4 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd2" req-7 "$T/key"
328+cp "$T/err" "$T/err.kept"; t repair-was-announced 0 grep -q "repaired: cut a torn last line" "$T/err.kept"
329+# a torn last line is never a record: the owner's next call cuts it, nobody else's does
330+redo; printf '99\tgarbage' >> "$P/chain.tsv"
331+t torn-seen 3 $I verify "$R" demo
332+t torn-not-cut-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2"
333+t torn-still-there 0 grep -q garbage "$P/chain.tsv"
334+t torn-cut-for-owner 0 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key"
335+t torn-gone 0 test "$(lines)" = "$(wc -l < "$T/done/chain.tsv")" -a -z "$(grep garbage "$P/chain.tsv")"
336+# an init that created the chain file and wrote nothing starts over
337+mkdir -p "$R/projects/e"; git init -q --bare "$R/projects/e/repo.git"; : > "$R/projects/e/chain.tsv"
338+t empty-chain-init 0 $I init "$R" e main public - "$T/key"; rm -rf "$R/projects/e"
339+# a staged payload is put in place only for the owner
340+redo; n=$(lines); mkdir -p "$P/staging"; mv "$P/records/$((n - 1))" "$P/staging/x"
341+t staged-not-restored-for-other-key 2 $I land "$R" demo main "$C4" "$T/work" "$T/rc" "$T/vd" req-7 "$T/key2"
342+t staged-still-staged 0 test ! -e "$P/records/$((n - 1))"
343+# the original import request, repeated after later landings, answers and adds nothing
344+redo; n=$(lines)
345+t import-replay-after-landings 0 $I import "$R" demo main "$T/ev" "$T/note" import-1 "$T/key"
346+t import-replay-added-nothing 0 test "$(lines)" = "$n" -a "$(ref main)" = "$C4"
347+# the project id is the digest of the signed record 1 payload
348+t id-is-payload-digest 0 test "$($I verify "$R" demo | cut -d' ' -f3)" = "$(sha256sum < "$P/records/1" | cut -c1-64)"
349+# git settings in the caller's environment do not reach the store
350+GIT_DIR=/nonexistent GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.bare GIT_CONFIG_VALUE_0=nonsense GIT_WORK_TREE=/nonexistent t env-not-inherited 0 $I verify "$R" demo
351+# a project whose repository is a link is no project, for verify and for the catalog alike
352+mkdir -p "$R/projects/lnk"; ln -s "$P/repo.git" "$R/projects/lnk/repo.git"
353+t no-linked-repository 2 $I verify "$R" lnk
354+$I catalog "$R" > /dev/null 2> "$T/caterr"; t catalog-leaves-out-linked 0 grep -q "lnk is not a project" "$T/caterr"; rm -rf "$R/projects/lnk"
355+# a linked project folder is left out, and nothing behind the link is touched
356+mkdir -p "$T/elsewhere"; echo keep > "$T/elsewhere/catalog.row"; ln -s "$T/elsewhere" "$R/projects/away"
357+$I catalog "$R" > /dev/null 2>&1; t linked-folder-untouched 0 test "$(cat "$T/elsewhere/catalog.row")" = keep; rm "$R/projects/away"
358+redo
359+# two catalog runs at once: one whole catalog, no leftovers
360+( $I catalog "$R" >/dev/null 2>&1 ) & ( $I catalog "$R" >/dev/null 2>&1 ) & wait
361+cp "$R/catalog.tsv" "$T/err.cat"; t catalog-race-whole 0 test "$(wc -l < "$R/catalog.tsv")" = 2 -a -z "$(ls "$R" | grep 'catalog.tsv\.')"
362+[ "$(wc -l < "$R/catalog.tsv")" = 2 ] || { echo "catalog was:"; cut -f1,4 "$R/catalog.tsv"; ls "$R" "$R/projects"; }
363+rm -rf "$R/projects/rsaproj" "$R/projects/half"; t catalog 0 $I catalog "$R"
364+t catalog-row 0 grep -q "^demo [0-9a-f]\{64\} main $C4 public$" "$R/catalog.tsv"
365+echo x >> "$P/records/1"; t catalog-leaves-out-broken 3 $I catalog "$R"; t catalog-empty 0 test ! -s "$R/catalog.tsv"
366+# ---- owner-key handover. Throwaway ed25519 keys in this temp store only; never ~/.ssh, never the live store.
367+HR=$T/hroot; HP=$HR/projects/demo; mkdir -p "$HP"
368+ssh-keygen -q -t ed25519 -N "" -C ho0 -f "$T/h0"
369+ssh-keygen -q -t ed25519 -N "" -C ho1 -f "$T/h1"
370+ssh-keygen -q -t ed25519 -N "" -C ho2 -f "$T/h2"
371+FP0=$(ssh-keygen -lf "$T/h0.pub" | awk '{print $2}')
372+FP1=$(ssh-keygen -lf "$T/h1.pub" | awk '{print $2}')
373+FP2=$(ssh-keygen -lf "$T/h2.pub" | awk '{print $2}')
374+BLOB0=$(awk '{print $2}' "$T/h0.pub")
375+BLOB2=$(awk '{print $2}' "$T/h2.pub")
376+write_pin() { printf '* %s\n' "$1" > "$T/owner-pins"; chmod 600 "$T/owner-pins"; }
377+write_pin "$FP0"
378+git init -q --bare "$HP/repo.git"
379+git --git-dir="$HP/repo.git" fetch -q "$T/work" "$C1"
380+git --git-dir="$HP/repo.git" update-ref refs/heads/main "$C1"
381+t ho-init 0 $I init "$HR" demo main public - "$T/h0"
382+t ho-import 0 $I import "$HR" demo main "$T/ev" "$T/note" h-import-1 "$T/h0"
383+t ho-land-before 0 $I land "$HR" demo main "$C2" "$T/work" "$T/rc" "$T/vd" h-req-1 "$T/h0"
384+n=$(wc -l < "$HP/chain.tsv")
385+t ho-pre-history-verifies 0 $I verify "$HR" demo
386+t ho-legacy-no-successor 0 test "$(grep -c $'\tSUCCESSOR\t' "$HP/chain.tsv" || true)" = 0
387+own0=$(sha256sum < "$HP/owner.pub" | cut -c1-64)
388+mkdir -p "$T/legacy-root/projects"
389+cp -a "$HP" "$T/legacy-root/projects/demo"
390+t ho-legacy-copy-still-verifies 0 $I verify "$T/legacy-root" demo
391+t ho-handover 0 $I handover "$HR" demo "$T/h0" "$T/h1.pub" rotate-1
392+cp "$T/err" "$T/err.handover"
393+t ho-pin-line-printed 0 grep -q "ipl: pin: demo $FP1" "$T/err.handover"
394+t ho-pin-file-updated 0 grep -q "$FP1" "$T/owner-pins"
395+t ho-adds-two-records 0 test "$(wc -l < "$HP/chain.tsv")" = "$((n + 2))"
396+t ho-owner-pub-unchanged 0 test "$(sha256sum < "$HP/owner.pub" | cut -c1-64)" = "$own0"
397+t ho-verify-after 0 $I verify "$HR" demo
398+$I verify "$HR" demo > "$T/ok"
399+t ho-ok-current-owner 0 test "$(awk '{print $7}' "$T/ok")" = "$FP1"
400+t ho-ok-chain-seq 0 test "$(awk '{print $8}' "$T/ok")" = "$(wc -l < "$HP/chain.tsv")"
401+t ho-ok-chain-head 0 test "$(awk '{print $9}' "$T/ok")" = "$(tail -n 1 "$HP/chain.tsv" | tr -d '\n' | sha256sum | cut -c1-64)"
402+t ho-expect-new 0 $I verify "$HR" demo --expect-owner "$FP1"
403+t ho-expect-old-fails 3 $I verify --expect-owner "$FP0" "$HR" demo
404+printf '* %s\n' "$FP0" > "$T/pin-old"; chmod 600 "$T/pin-old"
405+IPL_OWNER_PINS="$T/pin-old" t ho-legacy-with-old-pin 0 $I verify "$T/legacy-root" demo
406+nleg=$(wc -l < "$T/legacy-root/projects/demo/chain.tsv")
407+t ho-fork-expect-new-fails 3 $I verify "$T/legacy-root" demo --expect-owner "$FP1"
408+t ho-fork-land-expect-fails 3 $I land "$T/legacy-root" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-fork-1 "$T/h0" --expect-owner "$FP1"
409+t ho-fork-land-expect-adds-nothing 0 test "$(wc -l < "$T/legacy-root/projects/demo/chain.tsv")" = "$nleg"
410+# required: a pin file (successor FP) catches a pre-handover fork and an attacker re-hand, without --expect-owner
411+t ho-fork-pin-verify 3 $I verify "$T/legacy-root" demo
412+t ho-fork-pin-catalog 3 $I catalog "$T/legacy-root"
413+cp -a "$T/legacy-root" "$T/rehand-root"
414+printf '* %s\n' "$FP0" > "$T/attacker-pins"; chmod 600 "$T/attacker-pins"
415+IPL_OWNER_PINS="$T/attacker-pins" t ho-attacker-rehand 0 $I handover "$T/rehand-root" demo "$T/h0" "$T/h2.pub" attack
416+t ho-rehand-fork-pin-verify 3 $I verify "$T/rehand-root" demo
417+t ho-rehand-fork-pin-catalog 3 $I catalog "$T/rehand-root"
418+# pin file inside ROOT, group-writable, missing, and a disagreeing --expect-owner
419+printf '* %s\n' "$FP1" > "$HR/owner-pins"; chmod 600 "$HR/owner-pins"
420+IPL_OWNER_PINS="$HR/owner-pins" t ho-pin-inside-root 3 $I verify "$HR" demo
421+rm -f "$HR/owner-pins"
422+printf '* %s\n' "$FP1" > "$T/pin-gw"; chmod 660 "$T/pin-gw"
423+IPL_OWNER_PINS="$T/pin-gw" t ho-pin-group-writable 3 $I verify "$HR" demo
424+IPL_OWNER_PINS="$T/no-such-pins" t ho-pin-missing 3 $I verify "$HR" demo
425+t ho-pin-disagree 3 $I verify "$HR" demo --expect-owner "$FP0"
426+# catalog drops a project whose current owner is not the pin
427+write_pin "$FP1"
428+CR=$T/catpin
429+for spec in "p-ok:$T/h1" "p-bad:$T/h0"; do
430+ name=${spec%%:*}; key=${spec#*:}
431+ mkdir -p "$CR/projects/$name"
432+ git init -q --bare "$CR/projects/$name/repo.git"
433+ git --git-dir="$CR/projects/$name/repo.git" fetch -q "$T/work" "$C1"
434+ git --git-dir="$CR/projects/$name/repo.git" update-ref refs/heads/main "$C1"
435+ $I init "$CR" "$name" main public - "$key" >/dev/null
436+done
437+t ho-catalog-drops-mismatch 3 $I catalog "$CR"
438+cp "$T/err" "$T/err.catpin"
439+t ho-catalog-drops-mismatch-reason 0 grep -q "p-bad: current owner is $FP0, not $FP1" "$T/err.catpin"
440+t ho-catalog-keeps-pinned 0 grep -q "^p-ok " "$CR/catalog.tsv"
441+t ho-catalog-omits-mismatch 0 test "$(grep -c "^p-bad" "$CR/catalog.tsv" || true)" = 0
442+mkdir -p "$T/ipltmp"
443+TMPDIR="$T/ipltmp" $I verify "$HR" demo >/dev/null
444+t ho-verify-cleans-temp 0 test -z "$(ls -A "$T/ipltmp")"
445+n=$(wc -l < "$HP/chain.tsv")
446+t ho-idempotent 0 $I handover "$HR" demo "$T/h0" "$T/h1.pub" rotate-1
447+t ho-idempotent-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n"
448+cp -a "$HP" "$T/ho-after1"
449+t ho-new-key-land 0 $I land "$HR" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-req-2 "$T/h1" --expect-owner "$FP1"
450+t ho-new-key-land-verifies 0 $I verify "$HR" demo
451+n=$(wc -l < "$HP/chain.tsv")
452+t ho-land-expect-old-fails 3 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-expect "$T/h1" --expect-owner "$FP0"
453+t ho-land-expect-old-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n"
454+n=$(wc -l < "$HP/chain.tsv")
455+t ho-old-key-land-rejected 2 $I land "$HR" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-req-3 "$T/h0"
456+t ho-old-key-land-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n"
457+# swapping owner.pub to the successor key must still fail: owner.pub is the key record 1 names
458+cp "$T/h1.pub" "$HP/owner.pub"
459+t ho-tamper-owner-to-successor 3 $I verify "$HR" demo
460+cp "$T/ho-after1/owner.pub" "$HP/owner.pub"
461+t ho-owner-restored-after-tamper 0 $I verify "$HR" demo
462+# a forged SUCCESSOR not signed by the current key fails verify (actor is the attacker)
463+rm -rf "$HP"; cp -a "$T/ho-after1" "$HP"
464+"$L" successor demo "$FP1" "$FP2" "$BLOB2" forged > "$T/hpay"
465+head -n "$(wc -l < "$HP/chain.tsv")" "$HP/chain.tsv" > "$T/hchain.bak"
466+"$T/chain" add "$HP/chain.tsv" SUCCESSOR "$FP2" "$FP2" < "$T/hpay" >/dev/null
467+hs=$(wc -l < "$HP/chain.tsv")
468+cp "$T/hpay" "$HP/records/$hs"
469+awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/hmsg"
470+ssh-keygen -q -Y sign -n interplane -f "$T/h2" "$T/hmsg" 2>/dev/null
471+"$T/chain" add "$HP/chain.tsv" SIG "$FP2" "$hs" < "$T/hmsg.sig" >/dev/null
472+cp "$T/hmsg.sig" "$HP/records/$((hs + 1))"
473+t ho-forged-handover-fails 3 $I verify "$HR" demo
474+# P1: a SUCCESSOR whose actor is the current key, but whose SIG is by another key, must fail on the signature
475+rm -rf "$HP"; cp -a "$T/ho-after1" "$HP"
476+"$L" successor demo "$FP1" "$FP2" "$BLOB2" forged-sig > "$T/hpay2"
477+"$T/chain" add "$HP/chain.tsv" SUCCESSOR "$FP1" "$FP2" < "$T/hpay2" >/dev/null
478+hs=$(wc -l < "$HP/chain.tsv")
479+cp "$T/hpay2" "$HP/records/$hs"
480+awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/hmsg2"
481+ssh-keygen -q -Y sign -n interplane -f "$T/h2" "$T/hmsg2" 2>/dev/null
482+"$T/chain" add "$HP/chain.tsv" SIG "$FP1" "$hs" < "$T/hmsg2.sig" >/dev/null
483+cp "$T/hmsg2.sig" "$HP/records/$((hs + 1))"
484+t ho-forged-successor-bad-sig 3 $I verify "$HR" demo
485+cp "$T/err" "$T/err.forgedsig"
486+t ho-forged-successor-bad-sig-reason 0 grep -q "does not verify" "$T/err.forgedsig"
487+# an old-key LAND after a real handover, even if well-formed and signed by the old key, fails verify
488+rm -rf "$HP"; cp -a "$T/ho-after1" "$HP"
489+rd=$(sha256sum < "$T/rc" | cut -c1-64); vd=$(sha256sum < "$T/vd" | cut -c1-64)
490+"$L" land demo main "$C2" "$C4" "$rd" "$vd" forged-land > "$T/lpay"
491+"$T/chain" add "$HP/chain.tsv" LAND "$FP0" main < "$T/lpay" >/dev/null
492+hs=$(wc -l < "$HP/chain.tsv")
493+cp "$T/lpay" "$HP/records/$hs"
494+awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/lmsg"
495+ssh-keygen -q -Y sign -n interplane -f "$T/h0" "$T/lmsg" 2>/dev/null
496+"$T/chain" add "$HP/chain.tsv" SIG "$FP0" "$hs" < "$T/lmsg.sig" >/dev/null
497+cp "$T/lmsg.sig" "$HP/records/$((hs + 1))"
498+# the branch also needs to move for a would-be-honest land; either way it must fail
499+git --git-dir="$HP/repo.git" fetch -q "$T/work" "$C4"
500+git --git-dir="$HP/repo.git" update-ref refs/heads/main "$C4"
501+t ho-forged-old-key-land-after-fails 3 $I verify "$HR" demo
502+# two sequential handovers
503+rm -rf "$HP"; cp -a "$T/ho-after1" "$HP"
504+t ho-second-handover 0 $I handover "$HR" demo "$T/h1" "$T/h2.pub" rotate-2
505+t ho-second-verifies 0 $I verify "$HR" demo
506+t ho-third-key-land 0 $I land "$HR" demo main "$C4" "$T/work" "$T/rc" "$T/vd" h-req-4 "$T/h2"
507+t ho-third-key-land-verifies 0 $I verify "$HR" demo
508+n=$(wc -l < "$HP/chain.tsv")
509+t ho-first-key-after-two-rejected 2 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-5 "$T/h0"
510+t ho-second-key-after-two-rejected 2 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-6 "$T/h1"
511+t ho-retired-keys-add-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n"
512+t ho-third-key-lands-on 0 $I land "$HR" demo main "$C5" "$T/work" "$T/rc" "$T/vd" h-req-5 "$T/h2"
513+t ho-after-two-verifies 0 $I verify "$HR" demo
514+# --all: two projects, one call
515+AR=$T/allroot
516+for name in p1 p2; do
517+ mkdir -p "$AR/projects/$name"
518+ git init -q --bare "$AR/projects/$name/repo.git"
519+ git --git-dir="$AR/projects/$name/repo.git" fetch -q "$T/work" "$C1"
520+ git --git-dir="$AR/projects/$name/repo.git" update-ref refs/heads/main "$C1"
521+ $I init "$AR" "$name" main public - "$T/h0" >/dev/null
522+done
523+write_pin "$FP0"
524+t ho-all 0 $I handover "$AR" --all "$T/h0" "$T/h1.pub" rotate-all
525+t ho-all-pin-updated 0 grep -q "$FP1" "$T/owner-pins"
526+t ho-all-p1-verifies 0 $I verify "$AR" p1
527+t ho-all-p2-verifies 0 $I verify "$AR" p2
528+t ho-all-p1-has-successor 0 grep -q $'\tSUCCESSOR\t' "$AR/projects/p1/chain.tsv"
529+t ho-all-p2-has-successor 0 grep -q $'\tSUCCESSOR\t' "$AR/projects/p2/chain.tsv"
530+t ho-all-idempotent 0 $I handover "$AR" --all "$T/h0" "$T/h1.pub" rotate-all
531+# a5: single-project handovers leave NAME lines; --all must rewrite them, not leave them stale
532+A5=$T/a5root
533+for name in demo other; do
534+ mkdir -p "$A5/projects/$name"
535+ git init -q --bare "$A5/projects/$name/repo.git"
536+ git --git-dir="$A5/projects/$name/repo.git" fetch -q "$T/work" "$C1"
537+ git --git-dir="$A5/projects/$name/repo.git" update-ref refs/heads/main "$C1"
538+ $I init "$A5" "$name" main public - "$T/h0" >/dev/null
539+done
540+write_pin "$FP0"
541+t ho-a5-single-demo 0 $I handover "$A5" demo "$T/h0" "$T/h1.pub" a5-demo
542+t ho-a5-single-other 0 $I handover "$A5" other "$T/h0" "$T/h1.pub" a5-other
543+cp -a "$A5" "$T/a5-at-h1"
544+t ho-a5-all 0 $I handover "$A5" --all "$T/h1" "$T/h2.pub" a5-all
545+t ho-a5-pin-demo 0 grep -q "^demo $FP2$" "$T/owner-pins"
546+t ho-a5-pin-other 0 grep -q "^other $FP2$" "$T/owner-pins"
547+t ho-a5-pin-no-stale-demo 0 test "$(grep -c "^demo $FP1$" "$T/owner-pins" || true)" = 0
548+t ho-a5-pin-no-stale-other 0 test "$(grep -c "^other $FP1$" "$T/owner-pins" || true)" = 0
549+t ho-a5-demo-verifies 0 $I verify "$A5" demo
550+t ho-a5-other-verifies 0 $I verify "$A5" other
551+t ho-a5-catalog 0 $I catalog "$A5"
552+t ho-a5-catalog-rows 0 test "$(wc -l < "$A5/catalog.tsv")" = 2
553+t ho-a5-frozen-h1-verify 3 $I verify "$T/a5-at-h1" demo
554+t ho-a5-frozen-h1-other 3 $I verify "$T/a5-at-h1" other
555+t ho-a5-frozen-h1-catalog 3 $I catalog "$T/a5-at-h1"
556+# a3: a pre-existing per-name line that matches * must be rewritten by --all, not left at the old key
557+A3=$T/a3root
558+for name in a1 c3; do
559+ mkdir -p "$A3/projects/$name"
560+ git init -q --bare "$A3/projects/$name/repo.git"
561+ git --git-dir="$A3/projects/$name/repo.git" fetch -q "$T/work" "$C1"
562+ git --git-dir="$A3/projects/$name/repo.git" update-ref refs/heads/main "$C1"
563+ $I init "$A3" "$name" main public - "$T/h0" >/dev/null
564+done
565+printf '* %s\n' "$FP0" > "$T/owner-pins"
566+printf 'c3 %s\n' "$FP0" >> "$T/owner-pins"
567+chmod 600 "$T/owner-pins"
568+t ho-a3-all 0 $I handover "$A3" --all "$T/h0" "$T/h1.pub" a3-all
569+t ho-a3-c3-rewritten 0 grep -q "^c3 $FP1$" "$T/owner-pins"
570+t ho-a3-c3-not-stale 0 test "$(grep -c "^c3 $FP0$" "$T/owner-pins" || true)" = 0
571+t ho-a3-star-rewritten 0 grep -q "^\* $FP1$" "$T/owner-pins"
572+t ho-a3-c3-verifies 0 $I verify "$A3" c3
573+t ho-a3-a1-verifies 0 $I verify "$A3" a1
574+t ho-a3-catalog 0 $I catalog "$A3"
575+t ho-a3-catalog-rows 0 test "$(wc -l < "$A3/catalog.tsv")" = 2
576+# --all preflight is all-or-nothing: a mixed-owner store writes nothing
577+MR=$T/mixroot
578+for spec in "a1:$T/h0" "b2:$T/h2" "c3:$T/h0"; do
579+ name=${spec%%:*}; key=${spec#*:}
580+ mkdir -p "$MR/projects/$name"
581+ git init -q --bare "$MR/projects/$name/repo.git"
582+ git --git-dir="$MR/projects/$name/repo.git" fetch -q "$T/work" "$C1"
583+ git --git-dir="$MR/projects/$name/repo.git" update-ref refs/heads/main "$C1"
584+ $I init "$MR" "$name" main public - "$key" >/dev/null
585+done
586+na1=$(wc -l < "$MR/projects/a1/chain.tsv"); nb2=$(wc -l < "$MR/projects/b2/chain.tsv"); nc3=$(wc -l < "$MR/projects/c3/chain.tsv")
587+write_pin "$FP0"
588+t ho-all-preflight-mixed 2 $I handover "$MR" --all "$T/h0" "$T/h1.pub" rotate-mix
589+cp "$T/err" "$T/err.preflight"
590+t ho-all-preflight-announced 0 grep -q "preflight failed; nothing was recorded" "$T/err.preflight"
591+t ho-all-preflight-names-b2 0 grep -q "b2: current owner is $FP2, not $FP0" "$T/err.preflight"
592+t ho-all-preflight-a1-untouched 0 test "$(wc -l < "$MR/projects/a1/chain.tsv")" = "$na1" -a "$(grep -c $'\tSUCCESSOR\t' "$MR/projects/a1/chain.tsv" || true)" = 0
593+t ho-all-preflight-b2-untouched 0 test "$(wc -l < "$MR/projects/b2/chain.tsv")" = "$nb2"
594+t ho-all-preflight-c3-untouched 0 test "$(wc -l < "$MR/projects/c3/chain.tsv")" = "$nc3" -a "$(grep -c $'\tSUCCESSOR\t' "$MR/projects/c3/chain.tsv" || true)" = 0
595+# a retired key cannot become the owner again
596+rm -rf "$HP"; cp -a "$T/ho-after1" "$HP"
597+write_pin "$FP1"
598+n=$(wc -l < "$HP/chain.tsv")
599+t ho-refuse-prior-owner 2 $I handover "$HR" demo "$T/h1" "$T/h0.pub" rotate-back
600+cp "$T/err" "$T/err.prior"
601+t ho-refuse-prior-owner-reason 0 grep -q "already an owner" "$T/err.prior"
602+t ho-refuse-prior-owner-adds-nothing 0 test "$(wc -l < "$HP/chain.tsv")" = "$n"
603+# a crafted h0->h1->h0 chain, even honestly signed by h1, does not verify
604+"$L" successor demo "$FP1" "$FP0" "$BLOB0" rotate-back > "$T/hback"
605+"$T/chain" add "$HP/chain.tsv" SUCCESSOR "$FP1" "$FP0" < "$T/hback" >/dev/null
606+hs=$(wc -l < "$HP/chain.tsv")
607+cp "$T/hback" "$HP/records/$hs"
608+awk -F'\t' -v n="$hs" 'NR==n {printf "interplane-sig 1\nkind %s\nactor %s\nsubject %s\npayload %s\nprev %s\n",$3,$4,$5,$6,$7}' "$HP/chain.tsv" > "$T/hbackmsg"
609+ssh-keygen -q -Y sign -n interplane -f "$T/h1" "$T/hbackmsg" 2>/dev/null
610+"$T/chain" add "$HP/chain.tsv" SIG "$FP1" "$hs" < "$T/hbackmsg.sig" >/dev/null
611+cp "$T/hbackmsg.sig" "$HP/records/$((hs + 1))"
612+t ho-verify-refuses-returned-owner 3 $I verify "$HR" demo
613+cp "$T/err" "$T/err.back"
614+t ho-verify-refuses-returned-owner-reason 0 grep -q "already an owner" "$T/err.back"
615+# interrupted handover at each write point is finished by the same keys; after-sig no-op clears staging
616+for s in after-stage mid-record after-record after-sig; do
617+ rm -rf "$HP"; cp -a "$T/ho-after1" "$HP"
618+ write_pin "$FP1"
619+ n=$(wc -l < "$HP/chain.tsv")
620+ IPL_TEST_STOP=$s t "ho-stop-$s" 9 $I handover "$HR" demo "$T/h1" "$T/h2.pub" rotate-stop
621+ n1=$(wc -l < "$HP/chain.tsv")
622+ if [ "$s" = after-stage ]; then
623+ t "ho-stop-$s-nothing-recorded" 0 $I verify "$HR" demo
624+ t "ho-stop-$s-lines" 0 test "$n1" = "$n"
625+ elif [ "$s" = after-sig ]; then
626+ t "ho-stop-$s-verifies" 0 $I verify "$HR" demo
627+ t "ho-stop-$s-lines" 0 test "$n1" = "$((n + 2))"
628+ else
629+ t "ho-stop-$s-seen" 3 $I verify "$HR" demo
630+ t "ho-stop-$s-lines" 0 test "$n1" = "$((n + 1))"
631+ fi
632+ if [ "$s" = after-record ]; then
633+ t ho-stop-not-other-key 2 $I handover "$HR" demo "$T/h0" "$T/h2.pub" rotate-stop
634+ fi
635+ t "ho-stop-$s-finished" 0 $I handover "$HR" demo "$T/h1" "$T/h2.pub" rotate-stop
636+ t "ho-stop-$s-result" 0 test "$(wc -l < "$HP/chain.tsv")" = "$((n + 2))" -a -z "$(ls "$HP/staging" 2>/dev/null)"
637+ t "ho-stop-$s-final-verifies" 0 $I verify "$HR" demo
638+done
639+
640+echo "tools: $(git --version), $(ssh -V 2>&1), $(bash --version | head -1), $(sha256sum --version | head -1), $(flock --version), $(awk -W version 2>&1 | head -1), $(sed --version | head -1), $(cmp --version | head -1), $(getconf --version | head -1)"
641+if [ "$fail" = 0 ]; then echo "GATE PASS cases=$pass"; else echo "GATE FAIL pass=$pass fail=$fail"; exit 1; fi

ipl/tools/import-radicle.sh

new file mode 100755
@@ -0,0 +1,67 @@
1+#!/bin/bash
2+# import-radicle.sh ROOT KEY: one-time migration instrument (not part of the store).
3+# Copies every public project of ours from the old Radicle storage into ROOT with the reviewed
4+# snapshot tool (HardenOS gitstore/snapshot.om at a82c8504), then records it: PROJECT, IMPORT, signed.
5+# Reads the old store only. "Ours" means: this node signed refs there AND the old store names this
6+# node's key as the project's only delegate. Private projects are left out of this trial.
7+# The old store is $RAD_HOME/storage (default ~/.radicle/storage). No `rad` program is needed: the
8+# node id is IMPORT_NID (the z6Mk... key the old node signed with), and delegates, visibility, name
9+# and default branch are read with git from the project's identity document, the blob
10+# embeds/radicle.json of the commit refs/rad/id points to (the document `rad inspect` printed).
11+# ROOT/import.tsv gets one line for every repository of the old store that this node signed: name,
12+# old id, branch, old head, store head, and OK, SKIP (left out on purpose, with the reason) or
13+# REFUSED (a failure, with the reason). Repositories this node never signed get no line; they are
14+# counted. Exit 0 when nothing was refused and every project taken has the old store's head, else 1;
15+# 2 when the run could not start or the old store holds nothing.
16+set -u
17+ROOT=$1 KEY=$2
18+here=$(cd "$(dirname "$0")/.." && pwd)
19+OLD=${RAD_HOME:-$HOME/.radicle}/storage
20+( cd "$here/bin" && grep -q ' snapshot$' BUILD.sha256 && sha256sum -c --quiet BUILD.sha256 ) 2>/dev/null ||
21+ { echo "import: bin/ is not what build.sh built with the snapshot source (run build.sh OMC SHA2_OM CHAIN_OM SNAPSHOT_OM)" >&2; exit 2; }
22+[ -d "$OLD" ] || { echo "import: no old store at $OLD" >&2; exit 2; }
23+ME=${IMPORT_NID:-}
24+[[ $ME =~ ^z6Mk[1-9A-HJ-NP-Za-km-z]{44}$ ]] || { echo "import: IMPORT_NID must be the old node's key (z6Mk followed by 44 base58 characters)" >&2; exit 2; }
25+# the old store is read with no caller git settings
26+og() { env -i PATH=/usr/bin:/bin HOME=/nonexistent GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null git "$@"; }
27+mkdir -p "$ROOT/projects" "$ROOT/import-notes" || exit 2
28+: > "$ROOT/import.tsv"; bad=0; seen=0; shopt -s nullglob
29+for d in "$OLD"/z*; do
30+ rid=${d##*/}; seen=$((seen + 1))
31+ # a repository that cannot be read is a failure of this run; one this node never signed is not ours
32+ if ! mine=$(og --git-dir="$d" for-each-ref --count=1 --format=x "refs/namespaces/$ME/refs/rad/sigrefs" 2>/dev/null); then
33+ printf '%s\trad:%s\t-\t-\t-\tREFUSED cannot read the old repository\n' - "$rid" >> "$ROOT/import.tsv"; bad=$((bad + 1)); continue
34+ fi
35+ [ -n "$mine" ] || continue
36+ # a project we cannot inspect is a failure of this run, not a project left out on purpose
37+ if ! doc=$(og --git-dir="$d" cat-file blob refs/rad/id:embeds/radicle.json 2>/dev/null) ||
38+ ! dl=$(printf '%s' "$doc" | jq -er '.delegates[]' 2>/dev/null) || ! vis=$(printf '%s' "$doc" | jq -er '.visibility.type // "public"' 2>/dev/null) ||
39+ ! pl=$(printf '%s' "$doc" | jq -ec '.payload' 2>/dev/null); then
40+ printf '%s\trad:%s\t-\t-\t-\tREFUSED cannot inspect in the old store\n' - "$rid" >> "$ROOT/import.tsv"; bad=$((bad + 1)); continue
41+ fi
42+ if [ "$(printf '%s\n' "$dl" | grep -c .)" != 1 ] || [ "${dl%% *}" != "did:key:$ME" ]; then
43+ printf '%s\trad:%s\t-\t-\t-\tSKIP this node is not its only delegate\n' - "$rid" >> "$ROOT/import.tsv"; continue
44+ fi
45+ [ "$vis" = public ] || { printf '%s\trad:%s\t-\t-\t-\tSKIP not public\n' - "$rid" >> "$ROOT/import.tsv"; continue; }
46+ name=$(printf '%s' "$pl" | jq -r '."xyz.radicle.project".name'); br=$(printf '%s' "$pl" | jq -r '."xyz.radicle.project".defaultBranch')
47+ oldhead=$(og --git-dir="$d" rev-parse -q --verify "refs/heads/$br" 2>/dev/null)
48+ row() { printf '%s\trad:%s\t%s\t%s\t%s\t%s\n' "$name" "$rid" "$br" "${oldhead:-none}" "$1" "$2" >> "$ROOT/import.tsv"; }
49+ [ -n "$oldhead" ] || { row - "REFUSED no canonical head"; bad=$((bad + 1)); continue; }
50+ P=$ROOT/projects/$name
51+ if [ -e "$P" ]; then row - "REFUSED name already taken"; bad=$((bad + 1)); continue; fi
52+ "$here/bin/landrec" project "$name" "$br" public "SHA256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "rad:$rid" 00000000000000000000000000000000 >/dev/null 2>&1 || { row - "REFUSED name or branch breaks the record rules"; bad=$((bad + 1)); continue; }
53+ mkdir -p "$P" || exit 2
54+ "$here/bin/snapshot" "$d" "$P/repo.git" > "$ROOT/import-notes/$name.snapshot.log" 2>&1; src=$?
55+ if [ "$src" != 0 ]; then row - "REFUSED snapshot exit $src"; bad=$((bad + 1)); continue; fi
56+ ( cd "$P" && find repo.git.migration -type f -print0 2>/dev/null | sort -z | xargs -0 -r sha256sum ) > "$ROOT/import-notes/$name.evidence"
57+ printf 'Imported from the old Radicle store (rad:%s) on %s by tools/import-radicle.sh.\nThis head is history taken over as it was. It was not gated or reviewed through the native route.\n' "$rid" "$(date -u +%F)" > "$ROOT/import-notes/$name.note"
58+ "$here/ipl" init "$ROOT" "$name" "$br" public "rad:$rid" "$KEY" >/dev/null 2>> "$ROOT/import-notes/$name.snapshot.log" &&
59+ out=$("$here/ipl" import "$ROOT" "$name" "$br" "$ROOT/import-notes/$name.evidence" "$ROOT/import-notes/$name.note" "import-$rid" "$KEY" 2>> "$ROOT/import-notes/$name.snapshot.log") ||
60+ { row - "REFUSED record step"; bad=$((bad + 1)); continue; }
61+ newhead=$(printf '%s' "$out" | cut -d' ' -f5)
62+ if [ "$newhead" = "$oldhead" ]; then row "$newhead" OK; else row "$newhead" "MISMATCH"; bad=$((bad + 1)); fi
63+done
64+awk -F'\t' '{n[$6 ~ /^OK/ ? "ok" : ($6 ~ /^SKIP/ ? "skip" : "refused")]++} END {printf "import: ok %d, skipped %d, refused %d\n", n["ok"], n["skip"], n["refused"]}' "$ROOT/import.tsv"
65+echo "import: looked at $seen repositories in the old store; tools: identity from refs/rad/id:embeds/radicle.json via $(git --version), $(jq --version)"
66+[ "$seen" -gt 0 ] || { echo "import: the old store holds no repositories" >&2; exit 2; }
67+[ "$bad" = 0 ]

ipl/tools/receipt.sh

new file mode 100755
@@ -0,0 +1,103 @@
1+#!/bin/bash
2+# receipt.sh OMC SHA2_OM CHAIN_OM SNAPSHOT_OM WRONG_OMC TRIAL_ROOT OUT_DIR [EXPECTED_REFUSED ...]
3+# Run from a clean clone of the exact head. Builds, runs the gate and its wrong-compiler control,
4+# makes a trial signing key, imports the old store into TRIAL_ROOT, re-derives the catalog from full
5+# verification (with IPL_OWNER_PINS set to OUT_DIR/owner-pins, outside the trial store), compares
6+# every head with the old store on its own, accounts for every project of
7+# the old store that this node signed, and writes OUT_DIR/READY.json from what it measured. Nothing
8+# in READY.json is typed. The live forge catalog path uses ~/.config/interplane/owner-pins, installed
9+# by hand from the owner key's .pub; this script does not write that file.
10+# TRIAL_ROOT and OUT_DIR must not exist: a receipt is written once and never over another.
11+# EXPECTED_REFUSED names the projects whoever runs this expects the import to refuse. That is the
12+# runner's expectation, written into the receipt as such; it is nobody's decision about a project.
13+# Any other refusal, or an expected one that did not happen, fails the receipt.
14+# Exit 0 only when every step did what READY.json says it should and READY.json was written.
15+set -u
16+cd "$(dirname "$0")/.." || exit 2
17+[ $# -ge 7 ] || { sed -n '2,10s/^# \{0,1\}//p' "$0" >&2; exit 2; }
18+omc=$1 sha2=$2 chainom=$3 snapom=$4 wrong=$5 root=$6 out=$7; shift 7
19+invocation=$(printf ' %q' "$0" "$omc" "$sha2" "$chainom" "$snapom" "$wrong" "$root" "$out" "$@")
20+expected=$(printf '%s\n' "$@" | grep . | sort)
21+# the control needs a real other compiler: a missing file would also be refused, and prove nothing
22+[ -x "$wrong" ] && [ "$(sha256sum "$wrong" | cut -d' ' -f1)" != "$(sed -n 's/^omc-sha256 //p' PIN)" ] || { echo "receipt: WRONG_OMC must be a compiler other than PIN's" >&2; exit 2; }
23+[ -z "$(git status --porcelain)" ] || { echo "receipt: the tree is not clean" >&2; exit 2; }
24+[ ! -e "$root" ] || { echo "receipt: $root exists; a trial store is made fresh" >&2; exit 2; }
25+mkdir "$out" 2>/dev/null || { echo "receipt: $out exists; a receipt is never written over another" >&2; exit 2; }
26+mkdir -p "$root/TRIAL-KEY" || exit 2
27+head=$(git rev-parse HEAD); key=$root/TRIAL-KEY/trial_ed25519
28+ssh-keygen -q -t ed25519 -N "" -C "trial key made by tools/receipt.sh for $head; not an owner's key" -f "$key" || exit 2
29+# Pin outside the trial ROOT (never inside $root). Live forge/mirror hosts use
30+# ~/.config/interplane/owner-pins or IPL_OWNER_PINS; do not install that file from this script.
31+printf '* %s\n' "$(ssh-keygen -lf "$key.pub" | awk '{print $2}')" > "$out/owner-pins"
32+chmod 600 "$out/owner-pins"
33+export IPL_OWNER_PINS="$out/owner-pins"
34+echo "receipt:$invocation" > "$out/commands.txt"
35+run() { # NAME cmd...: the exact command, its log and its exit status
36+ local n=$1; shift; printf '%s:' "$n" >> "$out/commands.txt"; printf ' %q' "$@" >> "$out/commands.txt"; echo >> "$out/commands.txt"
37+ "$@" > "$out/$n.log" 2>&1; echo $? > "$out/$n.rc"
38+}
39+run build sh build.sh "$omc" "$sha2" "$chainom" "$snapom"
40+run gate bash tests/run.sh "$omc" "$sha2" "$chainom"
41+run gate-wrong-compiler bash tests/run.sh "$wrong" "$sha2" "$chainom"
42+run import tools/import-radicle.sh "$root" "$key"
43+run catalog ./ipl catalog "$root"
44+same=0; diff=0
45+while IFS=$'\t' read -r name id br h vis; do
46+ rid=$(sed -n 's/^alias rad://p' "$root/projects/$name/records/1")
47+ o=$(env -i PATH=/usr/bin:/bin git --git-dir="${RAD_HOME:-$HOME/.radicle}/storage/$rid" rev-parse -q --verify "refs/heads/$br" 2>/dev/null)
48+ s=$(env -i PATH=/usr/bin:/bin git --git-dir="$root/projects/$name/repo.git" rev-parse -q --verify "refs/heads/$br" 2>/dev/null)
49+ if [ -n "$h" ] && [ "$o" = "$h" ] && [ "$s" = "$h" ]; then same=$((same + 1)); else diff=$((diff + 1)); echo "$name old=$o store=$s chain=$h"; fi
50+done < "$root/catalog.tsv" > "$out/heads-differ.txt"
51+rc() { cat "$out/$1.rc"; }
52+tsv=$root/import.tsv
53+n_ok=0; n_skip=0; n_ref=0; n_rows=0; refused=""; catalog_lines=0; names_match=0
54+if [ -f "$tsv" ]; then
55+ n_ok=$(grep -c -P '\tOK$' "$tsv"); n_skip=$(grep -c -P '\tSKIP ' "$tsv"); n_ref=$(grep -c -P '\tREFUSED ' "$tsv"); n_rows=$(wc -l < "$tsv")
56+ refused=$(grep -P '\tREFUSED ' "$tsv" | cut -f1 | sort)
57+fi
58+if [ -f "$root/catalog.tsv" ]; then
59+ catalog_lines=$(wc -l < "$root/catalog.tsv")
60+ # by name, not only by count: the verified catalog is exactly the projects the import took
61+ [ -f "$tsv" ] && [ "$(grep -P '\tOK$' "$tsv" | cut -f1 | sort)" = "$(cut -f1 "$root/catalog.tsv" | sort)" ] && names_match=1
62+else : > "$root/catalog.tsv"; fi
63+[ -f "$tsv" ] || : > "$tsv"
64+# every line of the inventory is one of the three outcomes; every OK project is in the verified
65+# catalog and nothing else is; the refusals are exactly the stated ones
66+accounted=0; [ "$n_rows" = $((n_ok + n_skip + n_ref)) ] && [ "$catalog_lines" = "$n_ok" ] && [ "$n_ok" -gt 0 ] && [ "$names_match" = 1 ] && accounted=1
67+refusals_as_stated=0; [ "$refused" = "$expected" ] && refusals_as_stated=1
68+want_import=0; [ "$n_ref" = 0 ] || want_import=1
69+pass=0
70+[ "$(rc build)" = 0 ] && [ "$(rc gate)" = 0 ] && [ "$(rc gate-wrong-compiler)" = 2 ] && [ "$(rc import)" = "$want_import" ] && [ "$(rc catalog)" = 0 ] &&
71+ [ "$diff" = 0 ] && [ "$same" = "$n_ok" ] && [ "$accounted" = 1 ] && [ "$refusals_as_stated" = 1 ] && pass=1
72+jq -n --arg head "$head" --arg root "$root" --arg pin "$(cat PIN)" --argjson pass "$pass" \
73+ --arg gate_last "$(tail -n 1 "$out/gate.log")" --arg tools "$(grep '^tools: ' "$out/gate.log")" \
74+ --arg import_last "$(grep '^import: ok' "$out/import.log")" --arg import_tools "$(grep '^import: looked' "$out/import.log")" \
75+ --arg refused "$(grep -P '\tREFUSED ' "$tsv" | cut -f1,2,6 | tr '\t' ' ')" --arg skipped "$(grep -P '\tSKIP ' "$tsv" | cut -f2,6 | tr '\t' ' ')" --arg expected "$expected" \
76+ --argjson build_rc "$(rc build)" --argjson gate_rc "$(rc gate)" --argjson wrong_rc "$(rc gate-wrong-compiler)" --argjson import_rc "$(rc import)" --argjson catalog_rc "$(rc catalog)" \
77+ --argjson want_import "$want_import" --argjson n_ok "$n_ok" --argjson n_skip "$n_skip" --argjson n_ref "$n_ref" --argjson n_rows "$n_rows" \
78+ --argjson catalog_lines "$catalog_lines" --argjson same "$same" --argjson differ "$diff" --argjson accounted "$accounted" --argjson as_stated "$refusals_as_stated" \
79+ --arg commands "$(cat "$out/commands.txt")" --arg keyfp "$(ssh-keygen -lf "$key.pub" | awk '{print $2}')" \
80+ --arg logs "$(cd "$out" && sha256sum commands.txt build.log gate.log gate-wrong-compiler.log import.log catalog.log heads-differ.txt)" \
81+ --arg inventory "$(sha256sum < "$tsv" | cut -c1-64)" --arg catalog "$(sha256sum < "$root/catalog.tsv" | cut -c1-64)" \
82+ --arg binaries "$(cat bin/BUILD.sha256)" --arg when "$(date -u +%FT%TZ)" --arg host "$(uname -n) $(uname -m)" '
83+ {what: "interplane-native step 1, trial store",
84+ result: (if $pass == 1 then "every step below did what it should" else "FAILED: at least one step below did not do what it should" end),
85+ scope: "a local trial on this host; not installed, not serving, not the publishing route",
86+ head: $head, written: $when, host: $host, pin: ($pin | split("\n") | map(select(. != ""))), built: ($binaries | split("\n")),
87+ commands: ($commands | split("\n") | map(select(. != ""))),
88+ trial_key: {made_by: "this run, for this run", fingerprint: $keyfp, path: ($root + "/TRIAL-KEY")},
89+ steps: [
90+ {step: "build", exit: $build_rc, want: 0},
91+ {step: "gate", exit: $gate_rc, want: 0, last_line: $gate_last, tools: $tools},
92+ {step: "gate with another compiler (control: must be refused)", exit: $wrong_rc, want: 2},
93+ {step: "import", exit: $import_rc, want: $want_import, last_line: $import_last, tools: $import_tools,
94+ inventory_lines: $n_rows, ok: $n_ok, left_out_on_purpose: $n_skip, refused: $n_ref,
95+ refused_projects: ($refused | split("\n") | map(select(. != ""))), refusals_the_runner_expected: ($expected | split("\n") | map(select(. != ""))),
96+ refusals_are_exactly_the_expected_ones: ($as_stated == 1), left_out: ($skipped | split("\n") | map(select(. != ""))), inventory_sha256: $inventory},
97+ {step: "catalog from full verification", exit: $catalog_rc, want: 0, projects: $catalog_lines, catalog_sha256: $catalog,
98+ every_imported_project_and_nothing_else: ($accounted == 1)},
99+ {step: "head of every catalogued project compared with the old store and with repo.git", same: $same, different: $differ, want_different: 0}],
100+ trial_root: $root, logs_sha256: ($logs | split("\n")),
101+ not_done: ["ipl is shell: its decisions are not yet in Omega", "no agent grants, no HTTP actions, no mirrors, nothing served (steps 2 to 6)", "no owner key: the signing key is the trial key above", "private projects are not imported", "interruptions are tested by stopping the program at chosen points, not by cutting power"]}' > "$out/READY.json" ||
102+ { echo "receipt: READY.json could not be written" >&2; exit 1; }
103+[ -s "$out/READY.json" ] && [ "$pass" = 1 ]