stahl/AGENTS.md
Markus Zoppelt bab375f119 docs: trim the README, add one for iOS, and name screenshots after their scenes
The README drops the project structure and the long feature list, which went stale, and points at
AGENTS.md for working on it. The iOS how-to moves out of AGENTS.md into ios/README.md, with phone
screenshots. Screenshots are named after demo scenes, so one loop regenerates them all.

The landing page's letter and llms.txt listed everything that leaves the machine but missed the
update check.
2026-11-09 10:41:57 +01:00

7.8 KiB

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:

    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 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 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.

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:

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/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 and GitHub Actions. 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.