interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / docs / CONTRACT.md
| 1 | # forged interface contract (v2) |
| 2 | |
| 3 | Owner: ForgeServer. Applies to every unit composed into `forged`. Questions: `write agent://ForgeServer`. |
| 4 | |
| 5 | `forged` is ONE seeded-Omega program (OM-2), built with the pinned omc |
| 6 | (omega-mv `f4df8239`, `seed/out/omc` sha256 `3ad9f10f…3194`, at spark `~/work/flux/omega-mv`). |
| 7 | It serves sequentially: one request at a time, so all request/response state lives in **globals** |
| 8 | that every handler reads and writes **by name** (omc refuses a global as an argument, error 19). |
| 9 | Handlers never touch the http.om connection arrays `cs`/`io`. |
| 10 | |
| 11 | ## 1. Build and unit order |
| 12 | |
| 13 | `run.sh build` concatenates, in this order, and pipes into omc (`./run.sh units` prints the list): |
| 14 | |
| 15 | ``` |
| 16 | om2 |
| 17 | omega-mv seed/net/http.om (names h*, H*) |
| 18 | omega-mv seed/net/notls.om |
| 19 | omega-mv om/tls/sha2.om (sha256 for anyone: see its own header) |
| 20 | server/util.om (this contract: globals f*, helpers f*, texts tf*) |
| 21 | server/repos.om (allow-list helpers, repo metadata: both repository sources use them) |
| 22 | server/radsrc.om (Radicle source: RIDS.md allow-list, routing table; or .build/store.om + store/repos.om) |
| 23 | nodes/head.om (default branch from HEAD; or store/head.om) |
| 24 | browse/*.om or server/nobrowse.om ForgeBrowse prefix br* (fns), gb* / tb* (globals / texts) |
| 25 | dl/*.om or server/nodl.om ForgeDownloads prefix dl*, gd* / td* (dl/dlclone.om: the clone panel) |
| 26 | collab/*.om or server/nocollab.om ForgePatches prefix co*, gc* / tc* |
| 27 | social/*.om or server/nosocial.om ForgeSocial prefix so*, gs* / ts* |
| 28 | server/json.om server/counts.om (ForgeServer: JSON form fj* / tfj*, counts fz* / tfz*; docs/API.md) |
| 29 | store/moving.om (store-reading build only: the 503 "moving" answer mv*, fmvng; docs/API.md) |
| 30 | growth/*.om or server/nogrowth.om ForgeGrowth prefix gr* / gg* / tg*; docs/GROWTH.md; after counts so it can read them |
| 31 | (store-reading build: store/mvgrowth.om, /trending and /trending.json answer 503) |
| 32 | salvage/[0-9][0-9]*.om or server/nosalvage.om salvage (submissions) prefix sl* / gl* / tl*; docs/SALVAGE.md; |
| 33 | needs collab/ and social/ composed; salvage/collector.om is its own program |
| 34 | (store-reading build: store/mvsalvage.om, salvage/... answers 503) |
| 35 | community/[0-9][0-9]*.om or server/nocommunity.om Community Machines prefix cm_*; docs/COMMUNITY.md |
| 36 | (store-reading build: store/mvcommunity.om, community/... answers 503) |
| 37 | open/route.om or server/noopen.om open builds (Open Humanity shelf) prefix oh* / go* / to*; docs/OPEN-BUILDS.md; |
| 38 | needs salvage/ composed; open/intake.om is its own program |
| 39 | (store-reading build: store/mvopen.om, open/..., open.json, bring.sh, get.sh, |
| 40 | withdraw.sh answer 503) |
| 41 | research/route.om or server/noresearch.om research pages and questions prefix rx* / gx* / tx*; research/README.md |
| 42 | salvage, open and research each define <prefix>nav (slnav, ohnav, rxnav): one |
| 43 | entry in the forge row of server/pages.om fhead; the seam defines it empty |
| 44 | door/*.om or server/nodoor.om the agent door: event stream, feed prefix ev* / gev* / tev*; docs/AGENT-DOOR.md; |
| 45 | needs collab/ and social/ composed; evnav is its forge row entry |
| 46 | .build/agents.om server/agents.om (ForgeServer: agents.json, fqa* / tfqa*; .build/agents.om is server/agents.tsv |
| 47 | compiled by run.sh at every build) |
| 48 | server/pages.om server/jsonp.om (jsonp: the JSON of every other page, fy* / tfy*; after pages.om for its globals) |
| 49 | server/route.om server/main.om |
| 50 | ``` |
| 51 | |
| 52 | - A slice dir is composed only when it holds a `READY` file (ForgeServer sets it after a live test); |
| 53 | otherwise its seam is used. Check your unit composes BEFORE asking for integration: |
| 54 | `cd ~/work/forge/web && FORGE_TRY=<dir> FORGED_OUT=/tmp/x.try ./run.sh build` (rc 0 = composes). |
| 55 | - Every name you define (fn, global, text, const) MUST start with your prefix. Globals/texts are at |
| 56 | most 8 characters. Never define `f*`, `F*`, `tf*`, `h*`, `H*`. Texts are NOT forward-declared: |
| 57 | define a text above its first use. Known keyword clash: `faccess` (and likely other host-word |
| 58 | names) is refused with error 16. |
| 59 | - Files in your dir are composed in `ls` order. No `om2` line, no `fn main`, no `struct`, in your files. |
| 60 | - Functions may be called before their definition (forward calls work across units). |
| 61 | - The seam `server/no<slice>.om` defines your required functions with "not available" behaviour |
| 62 | (route returns 0; nodl also defines an empty `dlclone`). |
| 63 | |
| 64 | ### Store-reading build (interplane-native DESIGN.md step 2) |
| 65 | |
| 66 | `FORGE_STORE=<absolute store root> FORGED_OUT=<path> ./run.sh build` (optional |
| 67 | `FORGE_CLONE_BASE=https://<host>/<path>/`) builds the same source with a second repository source. |
| 68 | `run.sh storegen` writes `.build/store.om` (texts `tfsroot`, `tfcbase`, const `FSCB`), composed after |
| 69 | `server/repos.om`, and these units are composed in place of the default ones: |
| 70 | |
| 71 | | Default unit | Store-reading unit | What it gives | |
| 72 | |---|---|---| |
| 73 | | `server/radsrc.om` | `store/repos.om` | the allow-list, reload check, identifiers, identity words, JSON clone object, footer line, routing table | |
| 74 | | `nodes/head.om` | `store/head.om` | the default branch (the catalog's field instead of the HEAD file) | |
| 75 | | `dl/dlclone.om` | `store/clone.om` | the clone panel (no `rad clone` line; HTTPS only with a clone base) | |
| 76 | | `collab/`, `quiet/`, `growth/`, `salvage/`, `community/`, `open/` | their `server/no<slice>.om` seams | collab and quiet read Radicle patches and issues; growth, salvage, community and open need collab or salvage | |
| 77 | | `research/intake-route.om` | `research/noadd.om` | the intake runs `rad` through the open shelf | |
| 78 | |
| 79 | Both sources define the same words, used by the units around them: `fload` (fills the allow-list, returns |
| 80 | the count or -1), `fsrcchg` (true when the source changed: RIDS.md mtime, or the catalog's inode, size and |
| 81 | mtime), `fputid i` (the identifier in machine forms: `rad:<RID>` or `git:<64-hex id>`), `fhasal i` (repo i |
| 82 | has an old Radicle id), `fradsrc` (Radicle node data may be read: server/counts.om `fzseeds` and its line), |
| 83 | `fradwalk` / `fradseeds i` (the routing table), `fpjterms` (the identity words of the "For developers" |
| 84 | section), `fjclone i` (the JSON clone object) and the text `tfsf4` (the footer line). `fkgit` / `fkgiti` |
| 85 | stay in server/util.om: `store/repos.om` sets `fsrcst` to 1 and `fsrt` to the store root when it loads, |
| 86 | and they then name `<root>projects/<name>/repo.git`. `deploy` and `restart` refuse `FORGE_STORE`; a |
| 87 | store-reading build never writes `server/forged`. The store layout and its rules are interplane-native's |
| 88 | CONTRACT.md v0; `store/repos.om` says which of them forged checks. `store/tests/compare.sh` is the |
| 89 | acceptance test. |
| 90 | |
| 91 | The store repository home resolves its default branch once and pins the README/file links, |
| 92 | Files tab and clone panel to that commit. `brpinhd` copies `gbsha` into `fpin` (uchar 40), calls |
| 93 | `frepohd 0`, then clears `fpin[0]`; tree pages use the same wrapper. `fputpin` writes its 40 bytes. |
| 94 | A full 40-hex ref segment is interpreted as a commit even if a branch has that exact name. |
| 95 | Without `FORGE_CLONE_BASE`, the Git command is omitted but the pinned archive links remain. |
| 96 | An empty repository has no clone panel. |
| 97 | |
| 98 | The public Git edge, not `dlroute`, answers |
| 99 | `/drakestapleton/<repo>/archive/commits/<40-lower-case-hex>.zip|.tar.gz` |
| 100 | (`infra/nginx/snippets/bazinga-git.conf`, `infra/bazinga/omega-read`). The object must be a commit |
| 101 | reachable from a root `refs/heads` or `refs/tags` in the public filtered Git mirror, including |
| 102 | older history and commits on another branch or only under a tag. The download's prefix is |
| 103 | `<repo>-<sha>/`, ETag is the quoted SHA, and Cache-Control is `no-cache`. HEAD sends no body. |
| 104 | Malformed paths fall through to forged; a well-formed but unknown, non-commit or unreachable SHA |
| 105 | gets an empty 404 from the edge. Existing branch archives retain their branch-based prefix. |
| 106 | Forged's legacy `/archive/<7..40-hex>` remains a 302 only for a commit at a canonical head or tag |
| 107 | tip, otherwise 404. It does not implement the edge's `/archive/commits/` path. |
| 108 | |
| 109 | ## 2. Request (set by the server before dispatch; read only) |
| 110 | |
| 111 | Scalars are `global X ulong 1`, read with `get X 0`. |
| 112 | |
| 113 | | Global | Type | Meaning | |
| 114 | |---|---|---| |
| 115 | | `fmeth` | ulong 1 | 1 GET **or HEAD** (http.om drops the body of a HEAD response itself, so handlers treat HEAD as GET), 3 POST, 0 other. 2 is never delivered | |
| 116 | | `fpath`, `fpathl` | uchar 4096 | raw request path (before `?`), starts with `/`. The server already refused (400) any `..` or `.` segment (raw or `%2e`), `//`, NUL, control bytes, and paths over 4096 | |
| 117 | | `fqs`, `fqsl` | uchar 4096 | raw query string without `?` | |
| 118 | | `fbody`, `fbodyl` | uchar 65536 | POST body (at most 64 KiB; larger = 413 before dispatch) | |
| 119 | | `fck`, `fckl` | uchar 4096 | Cookie header value | |
| 120 | | `fip`, `fipl` | uchar 64 | client IP: `X-Real-IP` from nginx when present, else `127.0.0.1` | |
| 121 | | `fbase`, `fbasel` | uchar 64 | `/` or `/forge/` (from `X-Forge-Base`; any other value = `/`). Always ends in `/` | |
| 122 | | `fridx` | ulong 1 | allow-list index of the repo for `/<owner>/<repo>/...`, else 9999 | |
| 123 | | `frid`, `fridl` | uchar 64 | that repo's key: its RID **without** `rad:` (store-reading build: the old RID from record 1, or the 64-hex id of a project without one) | |
| 124 | | `fown`, `fownl` | uchar 64 | owner segment (`drakestapleton`) | |
| 125 | | `frepo`, `frepol` | uchar 128 | repo name exactly as in the allow-list | |
| 126 | | `frest`, `frestl` | uchar 4096 | the path after `/<owner>/<repo>`; empty for the repo home, else starts with `/` (e.g. `/tree/main/src`) | |
| 127 | | `fuser`, `fuserl` | uchar 64 | signed-in user name; `fuserl` 0 = signed out (set by `sosess`) | |
| 128 | | `fcsrf`, `fcsrfl` | uchar 64 | the session's CSRF token (set by `sosess`), for hidden form fields | |
| 129 | | `finm`, `finml` | uchar 256 | `If-None-Match` header value | |
| 130 | | `forig`, `forigl` | uchar 256 | `Origin` header value (empty when absent) | |
| 131 | | `facc`, `faccl` | uchar 512 | `Accept` header value (cut at 512); `fjwant` is true when it names `application/json` and not `text/html` | |
| 132 | |
| 133 | Allow-list (loaded at start, on the reload flag, and when the source changes): default build from spark |
| 134 | `~/handoffs/radicle/RIDS.md`, first table only; store-reading build from `<store>/catalog.tsv`: every |
| 135 | public line (there is no served list since 2026-11-14; RIDS.md is not read), every project checked as |
| 136 | `store/repos.om` says (folders not links, record 1 hashes to the id and names the same project, deny |
| 137 | list by name or old id, no old id already served, head equal to `refs/heads/<branch>`; a malformed |
| 138 | catalog serves nothing; a private line is skipped; a project that fails a check is left out with one |
| 139 | stderr line). `fan` (count), and per index `i < fan`: |
| 140 | `fputrn i` appends the name, `fputrid i` the key (no |
| 141 | `rad:`), `fputid i` the identifier (the bare `<RID>` since 9a4420a / `git:<id>`), `frnlen i`/`fridlen i` lengths, |
| 142 | `frnbyte i k`/`fridbyte i k` one byte. `frepoix` returns the index of the repo whose name equals |
| 143 | `frepo[0,frepol)` or 9999. A repo not in the table does not exist for any handler: the server returns 404 |
| 144 | before dispatch, and handlers MUST NOT read other storage dirs. The table holds `FAMAX` (256) |
| 145 | repositories (`fano` and the per-repo arrays, every loop over them `bound FAMAX`); a project past it is |
| 146 | left out alone ("the allow-list table is full"), and `store/tests/capacity.sh` alarms when the store's |
| 147 | public lines (or, in the default build, the RIDS.md first table) pass 192. In the store-reading build |
| 148 | the sandbox (`infra/spark/forged-sandbox.sh` with `FORGED_STORE`) holds only the projects |
| 149 | `forged-public.sh store_names` selects (public, valid name, not denied); a project created after the |
| 150 | start is bound at the next start. |
| 151 | |
| 152 | Constants: `tfgit` = `/usr/bin/git`, `tfdata` = `/home/drakestapleton/forge-data/`. Default build: |
| 153 | `tfstore` = `/home/drakestapleton/.radicle/storage/` (server/util.om, used by fkgit / fkgiti while `fsrcst` is 0); store-reading build: `tfsroot` |
| 154 | (.build/store.om). Owner name text `tfowner` = `drakestapleton`, owner NID text `tfnid` = |
| 155 | `z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK` (the namespace of copied Radicle refs). |
| 156 | |
| 157 | ## 3. Response (written by the handler) |
| 158 | |
| 159 | | Global | Meaning | |
| 160 | |---|---| |
| 161 | | `fob`, `fobl` | body, uchar 8388608. Append with the helpers below only (they cap at the size and set `fobtr` 1 when cut) | |
| 162 | | `fkind` | 0 = HTML **content fragment**: the server wraps it in the layout (header, footer) with title `fti`/`ftil` (uchar 256, plain text, escaped by the server). 1 = raw body with content type `fct`/`fctl`. 2 = redirect to `floc`/`flocl` (status 302 or 303). 3 = stream a file: path in `ffile`/`ffilel`, content type `fct`, size cap 512 MiB. 4 = stream a command's stdout: the argv left in `fpk` runs again at send time, its stdout goes out as a chunked body with content type `fct` (for output above `fxo`'s 16 MiB that the handler already ran once with `fexec`, e.g. browse `/commit/<sha>.diff`); a failure after the head cuts the connection without the last chunk | |
| 163 | | kind 5 (generated shelf stream) | `ohbody` fills the next complete-row batch in `fob` and returns true, or false at EOF; `ohbodyend` closes its input. `fsend5` sends chunked with `fct`, keeps HTML layout/translation and `format=text`, and calls again until EOF. No total response size limit. `fobtr` or a send failure closes without the final chunk, so a client detects an incomplete body. `server/noopen.om` provides the inactive seam. Used by `/open/` and `/open.json`; the developer page is unchanged. | |
| 164 | | `fct`, `fctl` | uchar 128 content type for kinds 1, 3, 4 and 5 | |
| 165 | | `fcd`, `fcdl` | uchar 512 optional `Content-Disposition` value (kinds 1 and 3) | |
| 166 | | `fsck`, `fsckl` | uchar 512 optional `Set-Cookie` value (`fsetsck t` / `fscc c`) | |
| 167 | | `floc`, `flocl` | uchar 4096 Location for kind 2. Build it with `flocb` (base) + `flocc`/`floct`; `flocrepo` appends `<owner>/<repo>` | |
| 168 | | `fetag`, `fetagl` | uchar 128 optional `ETag` value, quotes included (`fetc c`). With kind 1 or 3: when `finm` equals it, return 304 with kind 1 and empty `fob`; the server sends no body and no Content-Type | |
| 169 | | `fcc`, `fccl` | uchar 128 optional `Cache-Control` replacing `no-store` (`fsetcc t` / `fccc c`) | |
| 170 | | `fretry` | ulong; nonzero = also send `Retry-After: <fretry>` (seconds), e.g. with a 503 | |
| 171 | | `fcspsb` | ulong; nonzero = send the sandbox CSP `sandbox; default-src 'none'; img-src 'self'; style-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'` instead of the page CSP. Set it with `fsetsbx` (browse `/raw/`) | |
| 172 | |
| 173 | The server resets all response globals before each dispatch (kind 0, lengths 0). |
| 174 | Every response gets `Content-Security-Policy: default-src 'none'; style-src 'self'; img-src 'self'; script-src 'none'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'`, |
| 175 | `X-Content-Type-Options: nosniff`, `Referrer-Policy: same-origin`, `Cache-Control: no-store` (kinds 0-2). |
| 176 | No JavaScript, ever: no `<script>`, no `on*=` attributes, no `javascript:` URLs. |
| 177 | |
| 178 | ### Handler naming and dispatch |
| 179 | |
| 180 | ``` |
| 181 | fn brroute to long ForgeBrowse repo pages under /<owner>/<repo>[/...] (fridx set), and /<owner>/<repo>/search |
| 182 | fn dlroute to long ForgeDownloads /<owner>/<repo>/archive/..., /<owner>/<repo>/releases[...] |
| 183 | fn coroute to long ForgePatches /<owner>/<repo>/patches[...], /<owner>/<repo>/issues[...] |
| 184 | fn soroute to long ForgeSocial /login /logout /stars /settings, POST star/fav/follow, /<owner>/followers etc. |
| 185 | ``` |
| 186 | |
| 187 | Return 0 = not mine (the server tries the next handler, then its own pages). Otherwise return the HTTP |
| 188 | status (200, 302, 303, 304, 400, 403, 404, 405, 413, 429, 500, 501) and fill the response globals. |
| 189 | Order: `soroute`, `dlroute`, `coroute`, `brroute`, then server pages. A 4xx/5xx with `fkind` 0 and |
| 190 | empty `fob` gets the server's error page. When no handler claims a known repo feature path |
| 191 | (`/tree /blob /raw /blame /commits /commit /compare /branches /tags /releases /archive /patches |
| 192 | /issues /stargazers /search /labels`) the server answers 501 "Coming soon", and the reserved pages |
| 193 | `/login /logout /settings /new /stars /notifications /api` also answer 501 until claimed. An unclaimed |
| 194 | POST to `/<o>/<r>/star|unstar|fav|unfav` or to `<base>follow` / `<base>unfollow` (form field `user` |
| 195 | names the account) is 303 to `<base>login`. |
| 196 | For `/<owner>/<x>` where `x` is not a public repo, only `soroute` is asked (with `fridx` 9999). |
| 197 | |
| 198 | Machine form (ForgeServer, `docs/API.md`): before any slice, `froute` answers `<base>explore.json`, |
| 199 | `<base><o>/<r>.json` and (with `fjwant`) `/`, `/explore` and the repo home as JSON (kind 1). For a |
| 200 | repo home GET it first calls `fzprep` (reads what the logs added, `server/counts.om`); `frepohd` |
| 201 | then shows the counts when `frest` is empty, and the layout adds `<link rel="alternate">` to the |
| 202 | JSON form on explore and the repo home. Slices need not do anything for either. |
| 203 | |
| 204 | Every other page has a machine form too (card t_6b17c31a): the page answers JSON at its own URL when |
| 205 | `fjwant` is true. A slice handler of a page with a JSON form does, after the same validation as its |
| 206 | HTML path: `if fjwant` -> its JSON emitter (start with `fyrhead` / `fyuhead`, keys with `fyk`, values |
| 207 | with `fnum`, `fybool`, `fynull`, `fysx`, `fysv`, `fjstr`, `fjiso`, close with `fyend`; all in |
| 208 | `server/json.om` and `server/jsonp.om`); else `fyalt` (the layout then names the page's own URL as |
| 209 | `<link rel="alternate" type="application/json">`) and the unchanged HTML handler. Errors stay "return |
| 210 | the status with `fob` empty": for a JSON request `ferrpage` answers a `forge/error/1` document. Raw |
| 211 | byte routes (`/raw/`, `.patch`, `.diff`, archives, release assets) have no JSON form. Every schema is |
| 212 | documented in `docs/API.md` in the format `server/tests/jsonpages.py` parses; that test walks every |
| 213 | page under both bases. |
| 214 | |
| 215 | ### Social functions the server calls (ForgeSocial provides) |
| 216 | |
| 217 | ``` |
| 218 | fn sosess to long parse fck, set fuser/fuserl/fcsrf/fcsrfl; 1 signed in, 0 not |
| 219 | fn sostarn i ulong to ulong star count of allow-list repo i |
| 220 | fn sofavn i ulong to ulong favorite count of repo i |
| 221 | fn sofolln to ulong followers of the user named fown[0,fownl) |
| 222 | fn sofollg to ulong accounts that user follows |
| 223 | fn sobar to void append the star / favorite forms (or sign-in links) for repo fridx to fob |
| 224 | fn sofolbar to void append the follow form for user fown to fob |
| 225 | fn socsrfok to bool true when the body field csrf equals the session token (and signed in) |
| 226 | fn sostarsof to void append the list of repos the user fown starred to fob (profile tab) |
| 227 | fn sojstars to void the same list as a JSON array of {name, rid, path, stars} (forge/user/1 starred) |
| 228 | fn soload to long replay ~/forge-data log at start and on SIGHUP |
| 229 | ``` |
| 230 | |
| 231 | Edge (ForgeInfra): nginx strips `/forge/`, so `fpath` is always rooted at `/` on both domains; |
| 232 | `X-Forge-Base` only builds links and Locations. Redirect Locations MUST be base-prefixed (`flocb`). |
| 233 | The edge CSP forbids inline `style=` and `<style>`: use class names from the server stylesheet |
| 234 | `<base>assets/forge.css`, whose source is the text `tchrcss` of the generated unit `.build/chrome.om` (the site's |
| 235 | `:root` line and, between the site-chrome marks, its header and footer rules, made at every build by |
| 236 | `server/chromegen.om` from interplane.io `public/style.css`; checked by `server/tests/sitechrome.sh`) and the |
| 237 | texts `tfcssv` and `tfcss2..9` in `server/pages.om` (ask ForgeServer to add a class). `frepohd tab` and `dlclone` (the clone panel: rad, git over HTTPS, zip/tar.gz) are in |
| 238 | pages.om / dl/dlclone.om (store-reading build: store/clone.om, git over HTTPS only with a clone base, zip/tar.gz). |
| 239 | |
| 240 | The generated header marks the single `https://interplane.io/explore` link (Projects) current with |
| 241 | `aria-current="true"`; `tfcss2` styles it and the forge controls stay in their separate row. |
| 242 | `tchrfoot` holds the site's three-column footer through its SI line; forge-specific fine print is |
| 243 | followed by generated `tchrfend`, which closes the site's footer containers. The decorative rope band |
| 244 | between the site's main and footer is deliberately excluded. Responsive chrome rules and the later |
| 245 | Strand-system overrides retain source order and their enclosing at-blocks. |
| 246 | |
| 247 | ## 4. Helpers in server/util.om |
| 248 | |
| 249 | | Helper | Effect | |
| 250 | |---|---| |
| 251 | | `fput s view uchar *` / `fputc c uchar` | append raw bytes / one byte to `fob` | |
| 252 | | `fesc s view uchar *` / `fescc c uchar` | append HTML-escaped (`& < > " '`) | |
| 253 | | `fnum v ulong` | append decimal | |
| 254 | | `fputb` | append the base (`/` or `/forge/`) | |
| 255 | | `flink p view uchar *` | append base + `p` (`p` has no leading `/`): `flink tbx` → `/forge/x` | |
| 256 | | `fputrepo` | append `<owner>/<repo>` of the current request, escaped | |
| 257 | | `fputrl` | append the repo URL `<base><owner>/<repo>` | |
| 258 | | `fputown` / `fputrnm` | append the owner / the repo name, escaped | |
| 259 | | `frepohd tab ulong` | (pages.om) append the repo header: owner/repo title, description, `sobar`, clone line, tabs. tab: 0 Code 1 Commits 2 Branches 3 Tags 4 Releases 5 Patches 6 Issues | |
| 260 | | `fdesc i ulong` / `fputbr i ulong` / `fputlc i ulong` | append the escaped description / default branch / last commit line (`YYYY-MM-DD <sha7> <subject>`) of repo i | |
| 261 | | `fpeq t` / `fpre t` | `fpath` equals / starts with text `t` | |
| 262 | | `frsteq t` / `frstpre t` | the same tests on `frest` | |
| 263 | | `fqget n view uchar * to long` | find query param `n` in `fqs`, percent-decode (`+` = space) into `fval` (uchar 4096); returns length or -1 | |
| 264 | | `fbget n view uchar * to long` | same for the urlencoded POST body `fbody` | |
| 265 | | `flocb`, `flocc c uchar`, `floct t view uchar *` | build `floc`: base, then bytes | |
| 266 | | `fsetct t view uchar *`, `fsetcd t view uchar *`, `fsetti t view uchar *`, `ftic c`, `fcdc c`| set content type, Content-Disposition, title (and byte variants) | |
| 267 | | `fkgit` / `fkgiti i ulong` | start an argv in `fpk` (uchar 8192): `/usr/bin/git --git-dir=<storage>/<rid>` (store-reading build, `fsrcst` 1: `<store>/projects/<name>/repo.git`) for the current repo / repo i | |
| 268 | | `fkb`, `fka t view uchar *`, `fkopen`, `fkc c uchar` | argv builder (`fkb` empty; `fka` add an arg; `fkopen` start an arg and `fkc` append bytes to it) | |
| 269 | | `fexec tmo long to long` | fork + execprog argv `fpk` (no shell, empty env, stdin/stderr `/dev/null`, stdout into `fxo` uchar 16777216, length `fxol`; `fxotr` 1 when cut). Returns exit status, -1 timeout (killed), -2 cannot start | |
| 270 | | `fxput a ulong n ulong` / `fxesc a ulong n ulong` | append `fxo[a,a+n)` raw / escaped to `fob` | |
| 271 | | `flog t view uchar *` | one line to stderr (the access log is the server's) | |
| 272 | | `fpb`, `fpc c`, `fpt t`, `frdall to long` | build a file path in `fpth` (`fpb` = data dir), read the whole file into `fxo` | |
| 273 | | `fmtime to ulong` | st_mtime of `fpth` (0 when missing) | |
| 274 | | `fratelim to bool` | per-IP write limit (30 writes per 60 s), keyed on the full IP (64-bit FNV-1a, 256 slots, a full table evicts the oldest window); false = answer 429 | |
| 275 | | `fsetsbx` | use the sandbox CSP for this response (`fcspsb` 1) | |
| 276 | |
| 277 | Inputs: every user-supplied value is length-checked by the caller of `fqget`/`fbget` (they cap at |
| 278 | 4096) and escaped on output with `fesc`/`fescc`/`fxesc`. git args from users (refs, paths) MUST be |
| 279 | checked by the slice: refuse a leading `-`, NUL, control bytes and `..` segments, and pass them after |
| 280 | `--` where git allows. |
| 281 | |
| 282 | ## 5. Writes |
| 283 | |
| 284 | Before any handler runs, `froute` answers 403 to a POST whose `Origin` header is present and is not |
| 285 | exactly `https://interplane.io` or `https://www.aienos.com` (an absent Origin leaves the CSRF token to |
| 286 | decide). Every POST handler MUST: require `fmeth` 3, `sosess` signed in (else 303 to `/login`), `socsrfok` |
| 287 | (else 403), and the per-IP write limit `fratelim to bool` (false = 429). Then 303 back to the page. |
| 288 | |
| 289 | ## 6. Links |
| 290 | |
| 291 | Every link and form action is built from the base: `flink`, `fputb`, `flocb`. Never write a bare |
| 292 | `href="/` . The same page MUST be correct under `X-Forge-Base: /` and `X-Forge-Base: /forge/`. |