feat(cli): check the configuration

A key komorebi does not read is dropped without a word, so a typo in
komorebi.json costs a restart and a look at the log to find. A file that is not
JSON, or has a value of the wrong kind, is not read at all, and the daemon says
so only in its log. `komorebic check` reads the file the way the daemon does,
without starting it, and says in words what is wrong, with the line when it is
the file.

The check parses the file as JSON, then as a StaticConfig; the first that fails
is an error that shows the line serde stopped at, with the two before it and a
caret. The keys come from the schema of StaticConfig at every level, so the
check knows every key komorebi reads: a key only another platform reads is
listed once as accepted and ignored, because one komorebi.json serves every
platform; a key nobody has is a warning with the nearest key that exists.
Windows' custom layouts are a warning that they are not supported yet, an
applications file that is not there is a warning, and so is a workspace that is
only a name, which komorebi does not tile. A workspace that has
initial_window_placement_rules and appends windows to a container, by its own
window_container_behaviour or the file's, gets a note: an appended window has no
place of its own to be given.

komorebic exits with status 1 if and only if a finding is an error. The usage
page says what each finding means.

A wallpaper that is not a file is an error, and one no theme can be made from is
a warning. check_configuration also returns what the file asks of the desktop
(Wants): whether it draws borders, which animation style it asks for, and
whether it has wallpapers.

The checks of the desktop and of the key bindings come with those features.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:57 -07:00
1 parent 21017b573f
commit d04fc91234
13 files changed
+1545 -6

No files matched your search

