| 1 | # Progress |
| 2 | |
| 3 | ## This attempt (#3, Topcoat) |
| 4 | |
| 5 | 1,150 tests. Active milestone in [current.md](current.md). |
| 6 | |
| 7 | ### The per-file last-commit column — section 1's last gap |
| 8 | |
| 9 | Every file and directory in a listing now says what last changed it and when, linking to |
| 10 | that commit. It is the column 0006 deferred twice, and it is on the landing page and on |
| 11 | every subdirectory. |
| 12 | |
| 13 | - **One `git log --name-only` per listing, not one per entry.** At one fork per entry a |
| 14 | twenty-file directory was the ~230ms that made 0006 defer it in the first place. The |
| 15 | walk is `--format=%H%x00%ct%x00%s --name-only -z`, narrowed to the directory by a |
| 16 | pathspec, capped at **500 commits** — 500 that touched *this directory*, which is deep |
| 17 | enough that a real listing is attributed long before it. |
| 18 | - **Newest first, first mention wins, and a path under a child attributes to the child**: |
| 19 | `src/web/page.rs` in a listing of `src` is `web`'s row. The walk stops as soon as every |
| 20 | entry has an answer, so the cap is a worst case rather than the usual cost. |
| 21 | - **An entry the walk never reached shows nothing.** A blank is honest; the oldest commit |
| 22 | read is not the answer and would look like one. |
| 23 | - **`-z` output has no record boundary** — git writes one flat NUL-separated sequence of |
| 24 | fields and paths — so a record is recognised by shape: forty hex digits followed by a |
| 25 | field that parses as a time. That also survives a merge, which `--name-only` prints |
| 26 | with no file list at all. |
| 27 | |
| 28 | ### A kept-alive `git cat-file` — stage 2 of 0006 |
| 29 | |
| 30 | **Object reads no longer fork.** `infrastructure/cat_file.rs` keeps two `git cat-file` |
| 31 | processes per repository — `--batch-check` and `--batch` — in a pool in app context, and |
| 32 | `DiskGitQuery` writes lines to them instead of spawning. The port is unchanged and its |
| 33 | whole test suite passed unmodified, which is what "an adapter change behind an unchanged |
| 34 | contract" was supposed to mean. |
| 35 | |
| 36 | The landing page went from **15 processes and 115 ms to 4 and 31 ms**; a tree page from |
| 37 | 3 and 35 ms to 1 and 13 ms. The full table, the reasoning, and what stayed a process are |
| 38 | in the [third amendment to |
| 39 | 0006](decisions/0006-git-binary-behind-narrow-ports.md#amendment--20260906-stage-2-a-kept-alive-cat-file). |
| 40 | What is worth not rediscovering: |
| 41 | |
| 42 | - **`--batch-command` was rejected on the git version floor, not on shape.** It is the |
| 43 | better shape — one process, each line naming its verb — and it needs git 2.36. Ubuntu |
| 44 | 22.04 ships 2.34 and `install.sh` supports it deliberately. `-z` for NUL-delimited |
| 45 | *input* is 2.31 and is used, so a path containing a newline is one spec rather than two |
| 46 | requests. |
| 47 | - **A batch stream is positional, so a misread reply is silent corruption**, not an |
| 48 | error: every answer after it shifts by one, and the visible symptom is the wrong file's |
| 49 | bytes under the right filename. Hence the desync guard — the `--batch` request carries |
| 50 | the id, type and size `--batch-check` already gave, the reply header is *checked* |
| 51 | rather than parsed, and any mismatch kills the process. A process that merely died is |
| 52 | a different case and is respawned once per request. |
| 53 | - **The shim technique paid off a second time.** A `git` on `PATH` logging its arguments |
| 54 | gave every number in the table in about ten minutes, and it is how the "15 processes" |
| 55 | claim was checkable at all. |
| 56 | - **`ls-tree --long` became two questions.** A tree object carries no sizes, so the |
| 57 | listing is the tree object parsed here plus one bulk `--batch-check` for the blob and |
| 58 | symlink entries — chunked to 256 specs or 8 KiB, because writing more than a pipe holds |
| 59 | without reading deadlocks both ends. |
| 60 | - **A one-commit log is not a log.** `log(rev, 0, 1)` — the landing page's latest-commit |
| 61 | bar — is the revision's own commit object, so it costs no walk and no process. Anything |
| 62 | wider still runs `git log`, which is what walking history is. |
| 63 | - **git's `%s` is the first *paragraph*, folded onto one line, not the first line.** The |
| 64 | commit parser reproduces that, and a `gpgsig`'s continuation lines each begin with a |
| 65 | space — so the blank-looking ones inside a signature must not be read as the end of the |
| 66 | headers. |
| 67 | |
| 68 | ### Section 1 wave — read-only browsing · done |
| 69 | |
| 70 | **Every read-side `git` process is now bounded at 20 s** (`GIT_TIMEOUT` in |
| 71 | `git_query.rs`), and the child is `kill_on_drop` so a cancelled request takes git with |
| 72 | it. Added before blame and grep arrived, because those are the first reads that can |
| 73 | run long on a big repository, and five agents each adding their own bound would have |
| 74 | produced five. `GitQueryError::is_timeout()` is how a page tells "asked too much" |
| 75 | (render a state, offer less) from "git failed" (a 500). Tokio's `time` feature was |
| 76 | enabled for it. |
| 77 | |
| 78 | **Syntax highlighting (merged 2026-09-05).** `syntect` with the pure-Rust `default-fancy` |
| 79 | engine plus `two-face` (`syntect-fancy` feature) for the grammars the default set lacks — |
| 80 | TOML, Dockerfile, TypeScript — at +0.59 MiB on the binary. Decisions worth keeping: |
| 81 | |
| 82 | - **Classes, never inline colours.** Output is `ClassStyle::SpacedPrefixed { prefix: "hl-" }` |
| 83 | and every colour is a `--syntax-*` token in `styles.css`, so the palette follows the |
| 84 | theme. `ClassedHTMLGenerator` cannot be used because its spans cross line boundaries |
| 85 | and the blob view is one table row per line; `highlight.rs` drives `ParseState` + |
| 86 | `ScopeStack` itself, carrying parse state across lines but closing and reopening the |
| 87 | markup at each line end. |
| 88 | - **`hl-` classes are scope atoms, not positional**, so `.hl-function` alone would colour |
| 89 | every `meta.function` body. Single-atom selectors only for an atom that leads its scope; |
| 90 | the rest are compounds. Rule order in `styles.css` is load-bearing: `.hl-string` is |
| 91 | written after `.hl-punctuation` so a quote reads as its string, and the comment rule is |
| 92 | last. |
| 93 | - **The trailing newline is dropped by character, not `trim_end`** — the `_newlines` |
| 94 | syntaxes need it fed in, and it comes back escaped inside the output, sometimes before a |
| 95 | closing span. Left in, every row renders double-spaced. |
| 96 | - **Caps are 512 KiB and 10,000 lines**, both, because cost is per byte and per line. |
| 97 | Plain text is returned as `Plain` lines, not wrapped in colourless spans. |
| 98 | - **~87 ms per 1,255-line file in release**, uncached, paid on every view; debug is ~8× |
| 99 | slower and not the number to plan against. If it matters: cache per blob object id. |
| 100 | |
| 101 | **Branches and tags pages (merged 2026-09-05).** `/branches` and `/tags`, one |
| 102 | `for-each-ref` each, and the counts beside the switcher and in the sidebar are links. |
| 103 | |
| 104 | - **`%(HEAD)` is why the page is one process**: `for-each-ref` marks the default branch, |
| 105 | so nothing calls `symbolic-ref` on the happy path, and the compare link's base is read |
| 106 | from the pinned row. |
| 107 | - **Keep empty fields when splitting `for-each-ref` output.** A lightweight tag's |
| 108 | `%(*objectname)` is empty; filtering empties shifts its date into the id slot. There is |
| 109 | a test for exactly this. |
| 110 | - **Ordering is git's (`--sort=-committerdate`), pinning is the use case's.** The default |
| 111 | branch is a display decision, a stable partition in `list_branches`. |
| 112 | - **A lightweight tag's `%(contents:subject)` is the commit's subject**, so it is read only |
| 113 | when `%(objecttype)` is `tag`. `annotated` is its own field because an annotated tag may |
| 114 | carry an empty message. The row shows the peeled `%(*objectname)` so the sha is browsable. |
| 115 | - **"No tags yet" and "nothing pushed yet" are different sentences**; telling them apart |
| 116 | costs one `default_branch` call, only when the list is empty. |
| 117 | - **`refs.rs::timed_out` is the first web-layer place that renders a timeout as a state** |
| 118 | rather than a 500. When a second page wants it, move it to `web::context`. |
| 119 | |
| 120 | **Archive download and code search (merged 2026-09-05).** `/archive/{rev}.tar.gz` |
| 121 | and `.zip` streamed from `git archive`; `/search?q=&rev=` over `git grep -F`. |
| 122 | |
| 123 | - **`GitArchive` is a fourth narrow port, not a `GitQuery` method.** `GitQuery`'s contract |
| 124 | is capped bytes, collected; an archive is as large as the repository. It lives in |
| 125 | `infrastructure/git.rs` beside the protocol server and reuses `web::git::GitBody`, so |
| 126 | "one subprocess's stdout becomes a response body" is written once and used twice. |
| 127 | - **The archive use case is two steps, which is what makes the `ETag` cheap.** |
| 128 | `archive_repo` authorizes and resolves into an `ArchiveTarget` nothing else can |
| 129 | construct; `open_archive` runs git. A conditional request is answered from step one, |
| 130 | so re-downloading a tag costs one `cat-file`. The `ETag` is the resolved commit. |
| 131 | - **`git grep` is the one command whose exit status is an answer** (1 = no matches). |
| 132 | `run_within_allowing` takes an allowed-exit list and `NO_MATCHES` names the exception |
| 133 | at the call site, so the module's rule stays visible where it is broken. |
| 134 | - **`git grep -z` is not optional**: a path may contain colons, so the colon-separated |
| 135 | form has no unambiguous reading. The parser walks NULs. |
| 136 | - **`RepoPath` refuses a colon**, so `a:b.rs` is unsearchable as well as unbrowsable; the |
| 137 | parser drops those hits rather than link to a 404. Pinned by a test. |
| 138 | - **A search timeout is a page state** (`Searched::TimedOut`), the first real consumer of |
| 139 | `GitQueryError::is_timeout`. |
| 140 | - **Archive and search 404 a private repository for a stranger**, matching every other |
| 141 | read page rather than 0007's uniform 401, which exists so a git client can offer a |
| 142 | credential; a browser link gets no benefit from it. |
| 143 | - `topcoat dev` in a worktree exited rather than restarting after some source edits and |
| 144 | had to be relaunched by hand. Possibly two instances sharing a `target/`. Watch it. |
| 145 | |
| 146 | **Commit page and compare view (merged 2026-09-05).** `/commits/{sha}`, `/compare` |
| 147 | (form) and `/compare/{base}...{head}`, three-dot. Every sha in the log and the |
| 148 | latest-commit bar links to the commit page. |
| 149 | |
| 150 | - **The counts and the patch come from one `git` process**: `diff-tree --numstat -p` |
| 151 | writes numstat *first*, so a patch too large to draw still lists every file with real |
| 152 | `+a −b`. A second `--numstat` call would be paid on every page for the rare oversized |
| 153 | one. |
| 154 | - **`run_capped` reads through a pipe and kills the child** at `max_bytes + 1`; the exit |
| 155 | status is checked only when the cap was not hit, since a killed process says so. |
| 156 | - **`run_allowing` bends the "non-zero exit is a fault" rule for exactly two commands** |
| 157 | whose codes git's manual promises as answers: `grep` (1 = matched nothing) and |
| 158 | `merge-base` (1 = no common ancestor, 128 = broken). Both arrived in the same wave with |
| 159 | their own copy; the merge kept one. A third caller needs the same scrutiny. |
| 160 | - **Compare is three-dot** (merge-base to head): two-dot undoes everything base gained |
| 161 | since the branch left, a wall of deletions nobody made, and three-dot is what a pull |
| 162 | request needs. `...` is unambiguous because `RefName` refuses `..`. |
| 163 | - **The patch parser tracks hunk line counts**, never matching `diff --git`/`+++`/`---` |
| 164 | prefixes anywhere: a patch *of a patch* contains those as content. |
| 165 | - **Paths come from `---`/`+++`/`rename from`, not the `diff --git` header**, whose |
| 166 | `a/<old> b/<new>` has no defined split when names contain spaces. C-quoted names are |
| 167 | unquoted. |
| 168 | - **The compare form GETs to `/compare?base=&head=` and 307s to the path form**, so the |
| 169 | shareable URL is always the path one and no JavaScript is needed. |
| 170 | - **The file header is `sticky`, which is why the diff panel is not `overflow-hidden`**: |
| 171 | a hidden overflow makes an ancestor a scroll container and sticky sticks to nothing. |
| 172 | |
| 173 | **Blame (merged 2026-09-05).** `/blame/{rev}/-/{path}`, with `Code · Blame · Raw` in the |
| 174 | file header of both views. |
| 175 | |
| 176 | - **The porcelain parser is pure, in `application/blame.rs`.** `git blame --porcelain` |
| 177 | writes a commit's header block only the *first* time the commit appears; later runs are |
| 178 | a bare sha line looked up from an accumulated map. A code line can look exactly like a |
| 179 | header line, and **the leading tab is the only thing that tells them apart**. Both are |
| 180 | pinned by tests. `parse_blame` never fails: an unrecognised record is skipped. |
| 181 | - **`filename` is per commit, not per hunk**, carried on `BlameCommit`; that is what makes |
| 182 | the "moved from" marker work. |
| 183 | - **The use case reads the blob before blaming**, so binary, too-large and not-there are |
| 184 | decided by the blob page's rules from the same cap. Blame's own output cannot tell: a |
| 185 | binary file blames into garbage rather than reporting itself. Costs one `cat-file`. |
| 186 | - **The commit cell is one line tall, on purpose**: two lines and blame and blob disagree |
| 187 | about where line 400 is. Row height measured at 19.5px in both. |
| 188 | - **The age tint is linear in time, not rank**, five steps between the file's oldest and |
| 189 | newest commit, as `color-mix` of the primary in plain CSS. A file whose history is |
| 190 | bunched shows only the end steps; rank quintiles would always look richer and lie about |
| 191 | the gaps. A file written in one commit takes the top step. |
| 192 | - **Blame is 4 processes** (two `batch-check`s asking the same existence question, one |
| 193 | from the use case and one inside the adapter). A kept-alive `cat-file --batch` |
| 194 | collapses both — the same upgrade 0006 defers. |
| 195 | - **Headless Chrome writes screenshots to files; the puppeteer MCP tool does not.** |
| 196 | `--headless --hide-scrollbars --window-size=W,H --screenshot=path URL`. And `topcoat |
| 197 | dev` sometimes keeps printing "no changes; application up to date" while serving the |
| 198 | previous binary; `pkill -f "topcoat dev"`, wait for the port, restart. |
| 199 | |
| 200 | **The integration pass (2026-09-05).** The five branches merged, run as one app against |
| 201 | Steid's own history — 9 branches, 2 annotated tags, a public repository and a private |
| 202 | one — and every link crossing a feature boundary followed in a browser, in dark and in |
| 203 | light. **Nothing was broken at a seam**, which is the finding: five agents that could |
| 204 | not see each other agreed on URL shapes because the shapes were written down in |
| 205 | `ui.md` and in each other's handovers before the code was. |
| 206 | |
| 207 | - **A private repository 404s on all eleven read routes anonymously** — landing, log, |
| 208 | branches, tags, commit, search, tree, blame, raw, archive, compare. Every use case |
| 209 | takes an `Actor` and answers `Ok(None)`, and each page turns that into `not_found()`; |
| 210 | the uniformity is the architecture rule paying off rather than eleven separate |
| 211 | decisions. |
| 212 | - **Two gaps found, both entry points rather than breaks.** The About sidebar's Download |
| 213 | links can only ever offer the default branch, because the sidebar renders on the one |
| 214 | repository page that has no `{rev}`. And blame renders its lines unhighlighted while |
| 215 | the blob highlights them, `highlight.rs` and `blame.rs` having shipped on separate |
| 216 | branches. Both are in [current.md](current.md). |
| 217 | - **A wave needs a divergent branch to test compare with.** Every feature branch was an |
| 218 | ancestor of `main` after merging, so every branch row's Compare link correctly said |
| 219 | there was nothing to compare and exercised none of the diff. `git commit-tree` makes |
| 220 | one without a working tree. |
| 221 | - **Follow-ups the handovers named, done here:** blame's revision switcher (`Switch` |
| 222 | gained a `Blame` arm), `web::context::timed_out` shared by three pages, `.jsx` aliased |
| 223 | onto JavaScript, `token.rs`'s phantom `bg-muted`, and the two exit-status comments |
| 224 | that each claimed to be the only one. |
| 225 | |
| 226 | **Released as 0.3.0 (2026-09-06)** — the first version carrying the section 1 wave. |
| 227 | No migrations between 0.2.0 and 0.3.0, so the two binaries share a database and |
| 228 | `deploy.sh`'s rollback is a real one. First Linux release build with `syntect` and |
| 229 | `two-face`; both are pure Rust behind the fancy-regex features — the bullseye container |
| 230 | build took ~2 minutes and needed no changes. Deployed 2026-09-06 12:07 UTC+1, health |
| 231 | check passed first time. Probed live afterwards: landing, branches, tags, search, log, |
| 232 | commit and compare all under 0.25 s; the 113 KB `git_query.rs` blob and its blame both |
| 233 | ~0.65 s (highlighting, uncached, on the Lightsail box); `archive/main.tar.gz` answers with |
| 234 | the sha as `ETag`; an unknown repository 404s. |
| 235 | |
| 236 | ### Wave 2 — git features · done |
| 237 | |
| 238 | **Rename, default branch, archived (merged 2026-09-06).** All on the settings page, |
| 239 | which now reads as five sections. |
| 240 | |
| 241 | - **A rename moves the directory first, then writes the row**, compensating with a move |
| 242 | back if the save fails — the opposite order from delete, because a move is reversible |
| 243 | where a delete is not. `GitStorage::rename` refuses an occupied destination: with no |
| 244 | row naming it, whatever is there is an orphan, and adopting it hands someone else's |
| 245 | objects to this repository. **`fs::rename` silently replaces an empty directory on |
| 246 | Unix**, hence the explicit exists check. |
| 247 | - **No redirect from an old name**, single tenant; the form names `git remote set-url`. |
| 248 | Revisit at Milestone 7. |
| 249 | - **The default branch has no column.** git holds it in `HEAD`; a SQLite copy would be a |
| 250 | second answer that drifts. The write is `GitStorage::set_default_branch` (on the |
| 251 | storage port, since `GitQuery`'s contract is reading). **`symbolic-ref` accepts a |
| 252 | branch that does not exist**, which would make every page say "nothing pushed yet", |
| 253 | so the use case checks the name against `branches()` first — the same call that |
| 254 | renders the select, so one process for both. |
| 255 | - **Archived is a column and not a third visibility.** It says "finished", not "hidden": |
| 256 | clone, browse, search and download keep working, and an archived private repository is |
| 257 | a real, tested state. The push refusal sits in `serve_git` *after* the `Role::Owner` |
| 258 | check, so only someone who could otherwise push ever learns a repository is archived. |
| 259 | `DomainError::Archived` is its own variant: the owner is refused too, and it is the |
| 260 | one refusal the person hitting it can lift. The 403 carries a `text/plain` body so |
| 261 | `git push` shows the sentence behind `remote:`. |
| 262 | - **`update_repo` and `rename_repo` carry `archived` across explicitly**, because both |
| 263 | rebuild through `new()`, which resets it. |
| 264 | - The `repositories` column-migration test in `sqlite.rs` applies a **list** of |
| 265 | migrations; every future column on that table belongs in it. |
| 266 | |
| 267 | **Issues (merged 2026-09-06).** Per-repository issues with comments, an Issues tab, |
| 268 | and a number sequence pull requests will share. |
| 269 | |
| 270 | - **The sequence is its own table**, `repo_sequences (repo_id, next_number)`, not a |
| 271 | column on `repositories`: pull requests draw from it too, and allocating a number must |
| 272 | not write the row a push is contending for. **Allocation is one statement** |
| 273 | (`insert … on conflict do update … returning`), so SQLite's writer serialisation is |
| 274 | the whole concurrency story; `unique (repo_id, number)` makes it load-bearing. |
| 275 | - **Comments sit behind the issue's port**, one trait for the aggregate, two tables — a |
| 276 | deliberate departure from a literal "every table gets a trait". Same-second comments |
| 277 | tie-break on **insertion order**, not id: ids are random UUIDs and an id tiebreak made |
| 278 | a conversation read backwards, caught by a flaky test. |
| 279 | - **`markdown.rs` needed no change**: it writes every tag itself and never passes source |
| 280 | HTML through, so a `<script>` in an issue is inert text. That property is why |
| 281 | user-written markdown can render on the session cookie's origin at all. **Do not |
| 282 | reintroduce HTML passthrough.** |
| 283 | - **Third instance of the page-name shadowing trap**: `#[page] async fn comment` would |
| 284 | have shadowed a loop variable; the handler is `add_comment`. |
| 285 | - Author handles are resolved once per request (`Handles`); a deleted author renders as |
| 286 | "someone" rather than failing the page. |
| 287 | |
| 288 | **Import from a URL (merged 2026-09-06).** A second block on the new-repository page |
| 289 | mirrors a public `https://` source in the background; the row exists immediately in an |
| 290 | `importing` state. Verified against a real GitHub repository: 3,293 commits, 112 tags, |
| 291 | `HEAD` following the source, an ordinary repository afterwards. |
| 292 | |
| 293 | - **`import_state` is nullable and `NULL` is an ordinary repository**, so a page that |
| 294 | forgets about importing gets the behaviour it had. `import_source` outlives the state: |
| 295 | provenance stays true and a retry needs it. State attaches via `with_import(...)` after |
| 296 | construction, like `pinned`, rather than widening `from_trusted`. |
| 297 | - **The SSRF check is two halves and both are needed**: `ImportSource::new` refuses the |
| 298 | scheme, userinfo and literal non-public addresses; `DiskGitImport` resolves the host |
| 299 | and checks **every** address immediately before spawning git, because a public name |
| 300 | can resolve to loopback. A host with one public and one private answer is refused. |
| 301 | - **`GitImport` is a fifth narrow port**, not a `GitStorage` method: a ten-minute |
| 302 | network transfer that only runs in the background, `kill_on_drop`, |
| 303 | `GIT_TERMINAL_PROMPT=0` — which is load-bearing, since without it a private or |
| 304 | mistyped source hangs git on a username prompt forever. With it, GitHub's 401 for a |
| 305 | missing path reads as "could not read Username", which `import::explain` translates. |
| 306 | - **`import_repo` does not touch disk**; `git clone --mirror` creates the directory, so |
| 307 | the two-writes problem moves into `run_import`, which re-reads the row after the clone |
| 308 | because minutes have passed and the repository may have been deleted. The boot sweep |
| 309 | marks stuck `importing` rows failed; it is safe because it runs before anything is |
| 310 | spawned. |
| 311 | - **A push during an import is `DomainError::Unavailable` → 409**, after the permission |
| 312 | check so a stranger learns nothing. Clones during an import are still served: git |
| 313 | either finds refs or it does not. The 409 sentence reaches the terminal as a `remote:` |
| 314 | line. |
| 315 | - `tokio` gained `net` for `lookup_host`. No new crate. |
| 316 | |
| 317 | **Push events and webhooks (merged 2026-09-06).** One `push_event` per ref an |
| 318 | authorized push moved; webhooks at `/settings/hooks` deliver a signed JSON POST with |
| 319 | retries and a delivery log; `REMOTE_USER` reaches the reflog. |
| 320 | |
| 321 | - **Events are recorded from the application, not a `post-receive` script**: refs are |
| 322 | snapshotted before and after the receive-pack RPC and diffed. A hook script would need |
| 323 | installing on creation and on boot, syncing with the binary, and a channel back; it is |
| 324 | the right answer if per-push cost ever matters, and the only way to a `pre-receive` |
| 325 | refusal. **The recording hangs off the response body's EOF** (`GitBody::on_end`), |
| 326 | because `serve_git` returns while receive-pack still streams; a client that vanishes |
| 327 | mid-transfer records nothing. |
| 328 | - **`REMOTE_USER` was inert until `core.logAllRefUpdates` was turned on** — `git init |
| 329 | --bare` leaves bare repos with no reflog. `init_bare` now sets it; **repositories |
| 330 | created before this keep no reflog and there is no migration** (`git config |
| 331 | core.logAllRefUpdates true` in each bare repo). The `(none)` in the reflog identity is |
| 332 | `REMOTE_ADDR`, which Topcoat 0.5 discards. |
| 333 | - **A hook's secret is stored in the clear**, unlike a token: an HMAC needs the value, |
| 334 | and a leak forges a payload at one endpoint rather than acting as the owner. |
| 335 | - **SSRF in two halves**: `WebhookUrl::new` refuses schemes, credentials, private and |
| 336 | link-local ranges and packed address spellings (`127.1`, `2130706433`); the sender |
| 337 | resolves and checks every answer before dialling. `from_trusted` does not re-run the |
| 338 | rule, so a tightened rule cannot hide a stored hook from the page where it is deleted. |
| 339 | ~~`import` and `webhook` each carry their own `is_public`~~ — **one copy**, in |
| 340 | `domain/net.rs`, and it is the union of the two: each knew a range the other did not. |
| 341 | - **`ureq`, not `reqwest`**: already in the tree via Topcoat with rustls, so a feature |
| 342 | flag rather than a second TLS stack; blocking, hence `spawn_blocking`. |
| 343 | `http_status_as_error(false)` because a 4xx is what the delivery row records. New |
| 344 | direct deps `hmac`, `serde_json`, `ureq` were all already compiled transitively. |
| 345 | - **`X-Steid-Delivery` carries the push event's id**, the same on every attempt, since |
| 346 | deduplicating on it is the only reason a receiver reads it. Hooks are delivered to |
| 347 | concurrently, events sequentially per hook. The retry schedule is a parameter so tests |
| 348 | prove four attempts without waiting 2.5 minutes. |
| 349 | - `GitQuery::ref_snapshot` covers all of `refs/` and reports an annotated tag's own object. |
| 350 | |
| 351 | **The wave 2 integration pass (2026-09-06).** The four branches merged and run as one |
| 352 | app on port 3111, against Steid's own history with two annotated tags, four repositories |
| 353 | imported from GitHub — ripgrep, cargo, clippy, rust-analyzer — and a private one. Unlike |
| 354 | section 1's pass, **this one found real breaks**, and both were the same mistake in the |
| 355 | same shape. |
| 356 | |
| 357 | - **A settings save during an import ended the import.** `update_repo` rebuilds through |
| 358 | `Repository::new()` so the description rule lives in one place, and `new()` resets the |
| 359 | import trio; it carried `archived` across for exactly that reason and nobody noticed the |
| 360 | trio. The consequence was not cosmetic: the row said "ordinary repository" while |
| 361 | `git clone --mirror` was still writing into the directory, so the page read as an empty |
| 362 | repository, `refuse_writes` stopped refusing pushes into it, and the provenance was gone |
| 363 | for good. Two imports in the pass's own fixture lost their source before it was spotted. |
| 364 | `rename_repo` had the same shape with a smaller consequence — an imported repository |
| 365 | stops saying where it came from. **The general rule, now in current.md: every use case |
| 366 | that rebuilds through `new()` has to carry what `new()` resets.** |
| 367 | - **An imported repository had no reflog.** `git clone` leaves `core.logAllRefUpdates` off |
| 368 | exactly as `git init --bare` does, and an import never goes through `init_bare`. Found |
| 369 | by the new boot sweep reporting six repositories on an instance where every repository |
| 370 | had been created by current code — the six were the imports. `finish_mirror` sets it |
| 371 | now, beside the other two things that turn a mirror into an ordinary repository. |
| 372 | |
| 373 | What the pass walked, all in a browser or with `git` against a live instance: an import |
| 374 | of a real repository while its landing panel, profile badge, issues, settings and hooks |
| 375 | pages were read; `git push` into it refused with **409** and the sentence reaching the |
| 376 | terminal behind `remote:`, while `git clone` was served; after it landed, branches, tags, |
| 377 | a commit, blame, search, compare and both archive formats over 227 tags of imported |
| 378 | history. Then archiving: the push refusal in words, reads all still working, an issue |
| 379 | opened and commented *after* archiving, and nothing delivered to the hook because no push |
| 380 | can happen. Then a rename with a hook, a delivery log and an issue attached: all three |
| 381 | followed, and the next push's payload named the **new** repository and URL. A private |
| 382 | repository 404s anonymously on every route the wave added — issues, a single issue, new |
| 383 | issue, settings, hooks, one hook's deliveries — including while it is importing. |
| 384 | |
| 385 | - **The end-to-end webhook check is why `STEID_ALLOW_PRIVATE_WEBHOOKS` exists.** A real |
| 386 | push to a real receiver on `127.0.0.1:9099` delivered a signed JSON body with |
| 387 | `X-Steid-Delivery`, `X-Steid-Event` and `X-Steid-Signature-256`, accepted on the first |
| 388 | try in 1 ms, and the deliveries page shows both attempts green. The wave had settled for |
| 389 | a temporary source patch; a flag that warns at boot and is documented beside |
| 390 | `STEID_INSECURE_COOKIES` is the better shape, because a patch is invisible. |
| 391 | - **Decisions the pass settled**, all in current.md: issues stay writable on an archived |
| 392 | *and* on an importing repository; rename and archive are refused while an import lands |
| 393 | and the page renders both buttons disabled with one sentence; hooks may be added during |
| 394 | an import; delete stays outside the write guard because it is how a stuck import is |
| 395 | cleared; an import can never land in an archived repository, because a taken name is |
| 396 | refused before anything is cloned. |
| 397 | - **The settings page 500'd on an importing repository** before the pass, and not because |
| 398 | of the guard: `branches_of` asks git for the branch list, and against a directory that |
| 399 | is not there yet that is a failed process rather than an empty list. It is skipped |
| 400 | during an import now. |
| 401 | - **Screenshots** of the whole walk are in `target/shots/` under `integrate2-`. |
| 402 | |
| 403 | **The seams closed in the same pass**, each its own commit: |
| 404 | |
| 405 | - **`Repository::refuse_writes(RepoWrite)`** is the one place a repository says it is |
| 406 | closed for writing. The `RepoWrite` parameter is not decoration: an archived repository |
| 407 | must stay renameable — archived is *finished*, not *frozen* — so archiving cannot be a |
| 408 | blanket refusal. `Contents` refuses archived and importing; `Settings` refuses only |
| 409 | importing. |
| 410 | - **One `is_public`**, in `domain/net.rs`, and it is the **union** of the two copies: each |
| 411 | knew a range the other did not (import had `0.0.0.0/8` and the benchmarking range, |
| 412 | webhooks had IETF protocol assignments, documentation and the reserved top of IPv4 |
| 413 | space). The url-*text* rules stayed where they were, because only one type wants each. |
| 414 | - **The Issues tab counts on every repository page.** It was an optional parameter three |
| 415 | pages passed, so the number appeared and vanished as you moved around. It is now a field |
| 416 | on `RepoView`, which needed the read path split: **`visible_repo`** answers "may this be |
| 417 | seen" for browsing, blame, search, the commit page, the archive endpoint and the summary |
| 418 | read — all of which discarded the view anyway — and **`view_repo`** adds the frame's one |
| 419 | `count(*)`. Five issue pages stopped running a whole issue list purely for that number. |
| 420 | Zero renders as nothing: a mono `0` beside a tab reads as a measurement somebody took. |
| 421 | - **An issue's Comment and Close/Reopen share a row**, the Comment button reaching its |
| 422 | form by `form=` id rather than by containment — which is what keeps the textarea out of |
| 423 | the row. **`token.rs`'s Revoke** is ghost and small, like a hook row's Delete. |
| 424 | |
| 425 | ### Wave 3 — the simpler features · done |
| 426 | |
| 427 | **Paging, everywhere at once (merged 2026-09-06).** Every list that said "this list is |
| 428 | not paged" now pages, through one pattern and one control — the whole decision is in |
| 429 | [ui.md](ui.md#paging); what is worth not rediscovering: |
| 430 | |
| 431 | - **Offset (`?page=N`), not a keyset cursor — including for the git lists.** The cursor |
| 432 | is the textbook answer for a log and is wrong here: `git log` walks a date-interleaved |
| 433 | history rather than a chain, so "the commits before `<sha>`" (`git log <sha>^`) is not |
| 434 | the same set as "the rest of this log" once a merge is in it, and the other parent's |
| 435 | line would silently vanish from page 2. `--skip` is git's own answer, is exact, and is |
| 436 | what makes one control serve both the git and the SQLite lists. It costs a count per |
| 437 | page — `rev-list --count`, `count(*)` — which is also what buys "3 of 7". |
| 438 | - **Clamp, never refuse.** `?page=400` on a four-page list, `?page=banana`, a link into |
| 439 | a branch that has been force-pushed since: all are the nearest page that exists. |
| 440 | `application::paging::clamp` is the one rule, so `/api` cannot answer differently. |
| 441 | Walked in a browser: a bookmarked page 4 of a branch, force-pushed down to two |
| 442 | commits, renders those two commits and no control rather than a 500. |
| 443 | - **Two shapes of "page this", and the difference is not the storage.** A list that |
| 444 | arrives whole anyway is sliced in the use case (`Paged::slice`): branches and tags are |
| 445 | one `for-each-ref` whatever the page asks for, and a profile's repositories must be |
| 446 | cut *after* the visibility filter or page 2 would be short by however many private |
| 447 | repositories page 1 counted. A list a query can narrow gets `limit`/`offset` at the |
| 448 | port (issues, webhook deliveries), with a test per implementation that the second page |
| 449 | starts where the first ended. |
| 450 | - **`Option<usize>` where a list has a second caller that wants all of it.** |
| 451 | `list_branches(None)` is the settings form's default-branch `<select>` — an option |
| 452 | missing from it is a branch nobody can choose — and `list_repos(None)` is the profile |
| 453 | overview and `/api`. A page number would have silently truncated both. |
| 454 | - **The label-filtered issue list cannot be paged in SQL.** Which labels an issue wears |
| 455 | is a second table `list_issues` already reads whole to render the pills, so the filter |
| 456 | is applied in the use case and the page cut after it; the port's `limit`/`offset` |
| 457 | serve the unfiltered path, which is the one a thousand-issue repository lives in. |
| 458 | - **Search pages by file, not by line.** A file's matches are one block under its path, |
| 459 | so a page ends with the last file that fits and may overshoot 200 rather than print |
| 460 | the same heading twice. `SEARCH_LIMIT` (200) became the page and `SEARCH_MAX_MATCHES` |
| 461 | (1,000) the bound on a whole search: `git grep` output is still collected whole, so a |
| 462 | deeper page must not be able to raise what one query costs. **Every page re-runs the |
| 463 | grep** — there is nothing to resume from. |
| 464 | - **Redelivery stopped being a 50-row window.** The button can sit on any page now, and |
| 465 | the attempt number it writes counts every attempt the *event* has had — which the |
| 466 | window got wrong as soon as an event aged out of it. The read is unbounded for one |
| 467 | hook; noted in [current.md](current.md). |
| 468 | - **The control renders nothing at all on a one-page list**, and so does the sentence |
| 469 | above it. That is why most of these pages look untouched on a small instance. |
| 470 | |
| 471 | |
| 472 | **Markdown cross-links and highlighted fences (merged 2026-09-06).** `#12` and a bare |
| 473 | lowercase 7–40 hex word link to the issue and commit pages; fences with an info string |
| 474 | render through `highlight::fenced_lines`. |
| 475 | |
| 476 | - **References are matched by shape, never checked.** Existence would cost a query or a |
| 477 | `cat-file` per reference per render; the target pages already 404. `deadbeef` links, |
| 478 | deliberately. Uppercase hex does not. |
| 479 | - **The boundary rule is the whole trick**: the character before may not be |
| 480 | alphanumeric, `-`, `_`, `.` or `/` (so `src/deadbeef1`, `v1.0-abcdef1` and URL fragments |
| 481 | stay text); after, only alphanumeric, `_` and `-` disqualify, so `#12,` ends cleanly. |
| 482 | - **Fences are buffered, not streamed**, because a string can span lines; `Writer` |
| 483 | holds a `Fence` and writes the `<pre>` at `TagEnd::CodeBlock`. `fenced_lines` is |
| 484 | `source_lines`' sibling: an info string is a token, not a filename, and an empty line |
| 485 | inside `<pre>` must stay genuinely empty. |
| 486 | - **The "raw HTML never reaches the page" guarantee is intact**: the only unescaped |
| 487 | output shaped by the source is markup `highlight` wrote around text syntect escaped. |
| 488 | - `markdown::render` gained `Option<Crossref>`; `None` renders as before, which is what |
| 489 | posts will want until they have a repository to refer to. |
| 490 | |
| 491 | **Token expiry, last use, and a rate limit on git auth (merged 2026-09-06).** Three of |
| 492 | ADR 0007's deliberate omissions closed. |
| 493 | |
| 494 | - **Expiry is a closed set** (`TokenLifetime`: 30 days, 90, a year, never; 90 the |
| 495 | default), not a date picker; days are 86,400 s with no calendar. An expired token |
| 496 | authenticates exactly like an unknown one — 0007's uniform 401 — and the list is where |
| 497 | a person finds out. Both new columns are null for pre-existing tokens: retroactively |
| 498 | expiring a pasted credential would break a clone with nothing connecting it to an |
| 499 | upgrade. |
| 500 | - **`last_used_at` is written at most once a minute**, the comparison in the domain |
| 501 | (`should_record_use`), and a future timestamp never writes, so a clock that went |
| 502 | backwards cannot make every request a write. **`touch_last_used` is its own port |
| 503 | method and `save`'s upsert does not touch the column** — one writer per column, or a |
| 504 | stale save walks the last use backwards. Pinned by a SQLite test. |
| 505 | - **The git transport has its own limiter**, `GitAuthLimiter`, 60 per client per minute |
| 506 | (global 600): a clone authenticates two or three times, so sharing the 10/min login |
| 507 | budget would spend a sign-in allowance on one command. Only requests presenting a |
| 508 | credential count; an anonymous clone of a public repository is never throttled. The |
| 509 | 429 carries a `text/plain` body git shows behind `remote:`. |
| 510 | - `git_actor` returns `Result<Result<Actor, Response>>`: the outer error is a fault, the |
| 511 | inner is the 429 to send. |
| 512 | |
| 513 | **Atom feeds (merged 2026-09-06).** `commits.atom` and `issues.atom` per repository, |
| 514 | `/{handle}/feed.atom` for push activity, autodiscovery links in the head, muted "Feed" |
| 515 | links on the log, issues toolbar and profile. |
| 516 | |
| 517 | - **`/{handle}/feed.atom`, not `/{handle}.atom`**: Topcoat matches whole segments only, |
| 518 | so `{handle}.atom` is refused at registration; the extension must be its own segment. |
| 519 | - **Autodiscovery is derived from the request path** in `atom::discovered`, not |
| 520 | contributed by the page: `extensions(cx)` is immutable, only a `#[layer]` may insert, |
| 521 | and `.discover()` forbids a second layer at `/` beside `security_headers`. **If a page |
| 522 | ever needs to contribute to `<head>`** (a per-page `<title>`, which Steid still lacks), |
| 523 | the fix is one shared `#[layer("/")]` owning a request-scoped page-metadata cell with |
| 524 | `security_headers` folded in. |
| 525 | - **The activity feed counts no commits**: N would be a git process per entry on an |
| 526 | unauthenticated polled endpoint. Entries say what moved with `before → after` and link |
| 527 | to the compare page. The feed costs zero subprocesses. |
| 528 | - **`log_entries` is a second `GitQuery` method** (subject plus body) with its own |
| 529 | parser, because `parse_log` dropped empty fields — safe only while every field is |
| 530 | non-empty; a one-line message has an empty body. **`parse_log` has since been fixed |
| 531 | the same way**, so both parsers keep empty fields and drop only the `-z` terminator. |
| 532 | - **One escaper, and C0 controls are dropped, not escaped**: there is no escape for a |
| 533 | NUL and one byte would break the whole document. A feed's `updated` is the newest |
| 534 | entry's own time, never `now`. Entry ids are the alternate URL for commits and issues |
| 535 | and `urn:uuid:` for push events, since two pushes can share a compare URL. |
| 536 | - `PushEventRepository::list_recent` takes repository ids so the port answers no |
| 537 | authorization question; SQLite builds `in (?, …)` from the count. |
| 538 | |
| 539 | **Issue labels (merged 2026-09-06).** `/labels` per repository, pills on issues and |
| 540 | list rows, a Labels control on an issue, `?label=` filtering. |
| 541 | |
| 542 | - **A colour is one of eight palette names, never a hex value**, parsed with `FromStr` |
| 543 | returning `Result`; the eight are `--label-*` token pairs in `styles.css` for both |
| 544 | schemes. The pill CSS is plain CSS because the class is built at render time and |
| 545 | Tailwind never sees it. Adding a ninth is one variant and one token. |
| 546 | - **Assignments live behind the labels port** (no fields of their own) and are posted |
| 547 | as the whole ticked set via `Form<Vec<(String, String)>>` — a checkbox list posts one |
| 548 | key many times, which no struct field can hold, and replacing makes a double submit |
| 549 | idempotent. A foreign label id is `NotFound`, not dropped. |
| 550 | - **`?label=` narrows the toolbar's open and closed counts too**; a name matching no |
| 551 | label filters everything out rather than widening. **Labelling does not move an |
| 552 | issue's `updated_at`**: that clock marks when what the issue says changed. |
| 553 | - **Gotchas**: `#[path_param] struct Label(str)` cannot exist in `web/labels.rs` — the |
| 554 | name snake-cased is the URL parameter and it would shadow the domain type; the route |
| 555 | uses `{id}`, and getting it wrong panics at request time. A list row's disclosure must |
| 556 | not be `<details class="contents">`: the panel becomes a flex sibling and lands beside |
| 557 | the row. The row is the `<summary>` (links inside still navigate). |
| 558 | |
| 559 | **Wave 2 follow-ups (merged 2026-09-06).** Webhook on/off and Redeliver; import Retry |
| 560 | and a two-clone concurrency limit; `zip · tar.gz` on tag rows; a revision switcher on |
| 561 | search results; the detected language in the blob header; an orphan-directory sweep. |
| 562 | |
| 563 | - **A redelivery rebuilds the payload, it does not replay a stored body** (a delivery |
| 564 | row keeps what came back, not what went out); verified byte-identical with the same |
| 565 | signature on a real push. It is awaited in the request — one attempt, no backoff — |
| 566 | and its attempt number continues the event's sequence, taken from the page already |
| 567 | read, so only an attempt within the last 50 can be redelivered. The toggle takes the |
| 568 | wanted state, not "the other one", so a double click is idempotent. |
| 569 | - **`MAX_CONCURRENT_IMPORTS = 2`, chosen**: one serialises a small import behind a slow |
| 570 | one; many peak together during `index-pack` on a small box. The permit is taken |
| 571 | inside the spawned task so the form answers at once; the queue records *who* holds a |
| 572 | permit, keyed `{handle}/{name}`, because a semaphore cannot say. `ImportSlot` is a |
| 573 | `Drop` guard: two leaked permits would silently stop every future import. |
| 574 | `retry_import` mutates the loaded row rather than rebuilding through `new()` — the |
| 575 | wave 2 trap — and does not re-validate the stored source. |
| 576 | - **Two adjacent bare text nodes are one flex item**: the language label rendered as |
| 577 | `Rust7.3 KB` because `gap-3` separates elements, not text. Same class of silent |
| 578 | failure as `bg-muted`. |
| 579 | - **Orphan directories are moved aside, never deleted**, to |
| 580 | `<data_dir>/orphaned/<seconds>-<name>`; the sweep skips that directory, runs after the |
| 581 | import sweep (an interrupted import still has a row), and its decision is a pure |
| 582 | function over strings, not typed names — a directory that does not parse is exactly |
| 583 | what a sweep exists to notice. `GitStorage` gained `list_repo_dirs` and `quarantine`. |
| 584 | |
| 585 | |
| 586 | **The wave 3 integration pass (2026-09-06).** The six branches merged and run as one app |
| 587 | on port 3119 against this repository's own history — 190 commits, two branches, four |
| 588 | tags, 62 issues opened through the form, 55 of them labelled, one public repository and |
| 589 | one private. **One thing was broken at a seam**, and like wave 2's it was two branches |
| 590 | meeting rather than either being wrong on its own. |
| 591 | |
| 592 | - **A feed's cross-links were relative.** `markdown::Crossref` builds `/{handle}/repos/…` |
| 593 | for `#12` and a bare sha, which is right on a page — a relative link survives a |
| 594 | hostname change — and wrong in `issues.atom`, whose content is read in somebody's |
| 595 | reader where a bare path resolves against whatever they last fetched, if at all. The |
| 596 | entry's own `alternate` link, three lines away, was already absolute. `Crossref` gained |
| 597 | an `origin` the feed sets from `public_origin` and every page leaves `None`. Neither |
| 598 | branch could have found this: cross-links shipped before feeds, and feeds reused the |
| 599 | page's renderer, which is exactly the shape a pass exists to catch. |
| 600 | - **The rest held.** A `#12` and a sha in an issue body and in the README both land; |
| 601 | `?label=bug&page=2` keeps the filter and the Open/Closed links keep the label while |
| 602 | dropping the page; `/log` clamps `?page=400` and `?page=banana`; the log's Feed link |
| 603 | keeps `?rev=` on a paged revision; a 30-day token clones and pushes and the tokens page |
| 604 | then shows its last use; a tag's `tar.gz` extracts under `steid-<tag>/`; search's |
| 605 | switcher carries the query and drops the page; the blob header names Rust and TOML; |
| 606 | a webhook fired by a real push redelivered byte-identically as `try 2`. **Anonymous on |
| 607 | the private repository 404s on all twelve routes**, feeds and paged URLs included. |
| 608 | - **Four seams closed with the pass** rather than found by it: a `Clock` port, so no use |
| 609 | case reads the wall clock out of thin air; `orphaned` reserved as a handle, since the |
| 610 | boot sweep is written never to look inside a directory by that name; a test that reads |
| 611 | `styles.css` and pins it against `LabelColour::ALL` in both directions; and `parse_log` |
| 612 | keeping empty fields, the latent bug the feeds branch named while writing the second |
| 613 | parser. |
| 614 | - **Two findings, neither a break.** The Feed link on a filtered issue list offers the |
| 615 | unfiltered feed, and `latest_tag` breaks a same-second tie by refname — only reachable |
| 616 | from a fixture that tags twice in one second. Both in [current.md](current.md). |
| 617 | - **The README was rewritten** in the same pass: it still told a visitor that issues, |
| 618 | webhooks and search did not exist. The install path had drifted too — the published |
| 619 | target is `-gnu`, not the `-musl` the manual steps named. |
| 620 | |
| 621 | **Wave 3 merge note.** The feeds branch rebased cleanly onto the links branch and did not |
| 622 | compile: `markdown::render` had gained a parameter. A clean rebase is not a passing |
| 623 | build; every merge now runs the tests on main before the docs commit. |
| 624 | |
| 625 | ### Wave 4 — the deeper git features · done |
| 626 | |
| 627 | **The wave 4 integration pass (2026-09-06).** Six seams between the wave's features, |
| 628 | then the whole thing walked as one app. The walk is in |
| 629 | [current.md](current.md#the-wave-4-integration-pass--20260906); what is worth not |
| 630 | rediscovering: |
| 631 | |
| 632 | - **One thing broke at a seam.** Rendered headings gained ids, and both relative-link |
| 633 | resolvers were still stripping `#fragment` from a link they rewrote — each with a |
| 634 | comment saying the fragment had nothing to find, which had been true an hour earlier. |
| 635 | A feature and the thing that links to it landed in different commits, which is exactly |
| 636 | where an integration pass earns its keep. |
| 637 | - **A merge preview is cached per pair of commit ids**, in the adapter rather than the |
| 638 | use case: the port's contract is unchanged, and `merge_preview` is both the expensive |
| 639 | call and the one that writes. Content addressing is what makes the key safe — two |
| 640 | commit ids determine their merge completely, so a remembered answer cannot go stale. |
| 641 | Measured on a conflicted request: 43 ms then ~18 ms, and no new loose objects per view. |
| 642 | - **`Closes #n` is a domain parser and reads shape alone.** A bare `#4` stays a |
| 643 | cross-reference; the keyword must start a word and be followed by spaces and then the |
| 644 | reference, so `closes. #4` is two sentences. It runs **after** the branch has moved: a |
| 645 | failure there leaves an issue open, where the reverse would close issues for a merge |
| 646 | that never landed. A `Closes #n` naming a *pull request* closes nothing. |
| 647 | - **A followed count is capped at 500**, the last-commit column's number and for the same |
| 648 | reason — `--follow` reads a tree per commit. `CommitCount` carries `capped` beside the |
| 649 | total because "500" and "at least 500" are different statements, and the paging control |
| 650 | offers only the pages that were counted. |
| 651 | - **The delete-source checkbox needed the default branch**, which the page did not have. |
| 652 | It is asked for only when the merge box will draw a button at all, so a closed or |
| 653 | merged request costs no extra process. |
| 654 | - **Two seam expectations were not met, by prior decision rather than by breakage**: the |
| 655 | last-commit column still names the commit inside a merged branch rather than the merge |
| 656 | (git's own `--name-only` answer), and a merged request's Commits and Files tabs go |
| 657 | blank once the source branch is deleted, because both resolve refs live. Both are |
| 658 | recorded as open in `current.md` with what changing them would cost. |
| 659 | |
| 660 | **Pull requests carry labels (2026-09-06).** The same labels the issues wear, from the |
| 661 | same repository-wide set: pills on the list rows and on the request, a Labels control |
| 662 | for the owner, and `?label=` on `/pulls` with all three state counts obeying it. |
| 663 | |
| 664 | - **A second join table, `pull_request_labels`, not one polymorphic table.** A |
| 665 | `labelled (kind, subject_id, label_id)` would read tidily and would have to give up |
| 666 | both `on delete cascade`s: SQLite cannot point a foreign key at whichever table a |
| 667 | `kind` column names, so deleting a pull request would leave rows behind for the |
| 668 | application to sweep by hand. `IssueId` and `PullRequestId` are different types for |
| 669 | the same reason, and a `kind` column erases that at the boundary. The cost is a |
| 670 | parallel set of four port methods, which is mechanical. |
| 671 | - **The labels page stays one page.** Labels are the repository's, not a tracker's, so |
| 672 | there is one place to manage them — and the row now carries **two counts**, because |
| 673 | one total covering both would make "it comes off 3 issues" wrong for whichever kind it |
| 674 | was not counting. The pull request count is drawn only when it is non-zero. |
| 675 | - **A pill's destination is a parameter with a default** (`Filtering::Issues`), so the |
| 676 | existing call sites are unchanged and a pill on a pull request leads to the other |
| 677 | requests like it rather than to the issues. |
| 678 | - The filtered list is narrowed **in memory**, the issue list's shape and for its reason: |
| 679 | the pairs are already read whole to draw the pills. Filtering costs the other two |
| 680 | states' listings, and only when a filter is applied. |
| 681 | |
| 682 | **Highlighted diffs and one highlight cache (merged 2026-09-06).** The commit, compare |
| 683 | and pull-request diffs are coloured by the file's syntax; blob, blame and README fences |
| 684 | share a bounded cache. A 150 KB blob went from 327 ms to 15 ms on second view. |
| 685 | |
| 686 | - **The cache is keyed by content, so nothing can be stale**: a blob passes its object |
| 687 | id (free), blame and fences a SHA-256 digest. **Blame must not use the blob's id** — |
| 688 | its body is reassembled without a trailing newline and is not byte-identical. |
| 689 | `fenced` is in the key so a fence and a blob cannot collide. |
| 690 | - **Bounded by bytes (64 MiB), not entries**; the `lru` crate with default features off |
| 691 | carries the recency half. **The lock is not held across the highlight**: two concurrent |
| 692 | misses both compute and the second insert replaces the first — a wasted parse, never a |
| 693 | wrong answer. |
| 694 | - **`highlight::cache()` is a static that main also puts in app context** — the same |
| 695 | `Arc`, because `markdown.rs` renders with no `Cx` in reach and threading a parameter |
| 696 | through four call sites said nothing the static does not. |
| 697 | - **Diff hunks are highlighted twice, old side and new side**, never interleaved: an |
| 698 | unterminated string on a removed line would otherwise bleed over the added line |
| 699 | below. A hunk is parsed as if the file began at its first line; the limitation is |
| 700 | asserted by a test. The tints at 12%/20% were already legible under every token; |
| 701 | `styles.css` is unchanged. |
| 702 | |
| 703 | **File history, rendered markdown, submodules and symlinks (merged 2026-09-06).** |
| 704 | `/log/{rev}/-/{path}` follows a file through renames; a `.md` blob is a document by |
| 705 | default with `?view=source`; submodule rows link to an `https://` upstream from |
| 706 | `.gitmodules`; symlink rows show and follow their target. |
| 707 | |
| 708 | - **A file is followed, a directory is not**: git refuses `--follow` for a directory |
| 709 | with a fatal exit, so the use case asks what is at the path first — `list_tree`, then |
| 710 | `read_blob` with a **0-byte cap**, which resolves and sizes without reading, so |
| 711 | deciding costs no process. **`rev-list` has no `--follow`**, so a followed count is a |
| 712 | whole `git log --follow` walk, bounded only by the timeout. The count uses the same |
| 713 | `follow` as the listing or the total is smaller than its pages. |
| 714 | - **A path not there at the revision is a 404**, not an empty list: those are different |
| 715 | answers. |
| 716 | - **`.gitmodules` is read once per listing and only when a submodule is present**; |
| 717 | only `https://` becomes a link (`ssh://`, scp-style and relative URLs stay text with |
| 718 | the pinned sha). Symlink targets are read in bulk through the kept-alive cat-file, |
| 719 | capped at 100 per listing — past the cap none is read, since a half-filled column |
| 720 | says something false about the blanks. `resolve_relative` is shared by symlinks and |
| 721 | markdown and refuses absolute targets and walks out of the tree. |
| 722 | - **`render_with_links` declines images** on purpose (a README's images sit at the root |
| 723 | and rewriting trades a 404 for a broken image); the file view uses |
| 724 | `render_with_targets` with `Relative::{Link, Image}`. Resolution happens before the |
| 725 | scheme check, so a resolver cannot hand back `javascript:`. |
| 726 | - **`#[component]` drops outer attributes**, so `#[allow(clippy::too_many_arguments)]` |
| 727 | on one does nothing and an inner allow is a parse error: fold parameters into a |
| 728 | struct (`Listing<'a>`). The shadowing trap bit a fourth time (`let history = …`). |
| 729 | |
| 730 | **Pull requests (merged 2026-09-06).** Branch to branch within a repository, a |
| 731 | Pull requests tab, three sub-tabs, a merge box with merge-commit, fast-forward and |
| 732 | squash, source deletion, and a push event on merge so webhooks fire. |
| 733 | |
| 734 | - **A pull request is an issue with two branches and a merge attached**: it shares |
| 735 | `IssueNumber` and the `repo_sequences` allocator, so `#7` names one thing; |
| 736 | `/issues/{n}` and `/pulls/{n}` 303 to each other. **Three states, and merged is |
| 737 | terminal**: `merge` refuses a second call, which is what makes a double-submitted form |
| 738 | land one commit. |
| 739 | - **Nothing about the branches is stored while open** — every page resolves both refs |
| 740 | live, so a force-push is simply the new proposal; `merge_commit` is the one exception |
| 741 | because both branches may be gone afterwards. A branch resolves through `refs/heads/`, |
| 742 | never by bare name (`rev-parse spike` would happily answer with a tag). |
| 743 | - **`git merge-tree --write-tree` computes the merge in the object database** — the |
| 744 | third exit-status exception in `git_query.rs` (1 = conflicts), and **it writes** |
| 745 | unreferenced objects on every preview. `GitMerge` is its own port (`commit_tree`, |
| 746 | `update_ref`, `delete_ref`), not more `GitStorage` methods: that port's subject is a |
| 747 | repository's lifecycle, and these write inside one. Two verbs and no `merge`, so |
| 748 | fast-forward and squash compose in the use case. |
| 749 | - **Every ref move is a compare-and-swap** (`update-ref <ref> <new> <old>`); git's exit |
| 750 | code cannot distinguish a stale old value from a fault, so stderr's "but expected" is |
| 751 | matched. **The six steps' order is the design**: authorize and guard, recompute |
| 752 | mergeability, write the commit (safe to fail, unreachable), move the target guarded, |
| 753 | delete the source guarded, record events and mark merged. |
| 754 | - **A merge reaches webhooks through `record_push`** with synthesised snapshots, so a |
| 755 | merge and a push produce the same events. Merging meets the shared write guard |
| 756 | (`RepoWrite::Contents`); opening and commenting stay open on an archived repository. |
| 757 | - **git 2.38 detected once at boot** (`GitFeatures`); older git's `merge-tree` succeeds |
| 758 | at the wrong thing (a three-way diff), so the box says so and draws no button. The |
| 759 | install floor is unchanged; README notes the merge requirement. |
| 760 | - **Gotchas**: `commit-tree` needs git's `@<seconds> +0000` date form or it refuses `0`; |
| 761 | a `bg-merged` passed through `attrs` onto a Primary badge lost to `bg-primary` by |
| 762 | stylesheet order — hence a `Merged` badge variant. `--merged` is the theme's sixth |
| 763 | semantic colour, purple, git's convention. |
| 764 | |
| 765 | **Before deploying 0.4.0 (2026-09-06).** A `robots.txt` disallowing the paths that spawn |
| 766 | git or pack the repository (archive, search, blame, compare, log, commits) — browsing, |
| 767 | issues and feeds stay crawlable, they are the portfolio — and an `ArchiveLimiter` at |
| 768 | 10 per client and 60 global per minute, its own budget for the reason the git-auth one |
| 769 | is. Chosen over a Caddy rate limit because stock Caddy has none without a plugin, and |
| 770 | the limiter already existed. Nobody but the owner can write anything: there is no |
| 771 | registration, every write use case requires `Role::Owner`, and the exposure of a public |
| 772 | instance is git work on public repositories, not data. |
| 773 | |
| 774 | **Released as 0.4.0 (2026-09-06)** — waves 2, 3 and 4: import, issues, labels, webhooks, |
| 775 | pull requests, feeds, paging, token lifecycle, the kept-alive cat-file, file history, |
| 776 | rendered markdown, highlighted diffs and the caches. Thirteen additive migrations since |
| 777 | 0.3.0, so `deploy.sh`'s rollback still restores a database the old binary reads. |
| 778 | Merging pull requests needs git 2.38 on the server; the Lightsail box has 2.47. |
| 779 | |
| 780 | ### Milestone 0 — Skeleton · done |
| 781 | |
| 782 | Topcoat 0.5 app serving pages, `AppConfig` from `STEID_*` env, SQLite pool in app |
| 783 | context. Split into a library plus a thin binary — the domain layer had no consumers |
| 784 | yet and read as ~30 dead-code warnings in a bare binary, and it unlocks `tests/`. |
| 785 | Topcoat's link-time page discovery works from a library; that was checked, not assumed. |
| 786 | |
| 787 | **Requires rustc ≥ 1.95.** On older toolchains `cargo add topcoat` silently resolves to |
| 788 | an empty `topcoat v0.0.0` placeholder instead of failing. |
| 789 | |
| 790 | ### Milestone 1 — Identity, thin · done |
| 791 | |
| 792 | **Domain.** Typed IDs, `Email`, `PasswordHash`, `OrgName`, `Organization`, `User`, |
| 793 | `Membership`, `Role`, `Actor`, `Session`, `SetupToken`, `DomainError`. Value objects |
| 794 | pair `new()` (validates) with `from_trusted()` (skips, for rows already validated). |
| 795 | |
| 796 | **Application.** `claim_instance`, `login`, `resolve_actor`, `record_session`, |
| 797 | `end_session`, `sweep_expired`. `PasswordHasher` port with Argon2 and a stub. |
| 798 | |
| 799 | **Infrastructure.** Migrations for orgs, users, memberships, sessions. In-memory and |
| 800 | SQLite implementations of every port. Root layout, `/setup`, `/login`, `/logout`, home, |
| 801 | and `/api/me`. |
| 802 | |
| 803 | `describe_identity` is the first use case with two consumers — the home page and |
| 804 | `/api/me` both read through it. Until that existed, "the application layer is |
| 805 | transport-neutral" was an assertion with one caller behind it. |
| 806 | |
| 807 | **Verified in a browser and by curl:** wrong token refused with nothing written; |
| 808 | correct token creates org + user + owner membership and signs the owner in; session |
| 809 | authenticates; logout clears cookie and row; wrong password bounces; right one signs |
| 810 | in; re-claiming a claimed instance is refused. |
| 811 | |
| 812 | #### Decisions worth remembering |
| 813 | |
| 814 | - **`Actor` is an enum with an explicit `Anonymous`**, not `Option<UserId>`. Attempt #2 |
| 815 | used a placeholder `UserId("ssh-anonymous")` and it became a security hole. A variant |
| 816 | can't be forgotten the way a sentinel can. |
| 817 | - **`login` verifies a dummy hash when no user matched.** Returning early on the |
| 818 | unknown-email path makes it measurably faster and leaks which addresses have |
| 819 | accounts. A test pins that the dummy stays parseable — if it stops being, `verify` |
| 820 | bails early and the defence dies silently. |
| 821 | - **`SetupToken` compares in constant time.** An early-return comparison leaks how much |
| 822 | of the token is right, which recovers it a character at a time. |
| 823 | - **The setup token is only in app context while unclaimed**, so a claimed instance has |
| 824 | nothing for a claim attempt to match. |
| 825 | - **SQLite ignores foreign keys unless asked**, per connection. `foreign_keys(true)` |
| 826 | plus a test that a user pointing at a missing org is refused. |
| 827 | - **`sqlx migrate add` stamps versions to the second** — three calls in one second |
| 828 | collide, leaving apply order ambiguous between tables that reference each other. |
| 829 | - **An unparseable role surfaces as an error**, never as "no membership". The latter |
| 830 | silently downgrades an owner to no access. |
| 831 | - **`Secure` session cookies over plain-HTTP localhost fail silently.** See |
| 832 | [runbook.md](runbook.md#steid_insecure_cookies--development-only). This one actually |
| 833 | bit, and it looked exactly like broken auth logic. |
| 834 | |
| 835 | ### Milestone 2 — Profile page · done |
| 836 | |
| 837 | `/{handle}` is the real profile page: label, handle, bio, and the section frame for |
| 838 | repositories, writing, and projects. Public, renders signed out, 404s on an unknown |
| 839 | handle, and resolves regardless of casing. `/` forwards a signed-in owner to their own |
| 840 | profile. `/api/users/{handle}` serves the same read model as JSON. |
| 841 | |
| 842 | URLs settled as root handles with grouped application routes |
| 843 | ([0004](decisions/0004-root-handles-grouped-routes.md)), superseding |
| 844 | [0003](decisions/0003-scoped-urls.md) the same day. A twenty-word reserved list in |
| 845 | `OrgName::new` keeps handles from shadowing routes. |
| 846 | |
| 847 | #### Decisions worth remembering |
| 848 | |
| 849 | - **`PublicProfile` has no email field, deliberately.** `Identity` does, and `/api/me` |
| 850 | returns it, because that endpoint describes the caller to themselves. Giving the type |
| 851 | that reaches the page nowhere to put an email makes the leak impossible rather than |
| 852 | merely avoided. |
| 853 | - **`viewer_is_owner` is decided in the use case**, so the web form and `/api` cannot |
| 854 | disagree about who may edit. Tested for a signed-in stranger and a non-owner member — |
| 855 | "signed in" quietly becoming "allowed" is the usual failure. |
| 856 | - **`Organization::update_profile` clears on blank input** rather than storing |
| 857 | whitespace, so cleared and never-set are one state and the page renders one case. A |
| 858 | rejected edit applies nothing. |
| 859 | - **Bio length counts characters, not bytes.** A byte check would reject a bio of |
| 860 | accented text well under the limit. |
| 861 | - **`path_param` is an attribute macro in 0.5**, not function-like. The vendored crate |
| 862 | is the authority for the pinned version, not the docs on `main`. |
| 863 | - **Components are invoked bare inside `view!`**, and `if`/`match`/`for`/`let` are |
| 864 | native to the macro. |
| 865 | - **`#[query_params]` needs `error = …`** to work with `?`; otherwise the error borrows |
| 866 | from `cx` and escapes the handler. |
| 867 | - **Forms re-render on failure and redirect on success.** Redirecting after a |
| 868 | validation error throws away what was typed and hides the reason. |
| 869 | - **Styling is Tailwind via Topcoat's build script**, with registry components copied |
| 870 | in rather than depended on ([0005](decisions/0005-tailwind-and-copied-components.md)). |
| 871 | Components reference theme tokens, never raw colours. |
| 872 | |
| 873 | ### Milestone 3 — Repo model · done |
| 874 | |
| 875 | Repositories exist as records and as bare repos on disk, and they appear on the |
| 876 | profile. Domain, both persistence adapters, `GitStorage` with `DiskGitStorage` behind |
| 877 | it, `create_repo` / `view_repo` / `list_repos`, the `/{handle}/repos/new` form and |
| 878 | `/{handle}/repos/{name}` page, the profile's Repositories section, and |
| 879 | `/api/users/{handle}/repos`. How git is invoked is recorded in |
| 880 | [0006](decisions/0006-git-binary-behind-narrow-ports.md). |
| 881 | |
| 882 | **Verified in a browser and by curl:** the owner creates a repo through the form, a |
| 883 | bare repo appears at `{data_dir}/{handle}/{name}.git`, and it lists on the profile; a |
| 884 | private repo is absent for a signed-out visitor on both the page and `/api`; an unknown |
| 885 | handle 404s rather than answering `[]`. `git clone` does not work yet — Milestone 4. |
| 886 | |
| 887 | #### Decisions worth remembering |
| 888 | |
| 889 | - **`git init` on an existing repository exits 0 and re-initialises in silence.** |
| 890 | Measured, not assumed. So `AlreadyExists` has to be our own `path.exists()` check — |
| 891 | there is no exit code to key off. Refusing rather than adopting matters because a |
| 892 | directory with no matching row is an orphan from a crashed create, and re-initialising |
| 893 | it would resurface a private repository's objects under a fresh record. |
| 894 | - **`git init` creates missing parent directories itself**, so there is no |
| 895 | `create_dir_all` before it. This was in the plan and the probe removed it. |
| 896 | - **`--template=` takes a new bare repo from 18 files to 2.** The default seeds sixteen |
| 897 | `.sample` hooks. Timed at 15.2ms against 13.1ms across 20 runs — so the ~2ms is not |
| 898 | the reason; Steid installs its own hooks later and the samples would be noise to work |
| 899 | around. |
| 900 | - **`--initial-branch=main` is explicit** so the host's `init.defaultBranch` cannot |
| 901 | decide it. This machine's git already says `main`, which is precisely why a drift |
| 902 | would go unnoticed — hence the test. |
| 903 | - **`GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` are pointed at `/dev/null`**, and the |
| 904 | five `GIT_*` variables that redirect object storage are removed from the child |
| 905 | environment. `GIT_DIR` was checked and does *not* override an explicit path argument, |
| 906 | but `GIT_OBJECT_DIRECTORY` does redirect where objects land, and the failure is |
| 907 | silent — the repository just looks empty. |
| 908 | - **One `run_git` owns the invocation.** With a single caller this looks premature; it |
| 909 | is a private function rather than a public abstraction for that reason. The point is |
| 910 | that Milestone 4's `http-backend` spawn cannot quietly disagree about isolation. |
| 911 | - **`tokio::process` and `tokio::fs`, never the `std` equivalents.** `init_bare` is not |
| 912 | hot — ~13ms, once per repository — but `remove_dir_all` on a repo with real history |
| 913 | walks every loose object and would stall a runtime worker. The performance that |
| 914 | matters is Milestone 4's per-request spawn, not this. |
| 915 | - **`tempfile` for test fixtures, not `target/`.** Parallel-safe by construction and |
| 916 | self-cleaning on panic. Debris under `target/` would be actively harmful here, since |
| 917 | `init_bare` refuses a path that already exists. |
| 918 | - **Membership is resolved once per listing, not once per row.** Obvious in hindsight; |
| 919 | the shape that invites the mistake is filtering inside a loop that can `await`. |
| 920 | - **One empty state serves "no repositories" and "none you may see".** A distinct |
| 921 | message for the second — or any count — leaks that private repositories exist and how |
| 922 | many. Tested, because it is the kind of thing a later "helpful" tweak would undo. |
| 923 | - **`redirect()` is a 307, and 307 preserves the method.** Post/redirect/get needs a |
| 924 | 303, or the browser re-POSTs the form to its redirect target. Milestone 2's settings |
| 925 | form shipped with this and nothing caught it — every test passed, because the tests |
| 926 | are on the use case and the bug is in the reply. Found by following the redirect with |
| 927 | curl. The fix is a `StatusCode::SEE_OTHER` plus a `Location` pair inside `view!`, |
| 928 | wrapped as `web::context::location`, because `see_other()` is a response type and |
| 929 | `#[page]` must return a view for the layout to wrap the failure re-render. |
| 930 | `RedirectError::new` is private, so a 303 cannot be built as an error, and the |
| 931 | error-to-response path only downcasts topcoat's own error types — a custom one |
| 932 | becomes a 500. |
| 933 | - **`#[page]` returns a view; `#[route]` returns a response.** That is the whole reason |
| 934 | the redirect is spelled awkwardly: a form handler needs both a redirect and a |
| 935 | full-page re-render, and only the view path gets the layout. |
| 936 | - **Boolean HTML attributes take an explicit value in `view!`** — `required=(true)`, not |
| 937 | bare `required`, which fails to parse. `false` omits the attribute entirely, so |
| 938 | `selected=(bool)` on an `<option>` is correct rather than rendering `selected="false"`. |
| 939 | - **`topcoat ui add select` needs the `icon-iconify` feature and a staged icon set.** |
| 940 | The chevron comes from `feather`, staged in `build.rs`. No new crates, but the build |
| 941 | fails with a clear message until the set is staged. |
| 942 | - **`is_org_owner` moved to `application/authz.rs`** on its second caller. Owner-ness |
| 943 | gates the profile edit, repo creation, and later PATs and push; two copies of an |
| 944 | authorization predicate drift, and the direction they drift is open. |
| 945 | - **The compensating transaction is safe to do by path.** `remove` after a failed save |
| 946 | can only ever delete what `init_bare` just created, because the loser of a concurrent |
| 947 | create never gets past `init_bare`. Non-obvious enough that it is commented in the |
| 948 | code as well as here. |
| 949 | - **Compensation is best-effort.** If the removal also fails, the caller still gets the |
| 950 | error that started it — an orphaned directory is the documented failure mode, and |
| 951 | replacing the real error with the cleanup's error would hide the cause. |
| 952 | - **`InMemoryGitStorage` enforces `AlreadyExists` too.** A permissive fake would let |
| 953 | `create_repo` pass while the real adapter refused. The fake mirroring the rule is the |
| 954 | point of having two implementations. |
| 955 | - **`/api` resolves the handle without loading a profile.** `handle_param` split out |
| 956 | of `profile_for` so the repo listing route 404s on `list_repos`' own `None`. Routing |
| 957 | it through the profile would have made that `None` unreachable and left the page and |
| 958 | `/api` disagreeing about what an empty portfolio means — the exact duplication |
| 959 | `architecture.md` says to watch for. |
| 960 | - **The `/api` listing is a bare array, not an envelope.** Matches `/api/users/{handle}` |
| 961 | returning a bare object. Pagination later means a wrapper and a breaking change; taken |
| 962 | knowingly, since personal-first means a handful of repositories and there are no |
| 963 | consumers yet. |
| 964 | - **`Repository::description` stays.** Added unrequested and flagged; kept on review |
| 965 | because this milestone's own "Done when" puts repositories on the profile, which |
| 966 | makes it a consumer inside the milestone rather than speculation. Worth noting the |
| 967 | window that closed: the repositories migration had not yet been applied to the dev |
| 968 | database, so removing the column would have been a free in-place edit rather than a |
| 969 | second migration. |
| 970 | |
| 971 | ### Milestone 4a — Clone over HTTP · done |
| 972 | |
| 973 | `git clone` works against a public repository, for anyone, with no credentials. |
| 974 | `GitProtocolServer` (CGI-shaped) with `GitHttpBackend` behind it, the `serve_git` use |
| 975 | case, and three routes under `/{handle}/repos/{name}.git/`. Bodies stream both |
| 976 | directions. |
| 977 | |
| 978 | **Verified against a real client**, not only by unit test: an anonymous `git clone` of a |
| 979 | 201-ref repository returns 201 commits and 203 refs with `HEAD` matching the origin, on |
| 980 | protocol v2 and on v0; a private repository answers 404 to an anonymous clone but 200 to |
| 981 | its owner's browser session; `git push` is refused with 403; and unknown repo, unknown |
| 982 | handle, missing `service`, an unknown service, a missing `.git` suffix, and a |
| 983 | dumb-protocol object path all answer 404 while the repository page still answers 200. |
| 984 | |
| 985 | `git http-backend`'s contract, probed against git 2.50.1 by driving the CGI from a |
| 986 | throwaway server and cloning through it. Everything below is measured, not read. |
| 987 | |
| 988 | #### The contract |
| 989 | |
| 990 | - **`HTTP_CONTENT_ENCODING`, not `CONTENT_ENCODING`.** CGI gives only `Content-Type` and |
| 991 | `Content-Length` unprefixed names; every other request header is `HTTP_`-prefixed, and |
| 992 | `http-backend` looks for the prefixed one. **This is the finding that would have cost a |
| 993 | day.** With the wrong name, `http-backend` hands the still-compressed body to |
| 994 | `upload-pack`, which dies with `bad line length character` and the client reports |
| 995 | `fatal: expected 'packfile'` — nothing names gzip, or the environment, anywhere in the |
| 996 | failure. And it only happens once a repository has enough refs for the client to bother |
| 997 | compressing: a one-ref test repo passes. |
| 998 | - **`HTTP_GIT_PROTOCOL`** carries `version=2` through to `upload-pack`. Clones verified |
| 999 | on v2 and on `protocol.version=0`, both 201 commits, both gzipped. |
| 1000 | - **`GIT_PROJECT_ROOT` plus `PATH_INFO`**, where `PATH_INFO` is the on-disk path relative |
| 1001 | to the root. Steid's URL and its storage layout differ — `/{handle}/repos/{name}.git/…` |
| 1002 | against `{data_dir}/{handle}/{name}.git` — so the adapter rewrites the middle segment |
| 1003 | out. `GIT_PROJECT_ROOT` is the data directory. |
| 1004 | - **`GIT_HTTP_EXPORT_ALL=1` is required.** Without it every repository answers `Status: |
| 1005 | 404 Not Found` and `Repository not exported`, unless a `git-daemon-export-ok` marker |
| 1006 | file sits in the bare repo (confirmed: dropping that file in re-enables it). |
| 1007 | - **Headers are CRLF-terminated and end at `\r\n\r\n`.** No bare-LF variant was |
| 1008 | observed, but the adapter should accept one rather than hang. |
| 1009 | - **`Status:` appears only on failure.** Its absence means 200, and it must be |
| 1010 | translated, not forwarded as a header. |
| 1011 | - **`http-backend` sets its own `Content-Type` and cache headers** — `Expires: Fri, 01 |
| 1012 | Jan 1980`, `Pragma: no-cache`, `Cache-Control: no-cache, max-age=0, must-revalidate`. |
| 1013 | Steid forwards them rather than inventing its own. |
| 1014 | |
| 1015 | #### Decisions worth remembering |
| 1016 | |
| 1017 | - **`GIT_HTTP_EXPORT_ALL`, never `git-daemon-export-ok`.** The marker file is git's own |
| 1018 | visibility mechanism and it looks tempting, but visibility lives in the `repositories` |
| 1019 | table and the use case is what enforces it. A marker file would be a second source of |
| 1020 | truth for the same question, free to drift from the first, and the drift direction is |
| 1021 | "private repository still clonable". Steid decides; git is told to stop asking. |
| 1022 | - **`receive-pack` is refused by default** — `Status: 403 Forbidden`, `Service not |
| 1023 | enabled: 'receive-pack'`, without any configuration. Convenient for 4a, but the routes |
| 1024 | still refuse writes explicitly rather than leaning on it: a default that helpfully |
| 1025 | changes is not an authorization decision. |
| 1026 | - **A non-zero exit can arrive after the headers are already out.** The gzip failure |
| 1027 | exited 1 having emitted a complete, successful-looking header block. So the exit code |
| 1028 | cannot gate the response — by the time it is known, the status is sent. It belongs in |
| 1029 | the log. |
| 1030 | - **A missing repository is `Status: 404` with exit 0.** Failure is reported in the |
| 1031 | CGI stream, not the exit code, and the two disagree in both directions. |
| 1032 | - **The router is the allowlist.** Only `info/refs`, `git-upload-pack` and |
| 1033 | `git-receive-pack` are routed. Handed any other path, `http-backend` serves |
| 1034 | dumb-protocol object files straight off disk — a read of a repository nothing |
| 1035 | authorized. Verified: `/….git/objects/info/packs` answers 404. |
| 1036 | - **The endpoint is named by the route, not parsed from the path.** Three routes, three |
| 1037 | literal `GitEndpoint` values, and `serve_git` rebuilds `path_info` from the validated |
| 1038 | handle and name. The string that decides authorization and the string handed to git |
| 1039 | are therefore the same string. |
| 1040 | - **Existence is settled before permission.** A push to a repository the actor cannot |
| 1041 | see answers 404, not 403 — a 403 would confirm a private repository by that name |
| 1042 | exists. Costs nothing to get right at the start and is invisible to test later. |
| 1043 | - **`BufReader` is what makes the header/body split safe.** The reader keeps whatever it |
| 1044 | read past the blank line, so handing the reader itself back as the response body |
| 1045 | carries the already-buffered first bytes of the pack with it. Parsing headers into a |
| 1046 | separate buffer and then streaming the rest would silently drop them. |
| 1047 | - **The child's exit code cannot gate the response.** A protocol failure exits non-zero |
| 1048 | *after* a complete, successful-looking header block has been written. By the time the |
| 1049 | status is known it has been sent, so the exit code goes to the log and nowhere else. |
| 1050 | - **Stderr must be drained, not merely piped.** An unread pipe fills and blocks the |
| 1051 | backend mid-transfer. It is read in the same task that reaps the child. |
| 1052 | - **`body_limit` does not exist** in `topcoat-router` 0.5.0 — the warning carried from |
| 1053 | [0001](decisions/0001-git-over-http-not-ssh.md) is stale. Bodies are read by the |
| 1054 | handler with a caller-chosen limit via `to_bytes`, and the git routes take `Body` |
| 1055 | unbuffered so no limit applies at all. |
| 1056 | - **`impl<B> IntoResponse for http::Response<B>`** means a handler can return its own |
| 1057 | `http_body::Body` and Topcoat re-bodies it. That is what lets the pack stream without |
| 1058 | a framework-specific body type. |
| 1059 | |
| 1060 | ### Milestone 4b — Push and tokens · done |
| 1061 | |
| 1062 | `git push` works over HTTP for the owner, and a private repository is clonable by |
| 1063 | someone holding a token for it. `PersonalAccessToken` with both storage adapters, |
| 1064 | `issue_token` / `list_tokens` / `revoke_token` / `authenticate_token`, HTTP Basic on the |
| 1065 | git routes, and token management at `/{handle}/settings/tokens`. Decisions recorded in |
| 1066 | [0007](decisions/0007-tokens-over-http-basic.md). |
| 1067 | |
| 1068 | **Verified end to end**, issuing the token through the UI rather than seeding one: |
| 1069 | push of 201 refs to a public repo and to a private one; clone of the private repo |
| 1070 | returning 201 commits; anonymous clone of the public repo still open with no prompt; |
| 1071 | 401 with `WWW-Authenticate: Basic` for a private repo, a **nonexistent** repo, an |
| 1072 | unknown handle and a push advertisement alike; a wrong token challenged rather than |
| 1073 | accepted; and after revoking, both clone and push answer 401 while the public repo stays |
| 1074 | open. The token is shown once and never again on reload, the revoke button disappears |
| 1075 | from the list, and the page is 403 for anyone else. |
| 1076 | |
| 1077 | #### Decisions worth remembering |
| 1078 | |
| 1079 | - **`http-backend` refuses `receive-pack` by default, and Steid authorizing the push is |
| 1080 | not enough.** The symptom is a 403 that looks like Steid's own refusal but is git's: |
| 1081 | `Service not enabled: 'receive-pack'`. It needs `-c http.receivepack=true` **before** |
| 1082 | the subcommand. That flag is set from a `GitRequest` field the use case turns on only |
| 1083 | after the authorization check passes, so git remains a second refusal behind Steid's |
| 1084 | rather than being switched on wholesale — if the rules are ever wrong, git still says |
| 1085 | no. |
| 1086 | - **The uniform 401 is what makes authenticated cloning possible at all.** A git client |
| 1087 | offers a credential only after a 401, so the 4a behaviour of answering 404 for a |
| 1088 | private repository made an authenticated private clone unreachable. Extending the 401 |
| 1089 | to repositories that do not exist is what keeps it from leaking which private names |
| 1090 | are real. |
| 1091 | - **A bad credential falls through to anonymous rather than failing.** The caller then |
| 1092 | gets the same challenge as someone who presented nothing and can try again, which is |
| 1093 | also how a stale session cookie behaves. |
| 1094 | - **Basic accepts the token in the password field, or in the username with no password.** |
| 1095 | Git puts it in the password; people paste it into the username. The alternative is an |
| 1096 | authentication failure with nothing to explain it. |
| 1097 | - **Issuing a token deliberately does not redirect**, unlike every other form here. The |
| 1098 | secret exists only in that response, and surviving a redirect would mean putting a live |
| 1099 | credential in a URL — browser history, logs, referrers. Reloading issues a second |
| 1100 | token, which is harmless and visible in the list. |
| 1101 | - **Revoking someone else's token is `NotFound`, not `Forbidden`.** That a token id |
| 1102 | exists but belongs to another user is not a fact worth confirming. |
| 1103 | - **Tokens do not expire.** A credential pasted into a machine and forgotten is worth |
| 1104 | less if it stops working silently; revocation is the control that matters. |
| 1105 | - **`in_memory.rs` keeps `mod tests` in the middle of the file**, like `sqlite.rs`. |
| 1106 | Appending an implementation to the end lands it inside a later impl block. |
| 1107 | |
| 1108 | #### Measured, for Milestone 5 |
| 1109 | |
| 1110 | Taken at the end of 4b, on a 201-commit repository, 50 runs averaged per command: |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | | `git rev-parse HEAD` | 11.2 ms | |
| 1115 | | `git ls-tree -l HEAD` | 11.7 ms | |
| 1116 | | `git cat-file -p HEAD:` | 11.6 ms | |
| 1117 | | `git log -20 --format=…` | 11.8 ms | |
| 1118 | | `git for-each-ref` | 14.4 ms | |
| 1119 | |
| 1120 | **The cost is starting git, not the query** — every command lands in the same band |
| 1121 | regardless of the work it does, matching the ~13ms `git init --bare` from Milestone 3. |
| 1122 | A three-call page is therefore ~35ms of pure overhead, and a per-file last-commit column |
| 1123 | at one call per entry would be ~230ms for twenty files. This is the input |
| 1124 | [0006](decisions/0006-git-binary-behind-narrow-ports.md) asked for before reconsidering |
| 1125 | `gix` on the read path. |
| 1126 | |
| 1127 | ### Milestone 5 — Repo browsing · done |
| 1128 | |
| 1129 | A repository is readable on the web: the file tree at a revision, a file's contents with |
| 1130 | line numbers, and the commit log. `ObjectId` / `RefName` / `RepoPath` / `EntryKind` / |
| 1131 | `TreeEntry` / `CommitSummary` in the domain, a `GitQuery` port with `DiskGitQuery` and an |
| 1132 | in-memory fake behind it, `browse_repo` and `repo_log` read models, and pages at |
| 1133 | `/{handle}/repos/{name}`, `/tree/{rev}`, `/tree/{rev}/-/{path}`, `/log` and `/log/{rev}`. |
| 1134 | The read-path decision and its upgrade ladder are in |
| 1135 | [0006](decisions/0006-git-binary-behind-narrow-ports.md#amendment--20260829-the-milestone-5-read-path). |
| 1136 | |
| 1137 | **Verified against Steid's own repository, hosted on Steid.** A freshly created repo |
| 1138 | shows push instructions; after pushing 57 commits the page lists the tree; directories |
| 1139 | descend and breadcrumb back; `src/domain/session.rs` renders with line numbers and |
| 1140 | correct HTML escaping; the log shows 50 commits with author and relative time. Unknown |
| 1141 | revision, unknown path, `../etc/passwd`, unknown repo and unknown handle all 404, clone |
| 1142 | still works, and a private repository answers 404 to an anonymous visitor on **every** |
| 1143 | browse route while its owner sees it. |
| 1144 | |
| 1145 | #### Decisions worth remembering |
| 1146 | |
| 1147 | - **`cat-file --batch-check` with the spec on stdin is the lookup primitive.** It exits |
| 1148 | **0** and prints `<spec> missing` for anything unresolvable, which is what makes "not |
| 1149 | found" a *value read off stdout* rather than an exit code to interpret. The rule the |
| 1150 | adapter follows: **a non-zero exit is always an error; absence is a marker in the |
| 1151 | output** (`missing`, `ambiguous`, `dangling`, `notdir`). The obvious alternatives are |
| 1152 | worse — `rev-parse --verify --quiet` returns 1 for an unknown ref but 128 for a missing |
| 1153 | repository, and `ls-tree` pointed at a blob is a `fatal:` for what is, to a visitor, a |
| 1154 | 404. Passing the spec on **stdin** also means no revision or path can ever be read as a |
| 1155 | flag, whatever validation upstream does or stops doing. |
| 1156 | - **`git log` in a repository with no commits is a fatal error, not empty output**, hence |
| 1157 | resolving the revision first. An extra fork, in exchange for not reading meaning out of |
| 1158 | a localised stderr string. |
| 1159 | - **`%s` is git's *subject*, not the first line** — with no blank line in the message it |
| 1160 | joins the whole first paragraph with spaces. The adapter takes `.lines().next()` rather |
| 1161 | than trusting that. |
| 1162 | - **Negative `%ct` exists** in imported histories and would panic `UNIX_EPOCH + Duration`. |
| 1163 | - **A symlink is indistinguishable from a file in the object store** — both are blobs — so |
| 1164 | `read_blob` returns a symlink's target path as its content. Deliberate; making it |
| 1165 | `Ok(None)` would cost an extra `ls-tree` of the parent. |
| 1166 | - **The empty repository is a first-class state, not an error.** Steid creates |
| 1167 | repositories empty and Milestone 4 made it easy to have one never pushed to, so |
| 1168 | `default_branch` returning `None` means "no commits" and the page offers the three |
| 1169 | commands to push rather than a broken listing. |
| 1170 | - **`%2F` in a revision segment survives routing.** Topcoat matches on the raw path and |
| 1171 | percent-decodes after, so a slashed branch works as a single segment — which is what |
| 1172 | makes the `/-/` separator sufficient without a ref lookup. |
| 1173 | - **Three agents worked in parallel on disjoint files**, with the port, the fake and a |
| 1174 | non-panicking stub adapter written first so neither branch could break the other's |
| 1175 | build. The stub answering "nothing there" rather than `todo!()` is what let the pages |
| 1176 | be developed and run before the adapter existed. |
| 1177 | |
| 1178 | ### Milestone 5b — Deployable by anyone · in progress |
| 1179 | |
| 1180 | Distributed as a binary plus its `assets/` directory, installed by one command, behind |
| 1181 | Caddy for automatic HTTPS. `release.sh`, `install.sh`, `deploy/`, a `README.md`, and the |
| 1182 | operability the service needs: `/healthz`, `STEID_SETUP_TOKEN`, and rate limiting. |
| 1183 | |
| 1184 | #### Topcoat findings, both load-bearing |
| 1185 | |
| 1186 | - **`topcoat::start()` already handles SIGTERM.** `serve()` calls `serve_until(…, |
| 1187 | shutdown_signal())`, and that selects on Ctrl+C *and* SIGTERM on Unix: it stops |
| 1188 | accepting, drops the listener so a replacement process can bind the port, and drains |
| 1189 | in-flight requests up to `shutdown_timeout`. So systemd stop/restart does not cut a |
| 1190 | clone mid-pack, and **no wiring was needed** — the work was finding this out rather |
| 1191 | than building it. |
| 1192 | - **The peer socket address is not reachable from a handler.** `internal_serve` discards |
| 1193 | it at accept time (`let (stream, _remote) = accepted?;`) and never puts it on the |
| 1194 | request extensions; the context exposes only parts, method, uri, headers and |
| 1195 | extensions. **Any IP-based decision in Steid is therefore header-based by necessity**, |
| 1196 | not by choice, and closing that would take an upstream change. |
| 1197 | |
| 1198 | #### Decisions worth remembering |
| 1199 | |
| 1200 | - **The rate limiter keys on the *rightmost* `X-Forwarded-For` entry.** A proxy |
| 1201 | *appends* the address it accepted from, so the last entry is the one the nearest proxy |
| 1202 | wrote and the only one a client cannot forge. The leftmost — what "the real client IP" |
| 1203 | usually means — is exactly the attacker-controlled one. Two proxy hops collapse clients |
| 1204 | onto the inner proxy's address, which is stricter, so being wrong that way is safe. |
| 1205 | - **A global cap backs the per-key one**, because without a peer address a forged key |
| 1206 | cannot be disproved. It turns key forgery from a total bypass into a modest speed-up. |
| 1207 | The cost is that a flood can lock the login form for a minute — a recoverable denial |
| 1208 | against an unrecoverable guessed password. |
| 1209 | - **The limiter's map is bounded.** An unbounded map keyed by attacker-controlled values |
| 1210 | is itself the denial of service; at the cap it sweeps expired entries and otherwise |
| 1211 | falls through to the global window, which is stricter rather than permissive. |
| 1212 | - **glibc on bullseye, not static musl.** musl failed on `ring` (Debian's `musl-gcc` |
| 1213 | rejects `-m64`), but the decisive argument is that **musl buys a dependency-free binary |
| 1214 | and Steid hard-requires `git` on PATH** — the portability is unusable. Bullseye pins the |
| 1215 | glibc floor at 2.31, covering Debian 11+ and Ubuntu 20.04+; bookworm would need 2.36 |
| 1216 | and silently exclude Ubuntu 22.04. |
| 1217 | - **The runtime binary links a TLS stack it never uses.** `ring` ← `rustls` ← `ureq` ← |
| 1218 | Topcoat's `icon-iconify`/`tailwind`, whose `ureq` downloads the Tailwind CLI *at build |
| 1219 | time*. Those features are on the normal dependency as well as the build one, so the |
| 1220 | crypto ships too. Moving them would shrink the binary and drop an unused dependency |
| 1221 | from the attack surface. Not attempted; it is also what made the musl build fail where |
| 1222 | it did. |
| 1223 | - **`STEID_SETUP_TOKEN` does not undermine [0002](decisions/0002-first-run-claim-not-config-bootstrap.md).** |
| 1224 | What that ADR refused to put in configuration was the owner's *password* — long-lived, |
| 1225 | goes stale, ends up in a repository. This is the one-time claim secret the operator was |
| 1226 | already copying out of a log line. It is validated for strength, never printed, and |
| 1227 | ignored entirely once claimed. |
| 1228 | |
| 1229 | ### Gap-filling while 5b was blocked on DNS · done |
| 1230 | |
| 1231 | Built while the domain transfer was in flight, so none of it belongs to a milestone. |
| 1232 | Three things: repository settings, browse usability, and README rendering — the last of |
| 1233 | which is Milestone 6's markdown pipeline arriving early because a repository page needed |
| 1234 | it. |
| 1235 | |
| 1236 | #### Repository settings — a hole, not a feature |
| 1237 | |
| 1238 | Repositories were **create-only**. No edit, no delete, and therefore **no way to |
| 1239 | un-publish something published by accident**. Now: description and visibility are |
| 1240 | editable, and a repository can be deleted behind a type-the-name confirmation. |
| 1241 | |
| 1242 | - **Delete writes the row first, then the directory best-effort.** An orphaned directory |
| 1243 | only blocks reusing that name and is already `create_repo`'s documented failure mode; |
| 1244 | an orphaned row is a repository that lists on the profile and 404s when clicked. The |
| 1245 | visible failure is the worse one, so the ordering avoids it. |
| 1246 | - **Two different refusals, deliberately.** A repository the actor may not *see* is |
| 1247 | `NotFound` (a 403 would confirm a private repo by that name exists); one they can see |
| 1248 | but do not own is `Forbidden`, matching `create_repo`, because the resource is public |
| 1249 | anyway. The page collapses both to 404. |
| 1250 | - **Renaming is still impossible, now with a comment saying why.** The bare repo lives at |
| 1251 | `{data_dir}/{handle}/{name}.git`, so a rename is a directory move that breaks every |
| 1252 | existing clone — and doing the row half only breaks them silently. |
| 1253 | |
| 1254 | #### Markdown — raw HTML is structurally impossible, not merely disabled |
| 1255 | |
| 1256 | - **`pulldown-cmark` does not sanitise URLs.** Its `escape_href` only percent-escapes, so |
| 1257 | `javascript:` would have survived into a rendered README. The renderer uses a scheme |
| 1258 | **allowlist** (`http`, `https`, `mailto`, `ftp`, `ftps`, `tel`) and strips ASCII control |
| 1259 | characters *before* the check as well as on output, because browsers strip them too and |
| 1260 | `java	script:` is otherwise a live bypass. |
| 1261 | - **Adding the crate with `default-features = false` turned off its `html` feature**, so |
| 1262 | `push_html` does not exist in this build. The renderer therefore walks the event stream |
| 1263 | and writes every tag itself. Forced rather than chosen, and better: the emittable tag |
| 1264 | set is exactly what the writer spells out, so raw HTML cannot pass through by |
| 1265 | construction. `Event::Html` is written as *text*, so `<script>` is visible and inert |
| 1266 | rather than silently vanishing. |
| 1267 | - **Escaping goes through `topcoat::view::HtmlContext`**, the same escaper `view!` uses — |
| 1268 | not a hand-rolled one. |
| 1269 | - **Smart punctuation is off**: it rewrites `--flag` to an en dash, quietly corrupting CLI |
| 1270 | flags in README prose. |
| 1271 | - Relative *links* are rewritten into tree URLs; relative *images* are deliberately left |
| 1272 | alone, because a tree URL serves a page and rewriting would swap a 404 for a broken |
| 1273 | image. Pointing them at `/raw/` is the obvious follow-up now that route exists. |
| 1274 | |
| 1275 | #### Browse — the switcher and raw files |
| 1276 | |
| 1277 | - **`for-each-ref` asks only for `%(refname)`.** `%(objecttype)` is `commit` for both a |
| 1278 | branch and a lightweight tag, so the *namespace* is the only thing that answers |
| 1279 | branch-versus-tag. |
| 1280 | - **Raw files are served as `application/octet-stream`, always** — never the file's own |
| 1281 | type and never guessed from an extension — with `nosniff`, `Content-Disposition: |
| 1282 | attachment` and `default-src 'none'; sandbox`. A repository-supplied `.html` or `.svg` |
| 1283 | served as its real type on this origin is stored XSS against the viewer's session. |
| 1284 | `text/plain` was rejected because browsers render it and have been talked into sniffing |
| 1285 | it as HTML. The filename is repository content arriving in a header, so it is reduced to |
| 1286 | `[A-Za-z0-9._-]` against header injection. |
| 1287 | - **The switcher costs one more fork (~13ms) on tree and log pages**, measured |
| 1288 | interleaved against `ls-tree` to cancel out load — same band, confirming again that the |
| 1289 | fork is the cost. It is not called on the repository page or an empty repository. |
| 1290 | |
| 1291 | #### Verified |
| 1292 | |
| 1293 | Against a running instance with a deliberately hostile README: **zero real `<script>` or |
| 1294 | `<img>` tags in the output**, the markup present once as escaped inert text, the |
| 1295 | `javascript:` link stripped of its `href` while `https://example.com` survived, the table |
| 1296 | rendered, raw bytes SHA-256 identical with the headers above, the switcher listing a |
| 1297 | branch and a tag, and the Settings link visible to the owner and absent for anonymous. |
| 1298 | |
| 1299 | ### The profile page, rebuilt · done |
| 1300 | |
| 1301 | Flat navigation, per [ui.md](ui.md#the-profile-page). Tabs instead of stacked sections, |
| 1302 | one lead item distinguished by weight and space rather than size, hairlines instead of |
| 1303 | boxes, and a `/{handle}/repos` index for the tab to point at. |
| 1304 | |
| 1305 | #### Decisions worth remembering |
| 1306 | |
| 1307 | - **Existing rows were stamped with the migration time, not left at 0.** A repository |
| 1308 | pushed to for months would otherwise read "updated 56 years ago" on the very page the |
| 1309 | column exists to order. Wrong by a bounded amount and self-correcting on the first |
| 1310 | push, against wrong forever and looking broken. |
| 1311 | - **The single-pin invariant lives in the use case, not in a constraint.** The rule is |
| 1312 | "pinning this unpins that", and a unique index can only *refuse*, never unpin. The two |
| 1313 | writes are not one transaction; a crash between them leaves nothing pinned, which is |
| 1314 | the harmless direction. |
| 1315 | - **`updated_at` is touched on the authorized write path**, before the protocol is |
| 1316 | reached — so a clone never moves it and neither does a refused push. It records that a |
| 1317 | push was *authorized*, not that it succeeded; waiting for the subprocess would be a |
| 1318 | much larger change for a small gain. A failed touch is logged and does not fail the |
| 1319 | push. |
| 1320 | - **The lead is picked out of the listing**, not fetched separately, so the lead and the |
| 1321 | list cannot disagree about which repository is pinned. |
| 1322 | - **Ordering changed from name to recency**, and two existing tests had been passing by |
| 1323 | accident: everything created inside one second tied and fell back to the alphabet. |
| 1324 | |
| 1325 | #### Two Topcoat traps, both silent |
| 1326 | |
| 1327 | - **`let profile = …` in a module with `#[page] async fn profile` is a unit-struct |
| 1328 | pattern, not a binding.** The page's name is a unit struct in module scope. The error |
| 1329 | points at neither the page nor the shadowing. |
| 1330 | - **Forgetting `topcoat asset bundle` after `cargo build` produces a broken-looking |
| 1331 | page, not an error.** New utility classes are simply absent, so gaps collapse and type |
| 1332 | falls back to browser defaults — it reads as a design mistake. Cost one confused |
| 1333 | screenshot. |
| 1334 | |
| 1335 | ### Security review before going public · done |
| 1336 | |
| 1337 | Attempted with three blind reviewer agents; all three died to the machine sleeping, so |
| 1338 | the review was done directly instead. **Findings were verified by attacking a running |
| 1339 | instance, not by reading comments** — the codebase argues confidently for its own |
| 1340 | safety and those arguments are exactly what needed testing. |
| 1341 | |
| 1342 | #### What held, demonstrated rather than assumed |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | | Private repo: page, tree, log, settings, raw, `/api` | 404 on every surface; `/api` does not leak the name | |
| 1347 | | `rev=--upload-pack=touch /tmp/pwned` and five other injections | 404, no execution | |
| 1348 | | Four path-traversal spellings incl. `%2e%2e` and `....//` | 404 | |
| 1349 | | Login brute force | 10 attempts then 429 | |
| 1350 | | Error bodies | bare "not found", nothing internal | |
| 1351 | | Raw `.html` and `.svg` from a repo | `octet-stream` + `nosniff` + `attachment` + sandbox CSP | |
| 1352 | | Filename `ev"il; drop.txt` in a header | sanitised to `ev_il__drop.txt`, no header injection | |
| 1353 | | `<script>` in a viewed file | escaped, zero live tags | |
| 1354 | |
| 1355 | **The production cookie is `__Host-session; HttpOnly; Secure; SameSite=Lax; Path=/`** — |
| 1356 | the strictest cookie form available, and it forbids a `Domain` attribute so a |
| 1357 | compromised subdomain cannot inject one. |
| 1358 | |
| 1359 | **A near-miss worth recording:** the first check appeared to show production serving |
| 1360 | `steid-dev-session` with no `Secure`. It was a testing error — **`dotenvy` reads `.env` |
| 1361 | from the working directory**, and running the binary from the repo root picked up the |
| 1362 | gitignored dev `.env`. Verify from a neutral directory, and note the same trap applies |
| 1363 | to the deployment: the systemd unit's `WorkingDirectory=/opt/steid` means a stray `.env` |
| 1364 | there would silently override the environment file. |
| 1365 | |
| 1366 | #### The one real finding: no security headers on HTML |
| 1367 | |
| 1368 | Fixed with a layer, deliberately a layer rather than a per-handler concern — a page |
| 1369 | added without them would simply not have them and nothing would fail. |
| 1370 | |
| 1371 | - **Steid renders no JavaScript at all**, not a script tag on any page, so |
| 1372 | `default-src 'none'` is a policy the product can genuinely keep. That is far stricter |
| 1373 | than a typical CSP and worth defending: if a feature ever needs script, weakening it |
| 1374 | should be a deliberate decision. |
| 1375 | - `'unsafe-inline'` is granted for **styles only**, and only because Topcoat's icon |
| 1376 | macro emits `style="vertical-align: -0.125em"`. A framework constraint, not a choice. |
| 1377 | - **`Referrer-Policy: no-referrer`**, not the usual `strict-origin-when-cross-origin`: a |
| 1378 | private repository's URL contains its name, and a README may link anywhere, so a |
| 1379 | referrer would hand that name to whatever the visitor clicked. |
| 1380 | - Headers are set with `entry().or_insert()`, never `insert()` — the raw endpoint's own |
| 1381 | stricter `default-src 'none'; sandbox` must not be relaxed by a blanket overwrite. |
| 1382 | Verified that it survives. |
| 1383 | |
| 1384 | #### Not covered, and why |
| 1385 | |
| 1386 | - **The member-but-not-owner path could not be demonstrated.** There is no registration, |
| 1387 | so a second account cannot exist until Milestone 7. It is covered by use-case tests and |
| 1388 | nothing else — re-verify for real the moment a second account is possible. |
| 1389 | - **No automated test asserts the headers.** There is no HTTP-level test harness in this |
| 1390 | project, so a regression here would be silent. That is a gap, not a decision. |
| 1391 | - No dependency audit (`cargo audit` was not run), and no review of the deployment |
| 1392 | scripts beyond the earlier container dry-run. |
| 1393 | |
| 1394 | ### Deployed · jpgill.dev, 2026-09-04 |
| 1395 | |
| 1396 | Steid runs on the public internet at **https://jpgill.dev**, on AWS Lightsail (Debian 13, |
| 1397 | x86_64, 1 GB), behind Caddy with a Let's Encrypt certificate, hosting its own source. |
| 1398 | Installed with `install.sh --tarball`, since the instance that will serve the releases is |
| 1399 | the one being installed. |
| 1400 | |
| 1401 | #### What the first real deployment taught |
| 1402 | |
| 1403 | - **A domain transfer moves the registrar, not the nameservers.** The transfer to Amazon |
| 1404 | Registrar completed, the Route 53 zone held the right records, and every public resolver |
| 1405 | returned nothing — because the `.dev` registry still delegated to the old provider's |
| 1406 | nameservers. Diagnosed with `dig +trace`, which shows the delegation the world actually |
| 1407 | follows rather than the zone you are looking at. |
| 1408 | - **The domain was `jpgill.dev`, not `jpgilldev.com`.** Inferred from an email address and |
| 1409 | never confirmed, and by then it was baked into `install.sh`'s release URL and the |
| 1410 | systemd unit. Ask what the domain is. |
| 1411 | - **`.dev` is HSTS-preloaded.** Browsers refuse plain HTTP with no click-through, so the |
| 1412 | certificate is not optional — until Caddy has one the site is simply unreachable. |
| 1413 | - **The uniform 401 cost real time.** Pushing to a mistyped handle answered |
| 1414 | `Authentication failed` rather than "no such repository", because |
| 1415 | [0007](decisions/0007-tokens-over-http-basic.md) deliberately makes an absent repository |
| 1416 | indistinguishable from a private one. That trade was recorded as costing "a prompt on a |
| 1417 | typo"; in practice it cost ten minutes and a confident wrong diagnosis, with someone |
| 1418 | watching who knew the design. A stranger has nobody to ask. |
| 1419 | - **An upgrade silently discarded the operator's Caddyfile.** `install.sh` kept |
| 1420 | `steid.env` across a re-run but rewrote the Caddyfile unconditionally, so a hand-added |
| 1421 | `www` redirect vanished on the next upgrade and took the hostname with it. Now written |
| 1422 | on first install only, with `--force-caddyfile` and `--www`. Found by testing the |
| 1423 | upgrade path rather than waiting for it to happen. |
| 1424 | - **The upgrade path works and is verified**: claim, database, repositories, `steid.env` |
| 1425 | and Caddyfile all survive `install.sh` re-run against a newer tarball. |
| 1426 | |
| 1427 | #### Renaming a handle, done by hand |
| 1428 | |
| 1429 | `current.md` recorded a rename as "a directory move, not a row update". That was exercised |
| 1430 | for real, renaming `jpgilldev` to `jamesgill` on the live instance: **one `UPDATE orgs SET |
| 1431 | name` and one `mv` of `{data_dir}/{handle}/`**. Everything else — users, repositories, |
| 1432 | tokens, sessions — keys off ids, so nothing else moved, and the account, password and |
| 1433 | access token all survived. |
| 1434 | |
| 1435 | So a rename feature is genuinely two writes. What makes it more than that is the |
| 1436 | consequence: every existing clone URL breaks, and there is no redirect from the old |
| 1437 | handle. That is the part to design, not the mechanics. |
| 1438 | |
| 1439 | ### The shell: top bar and per-page widths · done (2026-09-05) |
| 1440 | |
| 1441 | The root layout gained a slim global top bar — wordmark to `/`, and either "Sign in" |
| 1442 | or `@handle` / Settings / Sign out — and stopped imposing a width. Pages now choose |
| 1443 | their own column via two components in `layout.rs`: `narrow` (48rem — profile, forms, |
| 1444 | settings) and `wide` (80rem — tree, blob, log, the repo page). Verified in the |
| 1445 | browser across visitor and owner states, including sign-out. |
| 1446 | |
| 1447 | #### Decisions worth remembering |
| 1448 | |
| 1449 | - **A slim bar plus contextual tabs, deliberately not an app shell.** The reasoning |
| 1450 | lives in [ui.md](ui.md#the-shell); the short form is that Steid's first audience is |
| 1451 | an anonymous reader of someone's site, and GitLab-style rail chrome tells that |
| 1452 | visitor they've landed in an admin tool. |
| 1453 | - **A `#[layout]` may take `cx: &Cx`** alongside `slot` — both recognized by name, no |
| 1454 | other parameters. Documented in the vendored `topcoat-router-macro` docs, not |
| 1455 | obvious from the README example. |
| 1456 | - **The layout imposes no width; pages wrap themselves.** Same philosophy as request |
| 1457 | helpers being functions: a page that forgets a container renders full-bleed, which |
| 1458 | is immediately visible, rather than silently inheriting a wrong one. |
| 1459 | - **The top bar costs an identity lookup on every page render** (session hash plus a |
| 1460 | user row). Fine over local SQLite; worth remembering if page queries are ever |
| 1461 | counted. |
| 1462 | |
| 1463 | ### The repository landing page · done (2026-09-05) |
| 1464 | |
| 1465 | `/{handle}/repos/{name}` became two columns — the file list and README on the left, an |
| 1466 | About sidebar on the right — and every repository page (tree, blob, log) picked up the |
| 1467 | same header and `Code` / `Commits` tab strip. New: a toolbar row carrying the revision |
| 1468 | switcher and branch/tag counts, a latest-commit bar, an About block with the |
| 1469 | description and detected licence, a facts list (commits, branches, tags, latest tag, |
| 1470 | pushed), and the clone URL moved into the sidebar. |
| 1471 | |
| 1472 | The layout and the map of where the next features slot in are in |
| 1473 | [ui.md](ui.md#the-repository-page). What is here is what the next session should not |
| 1474 | have to rediscover. |
| 1475 | |
| 1476 | **Verified** with the app running from a worktree on port 3100: this repository's own |
| 1477 | history pushed into it with two annotated tags and three branches, plus an empty |
| 1478 | repository and one with no README and no licence. Screenshots taken headless at 1280px |
| 1479 | and 800px, in both colour schemes, of the landing page, the empty and sparse states, a |
| 1480 | tree subpath, a blob and the log; the owner's view (with the Settings button) checked |
| 1481 | signed in. `cargo test` 467 passing, clippy clean. |
| 1482 | |
| 1483 | #### Decisions worth remembering |
| 1484 | |
| 1485 | - **The subprocess count was measured, not estimated.** A `git` shim on `PATH` logging |
| 1486 | every invocation: **15 processes** for a repository with a README and a licence, **10** |
| 1487 | without them, **1** for an empty one — up from 7. Worth repeating the trick; it took |
| 1488 | two minutes and contradicted a careful hand-count. |
| 1489 | - **The description has exactly one home, and it is the sidebar.** Putting it in the |
| 1490 | header too makes the header tallest on the repositories with the most to say, which |
| 1491 | pushes the code below the fold on exactly the pages that deserve it least. |
| 1492 | - **`repo_summary` takes the revision and the root listing the page already read.** A |
| 1493 | self-contained use case would have spent two more processes re-reading what the caller |
| 1494 | had in hand. The five calls it does make run under one `tokio::try_join!`. |
| 1495 | - **`organise_refs` was split out of `list_refs`** so the landing page gets the counts |
| 1496 | and the switcher's list from one `for-each-ref`. Two places deciding ref order is two |
| 1497 | places to change it. |
| 1498 | - **A `#[component]`'s name is a unit struct in module scope, and the copied-in |
| 1499 | components are in that scope too.** A parameter named `label` inside `repo.rs` does |
| 1500 | not bind — it parses as the `label` component's unit struct, and the error says |
| 1501 | "expected `str`, found `label`" without naming the component. The fix was renaming the |
| 1502 | parameter to `term`. This is the same trap `CLAUDE.md` records for pages; registry |
| 1503 | components widen it to every file that imports one. |
| 1504 | - **`bg-muted` is not a token.** Three `<pre>` blocks have been rendering with no |
| 1505 | background since they were written, silently — the exact failure `ui.md` describes for |
| 1506 | Tailwind classes the build never ships. `bg-surface` is the token. Two were fixed here; |
| 1507 | `token.rs` still has one. |
| 1508 | - **The clone URL wraps rather than scrolls.** In an 18rem column an `overflow-x-auto` |
| 1509 | URL looks like a truncated one, and the part hidden is the repository's own name. |
| 1510 | - **Light mode was checked by flipping the layout's `class="dark"` and rebuilding**, |
| 1511 | because there is no toggle. Nothing was wrong on these pages. That is the cheapest way |
| 1512 | to check it until a toggle exists, and it is worth doing before each UI step rather |
| 1513 | than after several. |
| 1514 | |
| 1515 | --- |
| 1516 | |
| 1517 | ## Reference: what attempt #2 proved |
| 1518 | |
| 1519 | Not this repo's progress. This is a catalogue of what was built and **verified working** |
| 1520 | in `steid-backup-2026-07-31`, so the rebuild can crib rather than rediscover. |
| 1521 | |
| 1522 | Final state: single crate, ~4,200 LOC, 60 passing tests, five milestones. |
| 1523 | |
| 1524 | ### Identity |
| 1525 | |
| 1526 | Domain model (User, Organization, Membership, Actor, Role), `Email` and |
| 1527 | `PasswordHash` value objects, typed IDs, `DomainError`, four repository ports with |
| 1528 | in-memory and SQLite implementations each. `RegistrationPolicy` (Personal / Invite / |
| 1529 | Open) driving which routes exist. Argon2 hashing behind a `PasswordHasher` port with a |
| 1530 | stub for tests. Use cases: `bootstrap_owner`, `register_user`, `login`, `create_invite`. |
| 1531 | Signed-cookie sessions via an `AuthUser` extractor. |
| 1532 | |
| 1533 | **Gotcha:** organizations must be saved before users — the FK runs that direction. |
| 1534 | Both `bootstrap_owner` and `register_user` had to be fixed for this. |
| 1535 | |
| 1536 | ### Repo model |
| 1537 | |
| 1538 | `Repository` entity, `RepoId`, `Visibility` (Public/Private), `RepoRepository` port, |
| 1539 | migration `006_create_repositories.sql`. `create_repo` use case validates the name, |
| 1540 | rejects duplicates, and initialises the bare repo on disk in the same call. Bare repos |
| 1541 | live at `{data_dir}/{org}/{repo}.git`, `data_dir` defaulting to `./data`. Repos are |
| 1542 | created empty, no initial commit, like GitHub. |
| 1543 | |
| 1544 | ### Git over SSH |
| 1545 | |
| 1546 | `GitStorage` port (`init_bare`, `repo_path`) with `DiskGitStorage` shelling out to |
| 1547 | `git init --bare`. `GitProtocolServer` port (`upload_pack`, `receive_pack`) with |
| 1548 | `GitBinary` spawning `git upload-pack` / `git receive-pack` via |
| 1549 | `tokio::process::Command` and pumping stdio with `tokio::io::copy`. |
| 1550 | |
| 1551 | `serve_clone` and `serve_push` use cases enforce visibility and actor checks **before |
| 1552 | any protocol byte flows** — that ordering is the whole point of putting them in the |
| 1553 | application layer. |
| 1554 | |
| 1555 | #### SSH channel bridging |
| 1556 | |
| 1557 | The fiddly part, and worth re-reading if SSH ever returns as a transport |
| 1558 | (milestone 8+ — [0001](decisions/0001-git-over-http-not-ssh.md) chose HTTP): |
| 1559 | |
| 1560 | - Store `Channel<Msg>` per `ChannelId` in the handler's map on `channel_open_session` |
| 1561 | - On `exec_request`, take the channel, split it with `into_stream()` + |
| 1562 | `tokio::io::split` |
| 1563 | - Take stderr via `make_writer_ext(Some(1))` **before** `into_stream()` — that call |
| 1564 | consumes the channel, so the order is not optional |
| 1565 | - No `data()` or `channel_eof()` handlers needed once the streams are split |
| 1566 | |
| 1567 | An earlier iteration used mpsc channels, custom `ChannelReader`/`ChannelWriter`, and a |
| 1568 | `spawn_blocking` thread. All of it was deleted and the result was simpler. |
| 1569 | |
| 1570 | ### SSH key auth and authorization |
| 1571 | |
| 1572 | `SshKey { id, user_id, name, fingerprint, openssh }` + port, migration |
| 1573 | `007_create_ssh_keys.sql` (`fingerprint` UNIQUE). Fingerprints are SHA256 via |
| 1574 | `russh::keys::ssh_key::PublicKey::fingerprint(HashAlg::Sha256)`, stored as `SHA256:…`. |
| 1575 | `add_ssh_key` parses the openssh blob, dedupes on fingerprint, and re-encodes to a |
| 1576 | canonical form before storing. |
| 1577 | |
| 1578 | `auth_none` rejects. `auth_publickey` fingerprints the offered key, looks it up, and |
| 1579 | on a match stores `user_id` on the handler; `exec_request` builds the real `Actor` |
| 1580 | from it. |
| 1581 | |
| 1582 | Authorization rules as shipped: |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | | Clone, public repo | open | |
| 1587 | | Clone, private repo | any membership in the repo's org | |
| 1588 | | Push | `Role::Owner` membership in the repo's org | |
| 1589 | |
| 1590 | Web UI at `/{owner}/keys` — owner-only, lists fingerprints, accepts openssh via |
| 1591 | textarea, revokes per-row. |
| 1592 | |
| 1593 | **Verified end-to-end:** clone with an unregistered key → `Permission denied` (exit |
| 1594 | 128); register via web UI → clone and push both succeed; second unregistered key → |
| 1595 | rejected at auth; revoke via web UI → subsequent clone rejected at auth. |
| 1596 | |
| 1597 | ### Security notes |
| 1598 | |
| 1599 | Attempt #2 ran with a **named, deliberate backdoor** between milestones: SSH accepted |
| 1600 | any connection and passed a placeholder `Actor` (`UserId("ssh-anonymous")`), leaving |
| 1601 | push open to anyone who could reach the port. It was recorded with an explicit |
| 1602 | tightening point (`ssh.rs::exec_request`) and a closing milestone, and it did close. |
| 1603 | |
| 1604 | That practice is worth keeping. When this attempt opens a hole to make progress, name |
| 1605 | it, name the line that closes it, and name the milestone. |
| 1606 | |
| 1607 | ### Never built |
| 1608 | |
| 1609 | Repo browsing (tree/blob/log), HTTP smart protocol, personal access tokens, flash |
| 1610 | messages, issues, PRs, blogs, pages, project showcases. Milestones 5–8 in |
| 1611 | [ROADMAP.md](ROADMAP.md) are all greenfield. |