mirror of
https://github.com/MarkusZoppelt/stahl.git
synced 2026-11-28 13:02:13 +01:00
scripts/update-rune.sh moves every Rune pin (the app's and ios/rust's) to one revision, the tip of Rune's dev branch by default, and refreshes both lockfiles. A weekly workflow runs it and opens a PR, like the flake.lock one, so CI says whether Rune's API moved under us. Dependabot now also updates ios/rust's lockfile.
157 lines
8.2 KiB
Markdown
157 lines
8.2 KiB
Markdown
# Agent notes
|
|
|
|
Guidance for AI agents (and humans) working on this repo.
|
|
|
|
## Rust style
|
|
|
|
- Prefer top-level `use` imports over inline fully-qualified paths. Write:
|
|
|
|
```rust
|
|
use std::fs;
|
|
...
|
|
fs::write(&path, data)?;
|
|
```
|
|
|
|
not:
|
|
|
|
```rust
|
|
std::fs::write(&path, data)?;
|
|
```
|
|
|
|
This applies even to single call sites and to imports inside a function body
|
|
(`use std::os::unix::fs::PermissionsExt;` inside a `fn` should be hoisted to
|
|
the top of the file instead).
|
|
|
|
- If an import is only needed under a `#[cfg(...)]`-gated function or block,
|
|
gate the `use` with the same `#[cfg(...)]` rather than importing it
|
|
unconditionally (which would produce an unused-import warning on other
|
|
platforms). Example: `#[cfg(unix)] use std::os::unix::fs::PermissionsExt;` in `tests/e2e.rs`.
|
|
|
|
- Run `cargo fmt` after adding/moving imports — rustfmt reorders and groups
|
|
`use` statements (including `#[cfg(...)]`-gated ones) and CI enforces this
|
|
via `cargo fmt --check` (`nix flake check` → `stahl-fmt`).
|
|
|
|
- `cargo clippy --all-targets -- --deny warnings` must be clean (also
|
|
enforced by `nix flake check` → `stahl-clippy`).
|
|
|
|
## Design
|
|
|
|
The look is decided: read [DESIGN.md](DESIGN.md) before changing a screen. Colours, type, shadows and
|
|
gradients come from `src/theme.rs` and the primitives in `src/view/ui.rs`, never from a page.
|
|
`tests/design.rs` fails on a page that reaches past them.
|
|
|
|
## Rune
|
|
|
|
The UI is [Rune](https://github.com/anomalyco/rune) and `rune-kit`, pinned to one git revision in
|
|
`Cargo.toml`. Rune is pre-release and moves fast, so read the README at the pinned revision rather
|
|
than trusting memory, and expect an update to move its API. Both crates must stay on the same `rev`.
|
|
Update it with `nix develop -c scripts/update-rune.sh [rev]`, which moves every pin (here and in
|
|
`ios/rust`) to one revision, the tip of Rune's `dev` by default, and refreshes both lockfiles. A
|
|
weekly workflow (`.github/workflows/update-rune.yml`) runs it and opens a PR.
|
|
|
|
The shape of the app: one `State`, and views that are pure functions of it. Rune re-runs them when
|
|
state changes, so a view must not do work or mutate anything.
|
|
|
|
Things that are easy to get wrong:
|
|
|
|
- `portfolio_rs` needs Tokio. Reach the backend through `State::run`: the work runs on Tokio, and its
|
|
result lands in `poll` on the UI thread. Headless code waits for it with `State::settle`.
|
|
- A row stretches its children by default. Use `row().center_y()` unless you want that.
|
|
- `TextInput` is 280pt wide unless told otherwise, and `TextInput::label` only names it for assistive
|
|
technology. Use `.width(None)` to fill a column and `ui::field` for a visible label.
|
|
- Write shortcuts with `ui::chord` or `ui::chord_keys`: Rune's command chords are Ctrl off macOS.
|
|
- A window can't refuse to close. `on_close` reopens it to ask about unsaved changes.
|
|
- Native menus, context menus, the Dock menu and `drag_out` are macOS only. Everything they do must
|
|
also be reachable through a shortcut or the command palette.
|
|
|
|
## Tests
|
|
|
|
`tests/e2e.rs` drives the real views and handlers through pointer and key input in Rune's headless
|
|
runtime. It needs no display or GPU, so `nix flake check` runs it. Tests can't judge how a screen
|
|
looks, so render the ones you changed and look at them:
|
|
|
|
```sh
|
|
cargo run --example demo -- --snap /tmp/x.png --scene holdings --at 2 --size 1320x860
|
|
```
|
|
|
|
Every screen has a scene in `examples/demo.rs`; add one with each new screen. The images in
|
|
`screenshots/` and `ios/screenshots/` are named after their scenes. Regenerate them when the UI
|
|
changes:
|
|
|
|
```sh
|
|
for f in screenshots/*.png; do cargo run -q --example demo -- --snap $f --scene $(basename $f .png) --at 2 --size 1320x860; done
|
|
for f in ios/screenshots/*.png; do cargo run -q --example demo -- --snap $f --scene phone-$(basename $f .png) --at 2 --size 390x844; done
|
|
```
|
|
|
|
Tests must not touch the user's config. `AppState::load_workspace` and `load_simple_file` save it
|
|
to the default location whatever they are given, so never call them. Go through `Backend`, whose
|
|
own versions save where it was told to, on a backend from `demo::backend`.
|
|
|
|
Updates are off unless given an `Updater`: `State::new` has a disabled one, and only `app::run` uses
|
|
`Updater::github()`. Tests use `app::headless_with_updater` with `demo::FakeReleases` and paths in a
|
|
temp directory, so they can't reach the network or replace the running binary. The macOS flow needs
|
|
`hdiutil`, so its test is ignored by default. After changing it, run it by hand:
|
|
`cargo test --lib -- --ignored mac_flow`.
|
|
|
|
When running the app by hand, use the demo, or isolate it from real data: set `HOME` to a temp
|
|
directory and `PORTFOLIO_RS_QUOTES=offline`. Opening a portfolio records a valuation in its history.
|
|
|
|
## iOS
|
|
|
|
[ios/README.md](ios/README.md) says how to build, run, script and install the iPhone and iPad
|
|
app. What matters when you change the shared code:
|
|
|
|
- `ios/rust` is its own Cargo workspace with its own lockfile. Keep its Rune `rev` the same as the
|
|
app's.
|
|
- The phone layout (`src/view/compact.rs`) is on when `State::compact` is, which the shell sets from
|
|
UIKit's horizontal size class. Pages size themselves with `ui::room` and `ui::columns`, never by
|
|
platform.
|
|
- Each phone screen has a `phone-*` scene. Render those at `--size 390x844`, and the others at an
|
|
iPad's sizes (`820x1156`, `1180x800`) when a page changes.
|
|
- An iOS app can't update itself (`update::SELF_UPDATES`) or take file drops. Rune's file dialogs
|
|
can't show in an embedded view, so with `State::platform_picker` the app asks through
|
|
`State::pick` and the shell answers with UIKit's document picker.
|
|
- Config and single-file history live in the app's `Library/Application Support`
|
|
(`XDG_CONFIG_HOME`, `XDG_DATA_HOME`). Paths shown on iOS go through `format::place`.
|
|
- Rune has no iOS clipboard, so the shell moves what the app copies to the pasteboard. Haptics play
|
|
for what `stahl_ios_tick` reports. Pull to refresh is `State::pull`, sliding rows are
|
|
`State::settle_swipes`, and the edge swipe is `State::go_back`.
|
|
- `site/render-icons.sh` renders the app icon into `ios/Shell/Assets.xcassets` along with the others.
|
|
Restore the other icons afterwards, because each render comes out a few pixels different.
|
|
|
|
## Landing page
|
|
|
|
`site/` is the landing page: plain HTML, CSS and JavaScript with no build step, deployed by
|
|
`.github/workflows/pages.yml`. Paths stay relative, because it's served from `/stahl/`.
|
|
|
|
- Its images and video come from the real app. When the UI changes, run
|
|
`nix develop -c site/render-media.sh`. The tour's input is in `site/media/tour.json`, and its
|
|
chapter times are repeated in `CHAPTERS` in `site/app.js`, so change them together.
|
|
- The sketches in `site/app.js` use the prices and targets in `src/demo.rs`, so its totals match the
|
|
footage. Change them together.
|
|
- The page makes specific claims about what the app does, including everything that leaves the
|
|
machine (the letter in `site/index.html`, and `site/llms.txt`). A change that makes one false, like
|
|
a new network request, has to update them.
|
|
- Its content security policy forbids contacting any other origin, and the letter says so. Keep it
|
|
that way: no analytics, and no fonts or scripts from anywhere else.
|
|
|
|
To preview it, serve `site/` on loopback with `python3 -m http.server --bind 127.0.0.1 -d site`.
|
|
|
|
## Nix flake maintenance
|
|
|
|
`rust-toolchain.toml` is the single Rust version pin, shared by rustup, the
|
|
release workflow, and the flake (through `rust-overlay`, because Rune needs a
|
|
newer compiler than nixpkgs ships). Do not add a second pin.
|
|
|
|
Dependabot owns Cargo (the app and `ios/rust`) and GitHub Actions, except Rune's git pin,
|
|
which `scripts/update-rune.sh` moves. A weekly workflow updates `flake.lock`.
|
|
|
|
## CI
|
|
|
|
`.github/workflows/ci.yml` uses `cachix/install-nix-action` (not
|
|
DeterminateSystems' installer/FlakeHub — keep this on plain, non-proprietary
|
|
Nix tooling) and runs `nix flake check` + `nix build .#stahl` on Linux and
|
|
macOS. A second job covers Linux, macOS and Windows with plain cargo, because Nix can't build for
|
|
Windows: clippy, tests, renders of the demo scenes (every one, or four on Windows), and a real window. It reads from the public
|
|
`cache.nixos.org` and `nix-community.cachix.org` substituters already declared in `flake.nix`'s
|
|
`nixConfig`; there is no project-specific push cache configured.
|