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.
8.2 KiB
Agent notes
Guidance for AI agents (and humans) working on this repo.
Rust style
-
Prefer top-level
useimports over inline fully-qualified paths. Write:use std::fs; ... fs::write(&path, data)?;not:
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 afnshould be hoisted to the top of the file instead). -
If an import is only needed under a
#[cfg(...)]-gated function or block, gate theusewith 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;intests/e2e.rs. -
Run
cargo fmtafter adding/moving imports — rustfmt reorders and groupsusestatements (including#[cfg(...)]-gated ones) and CI enforces this viacargo fmt --check(nix flake check→stahl-fmt). -
cargo clippy --all-targets -- --deny warningsmust be clean (also enforced bynix flake check→stahl-clippy).
Design
The look is decided: read 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 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_rsneeds Tokio. Reach the backend throughState::run: the work runs on Tokio, and its result lands inpollon the UI thread. Headless code waits for it withState::settle.- A row stretches its children by default. Use
row().center_y()unless you want that. TextInputis 280pt wide unless told otherwise, andTextInput::labelonly names it for assistive technology. Use.width(None)to fill a column andui::fieldfor a visible label.- Write shortcuts with
ui::chordorui::chord_keys: Rune's command chords are Ctrl off macOS. - A window can't refuse to close.
on_closereopens it to ask about unsaved changes. - Native menus, context menus, the Dock menu and
drag_outare 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:
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:
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 says how to build, run, script and install the iPhone and iPad app. What matters when you change the shared code:
ios/rustis its own Cargo workspace with its own lockfile. Keep its Runerevthe same as the app's.- The phone layout (
src/view/compact.rs) is on whenState::compactis, which the shell sets from UIKit's horizontal size class. Pages size themselves withui::roomandui::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 withState::platform_pickerthe app asks throughState::pickand 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 throughformat::place. - Rune has no iOS clipboard, so the shell moves what the app copies to the pasteboard. Haptics play
for what
stahl_ios_tickreports. Pull to refresh isState::pull, sliding rows areState::settle_swipes, and the edge swipe isState::go_back. site/render-icons.shrenders the app icon intoios/Shell/Assets.xcassetsalong 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 insite/media/tour.json, and its chapter times are repeated inCHAPTERSinsite/app.js, so change them together. - The sketches in
site/app.jsuse the prices and targets insrc/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, andsite/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.