interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / docs / collab-write.md
| 1 | # Collab writes (wave 2): comments, reviews and opening patches from the web |
| 2 | |
| 3 | Status: Phase A IMPLEMENTED and HOST_TESTED (wave 2); Phase B PROPOSED, waiting for Drake. |
| 4 | Owner: ForgePatches. The server has no Radicle write path; Phase B needs Manager and Drake approval. |
| 5 | |
| 6 | ## The rule this design keeps |
| 7 | |
| 8 | "Agents express intent. The forge retains authority." On Radicle, authority over a change is the |
| 9 | author's key: every COB change is a git commit signed by the author's node key, and every namespace's |
| 10 | refs are signed by its owner (`refs/rad/sigrefs`). So the forge server must never hold, derive or ask |
| 11 | for a user's private key, and must never write a change in the forge node's name for someone else. |
| 12 | A web comment that the forge signed would show the forge node as the author. That is false, so it is |
| 13 | not built. |
| 14 | |
| 15 | ## What Radicle requires (measured on spark, rad 1.10.3) |
| 16 | |
| 17 | - A change commit (`refs/namespaces/<nid>/refs/cobs/xyz.radicle.patch|issue/<id>`) has a tree with |
| 18 | blobs `0`, `1`, … (one JSON action each) and `manifest`; parents are the previous tips of that COB |
| 19 | plus the commits the actions name (`Rad-Related:` trailers) and the identity root |
| 20 | (`Rad-Resource:`). It carries a `gpgsig` SSH signature (SSHSIG, namespace `radicle`, sha256) by |
| 21 | the author's ed25519 key. Collab wave 1 reads the author DID from that key (`cosig`). |
| 22 | - The namespace's `refs/rad/sigrefs` commit holds blobs `refs` (the ref list) and `signature` |
| 23 | (64 bytes, a raw ed25519 signature over `refs`). Peers reject refs that do not match it. |
| 24 | - `ssh-keygen -Y sign` produces SSHSIG, which fits the change commit but not the raw sigrefs |
| 25 | signature. A complete web-signed write therefore needs two signatures, one of them raw. |
| 26 | |
| 27 | ## Phase A: compose on the web, run with `rad` (no server write path) |
| 28 | |
| 29 | The web composes and checks the action; the user's own node signs and publishes it. Built in |
| 30 | `collab/co9comp.om` (form decoder, text checks, compose store), `collab/co9form.om` (forms, POST |
| 31 | handlers) and `collab/co9page.om` (compose page, download). |
| 32 | |
| 33 | 1. A signed-in user (Radicle-key session, `docs/social.md`) gets a form under a patch page (comment |
| 34 | on the shown revision, or review it: no verdict, accept, reject) and under an issue page |
| 35 | (comment), and the forms `<o>/<r>/issues/new` (title, description) and `<o>/<r>/patches/new` |
| 36 | (title, description, draft). Lists link the two new forms. Signed out, each place shows a |
| 37 | sign-in link instead. |
| 38 | 2. `POST <o>/<r>/issues/<id>/compose`, `<o>/<r>/patches/<id>/compose`, `<o>/<r>/issues/new` and |
| 39 | `<o>/<r>/patches/new` pass the contract section 5 gate in order: signed out → 303 to `login`; |
| 40 | CSRF token wrong or missing → 403; more than 30 writes a minute from the address → 429. Then: |
| 41 | the target id (a unique prefix of 4..40 hex) is a COB of this repo, else 404; the revision |
| 42 | (field `rev`, default the latest) is an unredacted revision of the patch, else 400; `verdict` is |
| 43 | comment, review, accept or reject, else 400. Text: CRLF and CR become LF; it must be UTF-8 (no |
| 44 | overlong forms, surrogates or code points above U+10FFFF) without NUL, control bytes or DEL |
| 45 | (tab and LF allowed in a body; none in a title); trailing blanks and leading blank lines are |
| 46 | trimmed; body ≤ 60000 bytes and required for comments and the no-verdict review; title 1..256 |
| 47 | bytes on one line. A refusal is a 400 page naming the rule; nothing is kept. |
| 48 | 3. A checked compose is kept in memory (32 slots, oldest reused) for 15 minutes, bound to the |
| 49 | session's CSRF token, the repo and a 128-bit id from `/dev/urandom`; the POST answers 303 to |
| 50 | `<o>/<r>/compose/<id>`. Another session, a signed-out visitor, another repo or an expired or |
| 51 | altered id gets 404. |
| 52 | 4. The compose page shows the Markdown preview (the same renderer as the pages), the file to |
| 53 | download (`<o>/<r>/compose/<id>/<file>`, `text/markdown`, attachment) and the exact command for |
| 54 | sh, bash or zsh. The command holds only fixed words, hex ids and the RID; the user's text reaches |
| 55 | `rad` or `git` only through the downloaded file and `"$(...)"`, so nothing in it is ever parsed |
| 56 | by the shell: |
| 57 | - issue comment (`comment.md`): `rad issue comment <issue> --repo rad:<RID> --message="$(cat comment.md)"` |
| 58 | - patch comment (`comment.md`, on the revision): `rad patch comment <revision> --repo rad:<RID> --message="$(cat comment.md)"` |
| 59 | - review (`review.md`): `rad patch review <patch> --repo rad:<RID> --revision <revision> [--accept|--reject] --message="$(cat review.md)"`, or `--no-message` without text (no file) |
| 60 | - new issue (`issue.md`: title, blank line, description): `rad issue open --repo rad:<RID> --title="$(head -n 1 issue.md)" --description="$(tail -n +3 issue.md)"` |
| 61 | - new patch (`patch.md`, same layout), from the clone on the proposed branch: |
| 62 | `git push -o patch.message="$(head -n 1 patch.md)" [-o patch.message="$(tail -n +3 patch.md)"] [-o patch.draft] rad HEAD:refs/patches`. |
| 63 | git-remote-rad refuses a push option with a line break, so a one-line description goes in the |
| 64 | second `patch.message`; a longer one is set afterwards with |
| 65 | `rad patch edit PATCH_ID --repo rad:<RID> --message="$(head -n 1 patch.md)" --message="$(tail -n +3 patch.md)"`, |
| 66 | with the id git push printed. |
| 67 | 5. The user runs it from a clone; their node signs the change and sigrefs and announces them. The |
| 68 | forge's node fetches as it does today; the page shows the change once it is in storage, read by |
| 69 | the same wave 1 code. |
| 70 | |
| 71 | Phase A adds no trust path: the server only validates and renders text, and the POST handlers never |
| 72 | run `rad` or `git`. Replies, labels and state changes are not composed yet (the forms cover |
| 73 | comment, review, new issue and new patch). |
| 74 | |
| 75 | Measured with rad 1.10.3 in a throwaway profile (`collab/tests/compose.sh`): every command above, |
| 76 | run as shown, published its change and the forge then showed it; a title beginning with `-` or |
| 77 | holding quotes, `$(...)` or backticks is passed through unchanged; `rad patch review` without |
| 78 | `--accept`/`--reject` records a review without a verdict. |
| 79 | |
| 80 | ## Phase B: one-click writes signed in the user's own tool |
| 81 | |
| 82 | For users who do not want a terminal step per action, a small first-party signer (seeded Omega, with |
| 83 | ed25519 from the seed crypto) runs on the user's machine. The forge never sees the key. |
| 84 | |
| 85 | 1. The web builds the unsigned change commit bytes for the composed action (tree, parents = current |
| 86 | tips of that COB in the user's namespace or the root change, related commits, author |
| 87 | `<alias> <alias@nid> <ts> +0000`) and the new `refs` blob for the user's namespace, and offers |
| 88 | both as one download `forge-intent-<compose id>.txt` (hash of each part shown on the page). |
| 89 | 2. `forge-sign forge-intent-….txt` shows the user what will be signed (action JSON, COB, repo), |
| 90 | signs the commit (SSHSIG, namespace `radicle`) and the refs blob (raw ed25519), and prints one |
| 91 | armored block. |
| 92 | 3. The user pastes the block into the page. `POST …/submit` (session + CSRF + compose id, block |
| 93 | ≤ 8 KiB) checks, in order: compose id unused and unexpired; the session DID equals the |
| 94 | commit's signing key and the sigrefs key; `ssh-keygen -Y verify -n radicle` on the commit with |
| 95 | an allowed-signers line built from the DID; the raw signature over `refs`; the parents are still |
| 96 | the current tips (else 409 and a fresh compose); the action JSON is byte-equal to what was |
| 97 | composed. |
| 98 | 4. Only then does the server write: `git hash-object -w` for the blobs and the exact commit bytes, |
| 99 | and a compare-and-swap ref update (`git update-ref <ref> <new> <old>`) for the COB ref and |
| 100 | `refs/rad/sigrefs`, inside the user's own namespace only. All argv execs on the allow-listed |
| 101 | storage, no shell. |
| 102 | 5. The node announces the user's refs (`rad sync --announce`, or the node's own refs-announce), |
| 103 | which other peers verify against the user's signatures, not the forge's. |
| 104 | |
| 105 | Phase B is a Radicle storage write and a new trust path. It needs Manager approval, a negative-control |
| 106 | suite (forged commit signature, forged sigrefs signature, DID mismatch, stale parents, replayed compose |
| 107 | id, tampered action, oversized block, CSRF missing, unsigned session, rate floods) and an independent |
| 108 | replay of the verification with heartwood's own `radicle-cli` reading the result back. |
| 109 | |
| 110 | ## Opening a patch from the web |
| 111 | |
| 112 | A patch needs its head commit in storage. rad 1.10.3 has no `rad patch open`; a patch is opened by |
| 113 | pushing to the magic ref `git push rad HEAD:refs/patches` (git-remote-rad). Phase A: the page gives |
| 114 | that command with the push options measured on rad 1.10.3 (`-o patch.message=` once for the title |
| 115 | and once for a one-line description, `-o patch.draft`; an unknown option or a line break is refused) |
| 116 | and `rad patch edit` for a longer description (step 4 above). Phase B: only for heads already in the user's |
| 117 | namespace (pushed with `git push rad`), the web composes the `revision` action against that head and |
| 118 | signs it as above. The web never accepts uploaded git objects. |
| 119 | |
| 120 | ## Limits and safety (both phases) |
| 121 | |
| 122 | - Inputs (Phase A as built): comment, review and description ≤ 60000 bytes, title ≤ 256 bytes; |
| 123 | the request body is capped at 64 KiB by the server. Proposed for later: label ≤ 64 bytes and |
| 124 | ≤ 16 labels. All HTML output escaped as in wave 1; Markdown through the browse renderer. |
| 125 | - Rate: 30 writes per minute per IP and per DID (shared with the social gate), 60 signature |
| 126 | verifications per minute globally. |
| 127 | - Pages stay JavaScript-free: forms, 303 redirects and downloads only; CSP unchanged. |
| 128 | - Allow-listed repos only; a non-listed repo is 404 before any collab code runs. |
| 129 | - Email-only accounts cannot write: a write always needs the DID's signature. |
| 130 | - Raw diff cache (`<data>/collab/<rid>/<base>-<head>.full.diff`, `git diff --full-index`, `collab/co8cache.om`): at most 2 GiB |
| 131 | in total (`UnitConvert[Quantity[2, "Gibibytes"], "Bytes"] -> 2147483648`) and 512 MiB per file |
| 132 | (536870912 bytes); after each new file the least recently used files (status-change time, which a |
| 133 | cache hit refreshes) are removed until the total fits, as dl does for archives. A diff over the |
| 134 | per-file limit is refused with a page saying so and is not kept. Tested with the caps cut to |
| 135 | 560000 and 21000000 bytes (`collab/tests/cache.sh`). |
| 136 | |
| 137 | ## Status |
| 138 | |
| 139 | | Piece | Status | |
| 140 | |---|---| |
| 141 | | Read-only patches, issues, verdicts, diffs (wave 1) | IMPLEMENTED, HOST_TESTED (`collab/tests/check.sh`) | |
| 142 | | Verdict line: only an exact first line `VERDICT <word> head=<revision head>`, word MERGE, MERGE_AFTER_FIX or REJECT, no folder or file name (sec P3-1); patch page names the commit forged was built from (corr P1; run.sh writes `tcbldc`) | IMPLEMENTED, HOST_TESTED (`collab/tests/verdict.sh`, 11 checks) | |
| 143 | | Markdown descriptions, comments and review bodies (browse renderer) | IMPLEMENTED, HOST_TESTED (`collab/tests/check.sh`, browse md fixtures) | |
| 144 | | Phase A compose + `rad`/`git` command | IMPLEMENTED, HOST_TESTED (`collab/tests/compose.sh`, 89 checks) | |
| 145 | | Raw diff cache bound (2 GiB LRU, 512 MiB per file) | IMPLEMENTED, HOST_TESTED (`collab/tests/cache.sh`, 16 checks) | |
| 146 | | Phase B web submit with user signatures | PROPOSED, needs Manager approval | |