From a46fc6c977b70f79dd12ab20ad409af89f453092 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 18:33:26 +0000 Subject: [PATCH 1/2] Architecture: the reference split into a wiki of pages by area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docs/architecture.md becomes docs/architecture/: a home page that maps the pages, then one page an area, each opening with what it covers and a link home. Every section moves whole and unchanged; only heading levels, four relative links and one heading (the UI's « The gate, drawn ») change. scripts/architecture-links.mjs fails when a name after an arrow finds no section or more than one, and when a link into or between the pages leads nowhere; its test runs it on the repository. Three references broken before the split are repointed. Closes #1841 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BbVs5tCyTr9AasGra3Zzg3 --- .claude/skills/add-feature/SKILL.md | 4 +- .claude/skills/desktop-e2e-testing/SKILL.md | 2 +- .../skills/devnotes-security-review/SKILL.md | 2 +- .claude/skills/egui-ui/SKILL.md | 4 +- .claude/skills/performance-profiling/SKILL.md | 2 +- .claude/skills/platform-integration/SKILL.md | 4 +- .claude/skills/rust-guidelines/SKILL.md | 6 +- .github/workflows/ci.yml | 2 +- .github/workflows/website.yml | 2 +- CLAUDE.md | 8 +- CONTRIBUTING.md | 20 +- Cargo.toml | 3 +- README.md | 2 +- crates/ui/src/app/perf.rs | 2 +- docs/architecture.md | 6953 ----------------- docs/architecture/README.md | 51 + docs/architecture/backend.md | 328 + docs/architecture/decisions.md | 39 + docs/architecture/engine.md | 420 + docs/architecture/http/drawn.md | 229 + .../http/environments-and-scripts.md | 245 + docs/architecture/http/requests.md | 475 ++ .../i18n-accessibility-theming.md | 164 + docs/architecture/interface.md | 231 + docs/architecture/libraries.md | 567 ++ docs/architecture/notes/cards.md | 616 ++ docs/architecture/notes/editing.md | 446 ++ docs/architecture/notes/kinds.md | 445 ++ docs/architecture/overview.md | 137 + docs/architecture/releasing.md | 194 + docs/architecture/spaces-folders-board.md | 666 ++ docs/architecture/testing.md | 418 + docs/architecture/tools.md | 662 ++ docs/architecture/website.md | 92 + docs/architecture/window.md | 620 ++ docs/releasing.md | 6 +- scripts/architecture-links.mjs | 220 + scripts/architecture-links.test.mjs | 138 + 38 files changed, 7439 insertions(+), 6986 deletions(-) delete mode 100644 docs/architecture.md create mode 100644 docs/architecture/README.md create mode 100644 docs/architecture/backend.md create mode 100644 docs/architecture/decisions.md create mode 100644 docs/architecture/engine.md create mode 100644 docs/architecture/http/drawn.md create mode 100644 docs/architecture/http/environments-and-scripts.md create mode 100644 docs/architecture/http/requests.md create mode 100644 docs/architecture/i18n-accessibility-theming.md create mode 100644 docs/architecture/interface.md create mode 100644 docs/architecture/libraries.md create mode 100644 docs/architecture/notes/cards.md create mode 100644 docs/architecture/notes/editing.md create mode 100644 docs/architecture/notes/kinds.md create mode 100644 docs/architecture/overview.md create mode 100644 docs/architecture/releasing.md create mode 100644 docs/architecture/spaces-folders-board.md create mode 100644 docs/architecture/testing.md create mode 100644 docs/architecture/tools.md create mode 100644 docs/architecture/website.md create mode 100644 docs/architecture/window.md create mode 100644 scripts/architecture-links.mjs create mode 100644 scripts/architecture-links.test.mjs diff --git a/.claude/skills/add-feature/SKILL.md b/.claude/skills/add-feature/SKILL.md index 56158e060..efbc85590 100644 --- a/.claude/skills/add-feature/SKILL.md +++ b/.claude/skills/add-feature/SKILL.md @@ -5,7 +5,7 @@ description: Use when adding or changing a DevNotes feature end to end (core ser # Add a feature -1. Read the matching section of `docs/architecture.md` (headings are named in `CLAUDE.md`), the nearest existing feature of the same shape, and, for a screen that existed before 1.0.0, its Angular twin at the `angular-reference` tag (`git show angular-reference:src/app/…`; same look, same behaviour). Copy the layout; do not invent a new one. +1. Read the matching section of `docs/architecture/` (its home says which page holds what; headings are named in `CLAUDE.md`), the nearest existing feature of the same shape, and, for a screen that existed before 1.0.0, its Angular twin at the `angular-reference` tag (`git show angular-reference:src/app/…`; same look, same behaviour). Copy the layout; do not invent a new one. 2. Decide the side: data processing, filtering, rules and validation are the **core** (`crates/engine/src//{model,store}.rs`, service functions in `.rs`). The interface describes and displays. 3. Schema change? Run `database-migration` first. 4. The call: one function in `crates/ui/src/api/.rs`, the only place that names the engine, returning a `Pending` from the right `Backend` queue (`db` for anything touching the library or the index, `compute` for pure work, `spawn` for the network). A new `ErrorCode` gets its sentence in the UI's exhaustive `match` and its key in `fr.json` **and** `en.json`. @@ -13,5 +13,5 @@ description: Use when adding or changing a DevNotes feature end to end (core ser 6. Something asked of the OS (a dialog, the clipboard, the tray)? Run `platform-integration`. 7. Sealed data (titles, bodies, names, attachments) touched? Run `devnotes-security-review`. 8. Tests with the code: Rust inline or `crates/engine/tests/`; kittest over a real core (`testing::backend`/`unlocked`); a step of an e2e journey if a nominal path changes (`desktop-e2e-testing`). -9. Update `docs/architecture.md` and, only if a new trap exists, one line of `CLAUDE.md`. What the user sees: `docs/content/fr` and `docs/content/en` (`docs/content/README.md` says how), and, when they show the screen that changed, the README's GIFs (`docs/gifs/`, by `app::screens` then `--example tours`) and the site's scenes (`website/`, skill `marketing-site`). Publishing them is automatic. +9. Update the page of `docs/architecture/` the change belongs to and, only if a new trap exists, one line of `CLAUDE.md`. What the user sees: `docs/content/fr` and `docs/content/en` (`docs/content/README.md` says how), and, when they show the screen that changed, the README's GIFs (`docs/gifs/`, by `app::screens` then `--example tours`) and the site's scenes (`website/`, skill `marketing-site`). Publishing them is automatic. 10. Finish with `verify-change`, including a look at the window. Report what ran and what did not. diff --git a/.claude/skills/desktop-e2e-testing/SKILL.md b/.claude/skills/desktop-e2e-testing/SKILL.md index a2e3958bb..01b563602 100644 --- a/.claude/skills/desktop-e2e-testing/SKILL.md +++ b/.claude/skills/desktop-e2e-testing/SKILL.md @@ -5,7 +5,7 @@ description: Use when writing, running or debugging an end-to-end journey of the # Desktop e2e -`CONTRIBUTING.md` → "The end-to-end journeys" says how to run, watch, mend and extend them; `docs/architecture.md` → "The journeys, on the assembled window" lists the fourteen and what the driver does. What is worth knowing before touching one: +`CONTRIBUTING.md` → "The end-to-end journeys" says how to run, watch, mend and extend them; `docs/architecture/testing.md` → "The journeys, on the assembled window" lists the fourteen and what the driver does. What is worth knowing before touching one: - Build the flavour first, every time `crates/` changed: `cargo build -p app --features e2e --target-dir target/e2e` (its own target directory: no other build overwrites it). Then `cargo test -p e2e --test NN_name` for one journey, `cargo test -p e2e` for all — what CI runs on each OS. `cargo test --workspace` runs with `--exclude e2e`. - A journey is `e2e/tests/NN_name.rs`: one `#[test]` of named `step`s, what the person does then what they see. A nominal path goes into the journey it belongs to, as a step; a new file only for a new goal (15 at most). Branches, edge cases and error codes are unit tests'. diff --git a/.claude/skills/devnotes-security-review/SKILL.md b/.claude/skills/devnotes-security-review/SKILL.md index cd302dc06..ddd720126 100644 --- a/.claude/skills/devnotes-security-review/SKILL.md +++ b/.claude/skills/devnotes-security-review/SKILL.md @@ -17,4 +17,4 @@ Checklist on the change (`git diff main...`, and `git diff HEAD` for what is not 6. **Dependencies**: see `dependency-audit` if `Cargo.toml`/`package.json` changed. 7. Report findings by severity with file:line; state what you did not check. Do not auto-fix crypto findings. -Reference: `docs/architecture.md` → "Encryption at rest". +Reference: `docs/architecture/libraries.md` → "Encryption at rest". diff --git a/.claude/skills/egui-ui/SKILL.md b/.claude/skills/egui-ui/SKILL.md index 88bd350c5..ef68829b0 100644 --- a/.claude/skills/egui-ui/SKILL.md +++ b/.claude/skills/egui-ui/SKILL.md @@ -5,7 +5,7 @@ description: Use when writing or reviewing the egui interface (crates/ui, crates # egui UI -Source of truth: `docs/architecture.md` (« Decisions », « Interface (egui) », « Backend and events », +Source of truth: `docs/architecture/` (« Decisions », « Interface (egui) », « Backend and events », « Testing »). The look to reproduce, for a screen that existed there, is the Angular application, whole at the `angular-reference` tag (its `src/` and `e2e/`, e.g. `git show angular-reference:src/app/…`, D32): read a screen's component and its SCSS before changing it, and its captures. @@ -19,7 +19,7 @@ D32): read a screen's component and its SCSS before changing it, and its capture or the index (reads included); `compute` for pure work; `spawn` for the network (D11). Never `block_on`, never a lock taken while drawing. Only exception: a pure core function whose input the screen bounds, under 1 ms, called directly but still through `api/` (D12). Every concurrency - rule is in `docs/architecture.md` → "The concurrency rules"; one that is not there does not exist. + rule is in `docs/architecture/backend.md` → "The concurrency rules"; one that is not there does not exist. - A data rule (what a `{{field}}`, a variable name, a heading is) belongs to the core: `text`, `richtext`, `drawing` take its result as an argument and never redefine it (D10). - Drawing reads a screen's state (`&…State`) and may change its view (`&mut …View`: text being diff --git a/.claude/skills/performance-profiling/SKILL.md b/.claude/skills/performance-profiling/SKILL.md index 744ac0f89..910ddac58 100644 --- a/.claude/skills/performance-profiling/SKILL.md +++ b/.claude/skills/performance-profiling/SKILL.md @@ -9,4 +9,4 @@ description: Use when a DevNotes operation feels slow (query_notes, search, boar 2. Known facts: one lock serialises commands, and `query_notes` holds it for ~90 % of its cost; lists send previews (`PREVIEW_LINES`); side tables are read by bound ids up to 500, else by subquery; decrypting sealed fields dominates. 3. Fix at the owning layer (the core for data; a `QueryCell` compared by value, one call in flight; virtualise past ~100 rows; cache a costly `LayoutJob`; nothing costly in the frame). 4. Keep `autobenches = false`, `bench = false` and no `Drop` on `Corpus` (load-bearing). -5. Report before/after numbers on the same machine; update the table in `docs/architecture.md` → "Benchmarks" only for durable changes. +5. Report before/after numbers on the same machine; update the table in `docs/architecture/testing.md` → "Benchmarks" only for durable changes. diff --git a/.claude/skills/platform-integration/SKILL.md b/.claude/skills/platform-integration/SKILL.md index 6c00bd213..a8bd26398 100644 --- a/.claude/skills/platform-integration/SKILL.md +++ b/.claude/skills/platform-integration/SKILL.md @@ -7,7 +7,7 @@ description: Use when adding or changing what DevNotes asks of the operating sys `crates/platform` is the one place that names a native crate. Neither egui nor the core appears there; the interface asks it through plain functions and traits. -1. **Safe APIs only** (D7): `unsafe_code` is forbidden in every crate. A native need without a safe crate is a decision (`docs/architecture.md` → "Decisions"), not an `unsafe` block. +1. **Safe APIs only** (D7): `unsafe_code` is forbidden in every crate. A native need without a safe crate is a decision (`docs/architecture/decisions.md` → "Decisions"), not an `unsafe` block. 2. **One module per subject** (`paths`, `window`, `instance`, `motion`, `dialog`…), its OS differences behind `cfg(target_os)` inside it. What a screen calls is a trait when a test must fake it (`dialog::FileDialog`, the clipboard, the window): the fake answers, it never reimplements a rule. What only a desktop can run goes in the module's `system.rs`, out of Sonar's coverage and on the manual checklist (`docs/recette/recette.html`); everything a test can reach stays beside it. 3. **A new native crate** goes through `dependency-audit` first (licence in `deny.toml`'s allow list, advisories, maintenance), pinned exactly. Do not bump one as part of a feature. 4. **Start-up order is load-bearing** (`crates/app/src/main.rs`): script host, arguments, instance claim (fails closed: one process per profile, D16), logger, panic hook (location and thread, never the message, D18), preferences, then the window — created hidden, shown by the first frame, eframe persistence off. @@ -15,4 +15,4 @@ description: Use when adding or changing what DevNotes asks of the operating sys 6. **The `e2e` flavour** (`--features e2e`) adds eframe's inspection port, the software adapter and two doors — `--action ` and `DEVNOTES_E2E_DIALOG` — and nothing else; it takes no global key. A release build of it does not compile. Never widen it. 7. Test in the module: a temporary directory for anything on disk; a real second process only where the subject is processes (`instance`). -**Verify**: `cargo clippy --workspace --all-targets --all-features -- -D warnings`, `cargo test --workspace --exclude e2e`, then run the app on a temporary profile (`cargo run -p app -- --profile `) on each OS the change touches, and say which ones did not run. Reference: `docs/architecture.md` → "The binary, its profile and its window". +**Verify**: `cargo clippy --workspace --all-targets --all-features -- -D warnings`, `cargo test --workspace --exclude e2e`, then run the app on a temporary profile (`cargo run -p app -- --profile `) on each OS the change touches, and say which ones did not run. Reference: `docs/architecture/engine.md` → "The binary, its profile and its window". diff --git a/.claude/skills/rust-guidelines/SKILL.md b/.claude/skills/rust-guidelines/SKILL.md index ffb02ee4b..6f780aad9 100644 --- a/.claude/skills/rust-guidelines/SKILL.md +++ b/.claude/skills/rust-guidelines/SKILL.md @@ -12,7 +12,7 @@ rendered book, not at these files). Read the `` before applying a rule: the ## Order of precedence -1. `CLAUDE.md`, `.claude/rules/security.md`, `docs/architecture.md` and the local skills. +1. `CLAUDE.md`, `.claude/rules/security.md`, `docs/architecture/` and the local skills. 2. These guidelines. Keep it simple: a guideline is a reason to write less, plainer code, never a licence to add a @@ -22,9 +22,9 @@ layer. Apply it to the code you are changing; do not sweep the codebase unasked. | Guideline | Here | | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| M-ERRORS-CANONICAL-STRUCTS, M-APP-ERROR | Errors stay `AppError { code, params, detail }` with `ErrorCode` (→ "Error contract"); no `anyhow`, no backtraces in answers. | +| M-ERRORS-CANONICAL-STRUCTS, M-APP-ERROR | Errors stay `AppError { code, params, detail }` with `ErrorCode` (→ "Errors are codes"); no `anyhow`, no backtraces in answers. | | M-INTEGRATION-TESTS | Unit tests stay inline `#[cfg(test)] mod tests` at the bottom of the file; `tests/` holds the integration binaries, as today. | -| M-SMALLER-CRATES | The crates are the ones `docs/architecture.md` lists (« Overview »); a new crate is a decision, not a reflex. | +| M-SMALLER-CRATES | The crates are the ones `docs/architecture/overview.md` lists; a new crate is a decision, not a reflex. | | M-MODULE-DOCS, M-CANONICAL-DOCS | Comments record decisions, not narration (`CLAUDE.md`): short doc comments, no essays. | | M-LOG-STRUCTURED | Logging stays on `log`; what matters here is the redaction part — never log note content, passphrases, keys or tokens. | | M-STATIC-VERIFICATION | The lint set is the project's (`unsafe_code` forbidden, `clippy::pedantic` denied); an extra lint is a proposal to the user. | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95980c8ba..5312b059f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: - *stop-the-run - # The showcase site (docs/architecture.md → "The website"): its own project and lockfile. The + # The showcase site (docs/architecture/website.md → "The website"): its own project and lockfile. The # build fetches the latest release and asks GitHub for every download link. website: name: Website diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 0cd27ff7a..0a945a8ba 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -2,7 +2,7 @@ name: Website # devnotes.fr: the site built from `website/` and `docs/content/`, pushed as the whole content of # one commit to the `main` of `vmillet-dev/devnotes-website`, whose webhook deploys it -# (docs/architecture.md → "The website"). Two things change what it shows: a push to `main` that +# (docs/architecture/website.md → "The website"). Two things change what it shows: a push to `main` that # touches its sources, and a release, whose files the download page names. The second needs the # run that follows `Release`: what that workflow pushes with its own token triggers nothing. on: diff --git a/CLAUDE.md b/CLAUDE.md index a04db939c..bf3f0c5b1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,6 +1,6 @@ # CLAUDE.md -Guidance for Claude Code in this repository. `docs/architecture.md` is the detailed reference (headings quoted as → "Heading"): read the relevant section before a structural change and keep it in sync. Not this file, not the README. The decisions taken for the egui application (D1–D33) are its « Decisions » section; a decision is changed there first, never silently in code. +Guidance for Claude Code in this repository. `docs/architecture/` is the detailed reference, a wiki of pages by area whose home (`README.md` there) says what each page holds; a section is named by its heading after an arrow, unique across the pages, and `scripts/architecture-links.mjs` checks every such name: read the relevant section before a structural change and keep it in sync. Not this file, not the README. The decisions taken for the egui application (D1–D33) are its `decisions.md`; a decision is changed there first, never silently in code. ## Project @@ -82,7 +82,7 @@ Principles: ### Behaviours every screen keeps -Read at the `angular-reference` tag; the egui mechanism is in `docs/architecture.md` (→ "Backend and events"). +Read at the `angular-reference` tag; the egui mechanism is in `docs/architecture/` (→ "Backend and events"). - Writes are not optimistic: persist, adopt the answer, bump the revision; nothing reloads a view by hand. Time comes from an injectable clock. - Creating a note writes nothing until worth keeping. Editor drafts are keyed on note id and committed on blur and every closing path. → "Creating a note writes nothing". @@ -90,8 +90,8 @@ Read at the `angular-reference` tag; the egui mechanism is in `docs/architecture - `null` space = "all spaces". Nothing corpus-wide runs before saying what it touches (count from Rust). Sections are exhaustive and local-day based; search debounce 150 ms; "À trier" ends at `endOfLocalDay`; `pinnedFirst` is the user's choice. - Every library operation reports through the status notifier, even when nothing changed. - A card is two layers (→ "A card is two layers"). Every drag is a pointer gesture plus a keyboard twin. The board dims, never narrows; gestures commit on release, snapped to `GRID_PX`, saved debounced. Escape falls through modal → overlay → selection → search → up a folder level. The canvas keyboard is one table (`CANVAS_KEYS`); arrangement is the library's (`devnotes.notes.arrangement`). → "The board: the second view of a space", "Descending into a folder". -- A preference is applied on a button (only theme and density preview before Apply). Global shortcuts are first come, first served, stored under W3C `code` names and recorded as the system hears them (the character typed, the position on macOS). The window starts hidden and is shown when ready; its geometry is remembered without visibility. A silenced update is a version written down (`skippedUpdate`). → "Preferences", "Shortcuts: two vocabularies, two storage paths", "Window geometry". -- Theming: `ui::theme::tokens` (copied from the reference's `styles.scss`; text sizes, gaps and radii are its role scales `font`, `gap`, `radius`, each role defined once), read through `theme::palette(ctx)` / `theme::spacing(ctx)`; no colour, gap, radius, text-size or duration literal elsewhere (held by sweep tests). Dark the base, light with its own amber; text ≥ 4.5:1, held by a Rust test. Accessibility: 24×24 targets, destructive controls red at rest, modals stacked by the rungs of `dialog.model.ts`. → "Theming", "Accessibility", "The modal frame". +- A preference is applied on a button (only theme and density preview before Apply). Global shortcuts are first come, first served, stored under W3C `code` names and recorded as the system hears them (the character typed, the position on macOS). The window starts hidden and is shown when ready; its geometry is remembered without visibility. A silenced update is a version written down (`skippedUpdate`). → "Preferences", "Shortcuts: two vocabularies, two storage paths", "The binary, its profile and its window". +- Theming: `ui::theme::tokens` (copied from the reference's `styles.scss`; text sizes, gaps and radii are its role scales `font`, `gap`, `radius`, each role defined once), read through `theme::palette(ctx)` / `theme::spacing(ctx)`; no colour, gap, radius, text-size or duration literal elsewhere (held by sweep tests). Dark the base, light with its own amber; text ≥ 4.5:1, held by a Rust test. Accessibility: 24×24 targets, destructive controls red at rest, modals stacked by the rungs of `dialog.model.ts`. → "Theming", "Accessibility", "The widget kit". ### Tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 79d167dda..651e24ed3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,8 +7,8 @@ DevNotes is licensed under the [GNU GPL v3.0](LICENSE). Opening a pull request m to have your contribution distributed under those terms. DevNotes is Rust alone: an egui window over a core, in one process. The decisions taken for it -are in [docs/architecture.md](docs/architecture.md), "Decisions". It was an Angular + Tauri -application until 1.0.0, which stays whole, sources and scenarios, at the `angular-reference` +are in [docs/architecture/decisions.md](docs/architecture/decisions.md). It was an Angular + +Tauri application until 1.0.0, which stays whole, sources and scenarios, at the `angular-reference` tag. ## Getting set up @@ -115,12 +115,12 @@ a third time, never for one step. A control without an `author_id` gets one thro ## The scripts -| Command | What it does | -| ---------------------------------- | ----------------------------------------------------------- | -| `node --test "scripts/*.test.mjs"` | The release scripts' tests | -| `node scripts/prettier.mjs` | Copies the Prettier compiled in into `crates/text/prettier` | -| `cargo bench -p engine` | The core's benchmarks (not in CI; see docs/architecture.md) | -| `cargo run -p app --example icons` | Redraws `crates/app/icons/` from `devnotes.svg` | +| Command | What it does | +| ---------------------------------- | ---------------------------------------------------------------------------- | +| `node --test "scripts/*.test.mjs"` | The release scripts' tests, and the architecture wiki's references and links | +| `node scripts/prettier.mjs` | Copies the Prettier compiled in into `crates/text/prettier` | +| `cargo bench -p engine` | The core's benchmarks (not in CI; see `docs/architecture/testing.md`) | +| `cargo run -p app --example icons` | Redraws `crates/app/icons/` from `devnotes.svg` | ## The layout @@ -152,8 +152,8 @@ A change a user sees updates `docs/content/` in both languages, in the same pull Everything is filed by **subject**, not by technical nature. Each feature owns its model, its SQL and the service functions that expose it. Deleting `crates/engine/src/notes/` deletes the -feature. [docs/architecture.md](docs/architecture.md) is the detailed reference — read it before -a structural change, and keep it in step when you make one. +feature. [docs/architecture/](docs/architecture/README.md) is the detailed reference, a page an area +— read the one a structural change touches before making it, and keep it in step. ## Things that are not guesswork diff --git a/Cargo.toml b/Cargo.toml index db27d9518..f487eae4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,8 @@ opt-level = 3 # Speed first: "s" or 2 make the binary smaller and the core slower (a query over 8000 notes # +37 % or +7 %), and per-crate levels do not reach Rust code under fat LTO. No unwinding: a -# panic ends the process from its hook (D18). The figures: architecture.md, "The release binary". +# panic ends the process from its hook (D18). The figures: `docs/architecture/releasing.md` +# → "The release binary". [profile.release] lto = true codegen-units = 1 diff --git a/README.md b/README.md index 5c865690e..5f98fbf99 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ DevNotes asks for a passphrase the first time it runs, and at every launch after | [Your library, in detail](docs/security.md) | encryption, backups, and where your data lives | | [Changelog](CHANGELOG.md) | what changed, and when | | [Contributing](CONTRIBUTING.md) | building from source, testing, and the code conventions | -| [Architecture](docs/architecture.md) | how it is built, for whoever changes it | +| [Architecture](docs/architecture/README.md) | how it is built, for whoever changes it | ## License diff --git a/crates/ui/src/app/perf.rs b/crates/ui/src/app/perf.rs index 015a6bfb5..86b00b815 100644 --- a/crates/ui/src/app/perf.rs +++ b/crates/ui/src/app/perf.rs @@ -1,4 +1,4 @@ -//! The journeys `docs/architecture.md` keeps the figures of (« The window on the reference +//! The journeys `docs/architecture/testing.md` keeps the figures of (« The window on the reference //! corpora ») through the real application, without a window: a frame here is the pass and its //! tessellation, CPU only, the AccessKit tree a person without a screen reader never pays included. //! Nothing runs unless `DEVNOTES_PERF` names a profile written by the `reference_profile` bench; it diff --git a/docs/architecture.md b/docs/architecture.md deleted file mode 100644 index 7a6c678ad..000000000 --- a/docs/architecture.md +++ /dev/null @@ -1,6953 +0,0 @@ -# Architecture - -How DevNotes is put together, and the conventions to follow when extending it. -For build/run instructions see [CONTRIBUTING](../CONTRIBUTING.md). - -## Overview - -DevNotes is a desktop application in **one Rust process**: an **egui** window over a core that -owns everything that is not drawing. Since 1.0.0 there is no WebView, no JavaScript in the -interface and no IPC (→ "Decisions"). The core, -`crates/engine`, holds storage, encryption, the in-memory index of notes, HTTP, the tools; the -interface, `crates/ui`, calls it directly, through one façade and three queues, with no -serialisation in between (→ "Backend and events"). The one other process is the application -relaunched as a **script host**, which runs a request's scripts in QuickJS (→ "Request scripts, in -a process of their own"). The Angular + Tauri application it replaced stays whole at the -`angular-reference` tag: where a section below names one of its files, it is the behaviour the -egui screen was ported from, read there. - -**Where the work happens.** Data processing belongs to Rust. Filtering (space, full-text, -tags, languages, quick filters), grouping into display sections, facet aggregation and tag -normalisation, and the choice of what a card's footer shows all run in `crates/engine/src/notes/`. -The interface describes what the user asked for and draws the view it gets back — it does not -filter, sort or group. The deliberate exceptions are relative-time **formatting** (labels must age -on their own, without a round trip), syntax highlighting (it colours the in-flight editor draft, -which is not persisted yet), and plain UI concerns like keyboard shortcuts and drafts. - -``` -Cargo.toml the workspace: one version, every dependency once, lints, release profile -crates/engine/ the core (migrations/, resources/, sandbox/, tests/, benches/) -├── src/notes/ the notes feature: model, language, view, placeholder, trash, store/ -├── src/index/ the decrypted, folded notes of the open library, in memory -├── src/folders/ folders, the board, their geometry -├── src/http/ requests, collections, environments, sends, sockets, scripts, history -├── src/spaces/ the spaces feature: model, SQL -├── src/attachments/ the attachments feature: model, SQL (the bytes live on disk) -├── src/transfer/ import, export and share: bundle rules, the file, the exchange format -├── src/tools/ the Outils area: one pure module per group of tools, no lock, no store -├── src/host.rs what the core asks of its shell: paths and an event sink -├── src/db.rs connection, migrations, schema, stored-instant format, the db queue -├── src/error.rs the three errors and the translation between them -└── src/lib.rs the modules and the `Engine` -crates/text/ the editing core, egui-free: rope, undo, search, indent, highlighting, Prettier, {{…}} shield -crates/richtext/ a Note's document: blocks and marks, read from Markdown and written back -crates/drawing/ a Dessin, egui-free: the stored scene, its geometry, text lines, SVG and pictures -crates/i18n/ the interface's strings (translations/fr.json, en.json), plurals, formats -crates/platform/ what is asked of the operating system: paths, window, instance, tray, - shortcuts, clipboard, dialogs, notifications, autostart, updater -crates/ui/ the egui interface: the frame, its state, its screens, its widgets -crates/app/ the `devnotes` binary (main), its icons (`--example icons`) and packages -e2e/ the end-to-end driver, its SDK and the journeys, on the assembled window -golden/ test data: exact outputs the tests compare with (its README says which) -``` - -### Feature-first, not layer-first - -The core is filed by **subject**. `notes.rs`, `spaces.rs`, `folders.rs`, `attachments.rs`, -`http.rs`, `tools.rs` and `transfer.rs` are the features, and each owns everything about itself: -its model, its SQL, and the service functions that expose it. Deleting `src/notes/` deletes the feature. - -`changelog.rs` is the smallest of them, and the odd one out: it owns no table and reads no -database — the repository's `CHANGELOG.md` is baked into the binary by `include_str!` and -parsed by `changelog/model.rs`. It keeps the convention all the same, the service function in the file -and the rules in the module, which is what lets the parser be tested on its own. -`json.rs` is the other one without a table: it takes a text and answers what the JSON -visualiser draws — see [The JSON visualiser's model](#the-json-visualisers-model). - -`transfer` is the one without a `store.rs`: import and export read and write **whole -libraries**, so they compose the two other stores rather than owning a table. That is also why -it is the only feature allowed a `notes::store::all` — a raw note list, which no service function ever -returns to the interface (see [Data access](#data-access)). Its rules sit in two modules of its -own instead: `transfer/bundle.rs` (what travels with an export, how an import merges) and -`transfer/file.rs` (reading and writing the file, staged then renamed). - -Both follow the same three-part convention: - -| File | Holds | -| -------------------- | --------------------------------------------------------------------- | -| `.rs` | the service functions — validate, lock, delegate, translate | -| `/model.rs` | the types and the business rules, testable without opening a database | -| `/store.rs` | the SQL, and nothing else | - -`notes/` carries extra modules, all of them notes-specific vocabulary: `language.rs` -(the closed `Language` enum and the heuristics that guess one from pasted content), -`view.rs` (what is asked — `NotesQuery`, `NoteFilter` — what comes back — `NotesView`, -`NoteSection` — plus the search matching and chronological placement that produce it), -`trash.rs` (the 30-day retention, `TrashedNote`, and the purge that erases the attachment -files with the rows) and `checklist.rs` (the closed `NoteKind` enum, `ChecklistItem`, the -normalization of a list and its Markdown rendering). - -Its SQL is the one store large enough to be split, into `notes/store/`: `related.rs` for the -three side tables a note owns — tags, checklist items, `{{field}}` values, each keyed on -`note_id` and rewritten whole, so each read, replaced and bulk-loaded the same way — and -`trash.rs` for the queries that reason about `deleted_at`. ⚠️ `notes::trash` and -`notes::store::trash` are the retention's **rules** and its **SQL**; they are the same split -as `model.rs` and `store.rs` everywhere else. - -⚠️ `notes::store::trash` is a **soft** delete — it stamps `deleted_at` — where -`spaces::store::delete` and `attachments::store::delete` erase. `notes::store::trash::purge` -is the destructive one, and it is restricted to rows already in the trash. - -What is left at the root is what belongs to no single feature: - -| Module | Holds | -| ---------------- | ------------------------------------------------------------------------------------------------- | -| `error.rs` | `ValidationError`, `StorageError`, and the `AppError` a service function answers | -| `db.rs` | the connection and its `Mutex`, `open`/`open_in_memory`, plus `db::schema` and `db::migration` | -| `db::iso8601` | the stored-instant format — millisecond-exact, because the canvas sorts on a TEXT column | -| `host.rs` | what the core asks of its shell: `Paths` and an `EventSink` | -| `app_info.rs` | what the application says about itself, read from `Cargo.toml` at compile time by `build.rs` | -| `name.rs` | what a space and a folder share about their names: trimmed, never blank, unique whatever the case | -| `closed_enum.rs` | the `closed_enum!` macro: one literal per variant for serde, the column, `Display` and `FromStr` | -| `count.rs` | `saturating_u32`, the one conversion a count takes | -| `layout.rs` | the names on disk — a library's directory and the profile beside it | - -The library plumbing sits at the root too, and follows the features' split: the service functions in -`vault.rs`, `libraries.rs` and `backup.rs`, the work in a module of each — `vault::gate` (a -library opened under its key and handed to the `Mutex`), `vault::key` and `vault::file`, -`libraries::registry` (the registry and the directories it names) and `backup::copies` -(taking, listing, putting back and rewrapping the copies). `recovery.rs` is small enough to -hold its two functions and `set_aside` together. `attachments` does the same with -`attachments::files`, the bytes on disk beside their records. - -This replaces an earlier split into three technical layers (`commands/ → domain/ ← storage/`), -which cost three files and three modules per subject and a `check-layers.sh` script in CI to -hold the direction — for a back-end whose whole job is a CRUD over two entities. - -The property that split was really protecting survives on its own: `notes/model.rs`, -`notes/view.rs`, `notes/language.rs` and `spaces/model.rs` import no Diesel, -so their tests run without opening a database — section placement, timezone boundaries, tag -normalisation, search folding, footer choice and expiry thresholds, in a few milliseconds -with no fixture setup. - -The features are not fully independent, and that is visible rather than hidden: -`notes/store.rs` calls `spaces::store::exists` before filing a note, `spaces/store.rs` -moves notes out before dropping a space, and `folders/store.rs` writes `notes.folder_id`. The Diesel schema therefore stays shared in -`db/schema.rs` — splitting it per feature would break `allow_tables_to_appear_in_same_query!`. - -Serde attributes sit on the model types rather than on a separate DTO family: they shape the -export bundle and the stored JSON, and at this size a second set of types and their mapping -would cost more than it protects. The interface takes the same types, in the same process. - -## Decisions - -Taken for the egui application, and in force. Comments in the code name them by number; a number -missing here was the migration's own, and is over. A decision is changed here first, never silently -in the code. - -| # | About | Decided | -| --- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| D1 | Formatting | Prettier itself, in QuickJS (p95 340 ms for 13 kB when measured); native formatters only past 500 ms. | -| D2 | Mermaid | Not drawn since 1.0.2: its renderer weighed 16.6 MB of a 79 MB binary. A `mermaid` block is a code block, kept as written. | -| D3 | Spell checker | Never. | -| D7 | `unsafe_code` | Forbidden in every crate: only dependencies with a safe API. | -| D8 | Windows packages | NSIS alone, no `.msi`. | -| D10 | Data rules | One rule, one definition, in the core. `engine` depends on no editing crate; `text`, `richtext` and `drawing` take its results as arguments. Shared all the same: the `{{…}}` shield of `text`, and the `pulldown-cmark` options, which a test compares. | -| D11 | Work on the database | One worker: `Engine` owns a queue and the one "db" thread that runs it in order, reads included. `compute` for pure work, tokio for the network. → "The concurrency rules". | -| D12 | Calls from the UI thread | Allowed, through `api/`, for a pure function (no lock, no I/O) whose input the screen bounds and which stays under 1 ms at the p95 (the ranges of `{{fields}}` in the lines shown, the check of a variable's name…). Each says so beside it. | -| D13 | Drawing and state | Each screen has a state (read, changed in `apply`) and a view (changed while drawing: text typed, buffers, menus, scroll, gestures). State is tested on the real `Backend`, with `settle()`. | -| D14 | Keyboard | One order: IME → focused widget (`consume_key`) → `keys::dispatch` (modal, area, application), with entries marked `while_typing`. egui's keyboard zoom is off; Tab is egui's, except in the editors; shortcuts are stored under W3C `code` names, a global one as the system hears it (the character typed; the position on macOS). | -| D15 | Wayland or X11 | X11 (XWayland) as soon as `DISPLAY` exists, native Wayland otherwise: under native Wayland winit 0.30 delivers neither dropped files nor the window's visibility. There, and rarely, the window's position is not restored, closing to the tray minimises, and HTML pasted into a Note keeps its text only. | -| D16 | Profile, single instance | One application per profile: the instance's socket is named after the profile. `com.devnotes.app` by default, the packages' identifier; `--profile` for tests and development. | -| D17 | Caches of the interface | All in `LibraryCaches`, emptied with egui's widget memory when the library changes; not wiped byte by byte, as the threat model says. | -| D18 | Panics | A panic on any thread ends the process: the hook, installed first, logs the place and the thread, never the message (a slicing panic quotes the text), says so in a system box (never in the `e2e` flavour), then `exit(101)`. Nothing is caught; the database is checked at the next open. `panic = "abort"`. | -| D19 | Quitting during a write | Window hidden, db queue closed then drained (drafts, import, restore, passphrase), 30 s at most, then an exit that is logged; network sends are cancelled. | -| D20 | Waking the UI, start order | The input channel and the `Waker` (`OnceLock`) are made by `main` and filled by eframe's creation closure, where `Engine`, `Backend` and `AppState` are born. | -| D21 | Localised formats | Written by hand (`i18n::format`, French and English), held by `golden/intl`; no ICU. The system's language by `sys-locale`. | -| D22 | Highlighting's regex engine | `onig`: 1 MB of TypeScript in 2.7 s, against 12.9 s for `fancy-regex`. Highlighting never holds the UI thread. | -| D23 | A drawing's text and picture | One line break (Fabric's, in `drawing`) for the editor and the pictures; one way to a picture: the export's SVG, rasterised by `resvg`. | -| D24 | Captures | PNGs to be looked at by eye; nothing compares pixels. | -| D26 | Signature and updates | Signed by `cargo-packager` with the key of the first releases; updated by `cargo-packager-updater`: the NSIS installer (passive, `/P /R`) and the AppImage (replaced in place). `latest.json` gives each platform its `format`. | -| D27 | Version | `[workspace.package] version` alone; `release.yml` compares `Cargo.toml` and `Cargo.lock`. | -| D28 | Images shown | PNG, JPEG, GIF (first frame), WebP, BMP and ICO by `image`, SVG by `resvg`; anything else opens in the system's viewer. | -| D29 | No GTK on Linux | The process loads no GTK and opens no indicator library: the tray is a StatusNotifierItem and its menu, spoken over D-Bus (`ksni`); file dialogs go through the XDG portal (`rfd`, `xdg-portal`), toasts through D-Bus. The binary links the C library alone, so the AppImage carries no library and reads the system's, as the deb does. | -| D30 | Writes after a switch | Each `Library` opened has a number, from a counter of the process. A send notes it as it reads, and writes nothing once it has changed: cancelling at the switch frees the network, correctness does not depend on it. | -| D31 | E2E in CI | One job per system, `cargo test -p e2e` running the files one after the other, beside the Rust tests. Split one day by file names and measured times, never by a list kept by hand. | -| D32 | The Angular application | Out of the tree since 1.0.0; the `angular-reference` tag and its pre-release keep all of it. Where egui differs from it by decision rather than by limit, egui is right. | -| D33 | Workspace manifest | Each dependency declared once, version and common features, in the root `[workspace.dependencies]`; a crate takes `workspace = true` and adds only its own features. | -| D34 | Title bar | The application's own on every system: no decorations from the system, minimise, maximise and close at the bar's right end; macOS keeps its three buttons, at the left end. Moving and resizing are the system's (`StartDrag`, `BeginResize`). No way back to the system's bar. | - -## Interface (egui) - -`crates/ui` is the window: the frame, its state, its screens and its widgets. It is the shape of -the screen, and it calls the core through `ui::api` alone (→ "Backend and events"). Each -screen keeps the look and the behaviour of its Angular twin at the `angular-reference` tag -(D32); the subsections below describe that behaviour, and name the egui module that draws -it. - -### Where a file goes - -> **A folder's path is its place on screen**. What draws sits where it is drawn; -> what has no place on screen sits apart, filed by subject. - -| Question | Answer | -| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | -| Where is it drawn? | `notes/`, `http/`, `tools/`, `titlebar/`, `banners/`, `gate/`, `palette/` | -| Inside the notes area: beside, above, among, over the cards? | `notes/sidebar/`, `notes/header/`, `notes/canvas/`, `notes/overlays/` | -| What a screen remembers between frames? | `state/.rs` | -| Something with no place on screen (preferences, time, notifiers, shortcuts, updates)? | `services/.rs` | -| A call to the core? | `api/.rs`, the only files that name `engine` | -| A control two areas draw? | `widgets/`, which reads the theme and no state | -| A colour, a gap, a duration, a font, an icon? | `theme/` | - -`backend.rs` owns the engine and the queues, `keys.rs` the keyboard's order, `action.rs` the -actions a frame applies, `inputs.rs` what arrives from outside the frame (the core's events, a -second launch, the tray, a global shortcut). A screen that grows is cut into named drawing -functions, not into layers; a helper, a trait or a generic waits for its second real use -(`CLAUDE.md`). - -⚠️ **"Library" means two things.** In the interface it is the registry of libraries (the File -menu's dialog, `state::libraries`); in the core it is the open database and its key -(`db::Library`). Moving notes in and out of a file is `state::transfer`. - -### No router - -The areas, the list view and the board are **state**, not routes: there is no URL in a window. -The area is an application preference (`devnotes.area`), so the window reopens on it; the list -view or board is remembered per space (`state::board`). Every area's state lives in `AppState` -whether the area is drawn or not, so an area left keeps its scroll, its focus and its drafts, -and a native action (capture, new note, the palette) brings the notes back before it opens -anything. **One key per area**, `Ctrl+1/2/3`, read by physical key (`keys::APPLICATION`; on -AZERTY the digit row types `&é"`). The switch heads each area's rail and comes to the title bar -while the rail is put away (`titlebar::area_switch`). - -### Drawing, state and actions - -A screen's drawing reads its **state** (`&…State`) and may change its **view** (`&mut …View`: -text being typed, editor buffers, open menus, scroll, gestures); everything else it wants done -is an `Action` it pushes, applied by `AppState::apply` at the end of the frame (D13). Data flows -down as arguments, so a screen is tested with a literal; an action goes straight to the state -that owns it rather than up through its parents. `widgets/` is the exception that pushes nothing -and reads no state: it is the kit (→ "The widget kit"). - -A card cannot decide what its own click means — ticking, extending a range or opening depends on -the visible list — so it answers what was pressed and the canvas decides. - -**Menus, dialogs and their stacking** are one implementation each, in `widgets/`: `menu` (focus on -the first entry, arrows, sub-menus, Escape) and `DialogStack`, whose rungs are the reference's -`dialog.model.ts` in back-to-front order — the index is both the drawing order and the order -Escape follows. A dialog opened by another one (the fields form, from the palette) is drawn in -front of it whatever the order they opened in. The two banners are drawn under the title bar, -outside the stack, so a modal never covers them. - -### The editing core - -`crates/text` is under every editor that is not a one-line field, and knows no egui: - -- **`Buffer`** — the text, a rope (`ropey`), and its selection. Every edit goes through - `Buffer::replace`, which records it for undo and says from which line the text changed: what - the highlighter and the layout throw away starts there. Offsets are `char`s, everywhere in the - crate; the caret moves by grapheme, word and line. -- **`history`** — undo and redo by steps: one keystroke, one paste, one indent, one « replace - all ». Typing joins the step before it while it goes on where it left off, so one undo takes - back a word typed, not a letter. -- **`indent`** (Tab, Shift+Tab, a whole text swapped as one edit), **`search`** (a text or an - expression, case, whole words), **`diff`** (which lines a format or a revision changed), - **`words`** (a Note's words as it reads), **`shield`** (every `{{…}}` kept from a formatter's - reach), **`highlight`** and **`format`** (→ the two subsections below). - -`crates/richtext` is the same for a Note: its document, blocks and marks, read from Markdown and -written back, its edits and its undo (→ "A Note is written formatted, and stored as Markdown"). -The widgets that draw them, `widgets::editor` and `widgets::rich`, are `ui`'s: what a field or a -heading **is** stays the core's, handed to them as ranges (D10). - -### Rendering and virtualisation - -egui draws the whole window every frame it repaints, so what a frame costs is what is on screen, -never what is stored: - -- **Anything that can run to thousands of rows is virtualised**: `widgets::list` (uniform rows, - only those in the viewport drawn), the canvas (`notes::canvas::rows`: the view flattened into - rows of one height — a heading, then a row of cards — since cards are a fixed height in an - auto-filled grid), the code (`widgets::editor`, only the lines on screen laid out), the HTTP - history, console and socket log, the runner's results, the diffs. 30 000 rows draw fewer than - twenty. -- **What is costly to lay out is kept**: a `LayoutJob` in egui's galley cache, a card's - highlighted lines in its frame cache, a Dessin's picture as a texture in - `LibraryCaches` (bounded, emptied with the library scope, D17). -- **Nothing costly runs in the frame**: highlighting a long text, formatting, a - picture, a Calcul sheet and a JSON document are computed on `compute` or a thread of their own, - and the frame draws the last answer meanwhile. -- **The window repaints when something changed**, not continuously: an answer wakes it (the - `Waker`), a relative time asks for the instant its label changes (`request_repaint_after`), an - animation for its own frames; at rest the window costs nothing. - -### The keyboard - -**One order** (D14, `ui::keys`, → "A frame, its actions and its keys"): an input method composing -keeps every key; the focused widget consumes what it handles; then `keys::dispatch` reads what is -left by level — the top modal, the area on screen, the application — and the first that knows the -key takes it. Bindings are **tables**, one per level (`keys::APPLICATION`, the canvas's -`notes::canvas::shortcuts`…), from which the shortcut sheet is drawn, so a key cannot be bound and left -undocumented. A key is read **by position** (a W3C `code`, so `Ctrl+1` is the same key on AZERTY) -or **by character**; a global shortcut as the system hears it, by character, by position on macOS -(→ "Shortcuts: two vocabularies, two storage paths"). While a text field has the focus only the -entries marked `while_typing` are read. Every drag has its keyboard twin. - -### Syntax highlighting - -Every coloured code — a card excerpt, the editor, a Note's code block, an HTTP answer, generated -code — is coloured by **one grammar per language**: TextMate grammars run by `syntect`, the set -`bat` maintains (`two-face`), regular expressions by `onig` (D22), plus a Prisma grammar -of ours (`crates/text/syntaxes/`). `text::highlight` answers a line's stretches as the -reference's classes (`Token`: keyword, string, literal, name, property, meta, comment…), and -`ui::services::highlight::colour` gives each its colour from the theme — the reference's -`_code-theme.scss`, one for one. - -- **Which grammar a language takes is one table**, `ui::notes::language::syntax`, an exhaustive - `match` on the core's `Language`: a variant added in `closed_enum!` does not compile until it - has a grammar or `None` (plain text alone has none). Beside it in the same file: the label, the - name, the hue of the badge, the line-comment marker, the Prettier parser and the indent unit. - Adding a language is the variant and those arms — no migration: the column stores the literal - and carries no `CHECK`. -- **The grammars load on a thread at startup** (`text::highlight::warm`, a few hundred ms); until - then nothing is coloured, and the interface never waits for them. -- **Never in the frame.** A card's few lines are coloured at once and kept in egui's frame cache - while drawn; a long text is coloured by windows on a thread of its own, which keeps the - parser's state every `EVERY` (128) lines so an edit throws away only what follows it — a line - not reached yet is drawn plain meanwhile. 1 MB of TypeScript shows its first screen in ~25 ms - and is coloured whole in ~2 s, off the frame (`cargo test -p text --release budget -- --ignored`). -- **A line is a line.** A stretch that spans lines (a block comment, a string) is cut at each - line break, so a viewer's gutter and an editor's row draw one line each, nothing left open. -- The code is never interpreted: colouring only reads it. - -**Detection scores, and can say it does not know.** `from_content` guessed by _first match -wins_, down a hand-ordered chain of `if`s, and the order **was** the priority: a Rust -snippet carrying a match arm came back `js`, because `is_javascript` matched `=>` anywhere -in the text and sat near the end of the chain — which made JavaScript the default answer -rather than an answer. Fixing that meant finding the right slot in a list, and the next -language would need someone to find one again. - -Every language scores itself and the highest score wins. Three weights and no more: -`SIGNATURE` (nothing else writes it), `STRONG` (strongly associated, occasionally shared), -`WEAK` (many languages write it). A scale with ten steps would be the same invisible -ordering written differently — the point is that a marker declares how much it _proves_. - -⚠️ The two facts the old order encoded are weights rather than positions now: `` is the weakest marker in the file. - -⚠️ **It can abstain, and that is a behaviour change.** Below `MIN_CONFIDENCE` — one weak -marker — or on a **tie**, the answer is `txt`. `class Note { }` used to come back `js` and -is left alone now: it is written the same way in six of these languages, and a wrong answer -costs more than none, since it colours the body, badges the card and files the note under a -facet in the rail. Some notes that were coloured before are not any more. - -⚠️ `score_typescript` deliberately does **not** inherit JavaScript's markers: inheriting -them would make TypeScript score at least as much as JavaScript on every file, and a tie is -no answer. `score_scss` follows the same rule with CSS: a variable, a Sass at-rule or a line -opening on `&` is a signature, and a stylesheet with none of them is CSS. GraphQL's -`type User {` is TypeScript's shape too, so a definition is weak and a non-null type -(`ID!`, `[String!]!`), which TypeScript never writes after a name, is what outweighs it. - -**Most languages are chosen, not guessed.** Of the 142, detection answers 76 (`detectable`): -the first 26, and the 50 others that write something nothing else does — a Dockerfile's `FROM` -with its instructions, Terraform's `resource "…" "…" {`, `syntax = "proto3"`, nginx's -`proxy_pass`, a diff's hunk. The rest are only ever picked from the menu. ⚠️ **A language -added since is guessed on a signature or not at all** (`signed`): what else it writes only -adds to the signature, so none of them can tie an older language on a shared marker and turn -its answer into `txt` — `return ` scored Cypher three without one, and every Python function -came back as prose. A language that is another one plus something (TSX over TypeScript, -Cython over Python, JSON-LD over JSON, a Vue or Angular template over its HTML) adds to the -other's score, so it always outscores it once its own sign is there. A shebang names its -interpreter (`python3`, `node`, `perl`…), any other being a shell as before. - -⚠️ **`crates/engine/tests/corpus/` is what says whether this is better rather than differently -wrong.** One file per case, named `[-].txt`, read from disk and asserted -in bulk — adding a case is adding a file. Every detectable language has one, and each language -added since has a `txt-weak-.txt` holding only what it shares with others, which must -stay plain text (or what the older language makes of it: `html-weak-jsx.txt`). It earned its -keep immediately: CSS's "a selector and a declaration" scored a signature on -`export interface Note {` with `id: string;` inside it, **and** on PHP's `foreach (…) {` with -an `echo …;` inside it, so both tied at six and came back as prose. That shape is strong -evidence now, not proof; a unit or a custom property is what makes it a stylesheet. - -### Formatting a snippet with Prettier - -"Formater" (Shift+Alt+F) runs Prettier itself — 3.9.10, as `scripts/prettier.mjs` pins it — on the -editor's draft, **in QuickJS** (D1): `golden/format` holds its answers, byte for byte. -`text::format` holds all of it; the editor asks through `FormattingState`, on `compute`. - -- **One host, started by the first format and kept** (`text::format::host`): a thread of its - own with one QuickJS runtime — a runtime is not shared between threads — in which - `standalone.js` and nine plugins are evaluated once. `node scripts/prettier.mjs` copies them into - `crates/text/prettier/` after a bump; they are compiled in (2.4 MB). A host that cannot start - answers every format `Failed`. -- **Only text crosses**: the draft, the caret and Prettier's options, never code. The answer is - `Formatted` (the text, the caret, the changed lines), `Unchanged`, `Syntax` (Prettier's - one-based line and column), `Fields` or `Failed` — never a panic. Prettier counts the caret in - UTF-16 units, the editor in `char`s: converted on the way in and out. -- **Every `{{…}}` is shielded** (`text::shield`): read as code, `{{db_host}}` is two nested - blocks in JavaScript and a flow mapping in YAML. Each becomes an identifier of its own - length, made of a two-letter marker absent from the text, and comes back in order afterwards. - One missing, copied or moved past another and the answer is `Fields`: nothing is applied. -- **The snippet keeps its own shape:** `endOfLine: 'auto'` (Prettier's `lf` would rewrite a - CRLF snippet), and no final newline added where there was none. -- **Through the editor's own history**: `Editor::replace_all` is one step, so Ctrl+Z undoes a - format and the notice's "Annuler" is the same step (`Editor::undo`). The lines it changed are - marked in the gutter until the next keystroke. An answer about a text typed over meanwhile is - dropped. -- **The style is the library's** (`notes::prettier`, under `devnotes.notes.prettier`, read as - the reference wrote it), set from the button's chevron and applied as it is chosen. Its - indentation is by default "Éditeur", the Tab key's own level (`language::indent_unit`). -- **Formatting on save** (off by default): a snippet's body that changed is held back from the - save and written once formatted — or as typed if Prettier refuses it — so the revisions keep - one body, not two. Written after the editor closed, it goes by id; still open, the field - follows unless it was typed into since. A draft never written is saved as it is. -- The button stays drawn, disabled, on a language Prettier does not read - (`language::formatter`), its tooltip naming the language. - -### Exploring a JSON snippet - -A snippet whose language Rust has a reader for — JSON, YAML, TOML, XML (not HTML) — has a band of its own: **Code / -Graphe / Arbre**, « Côte à côte », and « YAML valide » or where the draft stops parsing. The model is Rust's — -see [The JSON visualiser's model](#the-json-visualisers-model); the interface draws it. Which -languages have a reader is one table, `json::read::explorable_format`; the explorer takes the -format for its messages, and nothing else in it is per format. - -- **The explorer reads no global state** (`ui::widgets::json_explorer`: the explorer, its graph and - its tree), so an HTTP response can show one too. Its state is the caller's `Explorer`, kept by - the **editor** (`overlays/editor/json_view.rs`) — two documents may be explored at once — and - the answer is `ExploredState`'s, a `QueryCell` on `compute` keyed on the opening: the view and - the text it was made of, whose spans point into it rather than into the draft typed since. -- **The draft is explored as it is typed**, debounced (250 ms), so the band answers for what is - on screen; a note just opened is explored at once, from its first level. The editor asks only - when the query changed: an action is a repaint, and asking every frame never settles. -- **Côte à côte**: the code on the left, the visualiser on the right, the line between them - `widgets::split_handle` (← → as its keyboard twin). The layout, the code hidden or not and the - share are `json_view::Layout`, kept by the notes area for the application's session and written - nowhere. Under 700 px of body it is not squeezed — the toggle is disabled and says so. The two - select in step: a node chosen selects its span in the code without taking the keys and lights - its lines (`EditorView::lit_lines`); the caret, moved by a key or a click, selects `entry_at` - its offset — never a selection the explorer set. Narrower than 600 px, the selection panel goes - under the graph with the path and its actions alone. A string is copied by its own text, - unquoted (`JsonRow.text`, `JsonLine.text`); anything else as it is written. -- **What is open is read back from each answer.** The interface keeps no set of its own: it sends - the paths of the nodes it was given, plus or minus the one clicked, and Rust decides what - that opens, caps included. Opening a container opens one level. Stepping to a match sends - it as `reveal`, and Rust opens what is above it — the interface never takes a path apart. -- **The graph draws in the layout's units**: a node's `x` and `width` in columns of the - monospace font at 11.5 px, its `y` in lines of 24 px, times the zoom; the edges are cubic - curves in the same units. Only the nodes on the ground are drawn and named: the e2e driver - presses « Ajuster à l'écran » before counting them. -- ⚠️ **One gesture for both**: a press that starts on a node moves it, anywhere else it pans, - and the wheel pans too; the zoom is three buttons. Every node, header and row takes its id from - its path (`widgets::region`), or a drag would lose its node when the culling changes. The - keyboard twin is a cursor and the ground the one tab stop: the arrows walk a node's rows, into a - child and back up, Enter opens or closes, Alt with an arrow moves the node, and Escape goes - up — at the root it lets go, and the editor closes. egui matches a key with extra Shift or Alt, - so Shift and Alt with an arrow are read first. -- An entry's AccessKit node carries its path as its description and a container's state as - `expanded`: what kittest and the e2e driver find it by, untouched by translation. -- "Voir dans le code" goes back to Code with the value **selected** — its span is in UTF-16 - units, turned into the rope's characters (`utf16_cu_to_char`) — and the code takes the keys. - -### The tools: one contract, and the rest written once - -The Outils area (`ui/src/tools/`) is a home, a rail and a frame, and a tool is what the frame draws. -**A tool is a pure Rust function and a drawing**; everything around it — the catalogue in its -panels, the search, the recent and starred tools, the breadcrumb, Vider — is written once, and -knows a tool only through the `Tool` trait (`tools/mod.rs`): - -- `update()`, once a frame on screen: what its inputs ask now, and the answers that came. -- `ui()`, its body in the frame, built from `tools/ui/`: two columns, fields, result and output - rows, a copy button, the reference table. -- `result()`, what "Enregistrer comme note" keeps, through the dialog an HTTP answer uses. ⚠️ An - output, never an input: an HMAC key or a password typed into a tool cannot reach a note, because - nothing in the contract carries one. -- `imported()`, what a note gave an input the catalogue lists in `from_note`, copied in once. A - key, a password, a token or a card number is never one: its field offers no import. -- `sample()`, which « Exemple » calls: the tool fills its inputs with test data, and replaces - what was there. Never a real secret (a token signed with « secret », the published example - IBAN). Optional: a tool with nothing to fill offers no button. -- `clear()`, which Vider calls. - -**The catalogue is one list** (`tools/catalogue.rs`), each tool in a file beside it: an id, a -category, keywords, the inputs a note can fill, and what makes its session. The name and the line -are read from the id (`tools..name`, `.description`). - -**What a tool holds lives for the session** (`tools::View`, a session a tool, made the first time -it is opened): left for another tool or for the notes, it is found as it was. In memory only — -never on disk — and gone when the library changes. ⚠️ A secret is never kept in a session: a key -or a generated password dies with the tool when it is left. - -**Every tool calls Rust the same way** (`tools::live::Live`, over a `QueryCell`, on the `compute` -queue): the request as the inputs change, debounced as a deadline, compared by value, and the -previous answer on screen until the next lands; `None` asks nothing. A tool's own failure, a line -that does not parse, is part of its answer and drawn in place; `Live` reports only the unexpected. - -⚠️ Since the previous answer stays on screen, whatever describes it — a label, a note's language -or title, a direction — reads `answered()`, the request that answer was computed from, and never -the inputs as they stand: for a debounce and a round trip they already describe the next one, and -a plain digest would read "HMAC-SHA256" — on screen, in a copy, in a note. - -**Searching the catalogue folds in the core and matches on screen** (`api::tools::fold`, called -directly, D12): it matches the translated names and lines, and Rust knows no string the user -reads. A tool is found by its name, its line, its keywords and **the name of its category**: -« generateur » finds the three tools filed under « Générateurs ». - -**The search reads inside the references too**, in a second group under the tools that match -(« Dans les références »): a row an entry, what it is called, what it means and where it lives -(« 418 I'm a teapot — Codes de statut HTTP »), four a reference then « n autres ». - -- **A reference is data apart from its drawing** (`catalogue/.rs`): the facts in a table of - its own, or in `catalogue/facts/.json` when a row has more to say than a line holds (a long - table of same-shaped Rust literals reads as duplication), its words in each language, the rows built from them, what a row is called away from - its table (`ReferenceRow::found_as`), and its own matcher when it reads a query its own way. The - reference's table draws those rows and the home searches them (`Table::found`, the list - `catalogue::REFERENCES`): one function builds, one matcher finds, so « too many » finds the - same rows from either field. -- **Built by the first thing typed, not by the home opening** (`home/hits.rs`): the nine tables - in the language on screen, once a language. A single character searches no reference — it is - nearly every row of each. -- **Choosing a row opens the reference on it** (`Tool::opened`, `Opening::OnRow`): its own search - emptied, the row brought into view once and lit, until the reference is searched by hand. - « n autres » opens it searched for what was typed on the home (`Opening::Searched`). - -**The keyboard reaches the results**: Enter in the field opens the first — a tool before a -reference's row, marked `↵` — the down arrow goes into them and the arrows walk them in the -order they are read, back up to the field; Escape empties the search, a second one leaves the -field. - -**The recent tools are an application preference** (`devnotes.recentTools`): which and when, -nothing typed into them. Sixteen are kept (`KEPT_RECENT_TOOLS`) and five shown -(`MAX_RECENT_TOOLS`): the home shows the five opened last, and the rail of an open tool the -first five that its section above does not already list — no tool twice in one rail, and five -all the same. A favourite is left out of the home's recents: it has its chip above them. - -**A tool is starred, and that is kept with the application too** (`devnotes.favouriteTools`): -ids in the order they were starred, read like any input — an id -the catalogue no longer has is dropped by whoever lists them, never -written out of the file for it. The same exception to « the tools keep nothing on disk » that -the recents and the zones are: an id, never what a tool holds. - -- **The star is a toggle** in the frame's header, and on each row of the home: shown on the row's - hover and on its own focus, always once on — full, in amber, so that on is not said by a colour - alone. It is a control of its own laid over the row's end, as a note's card is two layers. -- **« Favoris » is a section of the home above « Récents »**, the same chips, and an entry of - the rail above « Tous les outils » with its count; both are absent while there is none. -- **The entry narrows the home as a category does** (`Filter`: a category, or the favourites): - the starred tools in their own panels. Unstarring the last one widens the home again. A search - still answers over the whole catalogue, in its order — a favourite does not outrank a better - match. Ctrl+Shift+T opens the home on its search from any area. - -**"Enregistrer comme note" belongs to the frame**: one dialog for every tool and for an HTTP -response (`http/save_as_note.rs`). It asks for a title (the tool proposes one), a space and a -folder (those open in the notes by default) and tags; the kind and the language are the tool's -own. It takes the result as it stood on the click, and creates the note like any other, with the -source its caller names — "Outils / ", "HTTP / ". - -**An input can be filled from a note** (`ToolEntry::from_note`, in the catalogue): the tool names -its inputs a note may fill and which notes may — kinds, and for a snippet its languages -(`NoteInput`). The tool places `note_import` beside such an input: an input declared nowhere has -no button, so a key, a password, a token or a card number never takes a note. - -- **The picker asks Rust** for the kinds and languages declared (`query_notes`, every space) and - says what it lists (« Snippets JSON, YAML, TOML ou XML »). The note chosen is read whole by id, - and a todo list gives the Markdown copying it gives. -- **A copy, taken once**: the tool's input is set as typing would set it, and nothing ties the - tool to the note afterwards — editing or deleting the note leaves the tool as it was. The - converter reads a snippet in its own format; the diffs show the note's title over the side. - -**In Rust, a tool is a module of `engine/src/tools/`** (`text`, `url_parts`, …): pure functions -and their types, tested in place, called from `ui/src/api/tools.rs` on the `compute` queue — no -lock, and never on the window's thread. - -**A tool reading a file takes its path** (`tools/files.rs`): Rust reads the bytes where they -lie. What a tool shows of a file is refused past 10 MB -(`MAX_SENT_BYTES`), and a missing or unreadable file is part of the answer (`FileProblem`), -not an `AppError`. Bytes that are no text — a Base64 decoding — are written to a file the user -chooses, never to a note. - -⚠️ **The HMAC key never outlives the tool**: `Tool::left` zeroes it when the tool leaves the -screen, and Rust zeroes its copy once the digests are computed. The switch alone is remembered. A file is hashed a block at a time, so its size has no limit, and a pasted -signature is compared with every algorithm in both encodings, whichever are shown. With nothing -to hash it is still read, by its length alone (`DigestShape`): 64 hex characters are SHA-256 or -SHA3-256, and an HMAC has the shape of the hash it uses. - -**Randomness is the system's** (`getrandom`), never a seeded generator: a character is drawn by -rejection, so none comes up more often than another, and a system that gives no randomness is -an `AppError` rather than a weaker fallback. Generated passwords are the answer of a -`Live` and die with the tool. They may be kept as a note — the choice made for v0.9.0 — -but the tool's `ToolResult.warning` makes the dialog say why they had better not be, and its -button read "Enregistrer quand même". - -**A tool whose answer is one line is merged into a neighbour or enriched** (#564): the slug is a row -of the case converter, answered in the same call, and the URL codec and parser are one tool. - -**A case is written from words** (`tools/text.rs`): split at separators, at a capital after a -lower case or a digit, at the end of an acronym. The code cases strip accents when asked (`été` → -`ete`, `ß` stays a letter: transliterating is the slug's), the text cases keep them, and keep the -apostrophe binding an elided word to the next (`l'été`, `don't`). A French title leaves its small -words in lower case but the first, and capitalises after an elision (`de l'Été`). - -**A text is counted as a reader counts it and as a program does** (`tools/stats.rs`, -`unicode-segmentation`): characters as grapheme clusters (an accent written apart, a flag, a skin -tone are one), code points, UTF-16 units (JavaScript's `length`), UTF-8 bytes, words by UAX #29. -The frequencies are of those same characters, the invisible ones named rather than drawn blank. - -**Identifiers are drawn the same way** (`tools/identifiers.rs`): UUID v4 and v7, ULID, NanoID, -CUID2, `ObjectId` and KSUID, each a few lines held to its published vectors rather than a crate -each. A ULID batch drawn within one millisecond counts up, as its spec asks, so it sorts as drawn. -A pasted identifier is recognised by its shape and gives back the instant it carries and the part -of it that was drawn, with its bits; NanoID and CUID2 carry none, and are only named as possible. -The page dims a UUID's hyphens and picks out its version digit by position alone: the 8-4-4-4-12 -layout is fixed, so this is presentation, not a rule. - -**Bytes are written in six bases at once** (`tools/bases.rs`): Base64 padded, Base64 URL not -(the JWT convention), Base32 by hand to RFC 4648, hexadecimal, binary and decimal. A pasted text -is read by its shape, narrowest alphabet first — binary, hexadecimal (each group whole bytes, so -`67 97 102` is decimal), decimal, Base32 in capitals, Base64 URL by a `-` or a `_`, Base64 — and -the other readings its shape allows are named, any of them forced on request. A file keeps the -two Base64 alone. - -**A decoding that is a picture is shown** (`tools/image.rs`, read by `bases::decode`): PNG, -JPEG, GIF, WebP and SVG are known by their first bytes and sized by their header, and the answer -carries the picture. ⚠️ An SVG is drawn as a picture, nothing in it runs. Past 2 MB -(`PREVIEW_LIMIT`) the picture is still named and sized, and the page says it is not drawn rather -than drawing nothing. -« Enregistrer comme fichier » proposes the extension of what was recognised. A -`data:image/png;base64,…` URI pasted whole is read by its header — its payload is Base64 -whatever reading was asked — and a refusal inside it still counts characters from the text as -given. - -**A QR code is Rust's, the window draws its pixels** (`tools/qr.rs`, the `qrcode` crate): the -form becomes a payload there (Wi-Fi in the ZXing format, `mailto:`, a vCard 3.0 folded at 75 -octets), always in byte mode, so the capacity reads in the bytes typed. `qr::rgba` gives the -preview's texture, drawn `NEAREST` so that a module stays a square; the SVG and PNG files are -written from the same modules, so a download is the preview. ⚠️ The plate is white and the modules -black in both themes: an inverted code is not read by every scanner. The Wi-Fi password dies with -the tool (`Tool::left`), and a note keeping it is warned against, as a password is. - -**A CIDR block is computed on a `u128`** (`tools/cidr.rs`, `ipnet` for the reading): an IPv4 -address sits in its low 32 bits, so one set of arithmetic serves both families. A block is read -from `a/prefix`, `a mask` (a mask with holes refused) or a bare address, its host bits cleared and -said; a forced family reads IPv4 as its IPv4-mapped IPv6 block and back. What the block is comes -from the IANA special-purpose ranges, the most specific holding it, or « mixed » when it is wider -than one. ⚠️ Counts cross as decimal digits: an IPv6 one passes 2⁵³, and `::/0` holds 2¹²⁸, one -more than a `u128` — the page groups them with `BigInt`. A split offers the next three prefixes and -lists the first 256 subnets. Beside the block, in the same answer (`cidr/`): the address as one -integer, in full and under `in-addr.arpa` / `ip6.arpa` (past a `/24`, RFC 2317's classless zone); -the masks of the family, a choice applying its prefix to the address _as typed_, so going back finds -the same block; an address plan, needs placed the largest first so that each subnet starts on its -own boundary with nothing lost between two, what is left given as the fewest blocks; and a list — -blocks, addresses, `a - b` ranges — merged per family into the fewest blocks covering exactly the -same addresses, with the one block holding them all and what it holds beyond them. - -**A colour is Rust's to read** (`tools/colour.rs`): the four notations, `OKLab` and `OKLCH`, -the gamut, and the WCAG ratio — with the `0.03928` of `scripts/palette.test.mjs`, so the tool -and the palette's own check agree. The page paints the swatch Rust hands it. An `OKLCH` colour -sRGB cannot show gives up chroma, at the same lightness and hue, until it can, and says so. A -contrast that falls short is offered a fix: the nearest text colour reaching the next level for -body text, its OKLCH lightness alone moved toward black or white — whichever moves it less — -checked after rounding to the bytes its HEX writes, or said to be out of reach. - -**A conversion goes through one value** (`tools/convert.rs`): each format is read into a -`serde_json::Value` and written out of it, so any format reaches any other. ⚠️ `serde_json` -has `preserve_order` on: without it a `Map` sorts its keys, and a converted document would -come back in alphabetical order. YAML is `yaml-rust2`, maintained and pure Rust — `serde_yaml` -is archived; it expands aliases but not YAML 1.1 merge keys, so `<<` is applied in -`convert::merged` (the own keys win), for the conversion and the Diff alike — and XML is read -and written by hand around `quick-xml`, to one convention the tool states beside its result -(`@name`, `#text`, a repeated element as a list). What a format cannot hold — a TOML `null` in a list, a list at a TOML root, two XML roots, a name XML -refuses — is an answer carrying its `JSONPath`, never a guess. A key holding `null` is the one -exception: TOML leaves it out and the answer names it, since dropping it moves nothing else. The -two sides never hold the same format. - -**A generation is drawn from a seed** (`tools/generate.rs`, a `SplitMix64` — never for a -secret): the same seed and source give the same documents, and a generation without one draws a -seed and says which, so it can be kept. From a JSON Schema, the keywords it draws from are one -list (`UNDERSTOOD`); any other is listed back with its path, so a document that ignores a -`pattern` is never passed off as one that honours it. From an example — « Modèle », on screen — -each value is redrawn in its kind — a UUID, an email, an instant, a URL, words — at its -magnitude. - -- ⚠️ **An example read as a schema is said to be one, and draws nothing** (`AnExample`, - `schema::reads_as_a_schema`). Its keys were taken for keywords nobody knows, and a schema - with no known keyword allows anything: three strings of lorem ipsum, and a warning about - `email` and `createdAt`. An object reads as a schema when one of its keys is a keyword - **holding what that keyword holds** — `"type": "string"`, not `"type": "user"`; `properties` - over schemas, `required` over names — or when it holds nothing but the vocabulary - (`UNDERSTOOD` and `NOT_DRAWN`); `{}` is the schema that allows anything. The page offers to - read the text as a model, the same text under the other switch. -- **Each mode says what it expects** in a line under the switch, and « Exemple » fills the - sample of the mode on screen: a schema under « Schéma », a document under « Modèle ». The - mode is called « Modèle » because the button that loads a sample is « Exemple ». -- **The seed has one place, its field**: the one just drawn is said beside it (« · 3634897658 - utilisée ») with a pin, a toggle, that writes it there; pinned, « Régénérer » stays offered - and a line says it gives the same documents. « Régénérer » is the one name of that action in - the four tools that draw (JSON, Lorem ipsum, the passwords, the identifiers). The JSON - generator's seed is any text, handed to Rust as typed: a number up to `u32::MAX` is itself, - any other text its FNV-1a hash (`generate::fnv1a`, the identity tool's too). - -**A cron expression's runs are listed between two moments, and counted** (`tools/cron.rs`, -`croner`): « À partir de » and « jusqu'à », read in the zone chosen like the date that is -checked. A start alone lists the ten from there; both ends answer `CronWindow::Counted` — the -total, and every run up to fifty or the first and the last five past it — or why not (an end that does not read or -that a change of clocks skipped, an end before its start, more than ten years). - -- ⚠️ **The count is not the length of a list**, and not a walk either: a year at every minute - is half a million runs. It goes **by the day** (`count`): a day that lies whole in the window - and that no change of clocks cuts holds the same number of runs whenever it holds one — the - time fields know nothing of the date (`runs_a_day`) — so the search jumps from one matching - day to the next. Only the two ends and a day the clocks change on are walked run by run, - where `croner` alone knows what a skipped or a repeated hour does. A test holds it to the - walk, expression by expression, over both changes of clocks. -- **The shortcuts are typed for the user** (« aujourd'hui », « ce week-end », « vendredi - après-midi »): plain arithmetic on the date Rust says it is in the zone (`Read::now`), which - fills the two fields; no zone is computed in the page. -- **A date that does not match says the nearest run on either side** (`CronCheck::Checked`'s - `before` and `after`): a window of one minute is that question, and « no » leaves one asking - when, then. - -**The Diff compares texts, or values** (`tools/text_diff.rs`, `tools/diff.rs`). Its text mode -pairs lines on what they are compared as — the options strip what they ignore from that key alone, -so every line is drawn as typed — and a modified line is diffed again by words or characters to -mark what changed inside it. Both modes share their two texts; when both parse as JSON the text -mode offers the structured one rather than switching to it. - -**The structured mode compares values** (`tools/diff.rs`): objects key by key, lists by a longest -common sequence of their elements — one element inserted at the top is one change, not a change -of every element below it. Each change carries its `JSONPath`, the patch is RFC 6902 from A to -B (checked in the tests by applying it), and the two documents come back as aligned rows, -pretty-printed with B's keys in A's order when order is ignored, so the same keys meet on the -same row. The unified view is the same rows read one after the other, on the front. Each side -is read in its own format — by its shape (`convert::detect`) unless one is forced — through the -converter's readers, so a YAML and its JSON twin compare equal and the rows show both as JSON; -against XML, which has no types, `5432` and `"5432"` are the same value. - -**An instant is read from whatever was typed** (`tools/dates.rs`): a number by its magnitude -(seconds below 10¹¹, then milliseconds, microseconds, nanoseconds — each unit read from 1973 -on), unless a unit is forced; a text by its shape. ISO 8601, week and ordinal dates included, is -parsed by hand so that a refusal says at which character it stops; RFC 2822 is chrono's. A date -written without an offset is read in the machine's zone (`chrono::Local`, handed in as a -`TimeZone` so the tests fix one): a local time the clocks skipped is said, one they went through -twice is read as the earlier. ⚠️ chrono panics on a local time past its range, which an offset -can push its edges into — `within_range` refuses it first. How long ago or how far off is the -front's (`spanRef`), so it ages with the clock. - -**A gap between two dates is counted twice** (`tools/durations.rs`), each read by `dates::parse` -in the machine's IANA zone: by the calendar — whole months first, a day past a month's end -landing on its last (31 January plus a month is 28 February), then the wall clock — and by the -clock, in real seconds. The two part when the zone's offset differs at either end; the answer -then names the last change, found a day at a time back from the later date, then to the second. -An ISO 8601 duration is parsed by hand, so a refusal is located; « 1h30 » or « 90 min » are read -too and written back in ISO. Sixty seconds are carried into a minute and sixty minutes into an -hour (« 90 min » is `PT1H30M`), never hours into a day, which the clocks can make 23 or 25 hours -long. A month or a year has no length in seconds: such a duration has no -total. The words that spell either aloud are the front's, from typed parts. - -**A zone is the IANA database's**, compiled into the binary (`tools/zones.rs`, `chrono-tz`): -nothing is read from the system but the name of its own zone (`iana-time-zone`), so Windows and -Linux answer alike. A time is read by `dates::parse` and placed in the zone it was typed in: one -the clocks skipped says between which offsets, one they went through twice gives both readings -and places the one chosen. The machine's zone and the one typed in are always listed, whatever -the list holds. An abbreviation the database writes as an offset (`+0545`) is no name. ⚠️ The -list is the one thing a tool keeps on disk (`timeZones`, an application preference): a list of -zones is a preference, not something typed. It is read back name by name, and a zone Rust says it -does not know leaves it. An abbreviation several zones use lists them all rather than guessing. - -**A cron expression is read twice** (`tools/cron.rs`): by hand, field by field, so that a -refusal names its field and its token and the page can light the field under the caret; then by -`croner`, which counts the next runs in a zone and checks a date. Rust answers what each field -holds (`Piece`), never a sentence: `catalogue/cron/sentence.rs` builds it from translation keys — times -written as times when the minute and the hour are plain values, one clause per field otherwise. -When both day fields are set, either one matching is enough, as in cron, and the tool says so. -`@midnight` is expanded here, since `croner` does not know it. - -**A number is read exactly** (`tools/numbers.rs`, `rust_decimal`, never a float): a point or a -comma before the decimals whatever the language — the last mark when both appear, a repeated one -grouping thousands — spaces or underscores between thousands, an exponent. **A data size is -counted in bits** (`tools/sizes.rs`), every unit divided out of that one figure, so `1 GB` is -`1000000000` bytes and never nearly: each value comes back exact and rounded to the decimals -asked. The page writes the digits in its language (`formatDecimal`) and copies the exact value -(`app-result-row`'s `copied`); a value its rounding would write as 0 is written as a power of -ten instead (`formatScientific`). An all-lowercase `gb` is read as bytes, `Gb` as bits. A -transfer is the same bits over a rate (`tools/transfer.rs`), slowed by an efficiency held -between 50 and 100 %, answered to the second as typed parts and in days past a year; the common -connections it is also given for are Rust constants, their names translation keys. The -percentages are lines of a Calcul note now (`notes::calc`), not a tool. - -**A Unix mode has three ways in** (`tools/permissions.rs`): the octal digits, the letters `ls -l` -prints (its file-type letter read and named, `s`/`S` and `t`/`T` telling a special bit with and -without the execute one), and the grid of boxes. A field shows what was typed in it, or else -Rust's writing of the mode; a box flips one bit and writes the mode back as octal, which Rust -reads again — the page keeps no mode of its own. A mode that is probably a mistake — the others -richer than the group, anyone writing without the sticky bit, a setuid with no execute to act on — -is named by Rust as a typed warning and phrased by the page. - -**Check digits are Rust's** (`tools/checks.rs`): Luhn in a few lines, a card's network named from -its prefix and length as a hint, and an IBAN's mod 97 with its country's BBAN format checked by -`iban_validate`. That crate keeps its formats to itself, so the length each country expects is -a table summed from its registry, held to it by a test. A French or Monégasque IBAN is read in its -parts — bank, branch, account — and its RIB key checked apart from the IBAN's own. ⚠️ A card -number or an IBAN is a secret: it dies with the tool, which has nothing to save as a note. - -**A JWT is taken apart in Rust** (`tools/jwt.rs`), without a JWT crate — `jsonwebtoken` brings -`ring`: its header and payload decoded, `exp`, `nbf`, `iat` and `auth_time` read against now, -and its signature verified for HS256, HS384 and HS512 alone, in constant time -(`Mac::verify_slice`); the other families are named and left unverified, `alg: none` is flagged. -⚠️ The token and the secret die with the tool, and are zeroed in Rust once the answer is made; a note -keeps the decoded header and payload as one JSON document, after a warning, never the token. - -**The diff's « Données » tab compares documents, and says when a text is none** -(`tools/diff.rs`). ⚠️ Nearly any text is valid YAML — one plain scalar — so YAML accepted what -the other formats refused: an nginx file was announced « lu comme YAML » and compared as one -string changed into another. A side **read by its shape** that comes out as one value and no -object nor list is answered `NotStructured`, with the way back to the text tab, whose two -texts are the same two (`diff.a`, `diff.b`); a format **chosen by hand** is taken at its word. -The detection answers the narrowest format that fits (`convert::detect`): every JSON document -is YAML too, and one that parses as JSON is said to be JSON. « Exemple » belongs to the tab on -screen and fills both sides, each read by its shape again. - -**A reference is a table to search, and its words are a file of its own** -(`crates/i18n/translations/references/.{fr,en}.json`, read as `tools..words.…`), the -facts beside its `catalogue/.rs`: nothing is computed and nothing is kept as a note. `Reference` holds -the query and builds the rows once a language; `ReferenceTable` (`tools/ui/`) is the rest: the -search, folded like the catalogue's, the groups, the count, each row's key to copy. A row is -searched by its group's heading too (« redirection » finds every 3xx). Each group is a card, and -the cards flow into as many columns as the width holds, each never narrower than the reference's -`card_width`. - -⚠️ A reference's words are read with `i18n::as_written`, never `translate`: the Mustache sheet speaks -of `{{ }}`, which an interpolation would replace with nothing. - -**A fictitious identity is drawn from one list of names and a profile a country** — decided by -a spike before any list was written, because the obvious way was refused: a few thousand names -a country, hard-coded, is a megabyte of test data in the binary. - -- ⚠️ **One list of names, with no origin and no country attached to any.** The given names of - women, those of men and the surnames are a list each, in one file, in alphabetical order: - every country draws from it, and any name may come out anywhere. The spike had first sorted - them into « pools » an origin, a country drawing from a weighted mix of pools, with tests - holding each origin to its share. **That was withdrawn**: sorting people's names by where - they come from, or by the country they live in, is not something this tool does. Nothing - says it of a name any more — not the data, not a file's name, not the order of a file, not - a test. **A country is a profile** of what is its own: about twenty-five places (postcode, - city, region), thirty street names, and its formats — postcode, phone, the order of an - address, its account number and its identifiers. One more country costs a profile and its - places, not a list of names. -- **The budget is 100 KB for every list together**, held by a test that sums the files: about - 2 500 names at seven bytes a name, 18 KB, and thirteen countries of 25 places and 30 - streets, 18 KB — 36 KB in all, so the 150 KB first put forward was four times what is - needed and 100 KB leaves room for the countries that follow. -- **What was ruled out, and on what.** One pack a country (150 given names a sex, 150 surnames, - 40 places): about 5 KB a country, the same names written again under every country — and - names sorted by country, which is not done. Made-up names (syllables, Markov chains) cost - nothing and look like nobody: kept for nothing. The `fake` crate: about ten locales, none - of the identifiers this tool exists for, and its own generator beside the seeded `Draw` the - tools already have. ⚠️ Its cost in the binary was **not** measured: that needs a dependency - added, which is not done unasked. -- **Plain text, read once.** A list is a text file — its bytes and nothing more — split when - read. The same names as a Rust table of `&str` cost sixteen bytes a name on top of the - text, half as much again. The spike took them into the binary with `include_str!`; they - are **files shipped beside the application** since, read where they are (below). -- ⚠️ **Where the lists come from.** Written by hand, from what is commonly known of the most - frequent names and of the larger towns of each country: no dataset and no library was - copied. The script that would cut the open data of the statistics offices (INSEE, ONS, - Destatis, the US Census) to its most frequent names is **not written**: it downloads files, - which is asked for first. Until then a name's frequency is a judgement, not a figure. -- **Latin script only**, said plainly: a name from a language written otherwise is written as - it is romanised. Names in their own script wait for a romanisation beside them — the second - one feeding the e-mail address. -- **Valid means computed, and derived from the person where the number encodes them**: an - identifier is never drawn beside the identity it belongs to. The IBAN's mod 97 everywhere, - and the national key inside it where there is one (France's RIB key, Belgium, Spain, Italy, - Portugal). France: SIREN and SIRET (Luhn), the VAT key from the SIREN, the NIR with its - key — sex, year, month and department taken from the person. Belgium: national and company - numbers (mod 97). Germany: Steuer-ID and USt-IdNr (ISO 7064). Spain: DNI, NIE, NIF (the - letter of the remainder). Italy: codice fiscale — from the name, the birth and the place — - and partita IVA. The Netherlands: BSN (the « elfproef »). Portugal: NIF (mod 11). - Switzerland: AHV (EAN-13). Poland: PESEL, the date and the sex in it. Sweden: - personnummer (Luhn). The United Kingdom: NINO and VAT. Canada: SIN (Luhn). ⚠️ A number - that passes its key may belong to someone: no range is reserved for fiction but for a few - phone numbers and an e-mail domain, and the tool says so. -- **First version: France**, complete. **Then**: Belgium, Germany, Spain, Italy, Portugal, the - Netherlands, Switzerland, the United Kingdom, Poland, Sweden, the United States and Canada. - All thirteen are in the tool, their list written in its note; the budget still holds - more than half of itself for the ones that follow. - -**The identity tool is that design, for thirteen countries** (`tools/identity.rs`; -`ui/src/tools/catalogue/identity.rs`). A pure function of the options and a seed. -Four files under `tools/identity/`, each one thing: - -| File | What it holds | -| ------------ | ----------------------------------------------------------------------------------------------------------- | -| `data.rs` | The lists — one file of names, a file of places and streets a country — compiled in and held whole by tests | -| `profile.rs` | A country in a few lines: the order of an address, the shape of a phone number, a firm — nothing of a name | -| `numbers.rs` | The keys, a function each, each held to an example its country publishes | -| `papers.rs` | The numbers of a person, a firm and an account, a country at a time, built on `numbers.rs` | - -The lists weigh **36 KB** for the thirteen countries, held under `BUDGET` by a test that -sums the files. - -⚠️ **The lists are compiled into the application** (`include_str!` in `data.rs`), decided by the -owner after the standalone executable of 1.0.0 answered « Liste introuvable »: it is one file, -with no folder beside it. For a while they were files beside the executable, so that a name could -be corrected without a build; that is given up. - -- **The files are the source**: `crates/engine/resources/identity/` (`names.txt`, - `places/*.txt`), one `include_str!` each; nothing is installed beside the binary and nothing - is read from a folder at run time. -- **Read once, kept for the session** (`data::library`, a `LazyLock`): the texts are parsed at - the first card, every name drawn afterwards pointing into them. -- ⚠️ **A list is held whole by a test, not checked at run time**: the names have a list of each - kind, a country has places — every part of each — and streets under each place's own tag - (`every_list_compiled_in_is_whole`). A build that passed its tests cannot meet a list that - is not whole, so the tool has no « unreadable » answer. Windows line endings, which a checkout - may leave, are read through. -- **What is compiled in is the whole folder**: a test holds the folder to one file of names and - a file a country, and nothing else. -- **Not done**: lists of the user's own beside the shipped ones. - -- **The seed is text** — « devnotes » is one — hashed to the number the tools' `Draw` takes; - none given, one is drawn and said, and typing it back gives that person again. ⚠️ Only the - **year** of today is read: the ages are the ones reached during it, so the same seed gives - the same person all year rather than a birth date that moves with the day. -- ⚠️ **Every draw is made in one order whatever the options**: a sex that is imposed still - costs its draw, the given names are three draws however many are kept. Changing an option - changes what it names and nothing else of the person. -- **A place says what its country needs of it** (`Place`): a code — the INSEE code of a - French commune, the land-registry code an Italian codice fiscale ends on, a state's two - letters —, a postcode that may leave characters to draw (`#` a digit, `@` a letter, from - the letters the United Kingdom, the Netherlands and Canada all allow), the prefix of its - phone numbers, and a tag where a country speaks several languages: Brussels takes French - streets and « SRL », Antwerp Dutch ones and « BV ». **An address is written in the - country's order** (`Address::formatted`): « Hauptstraße 12, 10115 Berlin », « 12 High - Street, Manchester M1 4BT », « 12 Main Street, Chicago, IL 60601 ». -- ⚠️ **A surname in `-ski`, `-cki` or `-dzki` follows the person** (`data::borne`): a - woman's ends in `-a`. The grammar of the name, read off its ending and nothing else — it - sorts no one. **The same seed gives the same names whatever the country** — a test holds - it: the names are drawn before anything a country has of its own. -- **One implementation generates and verifies**: the IBAN's two digits and the Luhn digit are - `tools/checks.rs`'s own functions, and the test asks the checks tool whether each IBAN is - valid — its length for the country and, in France, the RIB key — in every country that has - one. The national key inside the account is computed where there is one: France, Belgium, - Spain, Italy's CIN, Portugal, the Dutch « elfproef », the digit of a Polish branch. -- **A number that encodes its bearer is read off them** (`papers::Bearer`), never drawn - beside them: France's social security number (sex, year, month, commune, Corsica's `2A` - counted as 19 for the key), Belgium's national number (birth, and a serial odd for a man — - read behind a `2` for a birth from 2000 on), the codice fiscale (the names, the birth, a - woman's day forty higher, the commune), the PESEL (the century in the month), the - personnummer (a `+` for a hyphen from a hundred years on). The others are a drawn body and - its key: Steuer-ID and USt-IdNr (ISO 7064), DNI and a company's NIF, partita IVA, the - Portuguese NIF and NIPC, BSN, AHV (EAN-13) and UID, the British VAT number, NIP and REGON, - organisationsnummer, the Canadian SIN. -- ⚠️ **What has no key is said, not dressed up** (`papers::UNKEYED`, - `IdentityAnswer::unkeyed`): a National Insurance number, a company number, a KvK-nummer, a - sort code and an account number are formats, and each the card shows carries « sans clé » - on its row, its title saying why. A country whose firms have no number with a key — the United States, Canada — - answers none, and the block says so rather than show a field made up. -- **Harmless where a range is kept for it**: `example.com`, `.org`, `.net` everywhere; a - phone number in the block the regulator keeps for fiction in **France** (ARCEP's blocks, one - a zone, written with each place), the **United Kingdom** (Ofcom's, a block a large town and - `01632 960` for the others, `07700 900` for a mobile), the **United States** and **Canada** - (`555-01xx` in the place's area code); the ten social security numbers the United States - keeps for advertisements (`987-65-4320` to `4329`), and a Canadian number starting with a - `0`, which Canada gives nobody. ⚠️ Elsewhere a phone number of the right shape may ring at - someone's (`Profile::fiction_phones`): the phone and the mobile carry « peut sonner » on their - rows. No range exists for an IBAN or a tax number: one that passes its key may be someone's. -- **Said where it changes something, not in a note under the card**: the tool is for - developers, and a band of warnings — the data is for tests, what « valide » means, the - countries, the JSON's fields — said what the card, the country menu and the JSON already - say. Two facts change what is done with a value, and they are marks on its row. -- ⚠️ **Written from memory, not from a register**: the towns' codes — INSEE, the Italian land - registry —, the area codes and the banks' codes were not checked against their official - tables, which would mean fetching them. A wrong one leaves a number that still passes its - key, and names another town. -- ⚠️ **The card evokes one and imitates none**: a monogram where a photo would be, no emblem, - no flag bar, no machine-readable zone, and nothing printed across it. A number that - is the person's own is on the card, **under the name its country gives it** — « Codice - fiscale », « BSN », « Sort code » are names, written the same in both languages; the rest - is three blocks — contact, bank, company — each value copied with a click. -- **Out**: « Copier en JSON » and the note take the JSON Rust wrote (`IdentityAnswer::json`, - the field names of `Identity`, which an export shares); a batch of one to a hundred people - is a file, JSON or CSV, written by Rust where the file dialog says and starting from the - person on screen. **Several countries take their turn in one file** (`PeopleBatch`), the - card's own first; a CSV holds the numbers of a person in one column, `kind:value` and a bar - between, since they differ from a country to the next. A CSV opens on a UTF-8 BOM, or a spreadsheet reads - `Şimşek` in its own code page, and is separated by what the export chose (`CsvSeparator`: - `;` for a French spreadsheet), kept as the application's `csvSeparator`. - -**Adding a tool**, the whole of it: - -1. `crates/engine/src/tools/.rs`: the function, its request and answer types, its tests. -2. `ui/src/api/tools.rs`: one function through `backend.compute`. -3. `ui/src/tools/catalogue/.rs`: a struct implementing `Tool`, its `make()`; `catalogue.rs`: an - entry and a `mod`. A reference is `Reference::of(table)` and a line of `REFERENCES`. -4. `tools..*` in both locales, its kittest over a real core, a row in journey 8's table, and its - state in `app::captures` by itself: `the_tools` walks the catalogue. - -What every tool draws alike is the kit, `tools/ui/`: `columns`, `line`, `section_head`, `text_area`, -`card`, `ResultRow`, `OutputRow`, `CopyValue`, `notice`, `code_output`. ⚠️ A row of a results card -gives its value two thirds of the card beside its name, which a long one turned into a strip -running down the page: past `LONG_RESULT` characters a value takes the card's width **under** its -name, held to eight lines it scrolls in, and its icon stays at its top. A results card -(`result_rows`) puts its rows two abreast once it holds two of `ROW_MIN`. - -The home's panels are stacks in columns: as many as `column_count` fits at 260 px, the panels cut -into consecutive stacks by `stack_in_columns`, the tallest as short as it can be: one tall panel -(the references) would leave the last columns of a large screen empty otherwise. A panel's height -is counted in rows, near enough to share the columns out. - -⚠️ **The line breaks tool never reads its text through a field**: a paste keeps its CRLF and CR -only from the native clipboard, so Coller reads it there, and the text is drawn with its endings. - -### State - -`ui::state` holds what the interface remembers between frames, one module per subject, all -fields of `AppState` (→ "State between frames" for `QueryCell`, `Revision` and `LibraryCaches`). -The notes are held by modules split by the question they answer: - -| Module | Answers | -| ------------------- | ---------------------------------------------------------------- | -| `notes_query` | which notes the canvas shows: a `QueryCell` over `query_notes` | -| `selection` | what is ticked, and the card a first `Delete` armed | -| `editor` | the note open, read whole by id, and its draft | -| `notes` | the notes' one writer: create, patch, delete | -| `board` | which view a space is looked at in, and what the board draws | -| `undo` | the last write that can be put back, and its bar | -| `spaces`, `folders` | the library's spaces and folders, and which one narrows the view | - -Beside them, one module per screen or job that is not the canvas: `trash` (loaded when its panel -opens, not by a permanent query), `tags` (global management: nothing runs before the core has -counted what it touches), `transfer` (import, export and share, each reporting), `palette`, -`attachments`, `placeholder_fill`, `note_revisions`, `formatting`, `calc_sheets`, -`drawing_pictures`, `explored`, `libraries`, `backups`, `security`, `help`, `tools`, `http/`. - -`notes_query` holds the **query** — search text, quick filter, tags, languages — and the -`NotesView` the core answered. It does no filtering, sorting or grouping: those are -`query_notes`'s, and everything the canvas draws is read from the view. - -- **The search is debounced** (`DEBOUNCE`, 150 ms): the field takes every keystroke, the query - is asked once the typing pauses. -- **The last view stays while the next loads**, and after an error: a keystroke never blanks the - canvas. One query in flight, the latest waiting — a burst asks the one in flight and the - newest, never one per pause (the core computes a query to its end once asked). -- **Its parameters are compared by value**, and they include the local **day**, not the instant: - a clock tick asks nothing again; midnight does, through `request_repaint_after`. -- **The space is a filter, not a label.** `None` means « all spaces » and is a choice, not a - loading state; an id matching no known space falls back to `None`. The space also scopes the - facet rails: a tag that filters nothing in the space is not offered. - -Creating a note files it in the active space, the first one in « all spaces »; with no space at -all creation is refused with a translated message. - -Rules of the house: - -- **The core is authoritative; writes are not optimistic.** A write persists, its answer is - adopted, and the `Revision` is bumped, so every view that reads notes — the list and the board - alike — asks again. Nothing is applied locally first, so nothing is rolled back on a failure: - the `ErrorNotifier` says it and the screen shows what is stored. ⚠️ A write that reloaded one - view only is what once left a todo list ticked on the board and unticked in the list. -- **One function writes a note's fields** (`state::notes`, with a `NotePatch` whose `None` is - « untouched »); closing the editor on an untouched note writes nothing. -- **Ids, instants and normalisation come from the core**, never from the interface; time comes - from the injectable clock (`services::time`). -- **The board dims where the list narrows**: a card there can be ticked, moved or deleted while - its note is outside the list's view, so a gesture resolves its note through the view on screen. - -### Display sections - -Sections are built in Rust (`crates/engine/src/notes/view.rs`) and arrive ready to render. -The front-end preserves the order it receives and never drops or merges a section. - -The classification into `pinned`, `today`, `week` and `older` is **exhaustive**: apart from -pinned notes, each note falls into exactly one section — a note belonging to no section is -unreachable in the UI, search included. An unparseable `created_at` lands in `older` rather -than disappearing. The `week` section is always present because it hosts the "paste or -create" ghost card. - -As soon as a search query, a tag selection or an opened folder is active, the view collapses -into a single flat `results` section. Spreading search results across date sections dilutes -them and hides matches at the bottom of the page. A quick filter (`pinned` / `untriaged`) -does **not** trigger this: it narrows a view that stays chronological. - -⚠️ `build_sections` takes `Option` rather than a bare `is_filtering`: `None` is the -chronological sections, `Some(ghost)` the flat list, and `ghost` says whether it is somewhere -a note can be **created**. The inside of a folder is — a note made there arrives filed, and it -is the one place where creating one files it — so the flat view keeps the ghost when the -folder is the whole reason it is flat. A result list is a list of what already matched, not a -place, so a search or a facet takes it away. - -Day boundaries are **local**, so the query carries `tzOffsetMinutes` alongside `now`. Without -it a note created at 23:00 would be filed under the wrong day. Beware the sign: JavaScript's -`getTimezoneOffset()` returns −120 for UTC+2, the opposite of what chrono's `FixedOffset` -expects. - -A section's key **is** its translation key (`'sections.' + key`), which is why the Rust enum -serialises to `"pinned"` / `"today"` / … and no user-visible label ever crosses the bridge. - -### What a card's footer shows - -The footer carries one of three things, and which one is a **product rule**, so it is decided -in `notes::model` and arrives as a tagged `footer` field: - -| variant | when | rendered as | -| -------- | ----------------------- | -------------------------- | -| `expiry` | the note has a deadline | `expiryRef(at, now)` | -| `source` | it has a context | the first path segment | -| `age` | everything else | `relativeTimeRef(at, now)` | - -The dated variants carry a **date, not a label**: formatting stays on the front so "4 min ago" -keeps ageing on screen without a round trip. That is the line — the back decides _what_ to -show, the front decides _how_. - -`expiringSoon` comes with it, computed against a single threshold in `notes::model`. It -previously lived only on the front (`isExpiringSoon`, 3 days) while the back separately -computed `has_expiring_notes` — two definitions of "soon" behind a hint that reads "to triage -soon". The section flag now derives from the same per-note value. - -### The five kinds of note - -A note is a `snippet`, a `note`, a `checklist`, a `calc` — a sheet, below — or a `drawing`, and `notes::kind::NoteKind` is a closed -enum for the same reason `Language` is: the front receives a generated union, so an unhandled -variant stops compiling rather than surfacing at runtime. - -**Only a snippet has a language** (`NoteKind::has_language`). A Note's body is prose and a -checklist has none: neither is read for one, a patch cannot give them one, and the language -rail — its facet and its filter — counts snippets alone, where a Note or a list would put -"Text" on it. - -**A kind is a facet with a count.** `NotesQuery.kinds` narrows like a tag or a language — the -list view turns into one flat `results` section, the board dims — and the kind rail -(`kind-rail/`, first in the facets panel) says how many notes of each kind the space holds: -`NotesView.kind_counts`, built by `view::count_kinds` from one `GROUP BY`, every kind in -`NoteKind`'s declared order and zeros included. Counted over the space and not the filter, -for the reason `available_tags` is: counted over the selection, pressing one chip would zero -the others. "All" is no kind selected, and an empty kind is offered only while pressed. -**The list view is ordered in Rust** (`NotesQuery.order`, `view::order_notes`): by the last -edit (the default), the creation, the priority, the format (the kind, then the language) or -the title, either way. ⚠️ Titles are sealed, so SQL cannot order them: they are folded once -per query and compared in Rust. Ties fall on the last edit, then the id, whichever way the -list runs, so two refreshes never swap neighbours. The order is not a criterion — the board, -which spreads the criteria into its own query, keeps the places its cards were given — and -the card's age names the date it is sorted by: "modifiée il y a 4 h", or "créée…" when -sorted by creation (`NoteFooter::Created`, set after the sections by `dated_by_creation`). -The closed enums derive `Ord` in declared order, which is what ranks a priority and a kind. - -**The list view gathers its cards four ways** (`NotesQuery.grouping`): by date, by priority, -by format, or all in one section. ⚠️ The dated sections split on **the date the list is -sorted by** — the creation date under the creation sort, the last edit otherwise — where they -used to split on the creation date while the list ran on the last edit, so the two could -disagree. Priority sections run from the most pressing down, and "none" is always there: it -holds the create card, and a new note lands in it. Format sections gather snippets by -language, then the Notes, then the lists (`SectionGroup`, declared in that order); the create -card rides the last one. Sections stay exhaustive, a pinned note heads its own group outside -the dated layout, and a search or a facet still makes one flat `results` list. Several -sections share a key (`format`), so each carries an `id` the canvas tracks it by, and a -`group` saying what it gathers, which the front names — a translation key, or a language's -own label. - -**"Trier et regrouper" sits in the topbar** (`notes/header/sort-menu/`): its button names the -order the canvas is in — "Priorité ↓" — and its menu sets the key, the direction, the -grouping and "Épinglées en tête" together, so it stays open on a choice. A new key starts -the way it reads first (`naturalOrder`: the newest and the most pressing on top, words from -A to Z). The choice is the library's (`devnotes.notes.arrangement` in -`LibraryPreferencesService`), read when the notes page opens — the library's preferences are -open by then — and written on every change; `readArrangement` trusts the file no further -than it reads, a value it cannot name staying default. The button leaves the topbar while -the board shows, which orders nothing. ⚠️ At the size the application ships with and the -rail open, the topbar holds one row with a few pixels to spare (`06-search-and-filters` -measures it): below 1280 px the button is a glyph, the order in its tooltip. - -**A priority is filtered the same way** (`NotesQuery.priorities`, `priority_counts`), both -counted by one helper, `view::counted`; its rail reads the levels from the most pressing -down, offers no chip for `none`, and stays away from a space where nothing has a priority. -The tags and the formats count their notes the same way (`tag_counts`, `language_counts`, a -`GROUP BY` each, `available_*` in their order), shown beside each chip. - -A checklist has **no body**. Its items replace `content` — they are not an addition to it — -and they live in `note_items`, keyed `(note_id, position)`. That key is the whole design: an -item has no identity beyond where it sits, so every write replaces the entire list, exactly -the way `note_tags` does. Nothing addresses a single item, and nothing generates an id for -one. Reordering is therefore an ordinary write, not a shuffle of rows under a primary key -that forbids duplicates halfway through. - -**The editor writes a list the way a text field would.** Enter cuts the item at the caret, -Backspace at the very start of one joins it to the item above, and several lines pasted into a -row become as many items — a list marker dropped, a `[x]` read as done — what stood around the -caret heading the first and ending the last. Each gesture is one write of the whole list. - -Three behaviours would go quietly wrong without a thought for the kind, and each is handled -where its rule already lived: - -- `notes::view::matches_search` scans the item texts as well. A checklist has no `content`, - so it would otherwise be findable only by its title. -- `transfer::model::to_markdown` renders `- [x] …` lines instead of a fenced block. An empty - ` ```txt ` block is not something anybody pastes into a ticket. -- Language detection is skipped. There is no body to read, and a format select over a note - that shows no code is a control with nothing to do — which is why the editor hides it too. - -Both fields carry `#[serde(default)]`. `transfer::Bundle` deserialises `Note` itself, so a -required key would have made every export file written before todo lists unreadable — -`FORMAT_VERSION` stays at 1 precisely because old files still read. - -**A bundle from a newer version degrades, it does not fail.** `Note` carries two closed -enums, `language` and `kind`, so a file written once `Language` has grown a `rust` variant -used to fail serde outright and take the other 499 notes with it. `read_bundle` now walks -the raw JSON first and brings any value this build cannot name down to the default, counting -the notes it touched; `ImportReport.notes_degraded` reports them, and `merge` counts only -those actually inserted, so re-importing the same file says nothing a second time. - -That settles an inconsistency the two read paths had by accident. The **database** read has -always degraded (`notes::store`, `TryFrom`: `row.language.parse().unwrap_or_default()`); -the bundle read refused. A bundle is the same data through another door, so it degrades too. -Degrading also loses less than skipping the note would: the title, body, tags and deadline -all arrive, only the colouring is dropped. What stays strict is the **bridge** — a `language` -the front end cannot name is still a deserialisation failure there, which is what lets the -generated union be trusted. - -⚠️ Consequences for `FORMAT_VERSION`: an added enum variant **does not** bump it. It is not a -format break, since the file still parses. It is bumped when a file written today would stop -being readable — and it is read off the raw JSON before the bundle is built, so a genuinely -future format answers with the designed message rather than with a serde error about a field. - -Progress (`done`/`total`) is **not** on the wire. The items already travel with the note, and -a counter beside them would be the identity mapper this codebase refuses elsewhere; the card -and the editor each count in a `computed()`. That is the same line as relative-time -formatting: presenting data the front already holds is the front's job. - -What _is_ on the wire is `DisplayNote.copy_text`: `Some(markdown)` for a checklist, `None` for -a snippet or a Note, whose `content` is already there. Counting an array is presentation; deciding that -a task list reads `- [x] …` is a rule, and it now has exactly one home — -`notes::checklist::to_markdown`, which sharing and exporting already used. The front end held -a second copy of that syntax, and one of the two was going to drift. - -**A note changes kind in Rust alone** (`notes::convert`, `convert_note`), from the editor's -« Type » menu, at the head of the band holding the space and the folder — the title bar keeps -its room for the title. A snippet and a Note keep their text as it is (a snippet reads it for a -language); a todo list gives its items to a Note as a task list and to a snippet as lines; a -text becomes one item -per line that is not blank, its list markers dropped and its `[x]` read as done. One -transaction; the body it replaces goes into the history like any edit's, so converting into a -todo list keeps the text it was made from. The command answers the body the note had -(`NoteBody`), which the undo writes back through `update_note`. `NotesStore.convertNote` first -writes what the editor still holds, awaited — a conversion landing under a write of the old body -would lose it — then bumps the editor session so its drafts re-seed. Code pasted into an empty -Note makes it a snippet with that same undo, back to the Note with the pasted text. - -### A Calcul note: one result a line - -A `calc` note is a sheet: its body is text, as a snippet's is — sealed, searched, its last 20 -revisions kept, exported in a bare fence — with no language. Each line is computed as it is -typed, and **the results are never stored**: they are computed when the sheet is read. - -**Rust computes, the interface writes** (`notes::calc`; the footer's sum and mean are `calc::summary`, -exact, and come back as values like any other). `evaluate_calc(sheet, today)` answers the -whole sheet — one `CalcRow` a line, with its spans for the colours and, after `en` or `à`, the -kind being converted — and `query_notes` gives a card its last four lines that gave something -(`DisplayNote.calc`, read from the whole body before it is cut). Values cross as exact decimals -in text, units as `UnitId`s, errors as codes: `ui::notes::calc` writes them -in the language on screen — its decimal mark, `Go` or `GB`, `j` or `d`, the date — and says `≈` -when the display rounds. `today` is the local day of the window (`CalcSheets.today`); the board, -which knows no time zone, gives its cards the UTC day. - -**The grammar** is a recursive descent over a lexer counting UTF-16 units, as the editor does -(`calc/lexer.rs`, `calc/eval.rs`): - -- **Numbers** take a comma or a point before the decimals, and thousands grouped by a space — - a plain, no-break or narrow one, so `1 578,13 €` as the front writes it reads back; a group is - three digits after at most three. Arithmetic is `rust_decimal`, exact — a factor such as `€/h` - is kept as a fraction, multiplied before it is divided, or `0,045 €/h` would read back as - `0,04499…`. A scale after a number multiplies it: `k`, `M`, `Md`/`bn`, `T`/`tn` in their case - (`m` stays a metre), `mille`/`thousand`, `million`, `milliard`/`billion`, `trillion` in any — - `billion` is 10⁹ for everyone, the French one is `mille milliards`. -- **Operators** are symbols or words: `plus`, `et`/`and`, `avec`/`with`; `moins`/`minus`, - `subtract`, `sans`/`without` (a subtraction: `hors` alone takes a percentage back off); - `fois`/`times`, `multiplié par`/`multiplied by`, `mul`; `divisé par`/`divided by`; `mod`, whose - remainder takes the divisor's sign. A parenthesis right after a value multiplies it: `6 (3)`. - `préc`/`prev` is the result of the last line above that gave one. -- **Text left out**: a label before a colon (`Prix : 11 € + 34,45 €`), a quoted text and the words - after a result that lead up to it (`275 € pour le "Modèle 227"`), parentheses after a value - holding words and no name (`999 € (pour l'iPhone)`). Words alone after a result are an error, - not prose: `5 jours ouvrés` says it is not read rather than give 5 days. -- **Units** (`calc/units.rs`, one table) are lengths, masses, durations, data sizes (the sizes - tool's factors), temperatures, and euros and dollars, which are units like the others: added, - multiplied, never converted into each other — ⚠️ no rate is fetched, so `100 € en $` is - refused on its line. A quantity carries its dimensions, so `€/h × h` is euros and a size `à` a - rate is a duration. A temperature is converted by formula, never by factor. Quantities of one - kind written side by side add up: `3 h 20 min`. Lowercase `to` and `mo` are left to English and - to the month. Frequencies are a second to the power of minus one (`1 / 2 s` is 0,5 Hz, - `60 Hz × 2 s` a number); `ns`, `µs`, `nm`, `µm` and the data sizes up to `YB`/`YiB` are - units of the table. **Screen units**: `pt` is the 72nd of an inch, `px` an inch over the - sheet's `ppi`, `em` and `rem` its sizes in pixels — 96 and 16 until a line `ppi = 326`, - `em = 20 px` or `rem = 18` sets them, from that line down (`Css`, carried by the walk). Those - three are settings, not names (`WordClass::Setting`), nor figures `total` or `préc` reads. `in` - is the inch after a number, but the conversion word before a notation or `%` (`255 in hex`). -- **Functions and constants** (`calc/maths.rs`): `racine`/`sqrt` (`racine 2 (8)`, a degree - before parentheses), `cbrt`, `log` (`log 2 (8)`, a base), `ln`, `abs`, `arrondi`/`round`, - `plafond`/`ceil`, `plancher`/`floor`, with or without parentheses; `pi`/`π`, `e`, `tau`/`τ`, - `phi`/`φ`, which a name hides. A root or a logarithm is exact where one exists (`sqrt 16` is 4), - through `rust_decimal`'s `maths`; an even root of a negative number, a logarithm of zero or - less are errors of their own. A degree is computed whatever its size, in a moment: powers go - by squaring, and past a `u32` a root is a fractional power. `le plus grand de 100 et 200`/`larger of`, `le plus petit de` - take numbers of one kind, `et` separating them there rather than adding. -- **Rounding** is the line's own value, so the lines below read it rounded: - `à 2 décimales`/`to 2 dp`, `à 5 chiffres`/`to 5 digits` (places too), `arrondi`/`rounded` - (a half away from zero), `arrondi supérieur`/`inférieur`, `au 10 près`/`to nearest 10`, - `au millier près`, `à la centaine près`, combined (`arrondi supérieur au 5 près`). A quantity - rounds in the unit it is shown in. The places asked for travel with the result (`CalcLine::Value.places`) - and decide its display over the sheet's « Décimales ». -- **Bases and bits**: `0xFF`, `0b1010`, `0o377` and `5,3e+3` are numbers; `en hex`/`bin`/`oct`/ - `sci`, `en base 2|8|16`, `hex(…)`, `bin(…)`, `int(…)` say how the line's plain number is written - (`CalcValue::Base`, `Scientific`, the front putting `0x` before the digits Rust sends). - `&`, `|`, `xor`, `<<`, `>>` take whole numbers, below the sums as in C. A result is tidied to - 25 figures before it is sent, so a quotient carried on is not `15,999…` (`tidy`). -- **Words** are one table (`calc/words.rs`): each concept a `CalcWord` with its spellings in - French and in English, read in both whatever the language on screen, so a sheet keeps its - meaning for everyone. The evaluator matches concepts, a spelling of several words included; a - spelling names one concept, except the ones `SHARED` declares, where the position decides - (`de` is `Of` after a percentage, `From` opening `de … à`). A **syntax** word (`en`, `de`, - `sur`, `hors`…) is reserved: `en = 5` is an error on its line. A **value** (`total`, - `moyenne`, `aujourd'hui`…) is a name of the sheet: one defined above hides it from its line - down, so a word added later never breaks a sheet that already uses it as a name. -- **A bare word** is read, where a value is expected, as a name defined above, then a value of - the table, then a syntax word opening a form (`de … à`), else an unknown name — but a form - spelled in several words wins over a name, which is one: `mensualité de …` is the loan even - where `mensualité` names a value (`phrase_ahead`). After a number or a conversion word it is - first a scale or a unit: `5 m` is metres even where `m` is a name. -- **The percentages tool's five questions** are lines: `20 % de 340`, `30 sur 120 en %`, - `de 80 à 100`, `250 + 20 %`, `300 hors 20 %`. A percentage added to a quantity is a share of it. -- **Every percentage form** turns on what a share is taken against (`Share`: `de`/`of`, - `de plus sur`/`on`, `de moins sur`/`off`, the longest read first): `5 % de plus sur 200` - applies it; `5 % de combien font 6`/`5% of what is 6` solves for the whole; `50 en % de 100`, - `70 as a % on 20` and `180 c'est combien de % de moins que 200` give a value as a share of - another; `50 à 75 c'est combien de %` and `40 to 90 as %` a signed change, `is what x` a - multiplier. After `en`: `fraction` (the simplest within 10⁻²⁰: `1/3`), `multiple`/`x` (`×4`, - `en multiple de 5`), `décimal`/`dec`. A proportion solves for its unknown, its ratio taken - first so the unit is kept: `6 est à 60 ce que 8 est à combien`. `x`, `a` and `multiple` are - values, not syntax: they stay free names. -- **Finance**, over years of the calendar's mean length, the amount keeping its currency: - `1 000 € après 3 ans à 7 %` (compound, `composés mensuellement`/`compounding monthly` or - quarterly, yearly, daily), `intérêts sur … après …`, `500 € investis 1 500 € récupérés` (×3), - `rendement annuel sur … investis … récupérés en 7 ans` (a percentage), - `valeur actuelle de … dans 20 ans à 10 %`, and a loan `sur 6 ans à 6 %`: `mensualité de`, - `coût total de`, `intérêts totaux de`. Its amount is read up to the words of the form - (`sur 6 ans` is no ratio there); `après`, `pendant`, `after`, `for` are a length only before - a number or a name holding a duration (`for the` is prose); a rate is a percentage - (`rateExpected`). English writes `$1,000` and `@ 7%`: commas group thousands after `$`, in - `1,000,000` and in `1,578.13`, never in a lone French `1,000`. -- **Dates** move by whole days, and by calendar months for months and years; two dates subtract - into days. A duration converted into weeks keeps the days left (`6 sem 3 j`). -- **Blocks** run from a `# heading` or a blank line to the next: `total` and `moyenne` read the - quantities above in theirs. `name = …` names a result from that line down; `//` starts a - comment, which is what a copied sheet carries its results in. -- **An error stays on its line** and says why; the others go on. A line with no number and no - name is a sentence, not a mistake. - -**The editor** (`calc-editor/`) is CodeMirror with the results laid over the right edge of each -line (`sheet-marks.ts`, widgets at the line's end, mapped through each edit until the next -answer), its theme its own (`calc-theme.ts`). A result is picked by a click, Shift for a range, -Ctrl for one more, or by selecting lines of the text; the footer adds them up and averages them -— in exact decimals, on the strings Rust sent (`decimalSum`) — and says when they are of -different units. Three application preferences change the display, never the computation: -« Décimales » (`calcDecimals`, Auto or 0 to 14, in the footer and in the preferences; Auto keeps -four significant figures and never fewer than two decimals, money two), « Format -des nombres et des dates » (`calcNumberFormat`: the language on screen or one of -`CALC_LOCALES`, written by `Intl` — a locale carries no data of ours) and « Format de date » -(`calcDateFormat`: numeric, short, long). They are the application's, not the sheet's: a sheet -shared or imported reads the same everywhere. The units and the messages stay in the language -on screen. A number is handed to `Intl` as the decimal text Rust sent, never as a float, which -would invent figures past the fifteenth. After `en` or `à`, the completion proposes the units of -the kind Rust read on that line (`CALC_UNITS`), written in the language on screen; elsewhere, -from the third letter, the values and the phrases of the table (`CALC_WORDS`) in the spelling of -the language on screen — the front writes no Calcul word of its own (`CalcWords`). A name hovered says -its exact value, the line it was given on and the lines that read it. - -**Copying** — `C` on the card, « Copier » in the editor or the palette — gives the text with each -result after its line as a comment (`CalcFormatter.copyText`): pasted into another sheet, the -comments are read past and the same lines compute again. The front writes it, since Rust knows no -word on screen; `DisplayNote.copy_text` stays `None`. **One result** copied -(`CalcFormatter.exact`) is pasted back into a sheet, so its thousands are never grouped, whatever -the number format: `1.578` (de-DE) and `1,578` (en-US) would read back as decimals, so every -format copies `1578,13 €` or `1578.13 €`; the result column keeps the format chosen. - -### A Note is written formatted, and stored as Markdown - -A Note is a kind of its own (`NoteKind::Note`), edited in the rich editor instead of the code -field (`Note::is_rich_text`), and its body is still one -string: it is sealed, exported, copied, searched and kept in revisions like a snippet's. A -snippet in `txt` is plain text, in the code field. What the editor writes is GitHub-flavoured -Markdown, and it offers only what that can hold — headings, emphasis, inline code, lists, task -boxes, quotes, tables, links, code blocks. No underline. A code block keeps its language in its -fence, picked from the toolbar while the caret is in it (`txt` writes the fence bare). Sharing -and exporting write a Note as the Markdown it is, where a snippet is fenced. - -- **The document is `richtext`'s** (egui migration, no egui in it): blocks and marked runs, - read by `pulldown-cmark` with the core's own options (`notes::markdown` holds the two equal in - a test) and written back byte for byte, as `golden/markdown` - and `golden/markdown-escape` hold. What the schema does not hold is read as what it shows: - raw HTML as its text, a footnote as its brackets, a reference link inline, a bare `https://` - address as a link to itself. A cell and a heading hold one line: their breaks are `
`. - `richtext::escape` is `escapeMarkdownText`, ported rule for rule. - Undo keeps the document and the selection before each transaction (`History`): a Note is a - few kilobytes. -- **Editing is `richtext::edit`'s**, the view `overlays/editor/rich.rs`'s. A caret is a path to a - leaf — a paragraph, a heading, a cell, a code block — through items, quotes and tables, and a - `char` offset; each operation takes the selection and answers the next one, as the reference's - keymap did: Enter in an empty item leaves the list, Backspace at an item's start lifts it, Tab - nests it under the one above. The view draws through `widgets::rich` (the reader's own - layout), which says where each leaf was laid out: the caret, a click and ↑ ↓ are read from those - galleys. A double click takes the word under the pointer — `text::word_around`, the code - editor's classes of a word — and a triple click the leaf. A Note opened and left is written back untouched — the Markdown is rewritten only once - something changed. After a toolbar button the text takes the keys back, as the reference's - `mousedown` kept them. A task's box is a control of its own (`rich-task`). -- **A paste reads the clipboard itself**: egui hands the field the text alone, so the editor asks - `platform::clipboard` (`arboard`) for the page's HTML. HTML the reference called formatted — - emphasis, a link, a heading, a list, a quote, a table, and no `pre` or `code` — goes in as - blocks (`richtext::from_html`, on `html5ever`'s tokenizer; `golden/html-paste` passes - whole); code pasted into an empty Note makes it a snippet, the conversion detecting its - language; anything else is text. A pasted image becomes an attachment, as in every editor. -- **Two copies**: Ctrl+C, Cut and the menu put text on the clipboard that keeps its blocks — - `- `, `3. `, `- [ ] ` on an item's first line, two spaces a level, `> ` in a quote — and none of the - inline marks (`richtext::edit::copied`); « Copy as Markdown » (Ctrl+Shift+C, the right-click - menu) writes the same selection as the Note's Markdown (`copied_markdown`). Both walk one - fragment, the selection cut out of the document; within one leaf, a copy is its text alone. -- **An embedded drawing is read where it is shown**: `devnotes:drawing/` asks - `LibraryCaches.pictures` (the large picture, by id, decoded off the frame and kept with the - thumbnails' limit); a drawing saved again drops it. Any other image stays as written: a Note - never fetches an address. **Ctrl+F and Ctrl+H** open the code's find bar over the text the reader - sees (`search_bar::Searchable`): no match crosses from one block into the next, and a - replacement wears what the match it replaces wore. - -- **⚠️ The escaping is the reference's, not a Markdown library's.** A general escaper turns - every `_ * ~ [ ] \` into syntax and `& < >` into entities, so `{{db_host}}` stops being a field - and `a -> b` is stored as `a -> b`. `richtext::escape` escapes a character only where it - would read as syntax and never inside a `{{field}}` (the shield, D10), held by - `golden/markdown-escape`. A `*` or `_` with a space inside (« 2 \* 3 \* 4 ») is kept as typed. -- **A card shows a Note's shape, not its Markdown.** `notes::markdown::outline` - (pulldown-cmark) reads the body into one line per block, each saying what it is — a heading, - an item and its marker, a task, a code block, text, table cells joined by `·` — and the card - draws those (`DisplayNote.outline`), cut to a card's lines. `plain` - is the same lines with their markers spelled out (`•`, `1.`, `☐`/`☑`): `cut_to_preview` - puts it in place of the body, one parse for both, marked `truncated` even when it is short — - a copy taken from the list rereads the Markdown instead of copying the words. The search - matches and quotes the readable body (`Note::readable_body`), folded once by the index: « rollout - window » finds `**rollout** window`, and a drawing is found by its words, never its scene. The - trash shows the same text, its first lines cut by the core (`TrashedNote.preview`), without - the body. A snippet names - its format on its card and in the palette, a Note and a list their kind (`notes::ui::kind_icon`). -- **Typing never changes the kind; a paste into an empty Note can.** Plain text pasted into an - empty Note is handed to `detect_language`. Prose - stays a Note and is written as it is; code is written as a snippet with its language, in one - patch, and the note moves to the code field with its characters intact — the rich editor - would have folded its indentation into paragraphs. -- **A code block is coloured by the code's grammars** (`text::highlight`, → "Syntax - highlighting"), its language as a label on the block, drawn plain until the grammars have - loaded. Tab indents as the code does (`indent_unit`). A card and a search read its lines as - they are (`notes::markdown::plain`). It is left at its end by a third Enter, after two blank - lines, and by ↓ on its last line when nothing follows it: `edit::leave_code` opens a paragraph - after it, which is not written while it is empty. -- **« Présenter » shows the Note full screen, a slide at a time.** Rust cuts the draft on - screen, not the stored body (`present_note`, `notes::markdown::present`): a slide starts at - each `#` or `##` heading and after each `---` rule outside any list, quote or fence, each slide - a slice of the body so it is drawn as written, empty ones dropped; the headings come back as a - tree, each with the slide it is on. `overlays::presentation` puts the Note's title first as a - cover and draws each slide with `widgets::rich` read only and larger — the editor's own blocks - and colours — from the top and the left margin, so a title is at one place on every slide, a - code block centred on the screen, no wider than its code, its lines wrapped. A slide taller than - the screen is drawn smaller but for its title, down to 60 %, then scrolls; it is measured out of sight in the pass - that first shows it, which egui draws over (`request_discard`). - ← → (and the keys a clicker sends), Home/End, `M` for the map, Escape out: a modal over - everything, the editor kept under it. `PresentationState` sends `ViewportCommand::Fullscreen` - only when the window was not full screen already, and gives back only what it took — on - leaving, and when another library opens. The map (`presentation::mind_map`, checked against - the `mind-map` corpus) rings the headings around the title, a share of the sector by leaves, - stretched to the screen; its headings are buttons over the links, one pressed opens its slide. -- **The editor says what it holds.** A "Note" badge sits where a snippet has its format menu, - and the footer counts the draft's words (`countWords`) where a snippet counts lines and bytes: - counting the draft is the interface's job, as the line count is. The toolbar runs headings, what - marks words (the link among them), blocks, then what is inserted, each tool naming its key. -- **A link opens on Ctrl+click**, through `platform::links`, which refuses any scheme but - `http` and `https`: a `file:` link is a program to run. A plain click places the caret, as it does everywhere else in the text, - so the pointer turns to a hand only while Ctrl is held, and the surface carries the "Ctrl+click - to open" tooltip: a link's own `title` is its Markdown title. The link form edits the words - and the address; words left as they were keep their formatting and only gain the mark. -- The draft is committed when the focus leaves and on every closing path, like the code's, so - the last keystrokes are not lost. -- **Tab is a character once lists and tables pass on it**: it nests a list item, moves to the - next cell, and otherwise types a tab. ⚠️ A tab starting a line is written ` ` - (`richtext::escape`), since Markdown reads a leading tab as an indented code block, or drops it - after a line break; reading decodes it back. - -### A Dessin: a scene, and its pictures beside it - -A Dessin (`NoteKind::Drawing`) is drawn in `overlays/editor/drawing.rs` over `drawing::Editor`. -**Its body is the scene alone** — `{ version, scene }`, the JSON of Fabric, which drew it in the -reference — and Rust reads it only for its words (`notes::drawing::words`, the texts on it, -through the groups): what a search matches and quotes, what a conversion or the Markdown share -gives. It has no field (`{{x}}` written on it is words), no revision (a scene compares as no -text), no copy (a card and the palette offer none: it is exported), and no conversion either -way — the kind menu names it and offers nothing. - -- **An arrow holds on to a shape by its edge, facing its other end, or by the middle of a side**: - `from` and `to` are the shapes' ids, `fromAnchor` and `toAnchor` (`top`, `right`, `bottom`, - `left`, on the shape's own plane) the side, absent for the edge. -- **⚠️ Its pictures are not in the body.** A list opens every body it searches, at every - keystroke; two PNGs are most of a drawing's bytes. They sit in `drawing_pictures`, one row - per drawing, both sealed as raw bytes, cascaded with the note: a small one for its card, a - large one for a Note that embeds it. The editor takes them only when it flushes — on blur and - on every closing path, never as it draws — and they go with the body in one patch - (`NotePatch.pictures`, validated as PNGs before the lock, written by `store::update_drawn` - in the patch's transaction; both empty takes them away). A new drawing's first pictures - follow the write that makes it (`NotesStore.editDraft`). A list sends none - (`cut_to_preview` clears the body): a card asks `drawing_thumbnail` once drawn, through - `DrawingPicturesStore`, kept until the drawing's next save (`updatedAt`) or its pictures' - (`redrawn`, which moves no date); a duplicate takes them, an export does not. A drawing - that has none, as one that came by import, has them taken when it opens: the editor asks - `hasPictures` and they go with its next flush. -- **`crates/drawing` reads the scene** (`Drawing::read`, `write`): an object is the fields it was - read with and is read through them, so a body comes back byte for byte (`golden/fabric`, in - Fabric's format); `serde_json`'s `preserve_order` and `float_roundtrip` are what hold that. -- **One line break, one way to a picture** (D23): `text::wrap` is Fabric's `_wrapLine` on the advances - of the embedded fonts, for the editor and the pictures; a browser kerns, so a word can break - elsewhere (one case of `golden/fabric-wrap`). `picture::svg` writes the export from the scene - and `resvg` rasterises it (`pictures`, 480 and 1,600 px). ⚠️ `resvg` knows no - `non-scaling-stroke`: a `strokeUniform` shape has its geometry scaled, not its plane. -- **What is drawn keeps its colours by name.** Each object carries a `hue` (ink, blue…), - painted from the tokens on `:root` (`paletteOf`), so a theme changed later redraws it; the - pictures are taken on the theme's paper (`--bg-1`). ⚠️ Fabric 7 places an object by its - centre: `left`/`top` are the middle of the box a drag covers. -- **An arrow started or ended on a shape stays on its edge** (`from`/`to` ids, `ends`, - `boundEnds`): it follows the shape as it moves, and a shape removed lets go of it. A path's - box is read when it is made, so an arrow whose ends move is made again in its place. -- **The look is the view's** (`drawing::camera`, `drawing::look`): zoom between 10 and 800 %, and - the pan, never in the scene. Wheel pans, Ctrl+wheel or a pinch zooms under the pointer, the - middle button or Space and a drag pans; Ctrl with +, −, 0 and the arrows, `F` for the whole. A - drawing larger than the stage opens fitted. `Editor::set_scale` keeps the handles and a click - at their size on the screen. -- **`drawing::Editor` holds every gesture**, in the scene's units, with no egui: `press`, `drag` and - `release`, a selection framed by its handles, each step read from the objects as they were when - the gesture began, so nothing drifts. The widget paints `marks`, the scene flattened to lines and - words. A click moves nothing: an arrow is rebound only when something moved. -- **The editor**: a toolbar in the app's look (selection, rectangle, ellipse, diamond, arrow, - freehand, text, by their letters; six swatches; undo, redo and delete; Escape drops the tool - and gives back the selection it was taken over, then drops the selection, then leaves), a - history of the scene's states, and an export as PNG or SVG (`drawing::export`), written with - `tools::write_file` where `FileDialog` says. ⚠️ `rfd`'s dialog blocks until answered, so the whole - export runs on `compute`, never on the window's thread. A journey answers it through - `DEVNOTES_E2E_DIALOG` (`Files::answer`). -- **A Note embeds one by its id**: `![title](devnotes:drawing/)`, the Markdown image of - TipTap's extension, drawn by a node view that asks `drawing_picture` (`rich-text-drawings.ts`); - the Note's body carries no picture. Inserted from the toolbar's « Insérer un dessin », whose - list is `list_drawings` (titles only opened), and which is there with no drawing to say there - is none. Any other image stays as written: the CSP loads nothing from elsewhere. -- **Its size is in its reference**: `devnotes:drawing/?w=50`, a percent of the text's width - from 10 to 100, read and written by `richtext::picture` alone; without one the drawing is at its - own size, and any other query is left as written. In the editor an image is picked by a click - or by the arrows, in the caret's place: a drawing's corners, its sizes and `Alt` with an arrow - change it, Backspace and Delete take it away (`editor/rich/images.rs`). Read and presented, it - obeys. - -### A list sends previews, and the body is read by id - -A card shows each body cut to its room — `notes::model::PREVIEW_LINES` lines, and at most -`PREVIEW_CHARS` characters, since a minified file is one line — and says so with -`DisplayNote.truncated`. `query_notes` answers no copy at all: its sections hold -`view::Card`s, the index's own `Arc` entries with the quote of what the search -found, and `NotesView::display(card)` computes what one card draws (footer, fields, chip, -counter, preview) for the cards on screen only. The cut is its **last** pass, as it is of -`board::build`: the fields, the matching and the search excerpt read the whole body first, so a -list still knows a snippet has a `{{field}}` on its fortieth line, and still quotes the line a -search found there. - -⚠️ **A note from a list is never edited.** `NotesStore.openNote` takes an id and reads the note -with `get_note`, every time: a draft seeded from a preview would write the first lines back -over the body on the first commit. Every other way into the open note is a write's answer, -which is the whole row, so the editor holds a whole note by construction. A later open, a new -note or a close while the read is on its way wins over it. - -A copy or a fill of a card goes through `NotesRepository.whole`, which reads the note only when -it is `truncated`: the card's copy button takes a function and asks at the click, and the ⚡ -form and the palette fill the whole body. A todo list is never cut — it has no body — and -copies its `copyText` without a round trip. - -The palette used to hand the note itself to the editor (#280), because nothing on the bridge -could read one the canvas filters hid. `get_note` is that read, so it passes the id like the -canvas does. The trash still sends whole bodies: it is not on the keystroke path, and nothing -in it is copied. - -### A card is two layers, and the click surface is the lower one - -A `