Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/devnotes-security-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Checklist on the change (`git diff main...`, and `git diff HEAD` for what is not
1. **Sealed line**: titles, bodies, sources, items, names, field values, attachments stay sealed; no new plaintext copy (logs, temp files, `open/`, caches, error messages, history that skips `mask`).
2. **Lock/unlock**: nothing answers while `Db` is empty; no command bypasses the lock; HTTP sends never hold the lock.
3. **Files**: staged then renamed for anything that must not be half-written; attachment names pass `model::stored_name`; no path built from imported ids without the filter; backups re-wrapped when the passphrase changes.
4. **Interface and platform**: the passphrase only in `PassphraseField` (never a `TextEdit`), eframe persistence off, every cache of library content in `LibraryCaches`; links opened `http`/`https` only (`platform::links`); `egui_inspection` only in the `e2e` flavour; request scripts only in the script host (QuickJS), never `eval` of note content elsewhere; nothing logged but codes and locations (D18): a new place where a person types gets a step in `state::logged_tests`, the sentinel session, and no log line formats a value that carries content with `{:?}`.
4. **Interface and platform**: the passphrase only in `PassphraseField` (never a `TextEdit`), eframe persistence off, every cache of library content in `LibraryCaches`; links opened `http`/`https` only (`platform::links`); `egui_inspection` only in the `e2e` flavour; request scripts only in the script host (QuickJS), never `eval` of note content elsewhere; nothing logged but codes and locations (D18): a new place where a person types gets a step in `state::logged_tests`, the sentinel session, no log line formats a value that carries content with `{:?}`, and what a person wrote reaches a line only through `engine::sensitive::Sensitive`, never in a `warn` or an `error` (D35).
5. **Network/privacy**: no telemetry, no data in URLs; `Authorization`/API keys masked in history.
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.
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Read at the `angular-reference` tag; the egui mechanism is in `docs/architecture

## Security and verification

- Never rewrite cryptography, key derivation or file formats unasked. Never log or commit passphrases, keys or note content (a panic hook logs location and thread, never the message — D18). eframe persistence stays off. `.claude/rules/security.md` holds the agent limits.
- Never rewrite cryptography, key derivation or file formats unasked. Never log or commit passphrases, keys or note content: what a person wrote reaches a log line only through `engine::sensitive::Sensitive`, whole in a debug build's terminal alone (D35); a panic hook logs location and thread, never the message (D18). eframe persistence stays off. `.claude/rules/security.md` holds the agent limits.
- **A change the user sees updates what shows it, in the same pull request**: `docs/content/{fr,en}` (the site and the application read it; `docs_quotes` fails on a label renamed), the README's GIFs in `docs/gifs/` (`cargo run -p app --example tours`) and the site's scenes when they show the screen that changed. Publishing is `website.yml`'s.
- Before saying a change is done, run the checks for what changed (`verify-change`) and report only what actually ran.

Expand Down
62 changes: 50 additions & 12 deletions crates/app/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ impl Build {
Self::E2e => LevelFilter::Trace,
}
}

/// How many lines below the file's level are kept for the next warning. None in a debug
/// build: its terminal shows what a person wrote, which must not reach the disk.
fn kept_before(self) -> usize {
match self {
Self::Debug => 0,
Self::Release | Self::E2e => BEFORE,
}
}

/// Whether what a person wrote is shown whole: in a debug build's terminal alone.
fn reveals(self) -> bool {
matches!(self, Self::Debug)
}
}

/// Kept by `main` until the end: dropping the handle stops the logger. `None` when the
Expand All @@ -75,6 +89,14 @@ pub(crate) fn start(directory: &Path) -> Option<LoggerHandle> {
start_as(directory, Build::RUNNING)
}

/// Shows what a person wrote whole, in a debug build: the binary's call alone, so that its
/// tests, which start the log too, never do.
pub(crate) fn reveal_in_development() {
if Build::RUNNING.reveals() {
engine::sensitive::reveal();
}
}

fn start_as(directory: &Path, build: Build) -> Option<LoggerHandle> {
let asked = std::env::var_os(LEVELS).map(|asked| asked.to_str().map(LogSpecification::parse));
let unreadable = matches!(asked, Some(None | Some(Err(_))));
Expand All @@ -93,7 +115,7 @@ fn start_as(directory: &Path, build: Build) -> Option<LoggerHandle> {
.try_build()
.and_then(|file| {
Logger::with(levels.clone())
.log_to_writer(Box::new(Kept::new(file, build.file())))
.log_to_writer(Box::new(Kept::new(file, build.file(), build.kept_before())))
.duplicate_to_stderr(build.terminal())
.format_for_stderr(line)
.start()
Expand Down Expand Up @@ -137,12 +159,14 @@ const BEFORE: usize = 200;
struct Kept {
file: FileLogWriter,
keeps: LevelFilter,
/// How many lines `before` holds at most.
room: usize,
before: Mutex<VecDeque<String>>,
}

impl Kept {
fn new(file: FileLogWriter, keeps: LevelFilter) -> Self {
Self { file, keeps, before: Mutex::new(VecDeque::with_capacity(BEFORE)) }
fn new(file: FileLogWriter, keeps: LevelFilter, room: usize) -> Self {
Self { file, keeps, room, before: Mutex::new(VecDeque::with_capacity(room)) }
}

/// The file's writer writes what it is handed: the lines are formatted as they come.
Expand All @@ -154,7 +178,7 @@ impl Kept {
impl LogWriter for Kept {
fn write(&self, now: &mut DeferredNow, record: &Record<'_>) -> std::io::Result<()> {
let below = record.level() > self.keeps;
if below && !ours(record.target()) {
if below && (self.room == 0 || !ours(record.target())) {
return Ok(());
}
let mut text = Vec::new();
Expand All @@ -163,7 +187,7 @@ impl LogWriter for Kept {
// Held until written: another thread's lines come before or after these, never between.
let mut before = self.before.lock().unwrap_or_else(PoisonError::into_inner);
if below {
if before.len() == BEFORE {
if before.len() == self.room {
before.pop_front();
}
before.push_back(text);
Expand Down Expand Up @@ -459,9 +483,9 @@ mod tests {

#[test]
fn a_warning_is_filed_after_the_lines_that_led_to_it_and_the_next_after_those_since() {
when_apart(Build::Debug, || {
when_apart(Build::Release, || {
log::info!(target: "ui::action", "#1 Notes::OpenNote");
log::debug!(target: "ui::backend", "db #1 notes::get 2 ms ok");
log::info!(target: "engine::notes", "updated note-1 (Note): content");
log::warn!(target: "ui::services::errors", "the first warning");
log::info!(target: "ui::action", "#2 Notes::Editor::Close");
log::error!(target: "engine::db", "an error");
Expand All @@ -474,10 +498,9 @@ mod tests {
holds_in_order(
&filed_from(&file, "lines before"),
&[
"— the 3 lines before —",
concat!(env!("CARGO_CRATE_NAME"), "::logging: Logging at"),
"— the 2 lines before —",
"ui::action: #1 Notes::OpenNote",
"ui::backend: db #1 notes::get 2 ms ok",
"engine::notes: updated note-1 (Note): content",
"] ui::services::errors: the first warning",
"— the line before —",
"ui::action: #2 Notes::Editor::Close",
Expand All @@ -504,8 +527,23 @@ mod tests {
}

#[test]
fn a_dependency_line_is_never_kept_for_the_file() {
fn a_debug_build_files_its_warnings_without_the_lines_before_them() {
when_apart(Build::Debug, || {
log::info!(target: "engine::notes", "updated note-1 (Note): content « psql -h prod »");
log::debug!(target: "ui::backend", "db #1 notes::update 1 ms ok");
log::warn!(target: "engine::notes", "a warning line");
});

let (terminal, file) = apart("a_debug_build_files_its_warnings_without_the_lines_before_them", &[]);

holds(&terminal, &["psql -h prod", "notes::update", "a warning line"]);
holds(&file, &["a warning line"]);
lacks(&file, &["lines before", "line before", "psql -h prod", "notes::update"]);
}

#[test]
fn a_dependency_line_is_never_kept_for_the_file() {
when_apart(Build::Release, || {
log::debug!(target: "wgpu_core", "a dependency's debug");
log::debug!(target: "engine::notes", "a debug line");
log::warn!(target: "engine::notes", "a warning line");
Expand Down Expand Up @@ -618,7 +656,7 @@ mod tests {
#[test]
fn a_panic_ends_the_process_once_its_place_is_in_the_log() {
if let Some(directory) = std::env::var_os(PANIC_IN) {
let _logger = start(Path::new(&directory));
let _logger = start_as(Path::new(&directory), Build::Release);
install_panic_hook();
log::info!(target: "ui::action", "#7 Notes::Delete");
panic!("psql -h prod -W hunter2");
Expand Down
1 change: 1 addition & 0 deletions crates/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn main() -> ExitCode {
}
};
let _logger = logging::start(&locations.logs);
logging::reveal_in_development();
#[cfg(feature = "profiling")]
let _profiler = profiler();

Expand Down
5 changes: 4 additions & 1 deletion crates/engine/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ fn copy(db: &Db) {
let directory = connection.directory().to_path_buf();

match rotate(&directory, &mut connection, Utc::now()) {
Ok(Some(target)) => log::info!("Library copied to {}", target.display()),
// The copy's name alone: its path holds the person's home.
Ok(Some(target)) => {
log::info!("Library copied: {}", target.file_name().unwrap_or_default().display());
}
Ok(None) => {}
Err(error) => log::warn!("No backup taken: {error}"),
}
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) mod count;
pub(crate) mod durable;
pub mod layout;
pub(crate) mod name;
pub mod sensitive;

use std::sync::{Arc, Mutex, MutexGuard};

Expand Down
61 changes: 61 additions & 0 deletions crates/engine/src/sensitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! What a person wrote, in a log line: whole in a development build's terminal, its length
//! everywhere else (D35).

use std::fmt;
use std::sync::atomic::{AtomicBool, Ordering};

static REVEALED: AtomicBool = AtomicBool::new(false);

/// Shows every [`Sensitive`] whole from now on. Called once by a development build's binary,
/// whose file keeps no line below a warning; nothing else calls it, the tests included.
pub fn reveal() {
REVEALED.store(true, Ordering::Relaxed);
}

/// Text a person wrote — a title, a body, a name, a URL —, in a line at `info` or below.
/// ⚠️ Never in a warning or an error: those reach the file of every build. No `Debug`, which
/// `{:?}` would print whole.
pub struct Sensitive<'a>(pub &'a str);

impl fmt::Display for Sensitive<'_> {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
shown(self.0, REVEALED.load(Ordering::Relaxed), out)
}
}

fn shown(text: &str, revealed: bool, out: &mut fmt::Formatter<'_>) -> fmt::Result {
if revealed {
return write!(out, "« {text} »");
}
match text.chars().count() {
1 => write!(out, "‹1 char›"),
count => write!(out, "‹{count} chars›"),
}
}

#[cfg(test)]
mod tests {
use super::*;

/// Both branches, the process's switch left alone: other tests run beside this one.
struct Shown<'a>(&'a str, bool);

impl fmt::Display for Shown<'_> {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
shown(self.0, self.1, out)
}
}

#[test]
fn what_was_written_is_its_length_until_revealed() {
assert_eq!(Sensitive("psql -h prod").to_string(), "‹12 chars›");
assert_eq!(Sensitive("é").to_string(), "‹1 char›");
assert_eq!(Sensitive("").to_string(), "‹0 chars›");
}

#[test]
fn revealed_it_is_whole() {
assert_eq!(Shown("psql -h prod", true).to_string(), "« psql -h prod »");
assert_eq!(Shown("psql -h prod", false).to_string(), "‹12 chars›");
}
}
2 changes: 1 addition & 1 deletion docs/architecture/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ in the code.
| 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. |
| D35 | Logs | Terminal: our crates from `debug` in a debug build, from `info` in a release. File: `warn` and `error`, after our last 200 lines. The e2e flavour files from `debug`, its terminal errors alone. Other crates at `warn`. A line says names, codes, ids, durations, never content (D18). `DEVNOTES_LOG` replaces the levels for one run. |
| D35 | Logs | Terminal: our crates from `debug` in a debug build, from `info` in a release. File: `warn` and `error`, after our last 200 lines in a release, alone in a debug build. The e2e flavour files from `debug`, its terminal errors alone. Other crates at `warn`. A line says names, codes, ids, durations; what a person wrote only through `Sensitive`, whole in a debug build's terminal, its length elsewhere, never in a warning (D18). `DEVNOTES_LOG` replaces the levels for one run. |
| D36 | Names | Six values of the root `Cargo.toml`'s `[workspace.metadata]`, read by `crates/brand` and `scripts/names.mjs` alone: every name of the code, the disk, the packages, the docs and the site follows them, save a few Cargo and files keep literal, held by a test. Renaming is the owner's call (→ "The application's names"). |
34 changes: 21 additions & 13 deletions docs/architecture/project/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ What the application writes about itself, where, at which level, and what a line
**In short**

- One log, two outputs: the terminal, for whoever launched it, and a file that keeps
warnings and errors, each after the lines that led to it.
warnings and errors, each after the lines that led to it in a release.
- Every action of the person is a line at `info`; every call to the core a line at `debug`.
- A line says names, codes, ids and durations — never what was typed.
- A line says names, codes, ids and durations; what was typed only through `Sensitive`, whole in
a debug build's terminal, its length everywhere else.
- `DEVNOTES_LOG` changes the levels for one run.

## The three outputs

`crates/app/src/logging.rs` starts the log before the window (→ "The binary, its profile and its
window"): one `flexi_logger`, a terminal and a file, each at its own level.

| Build | Terminal | File (`<slug>.log`) |
| ------------------ | ----------------------- | ----------------------- |
| debug | our crates from `debug` | `warn` and `error` |
| release | our crates from `info` | `warn` and `error` |
| the `e2e` flavour | `error` alone | our crates from `debug` |
| Build | Terminal | File (`<slug>.log`) |
| ----------------- | ----------------------- | ------------------------ |
| debug | our crates from `debug` | `warn` and `error` alone |
| release | our crates from `info` | `warn` and `error` |
| the `e2e` flavour | `error` alone | our crates from `debug` |

Our crates are the workspace's: the binary's own (`CARGO_CRATE_NAME`), `ui`, `engine`, `platform`, `text`,
`richtext`, `drawing` and `i18n`. Every other crate stays at `warn` in every build: its `debug`
Expand All @@ -44,12 +45,19 @@ Each line, on both outputs: local time to the millisecond, level, thread, target

## What a line may say

Names, codes, ids and durations; never what a person typed or wrote, a passphrase or a key
(D18). An error goes through `AppError::for_log`: its code, and its detail only where nothing typed
Names, codes, ids and durations; never a passphrase or a key (D18), and what a person typed or
wrote only through `engine::sensitive::Sensitive`. An error goes through `AppError::for_log`: its code, and its detail only where nothing typed
is in it. A panic is logged by its place and its thread, never its message. ⚠️ Never `{:?}` of a
value that carries content: a derived `Debug` prints the payload, a checklist's items or a request's
URL.

**`Sensitive`** is the one way into a line for a title, a body, a name, a URL: whole in a debug
build's terminal, `‹27 chars›` everywhere else. The binary of a debug build turns it on, once,
after the log starts (`logging::reveal_in_development`); a release, the e2e flavour and every test
leave it off. A debug build's file keeps no line before a warning, so what it shows stays in the
terminal; a release's journal, where a Linux desktop keeps its terminal, sees the length alone.
⚠️ Never in a `warn` or an `error`: those reach the file of every build. It has no `Debug`.

**The rule's guard** is `state::logged_tests` (`crates/ui`): a session applies the actions a person
sends — a library and its phrase, a space, a folder, four kinds of note, a field's value, an
attachment, a search, a move, a tag, the trash, an undo, a request with its header, body, variable,
Expand Down Expand Up @@ -106,14 +114,14 @@ call, and a list of exceptions would be one more thing to keep.
A warning alone says what failed, not what led to it, and a release's terminal is seen by no one.
`Kept`, the file's writer in `logging.rs`, keeps the last 200 lines below what the file keeps, of
our crates alone (a dependency's `debug` may hold a path or a URL): the lines the terminal shows
under the levels in force, the actions in a release, the calls too in a debug build. A warning or
an error writes them into the file first, then itself, and empties them:
under the levels in force, in a release. A debug build keeps none, its terminal showing what a
person wrote (→ "What a line may say"). A warning or an error writes them into the file first,
then itself, and empties them:

```text
— the 3 lines before —
— the 2 lines before —
2026-12-04 10:12:04.207 INFO [main] ui::action: #411 Notes::ClearSearch
2026-12-04 10:12:05.031 INFO [main] ui::action: #412 Notes::OpenNote
2026-12-04 10:12:05.033 DEBUG [db] ui::backend: db #412 notes::get 1 ms NoteNotFound
2026-12-04 10:12:05.040 WARN [main] ui::services::errors: errors.noteGone: NoteNotFound: …
```

Expand Down
Loading