A drawing app built for agent/human collaboration
Rust
A new icon, painted in klad
Indicode BV85642da5c327
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7db16a6..27a6e5b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,7 @@The first builds, and klad's licences.+- A new icon, painted in klad: a K in two brush strokes, one of them showing the points that keep it editable.- Drawings are `.klad` folders in a fresh format, `klad/6` (drawings from the first builds open as they are, except their bones, which are dropped). Drawings from before (`.draw` folders) do not open and are not converted.- Drawings live well in git: an edit changes only the files of what it edits (`doc.json` keeps no revision or id counter), and copies of a drawing edited apart, in a clone or a worktree, never make the same id, so edits to different layers merge. New ids end in the copy's two-letter tag (`l48qa`, `c12:s349qa`); `klad info` shows it. The editor follows a `git checkout` of an open drawing, and klad never renders an old picture from its cache after one. Recolouring several strokes or fills at once (the selection bar in the editor, or `klad recolour`) moves them to the new colour together and keeps each one's own shade, so a painted-over area stays painted. If a merge still leaves an id used twice, `klad repair` (or **Repair and open** when the drawing won't open) gives every later one a new id and moves its stroke files along.- Erasers, smudges and blends stay with the strokes they were drawn over: move, copy or delete the strokes and they come along (or split, when only some of the strokes move), and an eraser erases only its own strokes, so moving them never bites into the paint they land on. The selection bar shows what is attached, "attached only" moves it on its own (it attaches to what it lands on), and detach frees it (`klad detach`); a stroke its erasers wipe out completely is skipped by clicks and the lasso. `klad strokes --json` lists `on`, `attached` and `hidden`. Stroke files move to version 2 (format `klad/6`); older drawings open with nothing attached.diff --git a/CLAUDE.md b/CLAUDE.mdindex 5c4953e..ba481c2 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1,4 +1,4 @@-_Last updated: 2026-11-09 08:37_+_Last updated: 2026-11-10 12:10__Last updated: 2026-11-04 19:41_@@ -18,6 +18,7 @@ Agent-first 2D art application in Rust: a `klad` CLI for agents and a native edi- Guides in `docs/guide/` are short how-to pages for people in the editor. A page opens with one sentence on what it lets you do and stays under about 300 words; each section is one task titled as the goal, verb first, done the shortest way in numbered steps of one action each (where, then what, then what happens), at most five. No option catalogues, no alternatives, no explaining how klad works inside: the editor names its options and `?` lists the keys. Keys and editor labels in bold, labels exactly as the editor writes them. Getting started is the one tutorial: a single path from a new drawing to changing a stroke.- Never commit build output or binaries, and check `git status` before `git add -A`. `samples/` holds generators only; the bundles and pictures they make stay out of git.- Commit messages and docs name no one: say what changed and why.+- `main` is protected: never commit on it. Work on a branch off the newest `origin/main` (`feature/...`, `bugfix/...`); it reaches `main` through a pull request.**Done means**diff --git a/docs/DESIGN.md b/docs/DESIGN.mdindex af3cfba..989b5cd 100644--- a/docs/DESIGN.md+++ b/docs/DESIGN.md@@ -1,4 +1,4 @@-_Last updated: 2026-11-10 11:20_+_Last updated: 2026-11-10 12:10_# klad: design@@ -29,7 +29,7 @@ crates/Two binaries from one crate: `klad`, the command line, and `klad-editor`, the editor alone (a windowed program on Windows, the executable of `klad.app` on a Mac, started by the Linux AppImage). `klad open [bundle]` launches the same editor from the command line, on the bundle or, without one, on the start window (new, open, recent). `--no-default-features` builds `klad` without the editor. `klad --version` and the editor's About show the version and `git describe` of the commit it was built from (`crates/version.rs`, shared by both crates' build scripts; `KLAD_BUILD` overrides it).-**Platforms and packaging (M7).** Folders follow each platform: settings in `~/Library/Application Support/klad`, `%APPDATA%\klad` or `$XDG_CONFIG_HOME/klad`; downloaded fonts in the same places' data folder; drawings in `~/Drawings` by default. The open panel is `NSOpenPanel` on macOS and `rfd` elsewhere (the XDG portal on Linux, the common dialog on Windows). The pen: macOS reads `NSEvent`; elsewhere a pen that the system reports as a touch with force (Windows pens through `WM_POINTER`) draws with that pressure (`pen::from_egui`), and anything else draws as a mouse at full pressure; Linux tablets report no pressure through `winit` yet. `packaging/` makes the downloads: `macos/app.sh` builds `klad.app` (both binaries, lipo'd when several targets are given, the fonts, licences and skill in `Resources`, `.klad` declared as a document package of type `com.indicode.klad.drawing` so Finder shows a drawing as one item and opens it in klad) and a disk image; `archive.sh <target>` builds a `tar.gz` or `zip` with both binaries, `fonts/`, the licences and `SKILL.md`, and an AppImage on Linux when `APPIMAGETOOL` is set; `icon/` draws the icon in klad and packs `klad.icns` and `klad.ico`. Builds use the `dist` profile (no debug info, stripped, thin LTO); the samples hash the same from it. The fonts are found next to the binary (`fonts/`), in `../Resources/fonts` or `../share/klad/fonts`. On macOS a drawing opened from Finder arrives as an `application:openURLs:` message, which klad adds to `NSObject` before the event loop starts so it reaches whatever delegate `winit` installs; the paths queue up (`opened.rs`) and the start window or editor opens the last. `klad install` puts `klad` on the terminal's path (a link in `/usr/local/bin` through an administrator prompt on macOS, `~/.local/bin` on Linux, the user's `PATH` on Windows); the editor's document menu runs it as a job. `klad skill` prints the agent skill compiled into the binary; `klad samples` lists and copies the sample drawings a build carries (First start, below). Builds are sold on itch.io (later Steam) for macOS and Windows, and Linux is built from source: on a version tag the `release` workflow builds the Windows version and pushes it to itch.io with butler (never as a workflow artifact, which anyone could download from a public repository) and publishes the changelog section as the release notes, and `just itch-mac` builds and pushes the Mac app from a Mac; `check` runs the format check and the licence and advisory audit on every pull request and every push to `main`; `full`, started by hand from the Actions tab, runs clippy and the tests on Linux, the tests on macOS and the CLI build on Windows (they do not pass on the hosted runners yet, so they are kept off the commits; run `just lint` and `just test` before sending a change). The editor asks the GitHub releases API at most once a day (`updates.rs`, curl on a thread, off in the settings window) and, when a newer version is out, says so in the start window, the message line and About, with a link to what changed; it installs nothing. About's "check now" and `klad updates` check on demand (`updates::spawn`, a channel per check) and say why a check failed: no release published yet, no network, or a feed that does not parse.+**Platforms and packaging (M7).** Folders follow each platform: settings in `~/Library/Application Support/klad`, `%APPDATA%\klad` or `$XDG_CONFIG_HOME/klad`; downloaded fonts in the same places' data folder; drawings in `~/Drawings` by default. The open panel is `NSOpenPanel` on macOS and `rfd` elsewhere (the XDG portal on Linux, the common dialog on Windows). The pen: macOS reads `NSEvent`; elsewhere a pen that the system reports as a touch with force (Windows pens through `WM_POINTER`) draws with that pressure (`pen::from_egui`), and anything else draws as a mouse at full pressure; Linux tablets report no pressure through `winit` yet. `packaging/` makes the downloads: `macos/app.sh` builds `klad.app` (both binaries, lipo'd when several targets are given, the fonts, licences and skill in `Resources`, `.klad` declared as a document package of type `com.indicode.klad.drawing` so Finder shows a drawing as one item and opens it in klad) and a disk image; `archive.sh <target>` builds a `tar.gz` or `zip` with both binaries, `fonts/`, the licences and `SKILL.md`, and an AppImage on Linux when `APPIMAGETOOL` is set; `icon/` draws the icon in klad and packs `klad.icns` and `klad.ico` (the icon is two brush strokes with paint body, the ember one showing its path, points and handles as the point tool draws them; sizes of 64 px and under come from a second drawing with heavier strokes and no points, also kept as `icon-small.png` for small marks, and `build.sh <folder>` keeps both drawings to open in the editor). Builds use the `dist` profile (no debug info, stripped, thin LTO); the samples hash the same from it. The fonts are found next to the binary (`fonts/`), in `../Resources/fonts` or `../share/klad/fonts`. On macOS a drawing opened from Finder arrives as an `application:openURLs:` message, which klad adds to `NSObject` before the event loop starts so it reaches whatever delegate `winit` installs; the paths queue up (`opened.rs`) and the start window or editor opens the last. `klad install` puts `klad` on the terminal's path (a link in `/usr/local/bin` through an administrator prompt on macOS, `~/.local/bin` on Linux, the user's `PATH` on Windows); the editor's document menu runs it as a job. `klad skill` prints the agent skill compiled into the binary; `klad samples` lists and copies the sample drawings a build carries (First start, below). Builds are sold on itch.io (later Steam) for macOS and Windows, and Linux is built from source: on a version tag the `release` workflow builds the Windows version and pushes it to itch.io with butler (never as a workflow artifact, which anyone could download from a public repository) and publishes the changelog section as the release notes, and `just itch-mac` builds and pushes the Mac app from a Mac; `check` runs the format check and the licence and advisory audit on every pull request and every push to `main`; `full`, started by hand from the Actions tab, runs clippy and the tests on Linux, the tests on macOS and the CLI build on Windows (they do not pass on the hosted runners yet, so they are kept off the commits; run `just lint` and `just test` before sending a change). The editor asks the GitHub releases API at most once a day (`updates.rs`, curl on a thread, off in the settings window) and, when a newer version is out, says so in the start window, the message line and About, with a link to what changed; it installs nothing. About's "check now" and `klad updates` check on demand (`updates::spawn`, a channel per check) and say why a check failed: no release published yet, no network, or a feed that does not parse.### Stackdiff --git a/packaging/icon/build.sh b/packaging/icon/build.shindex 6d40f9f..ea65ddc 100755--- a/packaging/icon/build.sh+++ b/packaging/icon/build.sh@@ -2,13 +2,29 @@set -euo pipefailhere="$(cd "$(dirname "$0")" && pwd)"klad="${KLAD:?set KLAD to the klad binary, or run just icon}"-work="$(mktemp -d)"-trap 'rm -rf "$work"' EXIT-"$klad" new "$work/icon.klad" --width 1024 --height 1024 --layers 0 >/dev/null-python3 "$here/generate.py" | "$klad" apply "$work/icon.klad" >/dev/null+if [ -n "${1:-}" ]; then+ mkdir -p "$1"+ work="$(cd "$1" && pwd)"+else+ work="$(mktemp -d)"+ trap 'rm -rf "$work"' EXIT+fi+draw() {+ rm -rf "$work/$1.klad"+ "$klad" new "$work/$1.klad" --width 1024 --height 1024 --layers 0 >/dev/null+ for brush in icon-wet icon-dry; do+ python3 "$here/generate.py" --brush "$brush" | "$klad" brushes "$work/$1.klad" --set "$brush" - >/dev/null+ done+ python3 "$here/generate.py" ${2:-} | "$klad" apply "$work/$1.klad" >/dev/null+}+draw icon+draw icon-small --small"$klad" render "$work/icon.klad" --out "$here/icon.png" >/dev/null+"$klad" render "$work/icon-small.klad" --out "$here/icon-small.png" >/dev/nullfor size in 16 24 32 48 64 128 256 512 1024; do- "$klad" render "$work/icon.klad" --scale "$(python3 -c "print($size/1024)")" --out "$work/icon-$size.png" >/dev/null+ drawing=icon+ [ "$size" -le 64 ] && drawing=icon-small+ "$klad" render "$work/$drawing.klad" --scale "$(python3 -c "print($size/1024)")" --out "$work/icon-$size.png" >/dev/nulldonepython3 "$here/pack.py" "$work" "$here/klad.icns" "$here/klad.ico"-echo "$here/icon.png $here/klad.icns $here/klad.ico"+echo "$here/icon.png $here/icon-small.png $here/klad.icns $here/klad.ico"diff --git a/packaging/icon/generate.py b/packaging/icon/generate.pyindex b6f91f0..ff66928 100644--- a/packaging/icon/generate.py+++ b/packaging/icon/generate.py@@ -1,32 +1,151 @@import json+import random+import sysINK = "#1d2230"+INK_DRY = "#39425c"EMBER = "#d4612c"+EMBER_DRY = "#f09a48"+POINT = "#1aa7f2"+SCALE = 0.84+SHIFT = -28+++def place(points):+ return [(round(512 + (x - 512) * SCALE + SHIFT, 1), round(512 + (y - 512) * SCALE, 1)) for x, y in points]+++STEM = place([(392, 206), (384, 400), (394, 610), (372, 826)])+ARM = place([(760, 214), (716, 330), (624, 436), (404, 520)])+LEG = place([(404, 520), (486, 546), (571, 592), (628, 640), (685, 688), (748, 752), (782, 824)])+++def brush(fringe, grain):+ return {+ "format": "klad-brush/1", "name": "Icon brush", "tip": {"round": {"hardness": 0.92}}, "spacing": 0.03,+ "roundness": 0.85, "angle": "follow", "dynamics": {"size": {"pressure": {"min": 0.05}}},+ "grain": {"paper": {"seed": 29, "feature": 4}, "strength": grain, "pressure": 0.6}, "fringe": fringe,+ "body": 0.8, "color": {"pressure": {"min": 0.0}},+ }+++BRUSHES = {"icon-wet": brush(0.3, 0.14), "icon-dry": brush(0.75, 0.3)}+++def curves(points):+ return [[points[i], *points[i + 1:i + 4]] for i in range(0, len(points) - 1, 3)]+++def d(points):+ rest = " ".join("C " + " ".join(f"{x} {y}" for x, y in curve[1:]) for curve in curves(points))+ return f"M{points[0][0]} {points[0][1]} {rest}"+++def at(curve, t):+ u = 1 - t+ return tuple(u ** 3 * curve[0][k] + 3 * u * u * t * curve[1][k] + 3 * u * t * t * curve[2][k] + t ** 3 * curve[3][k]+ for k in (0, 1))+++def along(points, steps=36):+ pieces = curves(points)+ return [at(curve, i / steps) for curve in pieces for i in range(steps)] + [pieces[-1][3]]+++def offset(line, by):+ def normal(i):+ a, b = line[max(i - 1, 0)], line[min(i + 1, len(line) - 1)]+ dx, dy = b[0] - a[0], b[1] - a[1]+ size = (dx * dx + dy * dy) ** 0.5 or 1+ return -dy / size, dx / size+ return [(round(x + normal(i)[0] * by, 1), round(y + normal(i)[1] * by, 1)) for i, (x, y) in enumerate(line)]def layer(id, kind, **extra):return {"op": "add", "layer": {"id": id, "kind": kind, "name": id, **extra}}-def stroke(path, size, colour, pressure, brush="oil-load"):- return {"op": "stroke", "layer": "paint", "brush": brush, "size": size, "color": colour, "path": path,- "pressure": pressure}+def node(layer, **props):+ return {"op": "add", "node": props, "in": layer}+++def stroke(path, size, colour, second, pressure, brush="icon-wet", **extra):+ return {"op": "stroke", "layer": "paint", "brush": brush, "size": round(size * SCALE, 1), "color": colour,+ "second": second, "path": path, "pressure": pressure, "taper": [0, 0], **extra}+++def streaks(points, width, tones, seed, count, heavy):+ rng = random.Random(seed)+ line = along(points)++ def one(i):+ start = rng.uniform(0, 0.55)+ end = min(start + rng.uniform(0.3, 0.7), 0.97)+ first = int(start * len(line))+ moved = offset(line[first:max(int(end * len(line)), first + 4)], width * heavy * SCALE * rng.uniform(-0.38, 0.38))+ tone = tones[rng.random() < 0.55]+ return stroke("M" + " L".join(f"{x} {y}" for x, y in moved), width * rng.uniform(0.08, 0.22), tone, tone,+ [0.2, 0.8, 1, 0.8, 0.5, 0.15], brush="icon-dry", opacity=round(rng.uniform(0.16, 0.34), 2),+ seed=seed * 100 + i)+ return [one(i) for i in range(count)]+++def paint(heavy):+ ember = ["#e77a33", "#b94412"]+ ink = ["#343c55", "#11141d"]+ lock = {"op": "set", "id": "paint", "lockAlpha": True}+ free = {"op": "set", "id": "paint", "lockAlpha": False}+ return [+ stroke(d(ARM + LEG[1:]), 156 * heavy, EMBER, EMBER_DRY, [0.16, 0.36, 0.5, 0.56, 0.58, 0.7, 0.9, 1, 0.98, 0.8, 0.5, 0.2]),+ stroke(d(LEG[3:]), 148 * heavy, EMBER, EMBER_DRY, [0.96, 0.9, 0.66, 0.34, 0.1], brush="icon-dry"),+ lock,+ *streaks(LEG, 130, ember, 4, 9, heavy),+ *streaks(ARM, 74, ember, 5, 5, heavy),+ free,+ stroke(d(STEM), 140 * heavy, INK, INK_DRY, [0.86, 1, 0.98, 0.96, 0.92, 0.84, 0.7]),+ stroke("M" + " L".join(f"{x} {y}" for x, y in along(STEM)[20:]), 132 * heavy, INK, INK_DRY,+ [0.94, 0.9, 0.78, 0.5, 0.22], brush="icon-dry"),+ lock,+ *streaks(STEM, 120, ink, 6, 8, heavy),+ free,+ {"op": "set", "id": "paint", "effects": [{"relief": {"light": [-0.6, -0.8], "strength": 3.6, "softness": 4}}]},+ ]+++def points():+ line = {"paint": POINT, "width": 5, "cap": "round", "join": "round"}+ handles = (LEG[2], LEG[4])+ anchors = [(ARM[0], False), (ARM[3], False), (LEG[6], False), (LEG[3], True)]+ return [+ layer("points", "vector"),+ node("points", type="path", d=d(ARM + LEG[1:]), fill="none", stroke=line),+ node("points", type="path", d=f"M{handles[0][0]} {handles[0][1]} L{handles[1][0]} {handles[1][1]}", fill="none",+ stroke=line),+ *[node("points", type="ellipse", cx=x, cy=y, rx=12.5, ry=12.5, fill="#ffffff", stroke={"paint": POINT, "width": 5})+ for x, y in handles],+ *[node("points", type="rect", x=x - 16, y=y - 16, w=32, h=32, fill=POINT if chosen else "#ffffff",+ stroke={"paint": "#ffffff" if chosen else POINT, "width": 5}) for (x, y), chosen in anchors],+ {"op": "set", "id": "points", "effects": [{"shadow": {"x": 0, "y": 3, "radius": 5, "color": "#00000050"}}]},+ ]-def ops():- paper = {"linear": {"from": [0, 100], "to": [0, 924], "stops": [[0, "#f8f1e4"], [1, "#e6d6bd"]]}}+def ops(small):+ paper = {"linear": {"from": [0, 100], "to": [0, 924], "stops": [[0, "#f9f2e5"], [1, "#e8d9c0"]]}}+ rim = {"linear": {"from": [0, 100], "to": [0, 924],+ "stops": [[0, "#ffffffd0"], [0.35, "#ffffff00"], [0.7, "#00000000"], [1, "#0000001c"]]}}return [layer("plate", "vector"),- {"op": "add", "node": {"type": "rect", "x": 100, "y": 100, "w": 824, "h": 824, "radius": 186, "fill": paper},- "in": "plate"},+ node("plate", type="rect", x=100, y=100, w=824, h=824, radius=186, fill=paper),+ node("plate", type="rect", x=102, y=102, w=820, h=820, radius=184, fill="none", stroke={"paint": rim, "width": 4}),{"op": "set", "id": "plate", "effects": [{"shadow": {"x": 0, "y": 14, "radius": 22, "color": "#00000044"}}]},layer("paint", "paint", clip=True),- stroke("M396 226 C 390 420 402 600 388 806", 128, INK, [0.75, 1, 1, 0.95, 0.7], brush="oil"),- stroke("M440 540 C 530 456 620 366 748 250", 108, INK, [1, 0.95, 0.75, 0.45], brush="oil"),- stroke("M452 498 C 560 594 650 690 760 808", 118, EMBER, [1, 1, 0.9, 0.7, 0.4], brush="oil"),- {"op": "set", "id": "paint", "effects": [{"relief": {"light": [-0.6, -0.8], "strength": 1.6, "softness": 2.2}}]},+ *paint(1.34 if small else 1),+ *([] if small else points()),]if __name__ == "__main__":- print("\n".join(json.dumps(op) for op in ops()))+ if sys.argv[1:2] == ["--brush"]:+ print(json.dumps(BRUSHES[sys.argv[2]]))+ else:+ print("\n".join(json.dumps(op) for op in ops("--small" in sys.argv)))diff --git a/packaging/icon/icon-small.png b/packaging/icon/icon-small.pngnew file mode 100644index 0000000..df4fbbfBinary files /dev/null and b/packaging/icon/icon-small.png differdiff --git a/packaging/icon/icon.png b/packaging/icon/icon.pngindex ea5959a..09813ca 100644Binary files a/packaging/icon/icon.png and b/packaging/icon/icon.png differdiff --git a/packaging/icon/klad.icns b/packaging/icon/klad.icnsindex 90edc29..1d2aee6 100644Binary files a/packaging/icon/klad.icns and b/packaging/icon/klad.icns differdiff --git a/packaging/icon/klad.ico b/packaging/icon/klad.icoindex d9ad49f..d9df51b 100644Binary files a/packaging/icon/klad.ico and b/packaging/icon/klad.ico differ