Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

Notes stay inside their pane; done notes clear together

Indicode BV22082b5c451a
diff --git a/crates/app/src/editor/pins.rs b/crates/app/src/editor/pins.rs
index 567f499..52c01d7 100644
--- a/crates/app/src/editor/pins.rs
+++ b/crates/app/src/editor/pins.rs
@@ -132,7 +132,7 @@ impl Editor {
.unwrap_or_default();
}
- fn reread_pins(&mut self) {
+ pub(super) fn reread_pins(&mut self) {
self.pins = notes::read(&self.scene.bundle);
}
@@ -275,23 +275,27 @@ impl Editor {
go = Some((n.frame, n.id));
}
});
+ let mut clear = false;
if !done.is_empty() {
- ui.collapsing(format!("done ({})", done.len()), |ui| {
+ let id = ui.make_persistent_id("done notes");
+ let header = egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false)
+ .show_header(ui, |ui| {
+ let named = ui
+ .add(egui::Button::new(format!("done ({})", done.len())).frame(false))
+ .hint("show or hide the notes the agent marked done")
+ .clicked();
+ let cleared = ui
+ .with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ ui.button("clear all")
+ .hint("remove every done note, as klad notes --clear-done")
+ .clicked()
+ })
+ .inner;
+ (named, cleared)
+ });
+ let (_, head, _) = header.body(|ui| {
done.iter().for_each(|n| {
- ui.horizontal(|ui| {
- if ui
- .add(
- egui::Button::new(
- RichText::new(format!("{} {}. frame {}: {}", icon::CHECK, n.id, n.frame, n.text))
- .color(theme::WEAK),
- )
- .truncate(),
- )
- .hint("go to its frame and open it")
- .clicked()
- {
- go = Some((n.frame, n.id));
- }
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui
.button("open again")
.hint("the agent should look at it again")
@@ -299,9 +303,45 @@ impl Editor {
{
reopen = Some(n.id);
}
+ ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
+ if ui
+ .add(
+ egui::Button::new(
+ RichText::new(format!(
+ "{} {}. frame {}: {}",
+ icon::CHECK,
+ n.id,
+ n.frame,
+ n.text
+ ))
+ .color(theme::WEAK),
+ )
+ .truncate(),
+ )
+ .hint("go to its frame and open it")
+ .clicked()
+ {
+ go = Some((n.frame, n.id));
+ }
+ });
});
});
});
+ let (named, cleared) = head.inner;
+ clear = cleared;
+ if named {
+ let mut state = egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false);
+ state.toggle(ui);
+ state.store(ui.ctx());
+ }
+ }
+ if clear {
+ let removed = notes::clear_done(&self.scene.bundle)?;
+ self.reread_pins();
+ self.say(
+ Tone::Done,
+ format!("removed {removed} done note{}", if removed == 1 { "" } else { "s" }),
+ );
}
if let Some(id) = reopen {
notes::set_done(&self.scene.bundle, id, false)?;
diff --git a/crates/app/src/editor/ui_tests.rs b/crates/app/src/editor/ui_tests.rs
index da05334..2ad05b5 100644
--- a/crates/app/src/editor/ui_tests.rs
+++ b/crates/app/src/editor/ui_tests.rs
@@ -1096,6 +1096,66 @@ fn the_history_lists_you_and_the_agent_and_steps_back_to_a_clicked_step() {
let _ = std::fs::remove_dir_all(&path);
}
+#[test]
+fn notes_stay_one_line_inside_the_pane_and_done_ones_clear_together() {
+ use klad_core::notes;
+ let path = sample("notes-pane");
+ let long = "make the lantern glow warmer and push the shadow under the ledge further left, then soften the rim light on the far side of the rock";
+ {
+ let b = Bundle::open(&path).unwrap();
+ (0..3).for_each(|i| {
+ notes::add(&b, (40.0 * i as f32, 50.0), 0, &format!("{i} {long}"), "user").unwrap();
+ });
+ notes::set_done(&b, 2, true).unwrap();
+ notes::set_done(&b, 3, true).unwrap();
+ }
+ let mut h = harness(editor(&path), vec2(1440.0, 1000.0));
+ [
+ (Pane::Tool, true),
+ (Pane::Layers, true),
+ (Pane::Inspector, true),
+ (Pane::Notes, false),
+ ]
+ .into_iter()
+ .for_each(|(pane, collapsed)| {
+ if let Some(p) = h.state_mut().settings.layout.pane_mut(pane) {
+ p.collapsed = collapsed;
+ }
+ });
+ h.state_mut().reread_pins();
+ h.run_steps(3);
+ h.get_by_label_contains("done (2)").click();
+ h.run_steps(2);
+ let edge = h
+ .query_all_by_label(theme::icon::CLOSE)
+ .map(|n| n.rect().right())
+ .fold(0.0, f32::max);
+ assert!(edge <= 1440.0, "the panes' close buttons stay in the window: {edge}");
+ let rows: Vec<Rect> = h
+ .query_all_by_label_contains("make the lantern glow")
+ .chain(h.query_all_by_label("open again"))
+ .map(|n| n.rect())
+ .collect();
+ assert_eq!(rows.len(), 5, "{rows:?}");
+ rows.iter().for_each(|r| {
+ assert!(
+ r.right() <= edge + 0.5,
+ "a row runs past the pane: {r:?}, the pane ends at {edge}"
+ );
+ assert!(r.height() < 40.0, "a note stays one line: {r:?}");
+ });
+ h.get_by_label("clear all").click();
+ h.run_steps(2);
+ let left = notes::read(&Bundle::open(&path).unwrap());
+ assert_eq!(
+ left.iter().map(|n| n.id).collect::<Vec<_>>(),
+ [1],
+ "only the open note stays"
+ );
+ assert!(h.query_by_label_contains("done (").is_none());
+ let _ = std::fs::remove_dir_all(&path);
+}
+
#[test]
fn a_note_pinned_on_the_canvas_is_marked_done_by_the_agent_and_edited_from_its_pin() {
use klad_core::notes;
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
index 830ebfd..196dcc3 100644
--- a/crates/cli/src/main.rs
+++ b/crates/cli/src/main.rs
@@ -1591,13 +1591,17 @@ enum Command {
#[arg(long)]
json: bool,
},
- #[command(about = "Notes the human pinned on the canvas; --done <id> marks one as handled")]
+ #[command(
+ about = "Notes the human pinned on the canvas; --done <id> marks one as handled, --clear-done removes the handled ones"
+ )]
Notes {
bundle: PathBuf,
#[arg(long)]
done: Option<u32>,
#[arg(long, help = "Include notes already marked done")]
all: bool,
+ #[arg(long, help = "Remove every note marked done")]
+ clear_done: bool,
#[arg(long)]
json: bool,
},
@@ -3250,8 +3254,15 @@ fn run() -> Result<()> {
bundle,
done,
all,
+ clear_done,
json,
- } => history::notes(&bundle, done, all, json)?,
+ } => match clear_done {
+ true => {
+ let removed = klad_core::notes::clear_done(&Bundle::open(&bundle)?)?;
+ println!("removed {removed} done note{}", if removed == 1 { "" } else { "s" });
+ }
+ false => history::notes(&bundle, done, all, json)?,
+ },
Command::Diff {
bundle,
step,
diff --git a/crates/core/src/notes.rs b/crates/core/src/notes.rs
index 035ed9a..556bcaf 100644
--- a/crates/core/src/notes.rs
+++ b/crates/core/src/notes.rs
@@ -91,6 +91,14 @@ pub fn remove(bundle: &Bundle, id: u32) -> Result<()> {
write(bundle, &notes)
}
+pub fn clear_done(bundle: &Bundle) -> Result<usize> {
+ let (done, open): (Vec<Note>, Vec<Note>) = read(bundle).into_iter().partition(|n| n.done);
+ if !done.is_empty() {
+ write(bundle, &open)?;
+ }
+ Ok(done.len())
+}
+
pub fn read_selection(bundle: &Bundle) -> Option<Selection> {
serde_json::from_str(&fs::read_to_string(selection_path(bundle)).ok()?).ok()
}
@@ -125,7 +133,17 @@ mod tests {
assert!(set_done(&bundle, 1, true).unwrap());
assert!(!set_done(&bundle, 7, true).unwrap());
remove(&bundle, 2).unwrap();
- assert_eq!(read(&bundle), vec![Note { done: true, ..a }]);
+ assert_eq!(
+ read(&bundle),
+ vec![Note {
+ done: true,
+ ..a.clone()
+ }]
+ );
+ let c = add(&bundle, (1.0, 1.0), 0, "still open", "user").unwrap();
+ assert_eq!(clear_done(&bundle).unwrap(), 1);
+ assert_eq!(read(&bundle), vec![c]);
+ assert_eq!(clear_done(&bundle).unwrap(), 0);
write_selection(&bundle, Some("l1".into()), vec!["n3".into()], 0).unwrap();
assert_eq!(read_selection(&bundle).unwrap().nodes, vec!["n3"]);
fs::remove_dir_all(&dir).unwrap();
diff --git a/docs/DESIGN.md b/docs/DESIGN.md
index d76d981..bc7a38a 100644
--- a/docs/DESIGN.md
+++ b/docs/DESIGN.md
@@ -1,4 +1,4 @@
-_Last updated: 2026-11-07 08:55_
+_Last updated: 2026-11-07 09:41_
# klad: design
@@ -471,7 +471,7 @@ Scripts are any language that prints edit ops as JSON lines into `klad apply`. G
- Timeline layout and drags (M4 batch 3): the header is one toolbar row (fold, a frame field, transport, loop range and its fields, onion and its settings, shift K exposure, fps, length, zoom). Under it the selection toolbar (`editor/cells.rs`): new drawing, duplicate, link (the layer's drawings as thumbnails), unlink, delete, hold shorter, the hold as a field, hold longer, insert and remove a frame on this layer or every layer, copy cells, paste cells as copies or as links, retime (a menu: on ones, twos, threes, fit into n, reverse, ping-pong, every layer), in-between, redo in-betweens, new clip. What a press on the grid starts is decided where the press began (`press_at` and `drag_of`, tested): on the ruler it scrubs (shift marks the loop range), near a block's end it changes the hold, on the dot of a block's first cell it moves the block (the cursor is a hand there; since the M4 test only the dot, so a drag from the rest of that cell selects), on any other cell it selects (dragging extends over frames and rows). A hold drag or a move draws the block itself at its new length or place (the moved one faded where it was), not an outline; block labels stop before the grip lines at the block's end. A moved block is a `cel` `move` op, so drawings it lands on are pushed along; alt left and right move the drawing under the playhead by a frame. Clicking a clip's bar opens the clip window (name, loops, own fps, first and last frame as fields, delete, the Godot folder and export). Copied cells are the drawings and holds of the selected rows and frames (or the drawing under the playhead), pasted at the playhead on their own layers as `cel` `dup` or `link` ops in one batch; a drawing that was a link stays a link.
- In-between panel (M4 batch 4, `editor/between.rs`): "in-between" (the selection toolbar, the context menu, cmd K) opens a window instead of a menu: the first selected row's two keys as thumbnails with their frames (a frame not loaded yet says so), one on every frame or a count, spacing with the chart an animator draws between keys (key ticks at the ends, a tick per in-between where the spacing puts it), pairing (id, order, nearest shape; parts both keys have are named, they pair first), marks in one key only (leave, pop, fade, draw-on), and "make the in-betweens", which runs `klad inbetween` as a job (`between::args`). When the job ends its output is parsed into rows (`between::report`): each layer's pairs, parts and touching ends; an unpaired mark is a button that goes to the other key's frame, turns on the stroke tool and waits for one stroke to be picked, then makes the in-betweens again with that pair added to `--pair` (`pair_from`); a fill left out goes to its frame. "Check what a redo would remake" lists the in-betweens of the selection (or all) with their state from their marks' hash and authors (`redo_rows`): remade, drawn on by hand (keep them on top, the default; in-between them too; leave it) or edited (in-between it again, or leave it, the default); "redo them" runs one `klad inbetween --redo --only ... --keep-cels ... --force-cels ...`, one history step.
- History (M4 batch 4, `editor/history.rs`): the History pane lists the redo stack (as "undone" with who made the step, farthest first), a "the document is here" marker and the undo stack, latest first: who (you for the editor, the agent for the CLI), what, how long ago. Clicking a row undoes or redoes as many steps as it takes to stand right after it (`steps_to`), timed in the status line. The list is read again when the document's revision changes.
-- Notes on the canvas (M4 batch 4, `editor/pins.rs`): every open note is a pin, those of other frames dimmed with their frame, done ones on this frame checked in green. With the note tool a click on a pin opens its popover (the text to edit and save, done, remove, close); elsewhere it opens a popover for a new note at that spot ("pin it"). A right click on any pin, of this frame or a dimmed one of another, goes to its frame and selects it (an accent ring and its popover); Delete removes the selected note. The Notes pane lists the open notes (a click goes to the frame and opens the pin) and the done ones folded, each can be opened again. The editor watches `.cache/notes.json`, so the agent's `klad notes --done` shows at once.
+- Notes on the canvas (M4 batch 4, `editor/pins.rs`): every open note is a pin, those of other frames dimmed with their frame, done ones on this frame checked in green. With the note tool a click on a pin opens its popover (the text to edit and save, done, remove, close); elsewhere it opens a popover for a new note at that spot ("pin it"). A right click on any pin, of this frame or a dimmed one of another, goes to its frame and selects it (an accent ring and its popover); Delete removes the selected note. The Notes pane lists the open notes (a click goes to the frame and opens the pin) and the done ones folded, each can be opened again; every note is one line, cut to the pane's width (a done note's "open again" is laid out first, at the right, so the row never runs past the pane), and "clear all" beside the done header removes the done notes (`notes::clear_done`, `klad notes --clear-done`). The editor watches `.cache/notes.json`, so the agent's `klad notes --done` shows at once.
- Settings (M4 batch 4, `settings.rs`, `editor/prefs.rs`): the settings file carries a `version` (2; files without one, the M1 to M4 ones, load with the new fields at their defaults and are stamped 2), `keys` (command id to key labels such as `shift D`, only the changed ones), `uiScale` (0.75 to 2, egui's zoom factor, so every control grows with it) and `defaults` (brush and size for new windows, the shift K exposure, onion before, after and opacity, the grey around the canvas). The window has pen calibration, defaults, keys (search, change by pressing the key, no key, reset one or all) and layout. `commands::Bindings` holds the keys: a changed command's keys replace its first ones, a key another command already uses is refused and that command named (`taken_by`), holds (Q, W, space) keep their keys, and every key lookup (dispatch, hints, the palette, the strip's letters) goes through it.
- Export to Godot (M3 batch 3): the clip row has a "Godot folder" field (the document's `export.godot`; a typed folder is relative to the folder holding the bundle) and an "export to Godot" button, which runs `klad export <bundle> --godot` (with the typed folder and `--store` when it differs) as a background job of the same binary, so the CLI and the editor write the same files; its summary or error is a message.
- CLI forms in the editor (M5, S5.25, `editor/checks.rs`, `editor/export.rs`): refill this drawing and show gaps (the fill tool's options and the palette), fill like the first drawing (the timeline selection toolbar), a part name for the selected marks (the stroke inspector, the `part` op), show parts and show arcs of the selected mark or part over the clip (the palette), an export window (the document menu, cmd E: this frame, a layer, numbered frames or a sprite sheet, and Godot) and add a font file (the document menu and the text inspector, with the macOS open panel). The text tool (T, S5.26, `editor/text.rs`): a click starts a text on the active vector layer (or a new one when it is committed), typing shows on the canvas at once as a picture drawn by the same renderer while the node stays out of the document (an existing node is hidden in memory while it is edited), and Esc, a click outside or another tool commits it as one edit; a double click on text with V or T edits it in place. While typing the canvas holds egui's keyboard focus, so command keys type instead of switching tools. The font picker (the tool's options and the text inspector) lists klad's families drawn in their own face, the drawing's own files and, for a search, open families to download as a background `klad fonts --get` job. Paint with body (S5.23): a body slider at the top of the brush window, and relief in the inspector's effects with a light dial (click or drag towards the light). Everything but the part name runs the `klad` binary as a background job with the same arguments a person would type (`crate::start::draw_binary` finds it next to the editor, and next to the test binaries in tests), so the CLI and the editor do the same thing by construction; gaps and arcs read the command's `--json` and draw on the canvas until the next edit. The ops that draw from shapes (`ink`, `light`, `hatch`, `paint`, `scatter`) stay CLI only (principle 7).
diff --git a/docs/cli.md b/docs/cli.md
index db663bc..4803047 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -63,7 +63,7 @@ This reference is licensed under the MIT License (`LICENSE-MIT`), unlike klad it
- [`klad redo`](#klad-redo): Redo the last undone change
- [`klad log`](#klad-log): Recent changes, newest first
- [`klad selection`](#klad-selection): What the human has selected in the editor (layer and shapes, with bounds)
-- [`klad notes`](#klad-notes): Notes the human pinned on the canvas; --done <id> marks one as handled
+- [`klad notes`](#klad-notes): Notes the human pinned on the canvas; --done <id> marks one as handled, --clear-done removes the handled ones
- [`klad diff`](#klad-diff): Before and after renders of a change, side by side (default: the last one)
- [`klad info`](#klad-info): Paint cels with stroke counts and file sizes
- [`klad strokes`](#klad-strokes): List the strokes and fills of a paint layer's cel at a frame
@@ -3023,7 +3023,7 @@ Options:
## klad notes
```text
-Notes the human pinned on the canvas; --done <id> marks one as handled
+Notes the human pinned on the canvas; --done <id> marks one as handled, --clear-done removes the handled ones
Usage: klad notes [OPTIONS] <BUNDLE>
@@ -3038,6 +3038,9 @@ Options:
--all
Include notes already marked done
+ --clear-done
+ Remove every note marked done
+
--json
diff --git a/docs/skill/SKILL.md b/docs/skill/SKILL.md
index 036cbea..7e6831d 100644
--- a/docs/skill/SKILL.md
+++ b/docs/skill/SKILL.md
@@ -21,7 +21,7 @@ Keep renders small unless detail matters: `--scale 0.5` or `--focus <id>` costs
## What the user wants
-- `klad notes art.klad`: notes the user pinned on the canvas, each with a `--region` render command. Do the work, then `klad notes art.klad --done <id>`; the editor shows the pin as done at once and lists it under done in the Notes pane, so mark a note done only when it is.
+- `klad notes art.klad`: notes the user pinned on the canvas, each with a `--region` render command. Do the work, then `klad notes art.klad --done <id>`; the editor shows the pin as done at once and lists it under done in the Notes pane, so mark a note done only when it is. `--clear-done` removes the done ones, when the user asks for a clean list.
- `klad selection art.klad`: the layer, shapes, path and strokes the user selected in the editor (strokes as `<cel>:s<id>`), with bounds and a `--focus` command.
- `klad strokes art.klad <layer> --json`: the user's strokes with points and pressure, to trace their shapes (a ridge line and tree positions from a pen sketch, for example).