chore(layout): move the files of the repository to where they live in the komorebi monorepo

This commit is contained in:
LGUG2Z committed 2026-11-05 11:48:44 -08:00
1 parent eab0b6af35
commit df35d7b258
28 files changed
-6405

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
# Architecture
`komorebi-recorder` connects three things that do not know about each other: komorebi, which says what it is doing in
a log and in events on a socket; the operating system, which says what it is doing in its own trace and shows it on a
screen; and the person or agent who has to work out why they disagreed. It records all of them on one clock into a
session directory, and reads that directory back.
Two things about it vary independently, and everything below is arranged so that neither leaks into the other.
| axis | what varies | where the variation lives | what a session records |
|---|---|---|---|
| host | the OS the recorder runs on: macOS or Windows (a third `unsupported` host builds anywhere) | [`platform`](../komorebi-recorder/src/platform/mod.rs), selected by `cfg` | `host` in the manifest |
| flavor | the komorebi being recorded: komorebi for Mac or komorebi for Windows | `Rules` in [`analysis::flavor`](../komorebi-recorder/src/analysis/flavor/mod.rs), selected by data | `komorebi.flavor` in the manifest |
They are independent because a session recorded on one host is investigated on whichever machine the investigator has.
A session recorded on Windows is read on a Mac, and the other way round, so reading never asks which host it is
running on: it asks the session.
## The master clock
Everything in a session is stamped on one clock: the host's monotonic clock, in nanoseconds. That is
`mach_absolute_time` on macOS and `QueryPerformanceCounter` on Windows. Video frames and the OS trace are already on it.
komorebi's log lines carry UTC wall-clock time, so they are mapped onto it: the recorder samples a paired reading of
both clocks (an `Anchor`) at the start, every few seconds and at every sleep, and a `ClockMap` interpolates between
them. A `JumpDetector` notices sleep and clock steps by comparing how far each clock moved between two observations,
and the anchors on either side of the jump are what make the mapping right on both sides of it.
Three things are worth knowing before reading a session:
- The field names ending in `_mach_ns` keep their historical spelling. They hold master-clock nanoseconds on whichever
host recorded the session; the manifest's `host.clock` says which clock that was (`mach`, `qpc` or `std`). A name that
changed would stop older sessions being readable by newer builds and the reverse.
- The master clock is not the wall clock. On macOS it pauses while the machine sleeps, so video time skips a sleep
instead of showing a hole. Whether the performance counter counts a suspend on Windows is measured, not assumed.
(`doctor --probe clock` measures it.)
- A timestamp is a plain `u64` of nanoseconds. Nothing in the type system says which clock it is on: that is held by
convention, and by the tests that place records at known times.
## The platform facade
The rest of the crate never names a system API. [`platform`](../komorebi-recorder/src/platform/mod.rs) is a facade of
small modules (`clock`, `shell` and, as the recorder grows, `capture`, `power`, `session`, `trace`, `process`, `apps`
and `window`), and `cfg` selects the directory behind it: `platform/macos/`, `platform/win/` or `platform/unsupported.rs`.
Each host provides the same names with the same signatures. A missing or mismatched function is a compile error on the
host being built, and on no other, so the Windows host is built from a Mac by `just check-windows` and by CI, and
`unsupported` (which exists so that the commands that only read a session directory work on a Linux agent box) is built
only on a third OS.
Where one host has no analogue of something, the facade function exists on both and one answers "nothing": `trace::start`
on the `unsupported` host returns no taps and a line saying so, and `power::start` returns no watcher.
## Flavors and rules
Which komorebi produced a session decides what its events mean (a process id and an accessibility notification on a Mac,
a window handle and a WinEvent on Windows), how it hides a window (by moving it to a corner on a Mac, by cloaking it in
place on Windows) and how its log marks where a handler starts and ends. `Flavor` names the two and is recorded in the
manifest. `Rules` is the trait that holds what each knows, and `Flavor::rules` is where a name becomes rules. Code that
reads komorebi's output asks `Rules` and does not match on `Flavor`; only convention holds that, and it has exceptions:
the index of komorebi's source that log lines are mapped to, and the places the log and a checkout of the source are
looked for on disk, are keyed by `Flavor` directly.
The contract is a counting rule: a flavor implements every method of `Rules` that has no default, and the compiler
refuses an implementor that misses one. A method with a default is a question most flavors answer the same way, and the
doc of each says what the default is. `Rules::verified` is how a flavor says that its rules were written from komorebi's
source and have not been checked against a recording of it: an analysis that reads such a session says so.
## The session
A session is a directory. Its manifest, `session.json`, is the one file everything else is read through: the host and the
flavor, the clock anchors, the komorebi processes that were seen and how each was logging, the byte ranges of komorebi's
log that were recorded and the applications that were traced. It is written to a temporary file and renamed, so a reader
or a crash never sees half of one, and its `schema_version` is checked on every read: a manifest written by a newer
build is refused with an error that says so, rather than read wrongly.
The files beside it are the raw records, and they are written as the data arrives and never rewritten: komorebi's log
(`komorebi.log`, the exact byte range recorded), its events (`events.jsonl`, with full `State` snapshots in `states/`
only when they changed), and what happened to the recording itself (`recorder.jsonl`).
The OS trace is under `oslog/`, one file per stream.
Each display's video is `video-<id>[-<n>].mp4` with a `frames-<id>[-<n>].csv` beside it holding every frame's timestamp,
one segment to a file: a display that is unplugged and returns starts a new segment instead of extending the old one.
`timeline.jsonl` is the only derived file: a time-sorted index of every record that points into the raw files by byte
range. Anything that happens to the recorder leaves the raw files readable, and the index is rebuilt from them with
`reindex`. The file formats are specified on the `session` and `timeline` modules.
## Recording
The recorder starts its sources in an order that makes the sources that are not video a superset of the video's span
(the clock anchor, the OS trace streams, the subscription to komorebi and its first `State`, komorebi's log offset, and
last the video), and stops them in the reverse order.
While it runs, the machine is docked, undocked, put to sleep, woken with the lid opened and locked, and none of that may
lose what was already captured. A tracker turns what the OS says (or, on a Mac, what the two clocks disagree about) into
reactions: a display that is gone has its video finalized at once, one that returns starts a new segment, and every
stream is started afresh after a wake. The capture backend is a trait, so that these policies are tested with a scripted
backend that docks and undocks without hardware.
## Investigating
Reading a session never needs a window: `analysis` answers each question as a plain serializable value, and the command
line and the viewer present the same answers. Every command takes `--json`, which prints an envelope with the data, its
schema, warnings, whether it was truncated and a cursor, and failures exit with a code that says what kind they were.
## Rules and the layer that enforces them
| Rule | Enforced by |
|---|---|
| Every host provides the same functions with the same signatures | the compiler, for the host being built; `just check-windows` and CI build the Windows host from a Mac; nothing builds `unsupported` |
| A timestamp in a session is on the master clock | convention, and the tests that place records at known times: the type is a plain `u64` |
| An implementor of `Rules` answers every question that has no default | the type system: a missing method is E0046, proved by a `compile_fail` example on `Rules` |
| Code that reads komorebi's output asks `Rules` and does not match on `Flavor` | convention only |
| Rules that were not checked against a recording of komorebi say so | the framework path: an analysis that reads such a session adds a warning |
| A running recorder can be told from one that died | the OS: an exclusive lock on `recorder.lock`, held for as long as the recorder runs and dropped by the OS when the process ends however it ends |
| A manifest from a newer build is not read | a runtime error when the manifest is read, covered by `rejects_manifests_from_the_future` |
| A manifest is never half-written | write to a temporary file and rename |
| The raw files are never rewritten | convention: the index only references them, and `reindex` rebuilds the index from them |
+81
View File
@@ -0,0 +1,81 @@
# Contributing to komorebi-recorder
The project is a collection of contributions from both the project leaders and
community members. There are many ways to contribute, this can include content
in the project repositories, as well as contributing in public and private
conversation, assisting users, writing blog posts, and many other ways.
## How contributions are made
Contributions to the project primarily happen in the project source
repositories, but may also occur in other places, such as discussion forums and
public and private discourse.
## Contributing content to the Project
In order for the project leaders to manage sustained progress toward the
project goals and maintain project velocity, focus and quality, the project may
adjust the license terms over time.
Content contributed to the project must therefore be provided under
sufficiently liberal terms to allow these operations to proceed unimpeded. As
such contributions are accepted with the following understanding:
* Contributed content is licensed under the terms of the 0-BSD license
* Contributors accept the terms of the project license at the time of
contribution
By making a contribution, you accept both the current project license terms,
and that all contributions that you have made are provided under the terms of
the 0-BSD license.
## Zero-Clause BSD
```
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```
## Development environment
The project is built with Nix. `nix develop` (or direnv, whose `.envrc` is `use flake`) provides the
Rust toolchain with nightly `rustfmt`, `cargo-deny`, `cargo-nextest`, `ffmpeg`, `jq`, `just`,
`resvg` and `ripgrep`, and sets `KOMOREBI_MAC_SRC` and `KOMOREBI_WINDOWS_SRC` (with `_COMMIT`) to the komorebi
sources pinned in `flake.lock`. The tests that read komorebi's source need them, so run `cargo` inside
the shell.
The Windows code is type-checked from a Mac with `nix develop .#windows`, whose target is
`x86_64-pc-windows-msvc`. Nothing there runs it: a change to a `cfg(windows)` line is first run by the
`windows` job in CI.
On a Windows machine, the steps in [docs/dev/windows-checkpoints.md](docs/dev/windows-checkpoints.md)
say what to run and what to look for.
The icon is `komorebi-recorder/assets/watermelon.svg`. After changing it, run `just icon` to render the PNG that
the windows set and the ICO that Windows embeds, and commit the three together.
## Checks
Before pushing, run
```sh
just check
```
which runs formatting, clippy and the tests for macOS, clippy for Windows, rustdoc with its warnings as
errors for both hosts, and `cargo deny`. `just --list` shows the other recipes.
## Commits
Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/), as the pull request
template asks: the release notes are generated from them.
A change that alters what the documentation says (the rustdoc, the README, `docs/`) updates the
documentation in the same commit, so that the documentation never describes code that is not there.
+122
View File
@@ -0,0 +1,122 @@
# Design
This document records why the recorder is built the way it is. It is organized as questions, because each answer is a
decision that could have gone another way. The facts in it were measured or read from the code, and where a reason is a
judgment it says so. It is written in the first person only where the decision was the owner's.
## Why record the screen, the log, the events and the OS trace together?
Most of the komorebi bugs I see show up when a laptop is docked or undocked, or wakes when the screen is opened. To
reproduce one, I had to watch the screen, hand-grep komorebi's log and export the system log from Console, and there was
no way to say: at 00:12.5 in the video, what was komorebi doing, and what was the OS doing? The recorder puts the four on
one clock so that the question has an answer, and so that the answer also works the other way, from a log line to the
moment in the video.
OS-level tracing is in scope because the interesting seam is between komorebi and the system, and between the system and
the application being tiled; komorebi's own log only shows one side of each.
## Why one clock, and why that one?
Every record is stamped on the host's monotonic clock (`mach_absolute_time` on macOS, `QueryPerformanceCounter` on
Windows) because the two sources that cannot be re-stamped are already on it: ScreenCaptureKit frame timestamps and the
unified log's `machTimestamp` on a Mac, and Windows.Graphics.Capture frame times on Windows. komorebi's log lines carry
UTC wall-clock time, so they are mapped onto the master clock with paired readings of both clocks (anchors) sampled while
recording, interpolated piecewise so that a step or a sleep between two anchors does not smear the mapping.
The alignment is as good as that allows: video to OS trace within about one frame, and video to komorebi's log within
about one frame plus the error of the wall-clock anchor, tens of microseconds.
## Why are fields called `*_mach_ns` on Windows?
They hold nanoseconds on the master clock, whichever clock that was. The spelling is historical and was kept: renaming
them would make a session written by one build unreadable by another. The manifest's `host.clock` says which clock a
session was on.
## Why does the recorder never change komorebi's log level or lifecycle?
That was decided at the start: the recorder only observes. It warns when komorebi is logging at a level that leaves out
most of what the window manager decided, and says how to restart it, but it never restarts komorebi or changes its
settings. (The reason for the decision is not written down anywhere the design could be checked against; this entry
needs the owner's words.)
## Why does the accept loop never block, and why is an event stamped when its handler finished?
komorebi connects to each subscriber synchronously and sends a notification while it holds its own locks, so a recorder
that was slow to read would stall komorebi. The accept thread stamps the arrival, reads, and hands the event to a channel;
a writer thread does everything else. For the same reason the per-event window probe (`--probe-windows`) runs on the
writer thread and never on the accept thread.
komorebi sends the notification after it has handled the event, so the stamp is when the handler finished. The start of
the handler is the `processing event` line in komorebi's log, which is why `trace` pairs the two.
## Why ScreenCaptureKit through `objc2` and not the `screencapturekit` crate?
The `screencapturekit` crate needs a Swift bridge at build time, which complicates the nix build. `objc2-screen-capture-kit`
and its siblings exist at the versions the rest of komorebi already uses, so there is no Swift and no Xcode dependency.
## Why fragmented mp4, and why re-submit the last frame?
A recorder that is killed, or a machine that loses power, must not lose the recording, and a plain mp4 is unreadable
until it is finalized. Fragmented mp4 plays up to the last fragment. Two measured facts decided the rest: ScreenCaptureKit
only emits frames when the screen changes, and fragments are cut on media time, so a static display never flushed a
fragment; the capture therefore re-submits the last frame to keep it moving. And the duration `ffprobe` reports for a
truncated fragmented file under-reads, so recovery asks AVFoundation instead.
## Why a new file for every segment?
Docking and undocking, sleep and lock change what can be recorded, and I want the recording to carry on through all of
them without losing what was already captured. A display that disappears has its video finalized on the spot, so the file
is complete and playable whatever happens next, and a display that returns starts a new segment in a new file. Every
display's segments are listed in the manifest with their time spans, so a gap is a fact the session states rather than a
hole.
## Why raw files plus an index, and not one file or a database?
The raw files are written as the data arrives and are never duplicated or rewritten; `timeline.jsonl` only references byte
ranges in them, so the streams stay separate and can be reconciled or re-indexed later. The index can be rebuilt from the
raw files at any time (`reindex`), including after a crash and after a hand edit.
## Why does reading a session never ask which host it is on?
A session recorded on Windows is investigated on a Mac, and the other way round. The host and the komorebi flavor are
recorded in the manifest, and everything that reads a session asks the manifest.
## Why can a bug only be marked in the viewer?
The Record tab has no button for marking a bug, and a session's tab has one. I found it confusing to have two places to do
the same thing, so a bug is marked in a session's tab only. `komorebi-recorder annotate` writes the same annotations for a
script or an agent that has no window.
## Why is there one window?
Recording and reviewing used to be two windows, and the recorder's buttons for opening a recording started the other one.
Now the recorder is the pinned first tab of the one window and each recording is a tab after it, so there is one thing to
keep out of the video and out of komorebi's layout. It starts small, always on top, with only the Record tab, which is what
the old recorder window was for, and grows when a recording is opened.
## Why is the window untitled?
komorebi does not manage windows with an empty title, so an untitled window is never tiled: opening the recorder
does not move the layout of the machine whose bug is being recorded.
## Why is ffmpeg not part of the program?
ffmpeg is used only to extract frames (`frames`) and to make test videos, and never for capture. It is in the dev shell and
not in the packaged binary.
## Why is a komorebi source from a different commit "skewed" by files and not by commit?
The recorder's own commits advance the repository's head without touching komorebi, so comparing commits calls almost
everything skewed. The files that differ between the commit a session recorded and the commit indexed are what say whether
a line of the log can still be traced to the statement that wrote it.
## Why is the hidden-window check skipped on Windows?
komorebi for Windows hides a window by cloaking it where it is, so a window's rectangle says nothing about whether it is
hidden. The check that flags a window parked off screen on the showing workspace holds only where komorebi hides windows
by moving them, so it is skipped on Windows, and `--probe-windows` reads the real state from Windows instead.
## Why do the Windows rules say they are unverified?
They were written from komorebi for Windows' source. Until a recording of it has been read, an analysis that uses them says
so; `Rules::verified` is the flag, and it is flipped once the first checks on a Windows machine confirm the rules.
+200
View File
@@ -0,0 +1,200 @@
# Platform support
This document gathers, in one place, what differs by operating system. Most of the details are written down on the items
that implement them; here the same questions are answered once per host, so that someone who has to run the recorder on
a machine, or change it for one, does not have to read the code to find out.
The recorder is built for macOS, Windows and Linux (KDE Plasma). A fourth host, `unsupported`, builds on anything else so
that the commands that only read a session directory work there; recording says that it cannot.
## Status
| host | built | run |
|---|---|---|
| macOS (Apple silicon) | yes | yes: written and run on macOS 26 |
| Windows x86_64 | yes, natively on `windows-latest` and cross-compiled from a Mac | no: type-checked and cross-built only |
| Windows ARM64 | yes, cross-built on an x86_64 runner | no |
| Linux (KDE Plasma, x86_64) | yes, natively | decoding, the komorebi side of recording and the OS trace were run, with komorebi for KDE's in-memory desktop; the screencast was not: see [kde-checkpoints.md](dev/kde-checkpoints.md) |
| anything else | the `unsupported` host builds | nothing records |
Nothing that touches a real Windows desktop has been seen running: the Windows host was written from the Windows API
documentation and komorebi for Windows' source, and every claim below about Windows says what the code does, not what
was observed.
[windows-checkpoints.md](dev/windows-checkpoints.md) lists the checks that turn each into an observation.
## Vocabulary
- **Host**: the OS the recorder runs on. It decides how the screen is captured, which clock is read, how the OS says it
is going to sleep and what the OS trace is made of.
- **Flavor**: which komorebi is being recorded. There is one per OS, and a recorder watches the one on its own host, but
a session records its flavor, so a session from either can be read on either host.
- **Master clock**: the host's monotonic clock, in nanoseconds, on which every record in a session is stamped.
- **Session**: the directory a recording is written to.
- **Segment**: one contiguous stretch of one display's video, a file of its own. A display that is unplugged and plugged
in again has two.
## The same questions, per host
### The master clock
| | macOS | Windows | unsupported |
|---|---|---|---|
| clock | `mach_absolute_time`, scaled by `mach_timebase_info` | `QueryPerformanceCounter`, scaled by `QueryPerformanceFrequency` (10 MHz when Windows will not say) | the time since the first reading in the process, plus one second so that no reading is zero |
| `host.clock` in the manifest | `mach` | `qpc` | `std` |
| counts the time the machine sleeps | no | not known: measured, not assumed | no |
| other clocks read beside it | `mach_continuous_time`, which counts sleep | `QueryInterruptTime`, which counts sleep, and `QueryUnbiasedInterruptTimePrecise`, which does not | none |
Video frame times and the OS trace are on the master clock already on both hosts (ScreenCaptureKit and the unified log's
`machTimestamp` on a Mac; Windows.Graphics.Capture on Windows). The field names ending in `_mach_ns` are spelled that way
on every host: see [the architecture](ARCHITECTURE.md#the-master-clock).
### Noticing sleep, wake, lock and display changes
| | macOS | Windows |
|---|---|---|
| a sleep | found afterwards: the master clock pauses while the wall clock does not, which the recording loop sees by comparing the two many times a second | heard as it happens, from a hidden window on a thread of its own that receives suspend and resume; the lid, the displays' power state and session lock are registered for |
| the screen locked | polled: CoreGraphics' session dictionary | polled: being refused the input desktop means a lock screen or a UAC prompt, and the screen cannot be captured then either way |
| displays added, removed, resized | polled: `CGGetActiveDisplayList` and `CGDisplayIsAsleep`, which are cheap and need no permission | polled, and heard as a display-change message |
Windows is told when the lock happens as well as polling for it. What is done about each of these, on both hosts, is the
same: a display that is gone has its video finalized at once, a display that returns starts a new segment, and every
stream is started afresh after a wake instead of trusting the old one.
### Capturing the screen
| | macOS | Windows |
|---|---|---|
| API | ScreenCaptureKit, through `objc2` bindings, and AVFoundation's `AVAssetWriter` | Windows.Graphics.Capture (Windows 10 version 1803 or later), and a Media Foundation MP4 sink |
| permission | Screen Recording, granted to the terminal or app that launches the binary | none |
| default codec | HEVC | H.264 |
| other codec | H.264 (`--codec h264`) | HEVC is refused with an error: Media Foundation's MP4 sink does not write it |
| what is captured | each display, excluding the recorder's own processes by name | each monitor whole, so the program's windows ask to be left out (see below) |
| a still screen | a healthy stream still calls back about 30 times a second, so silence for four seconds means a stalled stream | Windows sends nothing while the picture does not change, so silence says nothing there |
The video of a display is written as fragmented MP4 on both hosts, in segments, so that the part written before a crash
can still be played. Because ScreenCaptureKit only emits frames when the screen changes, the macOS capture re-submits the
last frame so that a static display still flushes fragments.
### The OS trace
| | macOS | Windows |
|---|---|---|
| source | the unified log, through `log stream --style ndjson` child processes | WinEvents for every top-level window, through a hook, and the System Event Log |
| files | `oslog/komorebi.ndjson`, `oslog/system.ndjson` and one `oslog/apps/<exe>-<pid>.ndjson` per managed application | `oslog/system.ndjson` (the WinEvents, repeats folded) and `oslog/eventlog.ndjson` (warnings, errors and the display, power and GPU providers) |
| permissions | none: no `sudo` and no change to SIP | none |
| redaction | `<private>` values stay redacted | not applicable |
A host with no OS trace says so in the recording instead of failing to start streams that do not exist.
### Locking a session
A recording holds an exclusive lock on `recorder.lock` in its session for as long as it runs, and writes its process id
to `recorder.pid`. The OS drops the lock when the process dies, however it dies, so a lock that is held means a live
recorder and one that is free means there is none. Windows file locks are mandatory, which is why the pid is not kept in
the locked file.
### komorebi's log and how the recorder talks to it
| | komorebi for Mac | komorebi for Windows |
|---|---|---|
| data directory | `~/Library/Application Support/komorebi` | `%LOCALAPPDATA%\komorebi` |
| log | `komorebi_plaintext.log.<UTC date>` in the data directory | `%TEMP%\komorebi_plaintext.log.<UTC date>` |
| command and subscriber sockets | unix domain sockets in the data directory | unix domain sockets in the data directory, through `uds_windows` |
| `--log-level debug` | `komorebi --log-level debug` | `komorebi.exe --log-level debug`; `RUST_LOG=debug` also prints every dependency, so name the crate: `RUST_LOG=komorebi=debug` |
The wire protocol is the same on both. The recorder's own binary does not depend on either komorebi's crates.
### Decoding the recorded video
macOS decodes with AVFoundation's `AVAssetReader`, Windows with Media Foundation's Source Reader, and the `unsupported`
host with nothing: it says so when asked to open a file. Both real hosts are asked for BGRA frames at a chosen size, so
that a contact sheet never decodes more pixels than it shows.
### The window track
`record` samples every top-level window (on by default; `--window-track=HZ` picks the rate, `--no-window-track` turns it off) into `windows.jsonl` (see
`src/sources/windowtrack.rs`), listed by `platform::window::list`.
| | macOS | Windows |
|---|---|---|
| source | `CGWindowListCopyWindowInfo(OptionAll)`, layer 0 windows | `EnumWindows` once per tick, then cheap reads of each window |
| `id` | the window server's window number | the window handle (komorebi's `hwnd`) |
| `rect` | `kCGWindowBounds`, in display points | the visible frame (`DWMWA_EXTENDED_FRAME_BOUNDS`), in pixels |
| `visible` | `kCGWindowIsOnscreen` (false for windows on other spaces) | `IsWindowVisible`; invisible windows and tool windows are not listed |
| `minimized` | always false: the window server does not say | `IsIconic` |
| `cloaked` | absent | `DWMWA_CLOAKED` |
| `border` | set on the layer-0 windows owned by the `komorebi` process, which are komorebi's borders (`border_of` is never set; pair one with its window by rect, as `lag` does) | `komoborder-<id>` tool windows are listed (other tool windows are not), with `border` true, and `border_of` when the id is a window handle (a floating window); a tiled window's border is named for its container, see `windowtrack.rs` |
| `title` | `kCGWindowName` | `GetWindowTextW` |
| status | written against the `objc2` sources and not built or run | built and run |
### The program's own windows
The program has one window, with the recorder as its first tab and the recordings as the others. It must not be in the
video it is recording, in either of its sizes (the small always-on-top one and the full one), and komorebi must not tile
it. Every `komorebi-recorder` launch (`gui`, `view`, no command, and `komorebi-recorder-gui.exe`) shares one local socket,
so there is never a second window to exclude.
| | macOS | Windows |
|---|---|---|
| left out of the video | by name: every process called `komorebi-recorder` is excluded from the capture | each window asks to be left out of captures with `WDA_EXCLUDEFROMCAPTURE` (Windows 10 version 2004 and later) |
| left alone by komorebi | the windows have no title, which komorebi does not manage; there is no ignore rule to rely on, so they are never titled | the windows are titled `komorebi-recorder` only once the recorder has run `komorebic ignore-rule exe` for its executables (or no komorebi runs), and are otherwise untitled; `doctor` says which. The rule is komorebi's live one and is not saved: to keep it, see [recording a bug repro](usage/recording-a-bug-repro.md). Also `KOMOREBI_RECORDER_PROBE_WINDOW=1` makes a window ask komorebi whether it would manage it and write the answer to `komorebi-recorder-window-probe.txt` in the temp directory |
| icon | a slice of watermelon, which the Dock shows while a window is open (eframe sets it as the application's icon image). The program is a bare executable and not an app bundle, so Finder gives the file the generic executable icon | the same picture as the window and taskbar icon while a window is open, and compiled into both executables as a resource, which is what Explorer shows for the files; the installer shows it beside the program in Apps & features |
| executables | `komorebi-recorder` | `komorebi-recorder.exe` (console: run commands with this one) and `komorebi-recorder-gui.exe` (no console window) |
## Linux (KDE Plasma)
The Linux host records komorebi for KDE (`komorebi-for-kde`), on Plasma 6.8 or later, on Wayland. It is the
only Linux desktop the recorder knows: the screen comes from KWin's own screencast, and the windows from komorebi for
KDE. What is written from the sources and has not been seen to work on a real Plasma session is listed, one check each, in
[kde-checkpoints.md](dev/kde-checkpoints.md).
| | Linux (KDE Plasma) |
|---|---|
| master clock | `CLOCK_MONOTONIC`, `host.clock` is `monotonic`; it does not count the time the machine is suspended, and `CLOCK_BOOTTIME`, which does, is the reference clock |
| sleep, wake and lock | heard on D-Bus: logind's `PrepareForSleep` on the system bus and the screen saver's `ActiveChanged` on the session bus; whether the screen is locked is `org.freedesktop.ScreenSaver.GetActive`. The lid and the displays' power are not read; the displays are polled |
| the displays | the compositor's outputs, over Wayland (`wl_output` and `xdg_output`), kept up to date by a thread that reads the compositor's events. A display's `id` is the FNV-1a hash of the output's name, which is komorebi for KDE's id for a monitor with no serial number |
| capturing the screen | KDE's `zkde_screencast_unstable_v1`, which gives a PipeWire node and asks the user nothing; `pipewiresrc` reads it, and the frames are placed in the file's time as on Windows |
| permission | KWin offers the screencast only to a program whose desktop file lists `zkde_screencast_unstable_v1` in `X-KDE-Wayland-Interfaces`. `doctor` prints the file to write, with the path of the executable in it |
| the video | H.264 only, written by GStreamer (`x264enc` and `mp4mux`) as fragmented MP4 in segments, as on the other hosts. HEVC is refused. A display of an odd size, or one H.264 cannot take, is scaled by the pipeline |
| decoding | GStreamer: `decodebin` to BGRA at the size asked for, seeking to the key frame before the time and decoding forward. A frame's time is its stream time, because an MP4's edit list puts the media time of the first frame after zero |
| the OS trace | the journal: `oslog/system.ndjson` (`journalctl --user`, of `kwin_wayland`, `plasmashell` and `komorebi`, stream `journal`) and `oslog/eventlog.ndjson` (every warning and worse, stream `journal-warnings`). An entry's time is `__MONOTONIC_TIMESTAMP`, which is the master clock |
| the window track | komorebi for KDE's own *beliefs*, not KWin's geometry: only windows komorebi manages are listed, with komorebi's rect, each shown when its workspace is showing and it is in front of its stack. **Not done:** listing KWin's real windows. KWin has no D-Bus call that lists windows: `getWindowInfo` needs a UUID, and the only listing the recorder uses is `/WindowsRunner` `Match(query)`, which is a KRunner text search (it may need a minimum query length; not checked, so not relied on) and costs one `getWindowInfo` per window per tick. A complete, cheap source needs a KWin script (`loadScript` over `org.kde.kwin.Scripting`) that pushes `frameGeometryChanged`/`windowAdded` to a D-Bus service of the recorder's, or the `org.komorebi.Bridge` events; that was not built or tried on the Plasma guest. Until then the track on KDE cannot show a window komorebi does not manage, nor a frame that disagrees with komorebi's `rect` (use `--probe-windows` for per-event real frames). komorebi for KDE has no border windows (KWin's rounded-corners effect paints them), so there is nothing to mark `border` there |
| komorebi's sockets | `$XDG_RUNTIME_DIR/komorebi/` (the command socket `komorebi.sock` and the subscribers'), and the data directory where there is no runtime directory |
| komorebi's log | `~/.local/share/komorebi/komorebi_plaintext.log.<UTC date>`; the span of an event's handler is `handle_event` and of a command's `process_command` |
| the program's own windows | left out of the video by a KWin window rule (`excludefromcapture`, forced for the window class `komorebi-recorder`), which `record` writes to `~/.config/kwinrulesrc` and has KWin read; komorebi is told to ignore them by their application id, `komorebic ignore-rule class komorebi-recorder`, run before the window exists. Whether KWin honours the rule for a screencast of an output is a check still to make (K3) |
| the window's application id | the window's application id is `komorebi-recorder`, which is the `class` komorebi for KDE sees |
| `--probe-windows` | on by default, as on Windows: after each window event KWin is asked about the window (`org.kde.KWin.getWindowInfo`: the desktops it is on, minimized, its frame). komorebi's window is found by its class, title and frame through KWin's windows runner, because komorebi's ids are a count and not KWin's UUIDs. A window on a desktop that is not showing is `not visible`, one alone on `komorebi-park` is `cloaked` |
| ghost tiles | found from the frames komorebi has in its state, as on a Mac (a window in front on a showing workspace that has no frame anyone can see). No rule is proposed for one: komorebi for KDE's rules are in its own repository |
komorebi for KDE's rules are checked against the log and the events of a running komorebi (`komorebi --fake-backend`, an
in-memory desktop with no windows), and against its source. They are not checked against a recording of a real
desktop, so an analysis of a KDE session says so, as it does for Windows.
### What is needed on the machine
- the GStreamer plugins that read PipeWire (`pipewire`), decode and encode H.264 (`gst-libav`, `gst-plugins-ugly` for
`x264enc`), and mux MP4 (`gst-plugins-good`); the Nix package puts them on the plugin path;
- `libwayland-client`, which is opened when it is needed, and what the window draws through (`libxkbcommon`, `libGL` or
Vulkan): the Nix package and the dev shell put them on `LD_LIBRARY_PATH`;
- `ffmpeg` for `frames` and `selftest`, and nothing else.
## Degraded modes
- `record --no-video` records everything but the screen, on the same clock. It asks the system nothing about displays and
needs no permission.
- `record --no-komorebi` skips touching komorebi altogether, and `--no-oslog` skips the OS trace.
- A komorebi that is not running when a recording starts is not an error: it is noted, and the recorder subscribes when
it appears.
- The `unsupported` host investigates sessions and refuses to record.
## Advice by audience
- **Recording on macOS.** Grant Screen Recording to the terminal, and start komorebi with `--log-level trace`.
- **Recording on Linux (KDE Plasma).** Install the desktop file `doctor` prints, so that KWin offers the screencast, and start
komorebi for KDE with `--log-level debug`. Use `record --no-video` where there is no screencast to be had.
- **Recording on Windows.** There is nothing to grant. Use `komorebi-recorder.exe` for commands, since the GUI build
prints nowhere, and start komorebi with `--log-level debug` and `RUST_LOG=komorebi=debug`.
- **Investigating on any host.** A session is read the same everywhere. `ffmpeg` is needed only for `frames` and
`selftest`.
- **Changing code that has a host-specific part.** Provide the function on every host, and run `just check-windows` from a
Mac: it type-checks every `cfg(windows)` line, tests included.
+91
View File
@@ -0,0 +1,91 @@
# ETW spike: what an ETW tap would tell us about window management
Date 2026-10-28, Windows 11 26200, **not elevated** shell (user is in Performance Log Users). No recorder
code was written. Traces and scripts live in the session scratchpad, not the repo.
## Method
`logman create trace <n> -p <guid> 0xffffffffffffffff 0xff -o <n>.etl -ets` for Win32k, User32, Dwm-Core
and Shell-Core (one file session each, plus a real-time `-rt` Win32k session). Then a throwaway
WinForms window owned by a spawned `pwsh` (hwnd 0x2A80880, pid 10404) was driven with `SetWindowPos`
(move, resize, TOPMOST, NOTOPMOST), `ShowWindow` (minimize, restore, hide, show),
`DwmSetWindowAttribute(DWMWA_CLOAK)` and `SetForegroundWindow` over about 6 s. Sessions stopped, decoded
with `tracerpt <etl> -of CSV`. Nothing outside that window was touched.
## Elevation
- **Every session started without elevation**: Win32k, User32, Dwm-Core, Shell-Core, real-time and file.
Nothing was refused; membership of Performance Log Users is enough for user-mode provider sessions.
(`logman query -ets` listed all five as Running.) We did not try the kernel logger (NT Kernel Logger,
`SystemTraceProvider`); that one does need admin and is out of scope.
- `Microsoft-Windows-User32` {B0AA8734...} started fine but emitted **nothing** (2 header events only; it
has no registered manifest on this machine: `wevtutil gp` cannot find it). It is not a window-API trace.
- If a future machine does refuse, the command to try elevated is the same one:
`logman create trace x -p "{8C416C79-D49B-4F01-A467-E56D3AA8234C}" 0xffffffffffffffff 0xff -o x.etl -ets`.
## What the events contain
| Provider | Events in ~22 s | Notes |
|---|---|---|
| Win32k | 102,911 delivered, **817,109 lost** (default buffers) | about 4.7k/s kept, about 42k/s offered, while the desktop was idle |
| Dwm-Core | 216,834, 0 lost | about 10k/s |
| Shell-Core | 48,123, 0 lost | about 2k/s |
| User32 | 0 | nothing |
- **Win32k** is a graphics and input trace (CreateHandle/DestroyHandle/TransformHandle, FlipManager,
touch targeting, pseudo-device, "Info" ids 164/167/301/65...). 79 events carried our pid in the header
during the run, spread over ids 164, 166, 167, 45, 84-87, 452, 453, 2000, and none of them was a
window-management call. The hwnd 0x2A80880 appears in **no** Win32k payload; neither did our rect
(500x400, 600x450) or SWP flags. Payloads are untyped numbers to `tracerpt` (the manifest is in
win32kbase.sys, see below), so even a mapping would be reverse engineering.
- **Dwm-Core** carried our hwnd in 36 events, only in two kinds, both from `dwm.exe`:
- id 84, task `WINDOWNODE_GDISPRITE_ASSOCIATION`: hwnd, then handles. 26 hits.
- id 209 `Stop` (task 137): hwnd, 0, 0, then a 4x4 identity transform matrix. 10 hits. No rect, no
flags, no cloak bit, no z-order, no show/hide. The 10 hits for roughly 11 API calls cannot be tied to
a call without the timestamp alignment.
- **Shell-Core**: no hwnd or pid match at all for our window.
- **Who called?** Header PID/TID of every Dwm-Core event is `dwm.exe` (0x834) and the thread inside it
(0xA50/0xBFC). That is the *consumer* of the change, never the process that called `SetWindowPos`. For
Win32k the header pid is the process that ran the kernel path (ours, 10404, for our own work), which is
the closest to a caller found, but it showed only graphics events, not "this process moved window X".
Sample (Dwm id 209, trimmed):
`Microsoft-Windows-Dwm-Core, Stop, 209, ..., pid 0x834, tid 0xBFC, ..., 0x2A80880, 0x0, 0, 1.0 0 0 0 | 0 1.0 0 0 | 0 0 1.0 0 | 0 0 0 1.0`
## What WinEvents already give
The existing hook (`EVENT_MIN..EVENT_MAX`, `SetWinEventHook`) yields, per top-level window: hwnd plus
class and program (looked up), `EVENT_OBJECT_LOCATIONCHANGE`, `OBJECT_CLOAKED`/`UNCLOAKED`,
`OBJECT_SHOW`/`HIDE`, `SYSTEM_FOREGROUND`, `SYSTEM_MINIMIZESTART/END`, move/size start/end,
`OBJECT_REORDER`, with the event thread/time. Compared with ETW: WinEvents are *per window* and
semantic, ETW is *per frame* and about DWM internals. ETW added no hwnd-level fact the hook lacks, and
neither source yields the rect or flags (the hook consumer can call `GetWindowRect` at record time, which
is already the cheaper way).
## Cost of a tap
- Behind `platform::trace`, as a third tap beside the hook and Event Log. Crate options: `ferrisetw`
(real-time `UserTrace` and a callback, schema decode through TDH) or the `windows` crate
`StartTraceW/EnableTraceEx2/OpenTraceW/ProcessTrace`. About 1.5 to 2 days including dropping
events on a hot path and a session that must be stopped at crash (a leaked session survives the
process; use a unique name and `ControlTrace(STOP)` on startup).
- It fits the oslog record shape (`ts, source, process, message`), but only by flattening each event to
`provider:id task` plus untyped numbers, which is not useful to read.
- Noise is the problem: 10k to 40k events/s from Win32k and Dwm-Core with nothing happening, almost all
of it frame pacing. It would need a per-id allowlist and still shows nothing we want.
## Recommendation: **don't build it**
None of the four goals (hwnd, rect, flags, caller) come out of the providers that are available without
elevation. What would give them is not an ETW provider but a komorebi-side change:
1. Have komorebi log, at the place it applies a layout (its `WindowManager::update_*` and `Window::set_position`,
`hide`, `cloak` paths), the hwnd, target rect, SWP flags, and `reason` (which event or command caused
it) into its own state/notification stream; the recorder already ingests that stream.
2. If the *foreign* caller is wanted (an app fighting the tiling), the practical method is a `WH_CBT`
or `WH_CALLWNDPROC` hook with `WM_WINDOWPOSCHANGING`, which carries the `WINDOWPOS` struct (hwnd,
rect, flags) and runs in the caller's context. That needs a DLL injected and is a much bigger step
than a trace tap; the cheaper step is to take a `GetWindowRect` snapshot on each ObjectLocationChange
in the recorder (a few extra lines in `win/trace.rs`) and record the flags komorebi sets itself.
3. Revisit ETW only if a Microsoft-Windows-Win32k manifest with window-position events turns up in a
later Windows build, or if we accept the kernel logger (admin) for a one-off diagnostic.
+117
View File
@@ -0,0 +1,117 @@
# KDE checkpoints
`komorebi-recorder` is built and tested on Linux, but with no KWin to talk to: what touches a real Plasma session was
written from KWin's and komorebi for KDE's sources and has not been seen running. Each checkpoint below is a short list
of commands to run on a Plasma 6.8 session that runs komorebi for KDE, what to expect, and what to send back. The point
of each is to replace something read in a source with something observed.
Send back, for any step that does not behave: the exact command, what it printed, the output of
`komorebi-recorder doctor --json`, and the session directory if there is one.
## What has been seen
Against komorebi for KDE's in-memory desktop (`komorebi --fake-backend`, which has no windows) and the Wayland compositor
of WSLg (which has outputs and no screencast):
- `doctor` names komorebi for KDE and finds its socket in `$XDG_RUNTIME_DIR/komorebi`;
- `record --no-video` records its log, its commands as events with the handler of each, and the journal in two streams,
and `events`, `summary` and `findings` read the session with the KDE rules;
- the displays are listed from the compositor, with a size and a position;
- a made-up source of frames is written to an H.264 file, which the decoder reads back, at the size of the display and
at an odd size.
And in the Plasma guest of komorebi for KDE (`nix run .#run-kde`, KWin 6.8.2, komorebi with windows, headless over ssh;
the recorder from `nix build` runs in it, as the guest mounts the host's store):
- **K1:** `doctor` says `permitted: yes` and a recording works with no desktop file written. Whether KWin offers the
screencast to every program, or this guest's configuration allows it, was not found out.
- **K2:** a recording of the output is a playable H.264 file with the windows, the panel and the cursor in it, and its
length is the recording's. The frames' times were wrong at first (the GStreamer pipeline took the clock of the
PipeWire stream, which starts at zero) and are on the master clock now. The log, the events and their handlers line up.
- **K3:** the rule that leaves the recorder's window out of the capture works: a window of the class
`komorebi-recorder` that had the focus and was on top is not in the video, and one of another class is. KWin 6.8
rewrites `kwinrulesrc` with `Order=` in place of `count=` and `rules=`, and the recorder extends whichever the file has.
- **`--probe-windows`:** a window of an event is found in KWin and its facts are read: frame, minimized, the desktops. The
probes of a recording with workspace switches, a new window, a stack and a closed window agree with komorebi, and the
one of a window that was closed says it no longer exists. komorebi's workspaces are KWin's virtual desktops, so a
window of another workspace is not on the desktop that shows; the park desktop holds only windows hidden behind a
front one. What was not seen: a probe that disagrees with komorebi (nothing was broken), and a window that cannot be
told from another by class, title and frame (it has no probe).
## Getting the binary
```sh
nix build .#komorebi-recorder --out-link result
result/bin/komorebi-recorder doctor
```
The package wraps the program so that GStreamer finds its plugins (`gst-libav`, `x264enc`, the PipeWire source) and the
program finds `libwayland-client`. Outside Nix, install the same.
## K0: what komorebi for KDE really sends
Status: **can be run now, and is the most useful one.** The rules that read komorebi for KDE's events, `State` and log
were written from its source and checked against its log and commands, not against windows (the analysis says so in a
warning until they have been).
1. Start komorebi for KDE with debug logging: `komorebi --log-level debug` (or `RUST_LOG=komorebi=debug`).
2. `komorebi-recorder doctor`. Expect `komorebi for KDE`, `running: yes`, the socket under `$XDG_RUNTIME_DIR/komorebi`
answering a state query, the log directory `~/.local/share/komorebi` with a `komorebi_plaintext.log.<date>` in it, your
outputs, and `clock: Monotonic`.
3. Record 60 seconds with `--no-video`, and during them: open and close a few windows of different programs, focus
between them, drag one to a new place and drag-resize one, stack and unstack, switch workspaces
(`komorebic focus-workspace 1` and back), and lock and unlock the screen.
4. `komorebi-recorder events <session>`. Expect each window event with its window id, program and notification
(`WindowAdded`, `InteractiveMoveFinished`, ...), each with a handler. Send back any event named `unreadable` or
classified `other`, any window event with no handler, and any `MoveEnd` that is not classified `drag`.
## K1: the screencast is offered, and what it asks
Status: not run. This is the one the Linux host depends on.
1. `komorebi-recorder doctor`: under `capture`, `permitted: no` and the note with the desktop file.
2. Write `~/.local/share/applications/komorebi-recorder.desktop` as the note says (`Exec=` is the path of the executable
that runs), and start the recorder again. Expect `permitted: yes`. In the Nix package the program
is a wrapper that starts `.komorebi-recorder-wrapped`, and that is the executable the compositor sees, so it is the path
`doctor` prints (it is `current_exe`).
3. If it is still `no`: say where KWin looks for desktop files and how it matches the program to one. Whether a
desktop file in the user's `applications` directory is enough, whether `Exec=` has to be the executable's real path,
and whether a program started from a terminal is matched at all, are what this finds out. If it cannot be made to
work, the screencast portal (`xdg-desktop-portal`) is the way around it, behind the same `CaptureBackend`.
## K2: recording the screen
Status: not run.
1. `komorebi-recorder displays`. Expect each output with its size and position in the layout (logical pixels). Compare the
ids with komorebi's: `komorebic monitor-information` (they agree for a monitor with no serial number).
2. `komorebi-recorder record --duration 20`, and move windows during it. Expect a `video-<id>.mp4` for each output and
`frames-<id>.csv`, and in the session summary no error.
3. Play it with `komorebi-recorder view <session>`. Expect the picture to move with the windows, and the cursor in it.
4. `komorebi-recorder doctor --json`: the clock check (`latency`) of the segments should be near zero. A large number
means the frames' times are not on the master clock, which would be the PipeWire timestamps: send the numbers back.
5. Leave the screen still for ten seconds: the video should still advance (the last frame is repeated).
6. Unplug a monitor, or turn one off, if there is one to spare: the segment ends and a new one starts when it returns.
7. Suspend and resume: every output starts a new segment.
## K3: the program's own window
Status: not run.
1. `komorebi-recorder` with no command opens the window. Expect it to be titled `komorebi-recorder` and not tiled.
2. If it was tiled, `komorebic ignore-rule class komorebi-recorder` was not applied in time, or the window's class is not
what is expected: `komorebic state` says what the window's class is.
3. `record` writes a KWin window rule (`~/.config/kwinrulesrc`, group `komorebi-recorder-exclude-from-capture`) that
forces `excludefromcapture` for the class `komorebi-recorder`. Record with the window open and play the video: the
window should not be in it. If it is, say whether `kwinrulesrc` has the rule, whether System Settings > Window
Rules shows it, and what `qdbus6 org.kde.KWin /KWin supportInformation` says of the window's class.
## K4: the OS trace and the window track
Status: the journal was followed on a machine with no Plasma.
1. `record --duration 30`, and cause some noise: open a program that is not in the session, plug something in.
Expect `oslog/system.ndjson` to have `kwin_wayland` and `plasmashell` entries, and `oslog/eventlog.ndjson` the warnings.
A user who is not in the `systemd-journal` group may see none of the system's: the problems say so.
2. `record --duration 30` (the window track is on by default). Expect `windows.jsonl` with the windows komorebi manages, a window behind a
stack not shown, and a window of another workspace not shown.
+216
View File
@@ -0,0 +1,216 @@
# Windows checkpoints
`komorebi-recorder` is built for Windows from a Mac (and, in CI, on Windows), so nothing that touches a real
Windows desktop has been seen running. Each checkpoint below is a short list of commands to run on a Windows PC or
VM, what to expect, and what to send back. The point of each is to replace something read in
komorebi's source with something observed.
Send back, for any step that does not behave: the exact command, what it printed, the output of
`komorebi-recorder.exe doctor --json`, and the session directory if there is one.
## Getting the binaries
On the Mac, in this repository:
```sh
nix build .#komorebi-recorder-windows --out-link result-windows
ls result-windows/bin
# komorebi-recorder.exe console build: use this one to run commands and read their output
# komorebi-recorder-gui.exe the same program without a console window (shortcuts, the viewer)
```
Copy `komorebi-recorder.exe` to the Windows machine. The `windows` job of CI builds the same executables natively and
uploads them, with the installer, as artifacts of the run. To check that the Windows code still type-checks
without building it: `nix flake check` (the `komorebi-recorder-windows-clippy` check) or
`nix develop .#windows --command cargo clippy --all-targets`.
## W0: what komorebi for Windows really sends
Status: **can be run now, and is the most useful one.** Reading komorebi for Windows' events, state
and logs was written from komorebi's source and has not been checked against a recording of it (the
analysis says so in a warning until it has); this is what checks it.
1. Start komorebi for Windows with debug logging. The default of `RUST_LOG=debug` also prints every
dependency, so name the crate:
```powershell
komorebi.exe --log-level debug
```
(or set `RUST_LOG=komorebi=debug` first).
2. Describe the machine:
```powershell
komorebi-recorder.exe doctor
komorebi-recorder.exe doctor --json > doctor.json
```
Expect: `komorebi for Windows`, `running: yes`, a binary path and version, `log level: debug`,
`answers a state query: yes`, the log directory under `%TEMP%` with a `komorebi_plaintext.log.<date>`
in it, your displays with their scale, and `clock: Qpc`. `can record: yes` and `can decode: yes`
are what this build claims; whether they are true is W1 and W3. Anything under "things to know"
is worth reading. If the state query is
reported as answered with nothing, say what komorebi was doing (paused, another virtual desktop).
3. Record 60 seconds without video, and during them:
- focus a few windows of different programs (click, and with `komorebic.exe focus left|right`);
- drag a window to a new place, and drag-resize one;
- move windows with komorebic (`move`, `stack`, `unstack`, `focus-workspace 1` and back);
- open and close a program, and minimize and restore one;
- if you can: change the display scaling or resolution, connect or disconnect a monitor, switch to
another virtual desktop and back, lock (Win+L) and unlock once.
```powershell
komorebi-recorder.exe record --no-video --duration 60 --out C:\temp\w0
```
Expect a line per second with `events` counting up as you act, `komorebi log` growing and `OS
trace` counting up (WinEvents for every window, so it is busy while you work), then `session:
C:\temp\w0`. If the OS trace is too much or too little, say so: it is folded per window but its
volume on a real machine has not been seen. `--no-oslog` leaves it out.
4. Look at it, to see what the current (macOS-vocabulary) analysis makes of it. It is expected to be
wrong in places, and what is wrong is the point:
```powershell
komorebi-recorder.exe brief C:\temp\w0
komorebi-recorder.exe events C:\temp\w0 --json > events.json
```
5. Send back `doctor.json` and the whole `C:\temp\w0` folder, zipped. It contains the titles and
program names of your windows (`events.jsonl`, `states\*.json`, `komorebi.log`); redact them first
if that matters (they only need to still be valid JSON, and the Windows fixtures are scrubbed by
hand anyway).
Also worth one run, for the checks komorebi's state cannot make (it hides windows by cloaking them
in place): record with the probe on, and switch workspaces a few times (`komorebic.exe
focus-workspace 1`, `2`, `1`) while focusing windows.
```powershell
komorebi-recorder.exe record --probe-windows --no-video --duration 60 --out C:\temp\w0-probe
komorebi-recorder.exe overview C:\temp\w0-probe
```
`overview` should report nothing about hidden windows if komorebi and Windows agree. If it reports
`visible-window-hidden` or `hidden-window-visible`, `komorebi-recorder.exe trace C:\temp\w0-probe
event:<n>` shows what Windows said; say whether it is a real fault or a false alarm (a window mid
transition, say), and how many there were. The probe asks komorebi about a window by `DebugWindow`;
if komorebi stalls while it runs, say so.
Optional, for the part of the plan that stops the recorder window being tiled: for one window komorebi
manages and one it does not (get handles from `komorebic.exe state`), run
```powershell
komorebi-recorder.exe doctor --probe window --hwnd <handle>
```
and send what komorebi says.
## W1: capture and the clock across a sleep
Status: **can be run now.** Windows capture, the power watcher and the OS trace are built but have
never run on Windows; these are the first runs.
1. The clock across a sleep (see above): `doctor --probe clock --seconds 120`, sleeping the machine
for about a minute while it runs.
2. Capture on a static screen. Leave the screen completely still for most of it:
```powershell
komorebi-recorder.exe doctor --probe capture --seconds 20
```
Expect, per display, a segment with a handful of frames, `idle callbacks 0` (Windows says nothing
about a still screen), a file that `plays` for about the length recorded, and `latency` of a few
milliseconds to well under a second, `(NOT on the host clock)` absent. Check it with ffmpeg if you
have it: `ffprobe <session>\video-<id>.mp4`.
3. Two monitors, if you have them: the same again, and say what it printed for each.
4. Kill it and play the file. Start a longer one, then end it without letting it stop:
```powershell
komorebi-recorder.exe doctor --probe capture --seconds 60
# after 15 s, from another window:
taskkill /F /IM komorebi-recorder.exe
```
Then try to play `video-*.mp4` in the session folder (any player), and run
`komorebi-recorder.exe reindex <session>`. This answers whether Media Foundation's fragmented MP4
survives a kill (the part before the last fragment, about a second, should play) and whether
`reindex` can recover the session. Say what the player did and what `reindex` printed.
## W2: a real recording, and the machine doing the things
Status: can be run once W1 shows capture works.
```powershell
komorebi-recorder.exe selftest --seconds 8
komorebi-recorder.exe record --duration 60 --out C:\temp\w2
komorebi-recorder.exe reindex C:\temp\w2
```
`selftest` needs `ffmpeg` on PATH; expect `PASS` with the worst disagreement under 100 ms. During the
60 s recording: dock or undock a display, put the machine to sleep and wake it, lock and unlock
(Win+L), and close the lid if it is a laptop. Afterwards `komorebi-recorder.exe summary C:\temp\w2`
and `komorebi-recorder.exe at C:\temp\w2 <time> --source recorder` should show each as an incident
(`suspend`, `wake`, `lid-closed`, `screen-locked`, ...) next to the video gaps. Send back the session
folder (the video is large; the rest is what matters, say so if you leave it out) and anything that
looked wrong.
## W3: playing it back
Status: can be run once W1 shows capture works.
```powershell
komorebi-recorder.exe doctor --probe decode --file C:\temp\w2\video-<id>.mp4
```
Expect the video's size and duration, a first frame in well under a second, and a speed in frames
per second, then three seeks each answered with a frame at or just before the time asked for. Say
if any answers "no frame" or is far from what was asked.
## W4: our windows
Status: can be run once W1 shows capture works.
1. Start komorebi, then open the viewer on a Windows session: `komorebi-recorder-gui.exe view
C:\temp\w2`. It should open floating (not tiled into your layout) and be usable: moving, resizing,
minimizing and closing it. If komorebi tiles it, say so.
Its taskbar button and Alt+Tab entry should show the watermelon icon.
2. Ask komorebi what it thinks of it. Set `KOMOREBI_RECORDER_PROBE_WINDOW=1` before starting the
viewer (or the recorder window), wait a few seconds, and send back
`%TEMP%\komorebi-recorder-window-probe.txt`.
3. Open the recorder window (`komorebi-recorder-gui.exe`) and the viewer, record 10 s with them
open, and check neither appears in the video (`doctor` warns if this Windows is too old to keep
them out).
4. The OS trace: `komorebi-recorder.exe record --duration 20 --out C:\temp\w4` while moving a
window about, then `komorebi-recorder.exe trace C:\temp\w4 event:<a MoveResizeEnd or FocusChange>
--os`. It should list what Windows told komorebi around that event, grouped by program. Say what
the volume looked like (`summary` shows the counts) and whether it was too much or too little.
## W5: the installer
Status: can be run once CI has built one. WiX only runs on Windows, so what a Mac can check about the installer is
`tests/packaging.rs`; everything below is first seen here. The installer is not signed, so SmartScreen or Defender may
warn on the first run.
1. Download the MSI from the `windows` job's artifact (or the nightly release) and install it. Open a new shell and run
```powershell
komorebi-recorder doctor
```
That it runs proves the `PATH` entry. `Program Files\komorebi-recorder\bin` should hold `komorebi-recorder.exe` and
`komorebi-recorder-gui.exe`.
In Explorer both executables should show the watermelon icon, and so should the entry in Apps & features.
2. Install a second build over it, such as the next nightly. It should upgrade in place: one entry in Apps & features,
not two.
3. Uninstall it. The files and the `PATH` entry should go. If komorebi for Windows is installed from its own MSI, check
that it is untouched: the two installers must not upgrade or uninstall each other.
4. The ARM64 installer has only been cross-built on an x86_64 runner. If you have an ARM64 machine, repeat 1 to 3 with it.
@@ -0,0 +1,209 @@
# Investigating a Recording
A [recording](recording-a-bug-repro.md) answers "what was komorebi doing when this went wrong?" if you can read it.
`komorebi-recorder` has commands that do the reading, built so that a person or an agent can go from "the user says
this is broken" to "this is the line of komorebi that causes it" using what was recorded rather than guessing.
```
komorebi-recorder brief <session> # start here
komorebi-recorder brief <session> --compact # the same, in about 40 lines
komorebi-recorder findings <session> # everything the detectors found and an agent concluded
komorebi-recorder guide # the playbook, for an agent
```
Every command takes `--json`, which prints an envelope `{ok, schema, data, warnings, truncated, next_cursor, error}`;
`komorebi-recorder schema` lists the schemas and `komorebi-recorder schema brief/1` prints one. Exit codes: 0 ok, 1
error, 2 usage, 3 not found, 4 the session cannot answer (still recording, or the recorder died: `reindex` it), 5 over
budget, 6 an `assert` check did not hold.
## The viewer
```
komorebi-recorder view <session>
```
opens the recording in the window, for the person who made it (or anyone with the folder) to play, scrub and mark.
The Record tab of the same window has **Open session…** and **Open last** for the same thing.
There is only ever one window, for recording and for reviewing: its first tab is **Record** (see [Recording a bug
repro](recording-a-bug-repro.md#the-window)) and each recording is a tab after it. `komorebi-recorder view
<session>...` (from another terminal, or from the Record tab) adds tabs to the window that is already open and brings it
to the front, so several recordings can be loaded side by side. A recording that is already open is just switched to. **+** (or ⌘/Ctrl-T)
adds a start tab with your recent recordings and **Open…**, × (or middle-click, or ⌘/Ctrl-W) closes a tab (closing the
last one shows the Record tab), Ctrl-Tab and ⌘/Ctrl-1 to 9 move between them, ⌘/Ctrl-0 goes to the Record tab, and only the tab you are looking at plays. `view --new-window` skips all of this and
opens a window of its own.
- The **video** of every display, side by side. A display that was unplugged or asleep shows why it has nothing there,
and the others carry on. **State overlay** draws komorebi's idea of the layout over the picture: where each tiled
window was meant to be (dashed) and where it really was (solid, red if it looks wrong).
- The **timeline** under it has a lane for the **bug regions** you marked, komorebi's **events** (coloured by what kind,
with echoes faint), errors and warnings in komorebi's log, what happened to the **machine** (a display unplugged, a
sleep), the **findings** that look wrong, and the **video** each display has. Click anywhere to go there, drag to
scrub, pinch or ⌘-scroll to zoom, scroll to pan, Shift-drag to select a range.
- **Playing** goes forwards and backwards at 0.25× to 8×; J, K and L shuttle like a video editor; ← and → step one
frame; `,` and `.` jump between events. Press **?** in the window for every key.
- The **inspector** on the right: _Now_ is the state at the playhead and what has just happened; _Event_ is a selected
event traced end to end, as `trace` shows it, ending with what the OS trace recorded around it (komorebi's own calls
into the OS, the system, each application) as groups you can open; _Findings_ is what looks wrong, ranked; _Bugs_ is what was marked and
concluded; _Log_ is komorebi's own log, following the playhead.
### Marking the bug
Press **B** (or **Mark bug**) to describe the bug: the form takes the region from your selection (`[` and `]` mark its
ends, or Shift-drag on the timeline) or from the playhead, asks what goes wrong and what you expected, and saves it the
moment you press Save. Drag a region's edges on the timeline to adjust it. **Copy a prompt for an agent** in the _Bugs_
tab puts an instruction on the clipboard that starts an agent on `brief` with your description.
### Proposing a rule for a ghost tile
A _ghost tile_ is a tile of the layout that holds a window nobody can see: komorebi has the window in front on a
workspace that is showing, and it never was on screen. When a bug region you marked was made while one was there, the
_Bugs_ tab says so under the region, and **Propose a rule to komorebi-application-specific-configuration** opens a
form with the rule that would ignore that window: which window it was, what the recording showed of it, and the entry
that would go in the repository. Nothing is sent until you press **Send as a pull request**.
Sending clones the repository into a temporary folder, commits the rule on a new branch with a message that says what
was seen and why, and opens a pull request under your account with the credentials you already have set up for `git`
(and the GitHub CLI, `gh`, if you have it). With `gh` signed in, the branch goes to your fork of the repository, made
if you have none, unless you may push to the repository itself. Without `gh` the branch is pushed with `git` and you
are given the link that opens the pull request. If anything fails, the form says what, keeps the clone, and gives the
commands to push it and open the pull request yourself.
The rule goes in the file of the komorebi the recording is of, whatever you are looking at it on:
`applications.json` for komorebi for Windows and `applications.mac.json` for komorebi for Mac. It is always narrow
enough to leave the application's other windows alone:
| | komorebi for Windows | komorebi for Mac |
|---|---|---|
| matches | the program and the window class, as a composite rule | the application and the window title, as a composite rule |
| when the application's visible windows share that class | the title is added, if it tells them apart | (windows have no class) |
| when nothing tells the ghost from a visible window | no rule is written, and the form says why | no rule is written, and the form says why |
The entry is put where it sorts and the rest of the file is unchanged, line for line.
What counts as a ghost tile depends on what the recording can say. On Windows it needs the window probes that `record` takes by
default (see
[Probing windows on Windows](recording-a-bug-repro.md#probing-windows-on-windows)): Windows says whether each window is
on screen, and a ghost is one it said was cloaked or not visible on every read and never on screen. A Mac cannot be
asked, so there it is a window whose frame, as komorebi read it from the accessibility API, was never one a person
could see: zero-sized, or outside every display. That is weaker evidence, and the pull request says which it is. A
recording that has none of this has no ghost tiles to propose, which is not the same as having none.
Everything the viewer shows is also available from the command line, so an agent can investigate headlessly:
## What the user said
The first thing in a [brief](#brief) is the **bug region**: the stretch of the recording the user marked, with their
description of what is wrong and what they expected.
The user marks it in the viewer. To add one without a window, as a script or an agent would:
```
komorebi-recorder annotate <session> add --kind bug --start 12.5 --end 18 \
--text "the new window opens on the wrong monitor" --expected "it should open on the focused one"
komorebi-recorder annotations <session>
```
Times can be a video timecode (`12.5`, `1:02.5`), `logtime:<HH:MM:SS.mmm>`, `wall:<RFC 3339>`, `mach:<ns>`,
`event:<seq>`, `log:<line>`, `incident:<n>` or `bug:<id>` (`.start` or `.end`), each with an offset such as `+3s`. Every
command that takes a time (`at`, `range`, `frames`, `trace`, `diff`, `events`, ...) takes all of them.
`logtime:15:46:22.743` is a time of day as komorebi's log writes it (UTC), so a log line can be quoted as it is; the
date comes from the recording (the one on which the time falls inside it, if the recording crosses midnight).
`wall:15:46:22.743` means the same. It needs the prefix because a bare `1:02:03` is video time, and the two cannot be
told apart by their digits. `event:12` is when komorebi began handling event 12
and `event:12.end` when it finished.
## Commands
| Command | What it tells you |
| --- | --- |
| `brief` | The bug region(s) in the user's words, then what the recording shows around them: the events, what looked wrong, the state as it began and ended, what happened to the machine, and the events most worth tracing first, with why |
| `brief --compact` | The brief cut down to fit a small context window, about 40 lines: the user's words, one line on the state of the recording, the 3 highest-ranked findings (each with its id and the references to look at), and the exact commands to run next. `--json` gives `brief-compact/1` |
| `findings` | The detectors' findings and the findings an agent recorded, in one list (an agent's first, then the detectors' ranked as in `overview`). `--kind K` (`log-error`, or `invariant` for every `invariant:<kind>`), `--severity error\|warn\|info` (detector findings only), `--limit N`. `--json` gives `findings/1` |
| `overview` | The whole recording at a glance: what stands out, ranked (states that are wrong and for how long, windows that flap, event storms, slow handlers, errors, a display unplugged), anything near a bug region first |
| `state --at T` | What komorebi believed at a moment, and anything inconsistent in it: a window parked off screen on a workspace that is showing, a window in two places, a layout that was not applied |
| `diff A B` | What changed between two moments in terms a person would use: a window appeared, moved, was really somewhere else; focus moved; a monitor came or went |
| `events` | komorebi's events, classified (command, focus, lifecycle, drag, monitor, lock, and `echo`: the OS reporting back a move komorebi made itself), with the handler that ran and whether the state changed |
| `trace event:N` | One event end to end: what its handler logged, with the source statement for each line, what other threads logged meanwhile, and every change with who made it (see below). `--os` adds the OS trace around it: komorebi's own calls into the OS, the system and each application, split into while the handler ran and after |
| `lag [--window ID] [--tolerance N] [--grace-ms MS]` | For each window, every stretch it was off the rect komorebi's layout gave it (needs `--window-track`): start, end, duration, and the largest and last offset on each edge, in pixels (points on a Mac). With border windows in the track, whether the border or the window lagged. Offsets within the tolerance (default 8) and the grace after a layout change (default 500 ms, for animations) are not flagged. On KDE the track is komorebi's own state, so nothing is reported and the answer says why. The same episodes are the `geometry-lag:window` and `geometry-lag:border` findings |
| `window ID\|TEXT` | One window's life: when it appeared, moved, was parked off screen, was really somewhere else, and which event did each |
| `code event:N`, `code log:N` | The line of komorebi's source that wrote a log line, with the code around it |
| `logq QUERY` | Query komorebi's log by field, with no escape codes or span prefixes to strip: `level=ERROR and message~ghost`, `hwnd=0x77179C` (decimal and hex are the same window), `command=MoveWindow`; `--count`, `--group-by FIELD`, `--from`/`--to`, `--spans` |
| `search TEXT` | Where a word appears: komorebi's log, events, incidents, annotations (and `--oslog` for the macOS trace) |
| `changes` | When and where on each display the picture changed, and which events fall inside |
| `sheet` | A contact sheet image of frames with times, events and the bug region marked; `--windows` also draws each window's rect on the frames when the session has a window track |
| `motion [--region x,y,w,h]` | When, and how hard, a display or a region of it was moving: segments with start, duration, frame count, peak share of pixels changed and peak mean brightness delta (replaces scripting ffmpeg `tblend`) |
| `framediff A B [--region ..] [--png FILE] [--against SESSION]` | How two frames differ: changed share, mean and peak brightness delta, the box of change, and a PNG with the changed pixels in red |
| `blank --region x,y,w,h` | When a region was blank (one colour, named: `white`, `black`, a hex code) or frozen (identical to the frame before): "the window went white for 200 ms" |
| `measure [--region x,y,w,h] [--stat mean\|peak\|width] [--hz N] [--background 0-255]` | A statistic of a region on a fixed-rate timeline (default 30 Hz): each sample is the last frame shown at or before its time (the video has no fixed frame rate), with when that frame was shown. `mean` and `peak` are brightness 0 to 255; `width` is the *drawn width*: the horizontal extent, in display points, of the pixels that differ by more than 24 of 255 from the background (the most common brightness of the region, or `--background`), from the leftmost to the rightmost such column; 0 if none. Replaces ffmpeg scripts that crop and average. Samples with no frame (before the first one, or in a gap) are `null`. `--json` gives `measure/1` |
| `compare A B` | Two recordings side by side: duration, frames, effective fps, worst frame gap, motion, findings by kind, annotations, and the difference |
| `assert --check "KIND ARGS METRIC<=N"` | Pass/fail checks for a scripted scenario, repeatable. Kinds: `findings kind=K [severity=S] count<=N`, `log "<logq query>" count==N`, `motion [region=x,y,w,h] [from=T] [to=T] segments\|active_ms\|peak_share<=N`, `blank region=x,y,w,h [from=T] [to=T] [color=white] ms<=N`, `annotations kind=note\|bug\|finding count>=N`. Operators `== != <= >= < >`. Prints `PASS`/`FAIL` per check; exit 0 if all pass, 6 if one fails, 4 if one cannot be measured (no video), 2 if malformed. `--json` gives `assert/1` |
| `annotate`, `annotations` | Add, change and list bug regions, notes and findings |
| `mark TEXT` | While recording: drop a named point note (author `script`) onto the timeline from a script; it then appears in `annotations`, `brief` and the viewer like any note |
| `view [SESSION...] [--new-window]` | Open recordings in the window, each as a tab of the one window that is running (it is started if there is none and brought to the front if there is); `--new-window` makes a window of its own instead |
### Who changed it
komorebi sends the state _after_ each event, so what an event changed is the difference from the previous one. That
includes whatever background threads did since: the reaper (removes windows that no longer exist) and the workspace
reconciliator (moves windows between workspaces after a space change) change state **without sending a notification**.
`trace` therefore gives each change an _attribution_ with its evidence and how sure it is: `handler`, `reaper` (when its
log line names the window), `workspace-reconciliator`, or `unexplained`, which means state changed and nothing in the log
accounts for it. That is a finding in itself.
### From a log line to the source
komorebi's log says what happened but not where in its code. The recorder is built with an index of every `tracing`
statement in komorebi's source; `code` matches a recorded line to the statement that wrote it, says when several
statements read alike (`ambiguous`) or only print a value (`generic`), and flags the reaper and workspace reconciliator.
A mapping is only as good as the source it was made against, so every answer says whether the source the recorder was
built from is the komorebi that was recorded, by comparing the commit the recorded binary reports with the indexed
source and naming the files that differ. Lines in files that did not change are exactly as good as if the commits were
the same.
### What the data cannot tell you
- The event timestamp is when komorebi finished the handler. Time spent waiting for its lock or in accessibility calls
before the handler's first log line is invisible, so `handler_ms` is a lower bound.
- The recorder can receive notifications long after komorebi sent them, and in clumps. komorebi's own send time is its
`pushed notification to subscriber:` DEBUG line; `events --json` shows it as `pushed_video_s` next to the received
`video_s`, with `delivery_ms` between them, and `overview` reports a `delivery-batching` finding (info) instead of a
slow handler. A `slow-handler` finding in a log without push lines is marked as possibly delivery delay.
- The `events` listing's time is one **komorebi time** per event: `p` when it is komorebi's pushed time, `r` when the log
has no pushed line and it is only the received time (the header says so; `--json` has `komorebi_time.source` and
`komorebi_time_note`). The received time is still given as `video_s`. The pushed line is checked only for komorebi for
Mac's log; for Windows and KDE it is unverified, so expect `r` there if the log lacks it.
- At the default `info` level there is no log line for the end of an event handler, and few for the decisions inside it.
Start komorebi with `--log-level trace` before recording a bug you intend to investigate.
- The `rect` of a window in the state is read live from the accessibility API when the state is serialized: it is where
the window really was, which is what makes comparing it with where komorebi's layout put it meaningful.
- An `AXError` in komorebi's log comes from the application or the OS, not from komorebi.
### Finding ids
Each detector finding has an id like `f-04dc11`: `f-` and six hex digits of a fixed hash (FNV-1a) of its kind, its first
reference (`event:17`, `log:345`) and the ids of the windows it is about; a finding with no reference uses the
five-second bucket of video time it began in. It does not depend on the score or on the bug regions, so the same finding
keeps its id between runs and as annotations are added, and `findings`, `brief --compact` and `overview` name it the
same way. Two different recordings share an id only where the same kind of finding is at the same reference, so use ids
to compare analyses of one session (before and after a change to the detectors), not to match a bug across recordings.
An agent's findings keep their annotation id (`a-3f9c1e02`).
## Recording what you conclude
```
komorebi-recorder annotate <session> add --kind finding --about <bug id> \
--text "the Show handler tiles the window onto the display that is going away" \
--ref event:12 --ref log:340 --ref code:komorebi/src/process_event.rs:512
```
A finding with no evidence is refused, and every reference is checked to exist: the event, the log line, the video time,
the line of komorebi's source. A log line can be named by what it says or when it was written instead of by number:
`--ref 'log:"could not place window"'` (the one line of `komorebi.log` that contains the text, ignoring case),
`--ref log:15:46:23.677700` (the line written at that UTC time, as precisely as you write it; `HH:MM:SS` alone matches the
whole second) or `--ref log:2.72` (the line nearest that time of the video). A text or time that matches several lines
is a usage error (exit 2) listing the first few as `log:N: text`; pick one with `log:N`. When a reference was resolved
this way the command prints the `log:N` it chose and the line's text (on standard error, and in `warnings` with
`--json`), so you can check it is the statement you meant. Findings are stored in `annotations.jsonl` beside the bug region, so the person who
recorded the bug can see what was concluded and why.
@@ -0,0 +1,409 @@
# Recording a Bug Repro
`komorebi-recorder` records a bug while it happens: the screen, komorebi's log, every komorebi event and the macOS OS
trace, all on one clock, into a single _session directory_. Afterwards you can ask "what was komorebi doing, and what
was the OS doing, at 00:12.5 in the video?" and the other way around.
```
komorebi-recorder record --duration 30 # record without a window
komorebi-recorder # or open the window, with its Record / Stop tab
```
It is built for the situations where komorebi bugs actually show up: laptops that get docked and undocked, woken with the
lid opened, locked and unlocked. Recording carries on through all of that without losing what was already captured; see
[Docking, sleep and lock](#docking-sleep-and-lock).
## What is captured
| What | Where it comes from |
| ----------------------- | ----------------------------------------------------------------------------------------------------- |
| Screen | ScreenCaptureKit, one `mp4` per display per contiguous span (a _segment_), with every frame's timestamp |
| komorebi's log | The exact byte range of `komorebi_plaintext.log.<date>` written during the recording |
| komorebi's events | A subscriber socket: every `WindowManagerEvent` / socket message plus the full `State` |
| OS trace: komorebi | `log stream` for komorebi's own process: system frameworks (AX, LaunchServices, ...) as it calls them |
| OS trace: system | Accessibility, SkyLight, HIServices and workspace subsystems |
| OS trace: each app | `log stream` for **every process that owns a window in komorebi's state**, one file per app |
| Recording environment | Displays connecting, disconnecting and sleeping; machine sleep/wake; screen lock; restarts of komorebi or of a log stream |
The OS trace is what lets you see both seams: komorebi calling into the system, and the system talking to the apps
komorebi is tiling.
## On Windows
The same tool records komorebi for Windows, on the same clock, into the same kind of session
directory; a session recorded on one OS can be investigated on the other. What differs:
| | macOS | Windows |
| --- | --- | --- |
| Screen | ScreenCaptureKit, HEVC | Windows.Graphics.Capture, H.264 (Windows 10 1803+) |
| OS trace | the unified log: komorebi's process, the system, each managed app | WinEvents for every top-level window, folded when repeated, and the System Event Log's warnings and errors and its display, power and GPU providers |
| komorebi's log | its data directory | `%TEMP%\komorebi_plaintext.log.<date>` |
| Permission | Screen Recording, granted to the terminal or app | none |
| Executables | `komorebi-recorder` | `komorebi-recorder.exe` (console: use this to run commands) and `komorebi-recorder-gui.exe` (no console window) |
| Sleep | found from the host clock pausing | heard from Windows as it happens (suspend, resume, lid, displays off, lock) |
Start komorebi with `komorebi.exe --log-level debug` before recording a bug. (`RUST_LOG=debug` also
prints every dependency's log; `RUST_LOG=komorebi=debug` does not.)
`komorebi-recorder doctor` says what the machine can do, and `komorebi-recorder record --no-video` records without the
screen.
The window keeps itself out of the video (Windows 10 version 2004 or later).
## Before you record
- **Screen Recording permission.** macOS attaches the grant to the terminal (or app) that launches the binary, exactly as
it does for `komorebi` itself. The window shows a "Grant permission" button if it is missing.
- **komorebi's log level.** The recorder never changes komorebi's log level or lifecycle; it only warns. For a useful
repro, start komorebi with `komorebi --log-level trace` (or `RUST_LOG=komorebi=trace`) first. At the default `info`
level most of what the window manager _decided_ is not in the log.
- **`ffmpeg`** is only needed for `frames` and `selftest`. It is never used to capture. The `nix develop` shell provides
it; otherwise `brew install ffmpeg`.
There is one window for everything. It opens small (the Record tab alone, always on top, to leave over the application
you are reproducing a bug in) and grows when you open a recording; see [The window](#the-window). On Windows it is named
`komorebi-recorder` only once komorebi is told to ignore it:
at start the recorder runs `komorebic ignore-rule exe komorebi-recorder.exe` (and the same for
`komorebi-recorder-gui.exe`, the build with no console window) against the running komorebi, a live rule that is not saved. If
komorebi is not running the window is named too; if `komorebic` is not found or fails, and on a Mac, the window stays
untitled, because komorebi does not manage windows without a title, and the recorder says so on standard error and in
the window. Either way opening it does not move your layout around while you are trying to reproduce a layout bug.
`komorebi-recorder doctor` shows which you will get. To keep the rule across komorebi restarts, add this to your own
komorebi configuration (the entries below are in the shape of the application-specific configuration; in `komorebi.json`
the same match is an `ignore_rules` entry with `kind: Exe`, `id: komorebi-recorder.exe`, `matching_strategy: Equals`):
```json
"komorebi-recorder": {
"ignore": [
{
"kind": "Exe",
"id": "komorebi-recorder.exe",
"matching_strategy": "Equals"
}
]
},
"komorebi-recorder-gui": {
"ignore": [
{
"kind": "Exe",
"id": "komorebi-recorder-gui.exe",
"matching_strategy": "Equals"
}
]
}
```
It is also excluded from the video, as is any other `komorebi-recorder` process.
The window is one such process, in either size.
## Recording
Press **Record**, reproduce the problem, press **Stop**. The Record tab shows live counters, recent events (a display
being unplugged, a wake) and any warnings. The session is written to
`~/Library/Application Support/komorebi/recordings/<UTC timestamp>/` unless you pass `--out`.
The **Review** row of the tab has **Open session…** (choose a recording's folder) and **Open last** (the newest one);
each opens the recording as a new tab of this same window, and the window grows to show it.
### The window
`komorebi-recorder` (or `komorebi-recorder gui`) opens one window, and there is never a second: starting it again, or
running `komorebi-recorder view <session>`, raises the window that is already open instead. The first tab, **Record**,
cannot be closed, and says `REC` and the time in the tab bar while a recording is going, so you can look at another tab
and see that it still is (the recording carries on whichever tab is showing, and closing the window while recording
finishes the session first). The recordings you open follow it as tabs, and **+**, ⌘/Ctrl-T and ⌘/Ctrl-0 (the Record
tab) work as in a browser.
Started plainly, the window is _compact_: 420 by 380, always on top, showing the Record tab and nothing else, the small
control window you leave over the application you are reproducing the bug in. **Expand** (on the Record tab) makes it
the full window with the tab bar, and opening a recording does that for you; **Compact** goes back, and the choice is
remembered. While recording, the full window has a **pin on top** checkbox. Options such as `--fps` or `--no-komorebi`
given to `komorebi-recorder`/`gui` set up the Record tab of the window that gets started; if a window is already open
they are ignored. `--new-window` opens a window of its own instead of raising the open one.
With every display ticked, the recorder follows _all_ displays, including ones connected while it is recording. Untick a
display to record only the others.
Headless recording is the same thing without the window; Ctrl-C, `SIGTERM` or `--duration` stops and finalizes it:
```
komorebi-recorder record --out ./repro --duration 60
komorebi-recorder displays # list display ids
komorebi-recorder record --display 2 # record just one display
```
To record exactly while a script reproduces the bug, give the command after `--` with `--until-exit`:
```
komorebi-recorder record --until-exit --out ./repro -- ./repro.sh --slow
```
The recorder starts the command once the recording is under way, and stops the recording when the command exits. If
`--duration` or Ctrl-C comes first, that stops the recording and the command is terminated, so whichever comes first
wins. The command runs in the directory you are in, with this terminal's input and output, and has
`KOMOREBI_RECORDER_SESSION` in its environment: the session directory (an absolute path) that is being recorded, so
that anything the script runs can mark the moment with `komorebi-recorder mark` or annotate the session without being
told where it is. On Windows the command is terminated with `TerminateProcess`, which does not reach programs it
started.
The exit status of `komorebi-recorder record` is about the recording, never the command: it is 0 when the session was
finalised, whatever status the command exited with. The command's status is in the summary
(`command: ... exited with status 3`) and in `record --json` as `data.child` (`end`: `exited`, `stopped`,
`failed-to-start` or `not-started`; `exit_code`; `success`). `--json` on `record` prints the `record/1` envelope on
standard output (progress stays on standard error): the session directory, the duration, each display's frames, the
recorder's warnings and the command's status. `displays`, `reindex` and `selftest` take `--json` too.
Useful options:
| Option | Effect |
| ------------------------------------------ | --------------------------------------------------------------------------------------- |
| `--oslog-apps managed\|all-gui\|none` | Which apps get their own OS trace file (default: those komorebi manages) |
| `--trace-process NAME` / `--trace-pid PID` | Also trace an app komorebi does not manage |
| `--oslog-exclude NAME` | Never trace this (chatty) app |
| `--oslog-level debug\|info\|default` | Unified log level (default `debug`) |
| `--system-process NAME` | Add a system daemon to the `system` stream, e.g. `WindowServer` (see volume note below) |
| `--predicate P` | Replace the `system` stream's predicate |
| `--oslog-all` | One extra unfiltered system-wide stream (very large) |
| `--no-oslog`, `--no-komorebi` | Skip the OS trace, or skip touching komorebi entirely |
| `--no-video` | Do not capture the screen; record everything else on the same clock (see below) |
| `--window-track[=HZ]` | Sample every window's rect and state alongside the video: on by default at 30 Hz where windows can be listed; this picks another rate, 1 to 120 (see below) |
| `--no-window-track` | Do not sample the windows |
| `--no-probe-windows` | Windows: do not record what Windows says about each window event, which is on by default (see below) |
| `--fps N`, `--retina`, `--codec hevc\|h264` | Video settings (display-rate capture (`--fps 0`, the default; N caps it), logical points, HEVC by default) |
### Marking where the bug is
A bug is marked in one place, a session's tab, after the recording: `komorebi-recorder view <session>` opens it (the
Record tab's **Open last** does too), and **Mark bug** (or **B**) takes a stretch of the recording and what went wrong in
it. That marks a _region_, not a single moment. The Record tab has no button for it, so while recording there is nothing
to do but reproduce the problem.
This is what makes the recording useful to whoever investigates it, person or agent: your description is the ground
truth of _what_ went wrong, and everything else in the session is evidence of _why_. See
[Investigating a recording](investigating-a-recording.md#marking-the-bug).
### Marking steps from a script
A script that performs the repro can drop named markers onto the timeline while the recording is going:
```
komorebi-recorder mark "step 3: move window right"
```
A marker is a note by the author `script`, written at the moment the command runs, so it appears in `annotations`,
`brief`, `search`, `overview` and as a tick on the viewer's bug lane. `mark` prints the video time (`marked 00:03.28 (a-3f9c1e02): ...`) once the first frame has been captured and
the wall time (`marked 12:00:08.12Z (...)`) before that.
It marks the session named by `--session DIR`, else by the environment variable `KOMOREBI_RECORDER_SESSION` (which
`record --until-exit` sets for the command it runs), else the newest recording in komorebi's data directory that is
still running. A recording that has finished is refused: it has no "now" to mark; use `annotate <session> add` with a
time instead. `--json` prints the `mark/1` envelope.
### Checking the result from a script
`assert` turns the recording into a pass or fail, so the same script that reproduces the bug can end by saying whether
it happened. The exit status is the result: 0 when every check holds, 6 when one does not, 4 when one could not be
measured (for example `motion` on a recording without video) and 2 when a check is malformed.
```
komorebi-recorder record --until-exit --out ./repro -- ./repro.sh # repro.sh calls `komorebi-recorder mark` between steps
komorebi-recorder assert ./repro --check "annotations kind=note count>=3" --check "findings kind=layout-mismatch count<=0" --check "log \"level=ERROR\" count==0" --check "blank region=0,0,800,600 color=white ms<=100"
```
```
PASS annotations kind=note count>=3 (observed 4)
FAIL findings kind=layout-mismatch count<=0 (observed 2)
f-3a9c1e invariant:layout-mismatch at 00:03.280: ...
PASS log "level=ERROR" count==0 (observed 0)
PASS blank region=0,0,800,600 color=white ms<=100 (observed 0)
1 of 4 check(s): 1 failed
```
The first check confirms the script's `mark`s were recorded. A check is a kind, its arguments and a comparison
(`== != <= >= < >`); the kinds are `findings`, `log` (a `logq` query), `motion`, `blank` and `annotations`, and
times in `from=` and `to=` are any time the other commands take, including `event:N` and `bug:<id>`. `--json` prints the
`assert/1` envelope. `assert` only reads the session.
### Without video
`komorebi-recorder record --no-video` records everything but the screen: komorebi's events and log, the OS trace and
what happened to the recording environment, all on the same clock. Use it on a machine with no
display (or no Screen Recording permission), or when what is on the screen must not be recorded. It asks the system
nothing about displays. A session made this way has no video, so video time `00:00.000` is the moment the recording
started, and there is nothing for `frames` to show.
### Probing windows on Windows
komorebi for Windows hides a window by _cloaking_ it where it is, so its state cannot show whether a
window is really hidden. So on Windows `record` follows each window event with a read of the
window's real state from Windows (visible, cloaked, minimized, where it is) and, now and then, asks
komorebi whether it manages the window and which rules matched. `overview` then compares the two:
a window komorebi shows that Windows has hidden, one it hides that Windows shows, and a visible
window it does not manage (usually correct, with komorebi's explanation). It costs a few system
calls per event and a query to komorebi the first time a window is seen, and it reads nothing but
those facts. `--no-probe-windows` turns it off, and without it `overview` cannot say whether a window is
really hidden, nor find a ghost tile. It does nothing on a Mac, where a hidden window is parked in a
corner and the state says so, and asking for `--probe-windows` there is an error.
### Tracking where every window is
The per-event probe above says what one window looked like when something happened. The recurring
question is different: _which window was where, in this frame_. `record --window-track` (or
`--window-track=60`) lists every top-level window many times a second, with its rect, whether it is
visible or minimized and, on Windows, whether it is cloaked, front to back, into `windows.jsonl`. A
row is written only when something changed, plus a full row each second, so a still desktop costs
about one row a second and a busy one a few kilobytes a second. The recorder's own windows and tool
windows (tooltips, toasts) are left out, except komorebi's border windows (Windows and macOS), which are kept and marked `border` so that a border that lagged its window can be seen. It is on by default on every host that can list windows (Windows, macOS, KDE); `--no-window-track` turns it off and `--window-track=HZ` picks another rate (30 Hz is the default; the sampler does not catch up when a sample is late, it counts it and says so in the warnings). `komorebi-recorder sheet
<session> --windows` then draws each window's rect, labelled with its program and id, on every
frame of the sheet; a session with no track says so and gets a plain sheet. A recording that cannot
keep the rate says so in its warnings.
### Checking your setup
```
komorebi-recorder doctor # what this machine can do for a recording
komorebi-recorder doctor --json # the same, for a bug report
```
`doctor` says which komorebi is running (binary, version and commit, log level, whether it answers a state query and
where its log is), whether the screen can be captured and played back, whether `ffmpeg` is there, the displays and
their scale, and the host clock. Anything wrong is listed at the end in plain words. `doctor --probe clock|capture|decode`
measures one thing instead; `--probe clock` shows what the clock does while the machine sleeps (put it to sleep while it
runs).
## Docking, sleep and lock
The set of displays, and whether ScreenCaptureKit streams stay alive, changes underneath a laptop all the time. The
recorder is built so that **nothing already captured is put at risk by any of it**.
- **A display disappears** (unplugged, undocked, lid closed, or it goes to sleep): that display's video file is finalized
on the spot, so it is complete and playable whatever happens next. The other displays carry on untouched.
- **A display appears or returns:** after a one-second settle, it starts a new _segment_ in a new file
(`video-<id>-2.mp4`, `-3`, ...). Each segment is a whole file; `session.json` lists every one with its time span.
- **The machine sleeps and wakes:** the wall clock and the host clock are compared many times a second, so a sleep is
noticed the moment the machine wakes and the clock anchors on either side of it are recorded exactly. Every display is
then given a fresh stream rather than trusting the old one, because streams can stall across a sleep without reporting
anything. The host clock pauses while asleep, so video time skips the sleep instead of showing a hole.
- **A stream stalls or dies:** a healthy ScreenCaptureKit stream calls back about thirty times a second even when the
screen is not changing, so silence for a few seconds means a dead stream. That segment ends at its last sign of life and
a new one starts.
- **The screen locks, or another user's session comes to the front:** noted, and the displays are watched as above.
- **A `log stream` process dies** (for instance when logd restarts): it is restarted into the same file, appending.
- **komorebi exits or is restarted:** noted, and when it is running again the recorder re-subscribes and traces the new
process. komorebi not running when recording starts is not an error either.
All of this is recorded in `recorder.jsonl`.
It is shown as the `recorder` source, right next to the log lines and trace around it:
```
komorebi-recorder at <session> 12.5 --source recorder
```
`summary` marks a second in which something changed with `recorder=N`, `locate` says which segment of each display covers
a moment (and which displays had no video then), and `frames` extracts from the right segment.
### If the recorder dies
Everything is written as it arrives and the manifest is checkpointed every few seconds, so a crash, a `kill -9` or a
power loss does not lose the session. Video is written as fragmented mp4, which plays up to the last fragment (about a
second) even though it was never finalized, and a static screen is kept moving so that it, too, is flushed. To recover:
```
komorebi-recorder reindex <session>
```
This closes the segments that were still open (using the video files themselves to decide how much survived), rebuilds
the timeline, and marks the session `recovered`. The queries tell you to do this if you point them at an unfinished
session.
## Asking questions of a session
Times are video timecodes: `12.5`, `00:12.500` or `1:02:03`, or a time from komorebi's log such as
`logtime:15:46:22.743` (UTC), or `wall:...`, `event:12`. Video `00:00.000` is the first captured frame.
```
# everything within +-1s of 12.5s, grouped by source
komorebi-recorder at <session> 12.5
# one app's OS trace only, or one source
komorebi-recorder at <session> 12.5 --app Ghostty
komorebi-recorder at <session> 12.5 --source events
# a span, and a per-second digest of the whole recording
komorebi-recorder range <session> 10 15
komorebi-recorder summary <session>
# reverse: where in the video was this?
komorebi-recorder locate <session> --log-line 120
komorebi-recorder locate <session> --event-seq 7
komorebi-recorder locate <session> --utc 2026-10-26T19:43:35.062613Z
# look at the exact frame
komorebi-recorder frames <session> 12.5 14.0
```
Add `--json` to any query for machine-readable output, which is also what makes a session easy to hand to an LLM: the
generated `README.md` in every session directory explains each file and contains these commands with the session path
filled in.
## The session directory
```
session.json manifest: versions, displays and every video segment, clock anchors, log segments, streams, apps, warnings
video-<displayID>[-<n>].mp4 screen recording of one segment (variable frame rate: frames exist only where the screen changed)
frames-<displayID>[-<n>].csv every frame's host-clock timestamp
komorebi.log exact slice of komorebi's own log
events.jsonl, states/ subscriber notifications; full State stored only when it changed
state-start.json, state-end.json
windows.jsonl window track (on by default; not with --no-window-track): every window's rect, on change and once a second
recorder.jsonl what happened to the recording environment (displays, sleep/wake, lock, restarts)
annotations.jsonl bug regions, notes and findings (appended, never rewritten)
oslog/komorebi.ndjson unified log, komorebi's process (oslog/komorebi-<pid>.ndjson after a restart)
oslog/system.ndjson unified log, accessibility / SkyLight / workspace subsystems
oslog/apps/<exe>-<pid>.ndjson unified log, one managed application
timeline.jsonl merged, sorted index pointing into the raw files
README.md generated guide to this session
```
Raw files are never rewritten; `timeline.jsonl` only references them, so `komorebi-recorder reindex <session>` can rebuild
it at any time (including after hand-editing a log).
## How accurate is the alignment?
Everything is placed on the host monotonic clock (`mach_absolute_time`). Video frame timestamps and the unified log's
`machTimestamp` are on that clock directly. komorebi's log lines carry UTC wall-clock time and are mapped onto it with
anchors sampled every 5 seconds during the recording and at every sleep, so clock steps and sleep are handled.
- video to OS trace: within about one frame
- video to komorebi's log: within about one frame plus the wall-clock anchor error (tens of microseconds)
- subscriber events are stamped when the recorder receives them. komorebi sends the notification _after_ it has handled
the event, so the stamp is when the handler **finished**; the `processing event` line in `komorebi.log` is when it
began.
The `events` listing shows one **komorebi time** per event, so the two clocks are not mixed up: when komorebi pushed
the notification (`p`, from its DEBUG log line `pushed notification to subscriber:`), or, where the log has no such
line for the event, when the recorder received it (`r`). The fallback is stated in the listing's header and as
`komorebi_time_note` in `--json`, never silent. In JSON every event has `komorebi_time` with `source` (`pushed` or
`received`), `video_s`, `mach_ns` and `wall_utc`. The pushed line needs komorebi at `--log-level debug`. Matching it
to an event does not depend on the flavor, but it has only been checked against komorebi for Mac's log format and a
synthetic one; whether komorebi for Windows and for KDE log the line at all has not been checked against a
recording, and without it the listing falls back to `r`.
`komorebi-recorder trace` ties the two together.
`komorebi-recorder selftest` checks this on your machine: it records a rendered on-screen clock and compares the clock
visible in the video with the time the session predicts. The result is stored in `session.json` under `calibration`.
## Things to know
- **What can still be missing.** Events from a `log stream` during the moment it was dead and being restarted; komorebi
events while komorebi was not running; the last second or so of video if the recorder is killed rather than stopped; a
display's video while it was asleep or unplugged (there is simply nothing to record). Each of these leaves a line in
`recorder.jsonl` saying so, rather than a silent hole.
- **Windows komorebi manages are found through the window server.** komorebi's `State` has no process ids, so the
recorder resolves window ids to owning processes itself. A process that appears mid-recording gets its own stream as
soon as it shows up in a state or event; events it emitted in the few hundred milliseconds before that are missed
(`session.json` records `first_seen_mach_ns` for each app so you know where each file starts).
- **Volume.** Per-process debug streams are modest, but system-wide daemons are not: `launchservices` alone was ~500
events/s (~29 MB/min) and `runningboard` ~290 events/s on a normal desktop, which is why they are opt-in. komorebi's
own process emits a few hundred events per second while it is busy. The recorder warns when a stream is abnormal, since
`log stream` can drop events under extreme load.
- **`<private>` values stay redacted.** The tool needs no `sudo` and changes no SIP settings, and it does not do
syscall-level tracing.
- **Privacy.** The video contains whatever was on screen and application logs can contain window titles and URLs. Review
a session before sharing it.