+8 -3
View File
@@ -86,14 +86,15 @@ without a checkout of the toolchain.
unlocked (`monitor_reconciliator`, `reconcile`, `kwin::power`), sends its
subscribers a notification of each event, message and change of the monitors
it handles (`notify_subscribers`), and is configured by a `komorebi.json` that
it reads and reads again when it changes (`static_config`).
it reads and reads again when it changes (`static_config`), and checks it for
mistakes without the daemon (`check`).
- [`komorebi-client`](komorebi-client): a library that sends messages to the
daemon, reads its answers, subscribes to its notifications, and re-exports
the types they are made of.
- [`komorebic`](komorebic): the command line. A subcommand that asks something
of the daemon is one message on its socket; `quickstart`, `enable-autostart`,
`disable-autostart`, `start`, `configuration`, `log`, `data-directory`, `completions` and
the hidden `docgen` work without the daemon.
`disable-autostart`, `start`, `check`, `configuration`, `log`, `data-directory`,
`completions` and the hidden `docgen` work without the daemon.
- [`version`](version): the version string every binary reports.
The layouts, which turn a work area and a number of containers into a rectangle
@@ -276,6 +277,10 @@ autostart entry that has Plasma start komorebi at login. The Rust types that rea
(`schema.json`, written by `just jsonschema` and printed by `static-config-schema`), and the
module's `config` option is typed from that schema (`nix/komorebi-options.nix`, written by
`just nixgen`), so a configuration written in Nix is checked when it is evaluated.
`check` reads the file the way the daemon does and says in words what is wrong with it: JSON that
does not parse, with the line, a value komorebi does not read, a key that is not a setting (with
the nearest one that is), a workspace that is not tiled, and an applications file that is not
there. It exits with status 1 if something is an error.
A program such as a status bar can subscribe to the daemon's notifications: it
listens on a socket of its own, and after each event, each message and each
+13
View File
@@ -0,0 +1,13 @@
```text
Check komorebi configuration for common errors
Usage: check [OPTIONS]
Options:
-k, --komorebi-config <KOMOREBI_CONFIG>
Path to a static configuration JSON file
-h, --help
Print help
```
+38
View File
@@ -951,12 +951,34 @@ One `komorebi.json` is meant for every platform komorebi runs on, so [`StaticCon
mean nothing on KDE Plasma are fields that nothing reads. `StaticConfig::from(&WindowManager)`
goes the other way, for `GenerateStaticConfig`.
Because a key that is not read is dropped without a word, `komorebic check` is how a typo is
found. The checks are in [`check`], and they return [`Finding`]s (a [`Level`], a message, and a hint)
that `komorebic` gathers in a [`Report`]: [`check_configuration`] reads the file as JSON, then as a
[`StaticConfig`], as the daemon does, and an error from either shows the line serde stopped at,
with the two lines before it ([`snippet`]). [`check_keys`] then compares the keys of the file
with [`known_keys`], which are read from the schema of [`StaticConfig`] at the root, in a monitor
and in a workspace: a key that is in the lists of the other platforms' keys is a note, and any
other that is not in the schema is a warning with the nearest key (the edit distance, at most
three). The settings that mean something are looked at too: an application specific
configuration or a wallpaper that is not there, a wallpaper no theme can be made from, a workspace
that is only a name, which is not tiled, and a workspace that appends windows to a container and
has placement rules, which are not used then (the workspace's `window_container_behaviour`, or the
file's when it has none). [`check_configuration`] also returns the [`Wants`] of the file: whether
it draws borders, which animation style it asks for and whether it has wallpapers. `komorebic`
prints [`Report::render`] and exits with status 1 if [`Report::has_errors`].
| Rule | Enforced by | Proof | Escape hatch |
|---|---|---|---|
| A key komorebi does not read does not stop a configuration from loading | serde: [`StaticConfig`] ignores unknown keys, and a key of another platform is a field nothing reads | `the_keys_that_do_nothing_on_kde_are_accepted_and_ignored`, `fixtures_load_round_trip_and_only_lose_windows_only_keys` | none |
| The keys the parity test ignores are keys `StaticConfig` does not read | test: the ignore lists are compared with the schema of [`StaticConfig`] | `the_lists_name_no_key_that_is_read` | none |
| The example in the docs is the example file, which loads | test | `the_example_in_the_docs_is_the_example_file`, `fixtures_load_round_trip_and_only_lose_windows_only_keys` | none |
| A path to an applications file that is not there is skipped, and one that is there and is broken is an error | framework path: `handle_asc_file` returns early when the path does not exist, and parses the file otherwise | `a_missing_application_specific_configuration_is_skipped_not_fatal`, `an_application_specific_configuration_that_exists_but_is_broken_is_still_an_error`, `a_file_that_is_not_there_is_skipped_and_one_that_is_broken_is_an_error` | none |
| A file that is not JSON, or has a value komorebi does not read, is an error that shows the line | framework path: [`check_configuration`] reads the file as JSON, then as a [`StaticConfig`], and an error from either goes through [`snippet`] | `a_file_that_is_not_json_is_an_error_with_the_line`, `a_value_komorebi_does_not_know_is_an_error_with_the_line`, `a_file_that_is_not_json_fails_and_shows_the_line` | none |
| A key for another platform is a note, and a key that no platform has is a warning with the nearest key | framework path: [`check_keys`] sorts the keys of the file by [`known_keys`] and the lists of the other platforms' keys | `keys_for_another_platform_are_told_apart_from_mistakes`, `a_typo_is_a_warning_with_the_word_that_was_meant_and_does_not_fail` | none |
| The keys the check knows are the ones komorebi reads, at every level | framework path: [`known_keys`] reads them from the schema of [`StaticConfig`] | `the_keys_come_from_the_schema_at_every_level`, `a_whole_example_configuration_has_nothing_the_check_does_not_know` | built without the `schemars` feature, the check does not look at keys |
| Placement rules that are not used while windows are appended are a note, and a workspace that creates containers is not told so whatever the file says | framework path: [`check_configuration`] reads the workspace's `window_container_behaviour` before the file's | `placement_rules_that_are_not_used_while_windows_are_appended_are_noted` | none |
| A wallpaper that is not a file is an error, and a picture no theme can be made from is a warning | framework path: [`check_configuration`] looks at the wallpaper of each monitor and workspace once, and asks the theme generator for a palette when the wallpaper does not turn it off | `a_wallpaper_that_is_not_there_and_a_rules_file_that_is_not_there_are_found`, the `vm-check` VM suite for the warning | none |
| `komorebic check` exits with status 1 if and only if a finding is an error | framework path: `komorebic` exits through [`Report::has_errors`] | `a_good_configuration_passes`, `a_typo_is_a_warning_with_the_word_that_was_meant_and_does_not_fail`, `a_file_that_is_not_json_fails_and_shows_the_line` | none |
| The rules of an applications file and of the configuration add up | framework path: both are appended to the process-wide lists | `the_rules_of_the_configuration_and_of_the_file_add_up`, `every_file_of_a_list_is_read` | none |
| `schema.json` and `schema.asc.json` are what the Rust types print | Nix check `schema-fresh`, and a test that compares them with `komorebic`'s output | `schema-fresh`, `the_schema_files_of_the_repository_are_what_the_subcommands_print` | `just jsonschema` |
| The options the module is typed with are made from the committed schema | the hash of `schema.json` in the first line of `nix/komorebi-options.nix`, compared by `schema-fresh` | `schema-fresh` | `just nixgen` |
@@ -1229,6 +1251,8 @@ module's unit.
see-through, and the opacity they are given.
- [`kwin::effects`](../../komorebi/src/kwin/effects.rs): the KWin effect that draws the border,
its settings and the state komorebi keeps of it.
- [`check`](../../komorebi/src/check.rs): the checks behind `komorebic check`, the [`Finding`]s
they return and the [`Report`] `komorebic` gathers them in.
- [`process_command`](../../komorebi/src/process_command.rs): the thread that listens on the
socket, and what the window manager does with each message.
- [`state`](../../komorebi/src/state.rs): the [`State`] a `State` message is answered with,
@@ -1540,6 +1564,9 @@ A window is shown, and ends up on a tile:
and the example it evaluates them against; [`komorebi/tests/asc.rs`](../../komorebi/tests/asc.rs)
the applications files; [`komorebi/src/core/asc.rs`](../../komorebi/src/core/asc.rs) their
format.
- [`komorebi/src/check.rs`](../../komorebi/src/check.rs): the checks of `komorebic check`, with
their tests; [`komorebic/tests/check.rs`](../../komorebic/tests/check.rs) runs the command on
configurations and reads what it prints and its exit status.
- [`komorebi/src/process_event.rs`](../../komorebi/src/process_event.rs): what each event
does, and the thread that handles them.
- [`komorebi/src/process_command.rs`](../../komorebi/src/process_command.rs): the socket, what
@@ -1692,6 +1719,17 @@ A window is shown, and ends up on a tile:
[`StaticConfig::reload`]: ../../komorebi/src/static_config.rs
[`Workspace::load_static_config`]: ../../komorebi/src/workspace.rs
[`HOME_DIR`]: ../../komorebi/src/lib.rs
[`check`]: ../../komorebi/src/check.rs
[`Finding`]: ../../komorebi/src/check.rs
[`Level`]: ../../komorebi/src/check.rs
[`Report`]: ../../komorebi/src/check.rs
[`Wants`]: ../../komorebi/src/check.rs
[`Report::render`]: ../../komorebi/src/check.rs
[`Report::has_errors`]: ../../komorebi/src/check.rs
[`check_configuration`]: ../../komorebi/src/check.rs
[`check_keys`]: ../../komorebi/src/check.rs
[`known_keys`]: ../../komorebi/src/check.rs
[`snippet`]: ../../komorebi/src/check.rs
[`WORKSPACE_MATCHING_RULES`]: ../../komorebi/src/lib.rs
[`WindowManager::enforce_workspace_rules`]: ../../komorebi/src/window_manager.rs
[`WindowManager::already_moved_window_handles`]: ../../komorebi/src/window_manager.rs
+12
View File
@@ -355,6 +355,18 @@ one that another platform has: a configuration written for macOS names `applicat
which a KDE desktop does not have. The daemon warns and goes on. A file that exists and is not an
applications.json is a mistake in something the user wrote, and is an error.
## Why is a key komorebi does not know a warning, and a value it cannot read an error?
Because one `komorebi.json` is meant to work on every platform, and a key that komorebi for KDE
does not read may be one that another platform does. serde drops a key the types do not have, so
loading never fails because of one, and `komorebic check` does not fail for one either: the keys
only Windows or macOS reads are listed once as a note, and only a key that no platform has is a
warning, with the nearest key that exists, since it is most likely a typo and komorebi will not
have done what was meant. A value of the wrong kind is a different matter: the daemon does not
read the file (a daemon that is running keeps what it had), so the check shows the line and exits
with status 1. A workspace that is only a name is a warning too: it is not tiled, which is easy to
do without meaning to.
## Why does `nix/komorebi-options.nix` start with the hash of the schema?
Because the check that the options are fresh cannot make them again. `schemars-nixgen` makes
+2
View File
@@ -75,6 +75,8 @@ and what it does to the borders.
changes size, is unplugged or is plugged in, and
[Sleeping and locking](usage/sleeping-and-locking.md) what it does when the machine wakes up and
the screen is unlocked.
[Checking the setup](usage/checking-the-setup.md) explains how `komorebic check` finds the
mistakes in a configuration before the daemon does.
[Subscribing to notifications](usage/subscribing-to-notifications.md) explains how a program
such as a status bar follows what komorebi does. The [CLI reference](cli/start.md) has a page
for every `komorebic` command, generated from its help.
+79
View File
@@ -0,0 +1,79 @@
# Checking the setup
[`komorebic check`](../cli/check.md) reads your configuration the way the daemon does, and says in
words what is wrong with it. It does not need the daemon to be running, and it changes nothing.
```sh
komorebic check
komorebic check --komorebi-config ~/mine.json
```
It reads `komorebi.json` in the [config home](configuration.md#where-the-file-is), or the file
`--komorebi-config` names (`-k`; environment variables in the path are replaced). It prints a
section of findings, then the number of errors and warnings, and exits with status 1 if and only if
a finding is an error, so a script can run it before it starts the daemon.
## What a finding says
Each finding is on a line of its own, after its level, with advice under it when there is some:
| Level | Meaning |
|---|---|
| `ok` | Right as it is |
| `note` | Something to know |
| `warning` | Something that will not do what was meant: komorebi starts and carries on |
| `error` | Something that stops komorebi, or a part of it, from working |
## The configuration
The first section says where komorebi looks, and then what it finds in the file:
- **No file.** A `note`: komorebi starts with its defaults, and
[`komorebic quickstart`](quickstart-and-autostart.md#quickstart) has an example to begin from.
- **JSON that does not parse.** An `error` that shows the line, and the two before it, with a caret
under the place serde stopped:
```text
error bad.json is not valid JSON: expected ident at line 3 column 29
1 | {
2 | "resize_delta": 100,
3 | "mouse_follows_focus": tru,
| ^
```
- **A value komorebi does not read.** An `error` that shows the line the same way, for a value of
the wrong kind or a name that is not one of the choices (`"cross_boundary_behaviour":
"Sideways"`). The hint says that [`komorebic static-config-schema`](../cli/static-config-schema.md)
prints the schema, for an editor to check the file against.
- **A key that is not a setting.** A `warning`, with the nearest setting when one is near enough to
be what you meant, at the root of the file, in a monitor and in a workspace. komorebi reads the
file without it, so a typo is ignored, which is why the check says so:
```text
warning `resize_dlta` is not a setting komorebi has
did you mean `resize_delta`?
```
- **A key for another platform.** Not a mistake, since one `komorebi.json` can serve
[every platform](configuration.md#one-file-for-every-platform). The keys that only komorebi for
Windows or for macOS reads, and the keys komorebi for KDE reads and does nothing with, are listed
once, in a `note`. A workspace's `custom_layout` and `custom_layout_rules`, which Windows has, are
a `warning`: they are not supported yet.
- **An application specific configuration that is not there.** A `warning` for each file that
`app_specific_configuration_path` names and that does not exist: komorebi starts without it,
and the windows it names are managed like any other.
- **A wallpaper that is not a file.** An `error` for each wallpaper, of a monitor or of a
workspace, whose `path` is not a file: the shell has nothing to show.
- **A wallpaper no theme can be made from.** A `warning` for a picture of which the
[borders cannot take their colors](wallpapers.md#the-colors-of-the-borders), when
`generate_theme` is not `false`: the wallpaper is set and the borders keep the colors they have.
- **A workspace that is only a name.** A `warning` for a workspace with no `layout`, no `tile` and
no `layout_rules`, which komorebi does not tile.
- **Placement rules that are not used.** A `note` for a workspace that has
[`initial_window_placement_rules`](../initial-window-placement-rules.md) and
[appends windows to a container](stacking-windows.md) (`"window_container_behaviour":
"Append"`, on the workspace, or in the file when the workspace does not say): a window that is
appended has no place of its own to be given.
The check takes the keys it knows from the schema of the types the daemon reads the file with, at
every level, so it knows every setting komorebi reads.
+3 -1
View File
@@ -267,5 +267,7 @@ check-jsonschema --schemafile schema.json ~/.config/komorebi/komorebi.json
`check-jsonschema` reads plain JSON, so comments in the file have to come out first. The schema
does not stop komorebi from reading a file that does not follow it: a key it does not have is
dropped, as [above](#one-file-for-every-platform).
dropped, as [above](#one-file-for-every-platform). [`komorebic check`](checking-the-setup.md)
reads the file the way the daemon does, and names a key that is not a setting, with the nearest
one that is.
+2 -1
View File
@@ -14,7 +14,7 @@
//! after each event and each message the window manager handles.
//!
//! The crate also re-exports the types the messages and the answers are made of, so that a client
//! needs nothing else.
//! needs nothing else, and [`check`], the checks `komorebic check` runs.
//!
//! # Example
//!
@@ -58,6 +58,7 @@ pub use komorebi::LOG_DIR;
pub use komorebi::Notification;
pub use komorebi::NotificationEvent;
pub use komorebi::animation::AnimationPrefix;
pub use komorebi::check;
pub use komorebi::container::Container;
pub use komorebi::core::ApplicationIdentifier;
pub use komorebi::core::Axis;
File diff suppressed because it is too large. Load diff
+4
View File
@@ -32,6 +32,9 @@
//! [`struct@DATA_DIR`]: after each event, each message and each change of the monitors the window
//! manager handles, [`notify_subscribers`] sends every subscriber a [`Notification`] of it, with
//! the state.
//!
//! The checks of `komorebic check`, which read `komorebi.json` without starting the daemon, are in
//! [`check`].
use crate::core::ApplicationIdentifier;
use crate::core::DefaultLayout;
@@ -69,6 +72,7 @@ pub mod ring;
pub mod animation;
pub mod backend;
pub mod border_manager;
pub mod check;
pub mod container;
pub mod core;
pub mod desktop;
+54 -1
View File
@@ -102,7 +102,9 @@
//! `applications.json` in the config home, `enable-autostart` and `disable-autostart` write and
//! remove the entry that has Plasma start komorebi at login, `start` runs `komorebi` in the
//! background, with the
//! `komorebi.json` it is given with `--config`, `configuration` shows the path of the
//! `komorebi.json` it is given with `--config`, `check` reads the `komorebi.json` the daemon would
//! and reports what is wrong with it, exiting with status 1 if something is an error,
//! `configuration` shows the path of the
//! `komorebi.json` the daemon reads, `log` follows its log, `data-directory` shows where its
//! socket is, `completions` prints a completion script for a shell, and `static-config-schema`,
//! `application-specific-configuration-schema`, `notification-schema` and `socket-schema` print
@@ -827,6 +829,14 @@ struct Docgen {
output: Option<PathBuf>,
}
#[derive(Parser)]
struct Check {
/// Path to a static configuration JSON file
#[clap(action, short, long)]
#[clap(value_parser = replace_env_in_path)]
komorebi_config: Option<PathBuf>,
}
#[derive(Parser)]
struct Completions {
#[clap(value_enum)]
@@ -853,6 +863,8 @@ enum SubCommand {
Start(Start),
/// Stop the komorebi process
Stop(Stop),
/// Check komorebi configuration for common errors
Check(Check),
/// Show the path to komorebi.json
#[clap(alias = "config")]
Configuration,
@@ -1445,6 +1457,47 @@ fn main() -> eyre::Result<()> {
println!("There is no autostart entry at {}", target.display());
}
}
SubCommand::Check(args) => {
use komorebi_client::check::Finding;
use komorebi_client::check::Report;
let mut report = Report::default();
// where komorebi looks
let mut place = vec![];
if std::env::var_os("KOMOREBI_CONFIG_HOME").is_some() {
place.push(Finding::note(format!(
"KOMOREBI_CONFIG_HOME is set: looking in {}",
HOME_DIR.display()
)));
} else {
place.push(Finding::note(format!(
"KOMOREBI_CONFIG_HOME is not set: looking in {}",
HOME_DIR.display()
)));
}
let static_config = match args.komorebi_config {
Some(path) => {
place.push(Finding::note(format!(
"using the configuration file given with --komorebi-config: {}",
path.display()
)));
path
}
None => HOME_DIR.join("komorebi.json"),
};
let (findings, _) = komorebi_client::check::check_configuration(&static_config);
place.extend(findings);
report.push("Configuration", place);
print!("{}", report.render());
if report.has_errors() {
std::process::exit(1);
}
}
SubCommand::Start(args) => {
let mut command = &mut Command::new("komorebi");
+96
View File
@@ -0,0 +1,96 @@
//! `komorebic check`, as a person runs it: a configuration in, a report and an exit status out.
use std::path::Path;
use std::process::Command;
use std::process::Output;
fn check(config: Option<&str>, extra: &[&str]) -> (Output, String) {
static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
let dir = std::env::temp_dir().join(format!(
"kmc-cli-{}-{}",
std::process::id(),
NEXT.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let mut command = Command::new(env!("CARGO_BIN_EXE_komorebic"));
command.arg("check").env("KOMOREBI_CONFIG_HOME", &dir);
if let Some(config) = config {
let path = dir.join("komorebi.json");
std::fs::write(&path, config).unwrap();
command.arg("--komorebi-config").arg(&path);
}
command.args(extra);
let output = command.output().unwrap();
let text = String::from_utf8_lossy(&output.stdout).into_owned();
let _ = std::fs::remove_dir_all(Path::new(&dir));
(output, text)
}
#[test]
fn a_good_configuration_passes() {
let (output, text) = check(
Some(
r#"{ "border": true, "monitors": [ { "workspaces": [ { "name": "a", "layout": "BSP" } ] } ] }"#,
),
&[],
);
assert!(output.status.success(), "{text}");
assert!(text.contains("is valid"), "{text}");
assert!(text.contains("0 error(s), 0 warning(s)"), "{text}");
}
#[test]
fn a_file_that_is_not_json_fails_and_shows_the_line() {
let (output, text) = check(Some("{\n \"border\": tru,\n}\n"), &[]);
assert_eq!(output.status.code(), Some(1), "{text}");
assert!(text.contains("not valid JSON"), "{text}");
assert!(text.contains("2 | \"border\": tru,"), "{text}");
assert!(text.contains("^"), "{text}");
}
#[test]
fn a_value_that_does_not_exist_fails_and_shows_the_line() {
let (output, text) = check(
Some("{\n \"cross_boundary_behaviour\": \"Sideways\"\n}\n"),
&[],
);
assert_eq!(output.status.code(), Some(1), "{text}");
assert!(
text.contains("does not match what komorebi reads"),
"{text}"
);
assert!(text.contains("2 |"), "{text}");
}
#[test]
fn a_typo_is_a_warning_with_the_word_that_was_meant_and_does_not_fail() {
let (output, text) = check(
Some(r#"{ "bordr_width": 10, "border_style": "System" }"#),
&[],
);
assert!(output.status.success(), "{text}");
assert!(text.contains("`bordr_width` is not a setting"), "{text}");
assert!(text.contains("did you mean `border_width`?"), "{text}");
// a key for another platform is not a mistake
assert!(
text.contains("accepted and ignored here: border_style"),
"{text}"
);
assert!(text.contains("1 warning(s)"), "{text}");
}
#[test]
fn no_file_is_not_an_error() {
let (output, text) = check(None, &[]);
assert!(output.status.success(), "{text}");
assert!(text.contains("starts with its defaults"), "{text}");
}
+1
View File
@@ -1110,6 +1110,7 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() {
"border.md",
"cancel-preselect.md",
"change-layout.md",
"check.md",
"clear-all-workspace-rules.md",
"clear-named-workspace-layout-rules.md",
"clear-named-workspace-rules.md",