From fce7526fcf746240fd5beebc3f1b13e19dd3252d Mon Sep 17 00:00:00 2001 From: Dasemu Date: Wed, 21 Oct 2026 03:59:42 +0200 Subject: [PATCH] docs: app build/run guide, analyze via dart on non-ASCII paths Co-Authored-By: Claude Opus 5.5 --- .claude/hooks/stop-check.sh | 5 +-- CLAUDE.md | 11 +++++-- LESSONS.md | 6 ++++ docs/README.md | 1 + docs/app.md | 62 +++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 docs/app.md diff --git a/.claude/hooks/stop-check.sh b/.claude/hooks/stop-check.sh index f78831e..68dcb0c 100755 --- a/.claude/hooks/stop-check.sh +++ b/.claude/hooks/stop-check.sh @@ -6,7 +6,8 @@ if [ -f Cargo.toml ]; then out=$(cargo clippy --workspace --all-targets -q -- -D warnings 2>&1) || fail clippy "$out" out=$(cargo test --workspace -q 2>&1) || fail "cargo test" "$out" fi -if [ -f app/pubspec.yaml ] && command -v flutter >/dev/null; then - out=$(cd app && flutter analyze 2>&1) || fail "flutter analyze" "$out" +if [ -f app/pubspec.yaml ] && command -v dart >/dev/null; then + # dart analyze: flutter analyze crashes on non-ASCII project paths. + out=$(cd app && dart analyze 2>&1) || fail "dart analyze" "$out" fi exit 0 diff --git a/CLAUDE.md b/CLAUDE.md index fc9c60f..d7d427a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,11 +8,14 @@ and an optional self-hosted sync server. Local-only (standalone graph) or client ## Commands - Format: `cargo fmt --all` (Rust), `dart format app/` (Flutter) -- Lint: `cargo clippy --workspace --all-targets -- -D warnings`, `cd app && flutter analyze` +- Lint: `cargo clippy --workspace --all-targets -- -D warnings`, `cd app && dart analyze` + (`flutter analyze` crashes on non-ASCII paths like `Darío/`) - Test: `cargo test --workspace`, `cd app && flutter test` - Run server: `cargo run -p synapse-server` -- Run app: `cd app && flutter run -d linux` (or `-d windows`, an Android device) -- Regenerate FFI bindings: `cd app && flutter_rust_bridge_codegen generate` +- Run app: `cd app && flutter run -d linux` (or `-d windows`, an Android device); Flutter SDK + in `~/development/flutter/bin`. Graph dir override: `SYNAPSE_GRAPH=/path`. See `docs/app.md`. +- Regenerate FFI bindings: `cd app && flutter_rust_bridge_codegen generate` (frb 2.13.0; commit + the generated Rust and Dart files) ## Architecture Cargo workspace under `crates/`, Flutter app under `app/`. Details in `docs/architecture.md`, @@ -28,6 +31,8 @@ roadmap in `docs/plan.md`. ## Conventions - The Flutter app never touches storage directly; everything goes through `synapse-ffi`. + UI code depends on the `GraphBackend` interface, not the generated FFI class (tests use an + in-memory backend). - Core crates are sync-free of UI concerns and must compile for Android (no desktop-only deps in `synapse-core`). - IDs are UUIDv7 (time-ordered). Journals are keyed by local date `YYYY-MM-DD`. diff --git a/LESSONS.md b/LESSONS.md index 8592c36..c01b51c 100644 --- a/LESSONS.md +++ b/LESSONS.md @@ -1,3 +1,9 @@ # Lessons Recurring mistakes and how to avoid them. Add an entry when a mistake repeats. + +- `flutter analyze` crashes ("FormatException: Unexpected end of input" from the analysis + server) when the project path has non-ASCII characters (`~/Hacking/Darío/...`). Use + `dart analyze` locally; CI paths are ASCII so `flutter analyze` is fine there. +- Generated FFI types share a namespace with Flutter widgets in Dart: avoid DTO names such as + `PageView`, `Page`, `Route` in `synapse-ffi`. diff --git a/docs/README.md b/docs/README.md index 77b56e4..0dc4bf5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,4 +2,5 @@ - [plan.md](plan.md): product scope and roadmap. - [architecture.md](architecture.md): crates, data model, storage and sync design. +- [app.md](app.md): Flutter app and FFI: build/run per platform, editor behaviour. - [server.md](server.md): running and deploying the sync server. diff --git a/docs/app.md b/docs/app.md new file mode 100644 index 0000000..9a40845 --- /dev/null +++ b/docs/app.md @@ -0,0 +1,62 @@ +# App (Flutter) and FFI + +## Layout +- `crates/synapse-ffi`: the only API the app sees. `src/api/` is scanned by + `flutter_rust_bridge` (v2.13): `graph.rs` (opaque `SynapseGraph` handle, reads), `outline.rs` + (block editing), `search.rs` (title/block lookup until `synapse-search` is wired), `dto.rs`. + Extension points for search/AI/history/CalDAV/sync are documented in `src/api/mod.rs`. +- `app/`: Flutter client. `lib/src/rust/` is generated; `rust_builder/` is the cargokit glue + that builds `synapse-ffi` as part of `flutter build`/`run` (paths point at + `../crates/synapse-ffi`). +- `app/lib/src/`: `backend/` (`GraphBackend` interface + FFI implementation), `state/` + (app state, write queue, outline controller and algorithms), `editor/` (block row, editor, + Markdown renderer, autocomplete), `views/` (journals, page, timeline, all pages, quick + switcher, shell), `theme/`. + +## Toolchain +- Flutter stable (3.47+) on `PATH`, Rust stable, `cargo install flutter_rust_bridge_codegen + --version 2.13.0 --locked`. +- Linux desktop: `clang cmake ninja-build gtk3-devel` (Fedora) / `clang cmake ninja-build + libgtk-3-dev` (Debian/Ubuntu). +- Android: Android SDK + NDK (cargokit installs the Rust targets with rustup). +- Windows: Visual Studio 2022 with "Desktop development with C++", Rust MSVC toolchain. + +## Build and run +```bash +cd app +flutter run -d linux # debug, builds the Rust crate via cargokit +flutter build linux --release # build/linux/x64/release/bundle/ +flutter run -d # or: flutter build apk --release +flutter build windows --release # on Windows +``` +The graph lives in the platform app-support dir (`~/.local/share/es.zenvairo.synapse/graph` +on Linux). Override it with `SYNAPSE_GRAPH=/path/to/graph`. + +## After changing the FFI API +```bash +cd app && flutter_rust_bridge_codegen generate +``` +Commit the regenerated `crates/synapse-ffi/src/frb_generated.rs` and `app/lib/src/rust/`. +`frb_generated.rs` is excluded from rustfmt. + +## Checks +- `cargo test -p synapse-ffi` (outline semantics against the real core). +- `cd app && dart analyze && flutter test` (editor key handling runs against an in-memory + backend that reuses the Dart outline algorithms). +- `flutter analyze` crashes when the project path contains non-ASCII characters (its LSP + channel miscounts bytes); `dart analyze` runs the same analysis. + +## Editor +- Blocks render Markdown when idle and become raw-Markdown text fields when focused. +- Keys: Enter split (at start: new block above), Shift+Enter newline, Tab/Shift+Tab + indent/outdent (Logseq's direct outdenting), Backspace at start merges into the previous + block, Delete at end pulls the next one in, ↑/↓/←/→ cross block edges, Alt+Shift+↑/↓ move + among siblings, Ctrl+↑/↓ collapse/expand, Ctrl+Enter cycles TODO/DONE, Esc leaves editing. +- `[[`, `((` auto-pair; `[[`, `#` and `((` open autocomplete (↑/↓, Enter/Tab, Esc). +- Drag a bullet onto a row: upper half = before, lower half = after, lower half to the right + = first child. +- Edits apply locally at once and go to the core through one serial write queue (text saves + are debounced 350 ms); after structural edits the outline is re-read and the core's + structure wins if they ever disagree. +- App shortcuts: Ctrl+K quick switcher, Ctrl+Shift+J journals, Ctrl+Shift+T timeline, + Ctrl+\ sidebar, Alt+←/→ back/forward.