steid

@jamesgill /

steid/CLAUDE.md
Markdown11.2 KBRendered·Source·Blame·History·Raw
1# Steid
2
3A version control server, in Rust, that is entirely yours. One tenant, one binary, one
4database, one owner. It is built to be stable, secure, fast and simple, and to do
5nothing else — not a GitHub clone, not a platform.
6
7**Boring wins.** Use that to break ties: between two designs, choose the one that is
8more predictable, more isolated, or has fewer moving parts. A feature that makes a page
9more interesting but less certain loses.
10
11## Read first
12
13`plans/` is the source of truth and is tracked in git. Read it at the start of a
14session rather than inferring intent from the code.
15
16| File | Holds |
17|---|---|
18| `../plans/launch.md` | the workspace launch plan: the order of work across Steid and Steid Cloud, since 2026-10-01 |
19| `plans/ROADMAP.md` | vision, stack, the single milestone ladder |
20| `plans/current.md` | the active work only — Steid's launch items, open items, known gaps, backlog |
21| `plans/progress.md` | what shipped, and the decisions worth not rediscovering |
22| `plans/architecture.md` | layer rules and conventions |
23| `plans/runbook.md` | how to run it, config, manual verification |
24| `plans/decisions/` | ADRs; `TEMPLATE.md` defines the format |
25
26## Keep the docs current
27
28**Before reporting work complete, update `plans/`.** This is part of finishing the
29work, not a follow-up chore — the project has been restarted three times and the
30previous attempts lost their reasoning at exactly these handover points.
31
32- `current.md` — tick off finished steps; move completed work out to `progress.md`.
33 If it starts reading like a changelog, it has drifted.
34- `progress.md` — record decisions and gotchas that aren't obvious from the code. The
35 test is: would the next session waste an hour rediscovering this?
36- `ROADMAP.md` — only when a milestone's status actually changes.
37- `decisions/` — a new ADR when a choice would be expensive to reverse or constrains
38 future work. Write it when the decision is made; reconstructed rationale is fiction.
39
40Also update `current.md` when a *new* problem is found — an unfinished item, a
41shortcut taken, a hole opened. Carry those forward explicitly at milestone rollover
42rather than letting them vanish.
43
44Skip all of this for typos, formatting, and dependency bumps.
45
46## Working style
47
48- **Commit directly to `main`.** No feature branches — solo repo. Cleanliness comes
49 from small, self-contained commits that each compile, not from branching.
50- Small steps. Build up slowly; prefer a working increment over a big drop.
51- Explain *why* in commit messages, not just what.
52
53### Plan the step, then execute it
54
55Milestones are planned in `current.md` as a list of steps. **Before executing a step,
56lay out what it will contain — files, signatures, the tests worth writing, and any
57decision inside it — and wait.** Then do that one step and stop.
58
59A milestone-level sketch is not a step-level plan. Answering the open questions in a
60plan is not the same as approving the code; ask before starting.
61
62### Decisions belong to the user
63
64Surface a choice rather than picking a sensible-looking default, especially anything
65expensive to reverse: URL shape, storage layout, visibility defaults, dependencies.
66Give a recommendation and the trade-off, then let them decide.
67
68Corollary: **don't add scope that wasn't asked for.** If something seems obviously
69needed, propose it. `Repository::description` was added unrequested and had to be
70flagged after the fact.
71
72### Docs ship with the code
73
74Update `plans/` in the **same commit** as the change it describes, not a follow-up
75`docs:` commit. This has slipped repeatedly; a separate commit is the symptom.
76
77## Conventions
78
79Full detail in `plans/architecture.md`. The short version:
80
81- **Layers:** `domain` (no knowledge of HTTP/SQL/git/Topcoat) → `application` (use
82 cases and ports) → `infrastructure` (adapters, web). Dependencies point inward.
83- **Every use case takes an `Actor`** and enforces authorization before any side
84 effect — one place, reachable from a page, an `/api` route, or a future transport.
85- **Typed IDs**, never raw `String` for entity references.
86- **`new()` validates, `from_trusted()` doesn't.** Storage adapters use
87 `from_trusted`; re-validating stored rows makes a tightened rule unreadable.
88- **`from_str` returns `Result`, never `Option`.** A silently-defaulted enum surfaces
89 later as the wrong permissions.
90- **Every repository port gets two implementations** — in-memory (what makes use cases
91 testable without a database) and SQLite.
92- Request helpers are **functions taking `cx`**, not middleware or extractors. A page
93 that forgets to call one gets nothing; a route added without middleware silently
94 gets someone else's data.
95- Safe Rust only. No `unsafe`.
96
97## Topcoat, as we use it
98
99Working knowledge that is easy to get wrong and slow to rediscover:
100
101- **Components are invoked bare inside `view!`** — `label(attrs: …, "Text")`, not
102 `(label(…)?)`. `if`, `match`, `for` and `let` are native to the macro.
103- **`#[path_param]` is an attribute on a tuple struct** — `#[path_param] struct
104 Handle(str);` — and the struct name snake-cased is the URL parameter.
105- **`#[query_params]` needs `error = …`** to be usable with `?`; otherwise the error
106 borrows from `cx` and escapes the handler.
107- **`redirect()` is a 307 and preserves the method**, so it must never end a form POST —
108 the browser re-POSTs to the target. Post/redirect/get needs a 303. `see_other()` is
109 that status but is a *response* type, and `#[page]` must return a view so the layout
110 can wrap a failure re-render, so use `web::context::location` with
111 `StatusCode::SEE_OTHER` inside `view!`. `Err(redirect(..).into())` is still right for
112 a **GET** guard sending a visitor elsewhere.
113- **Static routes beat parameterised ones**, so `/auth/login` still wins over
114 `/{handle}`.
115- **Forms redirect on success and re-render on failure.** Redirecting after a validation
116 error discards what was typed and hides the reason. The success redirect is a 303 —
117 see above.
118- **Boolean attributes need a value** — `required=(true)`, not bare `required`. A `false`
119 omits the attribute entirely, so `selected=(bool)` is correct.
120- **`view!` needs `__cx` in scope, so a plain `async fn helper(cx: &Cx) -> Result`
121 cannot build a view.** Make it `#[component] async fn helper(cx: &Cx, …)` — a
122 component may declare `cx: &Cx` and it is *not* passed at the call site. The error is
123 a bare "cannot find value `__cx`" pointing into the macro, which names nothing useful.
124- **A `#[page]` or `#[component]`'s name becomes a unit struct in module scope**, so it
125 shadows anything of the same name elsewhere in the file — parameters *and* `let`
126 bindings. A component called `commits` broke `fn commit_log(commits: &[CommitSummary])`;
127 separately, `let profile = …` inside a module containing `#[page] async fn profile`
128 parses as a **unit-struct pattern rather than a new binding**, and the error mentions
129 neither the page nor the shadowing. Name locals for what they hold, not for the page
130 they serve.
131- **Catch-all params are `{*path}`, read with `#[path_param] struct Path(str);`** — the
132 `*` is not part of the name. The whole tail arrives as one percent-decoded string.
133 Matching happens on the *raw* path, which is why `%2F` inside a `{rev}` segment
134 survives as a single segment and decodes to a slash.
135- **Tailwind only ships classes the app already uses.** `build.rs` scans the real
136 sources, so a class that appears nowhere in `src/` is absent from the built CSS and
137 fails silently — spacing collapses, nothing errors. A throwaway mockup must therefore
138 be written in plain CSS against the theme's custom properties, not in Tailwind against
139 the served stylesheet. Dark mode is a `.dark` class on an ancestor, not
140 `prefers-color-scheme`.
141- **UI components reference theme tokens, never raw colours** — see `styles.css`. A
142 hardcoded colour follows neither a palette change nor the colour scheme. Registry
143 components are copied in by `topcoat ui add`, not depended on.
144
145## Before saying it's done
146
147```bash
148cargo test
149cargo clippy --all-targets # expect zero warnings
150cargo fmt
151cargo audit # expect zero vulnerabilities
152```
153
154`cargo audit` needs `cargo install cargo-audit --locked` once. A transitive advisory is
155usually one `cargo update -p <crate>` — bump only the crate the advisory names.
156
157Report counts accurately — don't state a test number without running it.
158
159Verify behaviour rather than asserting it. A passing unit test is not evidence that a
160page works; the session-cookie bug passed every test and failed silently in the
161browser. Say plainly what was checked and what wasn't.
162
163### End with what it now lets the user do
164
165Close every completion report with a short rundown in user terms: what can be done now
166that couldn't be before, and how — the URL, the command, the thing to click.
167
168**If the answer is "nothing yet", say so plainly**, and name what is still missing
169before the capability appears. A step that adds no user-visible capability is normal
170and expected; going several steps without noticing is not. Two attempts died inside
171plumbing that felt like progress, and this is the check against a third.
172
173It is a rundown of capability, not of files touched — that is the commit message's job.
174
175## Gotchas
176
177- **Topcoat 0.5 needs rustc ≥ 1.95.** On older toolchains `cargo add topcoat` silently
178 resolves to an empty `topcoat v0.0.0` placeholder instead of failing.
179- **Read the vendored crate, not GitHub `main`.** Topcoat is very new (first release
180 2026-07-22) and its repository has already diverged from the released version. The
181 authority for the pinned version is
182 `~/.cargo/registry/src/*/topcoat-0.5.0/docs/` and the sibling `topcoat-*-0.5.0`
183 crates. Checking `main` is how `path_param` was got wrong.
184- **`STEID_INSECURE_COOKIES=true`** is set in a gitignored `.env` for local dev,
185 because a `Secure` cookie is dropped silently over plain-HTTP localhost. Never
186 deploy it.
187- **The setup token is in memory only**, so every restart — including each `topcoat
188 dev` rebuild — mints a new one.
189- Don't leave background servers running; the user drives the app.
190- **`cargo build --release` alone produces a binary that will not boot.** `main` calls
191 `AssetBundle::load()`, which walks up from the executable looking for
192 `assets/manifest.toml` — and `build.rs` does not write one. `topcoat asset bundle`
193 does, and it runs `cargo build` itself, so it is the build command, not a step after
194 it. A `cargo build`-only container image compiles cleanly and then fails at startup
195 with `NotFound`. Found while writing the Dockerfile.
196- **`topcoat asset bundle` after a manual build**, or the CSS served is stale.
197 `topcoat dev` does it for you. **The symptom is silently wrong layout, not an error** —
198 new utility classes simply do not exist, so gaps collapse and sizes fall back to
199 defaults, and the page looks like a design mistake rather than a stale build.
200- **The build needs network beyond crates.io**: `build.rs` downloads the standalone
201 Tailwind CLI from GitHub releases, and those binaries are glibc-linked — which is why
202 the container is Debian on both stages and a musl/Alpine builder fails at `cargo
203 build`.
204- In `sqlite.rs` and similar, **every implementation precedes the `mod tests` block**.
205 Appending to the end of the file otherwise lands inside the wrong block.