Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3131c02
D94 — shell: the tests read every sentence of words.rs against the vo…
kitokey-sam[bot] Nov 14, 2026
6535ebb
D94 — shell: the voice guide's ratchet keyed by sentence, not counted
kitokey-sam[bot] Nov 14, 2026
c18adb6
D94 — shell: a sentence of no named language held to both lexicons
kitokey-sam[bot] Nov 14, 2026
0d0a34c
D94 — shell: a settings file refused says which setting and what to d…
kitokey-sam[bot] Nov 14, 2026
46786e6
D94 — shell: the settings' log line declared under the window's K
kitokey-sam[bot] Nov 14, 2026
2ceff1c
D94 — shell: a comment's placeholders read against all it covers
kitokey-sam[bot] Nov 14, 2026
31a3f0e
D94 — shell: a locale compared and a target named are no sentence
kitokey-sam[bot] Nov 14, 2026
129f637
D94 — shell: only the literal right after a word of the code is the c…
kitokey-sam[bot] Nov 14, 2026
6d04754
Merge branch 'shell/d94-words-rules' into shell/d94-settings-words
kitokey-sam[bot] Nov 14, 2026
301716f
D94 — shell: #783's sentences held by the voice guide's tests
kitokey-sam[bot] Nov 14, 2026
ecf133a
Merge remote-tracking branch 'origin/main' into shell/d94-words-rules
kitokey-sam[bot] Nov 14, 2026
fc3b37e
D94 — shell: Settings' « Général » heading carries its comment
kitokey-sam[bot] Nov 14, 2026
02c2f33
Merge origin/main into shell/d94-words-rules
kitokey-sam[bot] Nov 14, 2026
bcb8e8f
shell: #807's five sentences carry the guide's comment; « Minutes sto…
kitokey-sam[bot] Nov 14, 2026
5612d21
Merge shell/d94-words-rules into shell/d94-settings-words
kitokey-sam[bot] Nov 14, 2026
334eba5
shell: the keys a settings refusal names are held to the file's field…
kitokey-sam[bot] Nov 15, 2026
c357426
Merge origin/main into shell/d94-settings-words
kitokey-sam[bot] Nov 15, 2026
596ccd2
Merge origin/main into shell/d94-settings-words
kitokey-sam[bot] Nov 15, 2026
336011e
Merge origin/main into shell/d94-settings-words
kitokey-sam[bot] Nov 15, 2026
0dd8193
Merge origin/main into shell/d94-settings-words
kitokey-sam[bot] Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/shell/MANIFEST.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ evidence:
- pattern: '"message":"shell\.command_failed"'
level: warning
scenario: AB
# The window's K starts once on a settings file broken by hand: settings.rs's sentence goes to
# the log, the user is told which setting and what to do (#783).
- pattern: '"message":"shell\.settings_unread"'
level: warning
scenario: K
# A failure of the page's own, thrown then rejected; any other kind of the page's is not provoked.
- pattern: '^(?=.*"message":"shell\.page_failed")(?=.*"kind":"ScenarioI")'
level: error
Expand Down
13 changes: 10 additions & 3 deletions modules/shell/scripts/e2e_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8467,8 +8467,11 @@ def folder_field():
held = window.file.read_text()
lines = [line for line in held.splitlines() if not line.startswith("keep_audio")] + ["keep_audio = 0"]
broken = "\n".join(lines) + "\n"
refused = "Le réglage n’a pas été enregistré\u00a0: le fichier des réglages ne peut pas être lu\u00a0: corrigez-le, puis réessayez.".replace("\xa0", " ") # WebDriver's `.text` reads U+00A0 as a space
locked_said = "Le fichier des réglages ne peut pas être lu\u00a0: Kitokey ne l’écrit pas tant qu’il n’est pas corrigé.".replace("\xa0", " ") # WebDriver's `.text` reads U+00A0 as a space
# Which setting, on which line, and what to do (#783) — never settings.rs's own sentence.
# WebDriver's `.text` reads U+00A0 as a space.
which = lambda line: f"Ligne {line} : « keep_audio » vaut « always » ou un nombre de jours, de 1 à 36\u202f500. Corrigez-le." # noqa: E731
refused = f"Le réglage n’a pas été enregistré : le fichier des réglages ne peut pas être lu. {which(len(lines))}"
locked_said = f"Le fichier des réglages ne peut pas être lu : Kitokey ne l’écrit pas tant qu’il n’est pas corrigé. {which(len(lines))}"
unreadable = lambda: browser.find_element(By.ID, "settings-unreadable").text # noqa: E731
window.file.write_text(broken)
changed(lambda: browser.find_element(By.ID, "reminder").click())
Expand All @@ -8484,6 +8487,9 @@ def folder_field():
lines = [line for line in held.splitlines() if not line.startswith("keep_audio")] + ["keep_audio = 0"]
window.file.write_text("\n".join(lines) + "\n")
raw = f'settings.toml, line {len(lines)}: keep_audio is "always" or a number of days'
# The file's line has moved with developer mode written: the sentences name the new one.
refused = f"Le réglage n’a pas été enregistré : le fichier des réglages ne peut pas être lu. {which(len(lines))}"
locked_said = f"Le fichier des réglages ne peut pas être lu : Kitokey ne l’écrit pas tant qu’il n’est pas corrigé. {which(len(lines))}"
changed(lambda: browser.find_element(By.ID, "reminder").click())
said = not_saved()
check("developer mode on, the raw text is under the sentence of the command that failed, without its path", said == f"{refused}\n{raw}", said)
Expand Down Expand Up @@ -8753,7 +8759,8 @@ def log_message(self, *_):
wait_for(browser, lambda b: b.find_elements(By.CSS_SELECTOR, "#settings .warn"))
warned = browser.find_element(By.CSS_SELECTOR, "#settings .warn").text
locked = browser.execute_script("return [...document.querySelectorAll('#settings input, #settings select')].every(e => e.disabled)")
check("a settings file that cannot be read is said so, and nothing can be changed", warned == "Le fichier des réglages ne peut pas être lu : Kitokey ne l’écrit pas tant qu’il n’est pas corrigé." and locked, warned)
which = "Ligne 3 : « keep_audio » vaut « always » ou un nombre de jours, de 1 à 36\u202f500. Corrigez-le." # U+00A0 read as a space
check("a settings file that cannot be read is said so, which setting and what to do, and nothing can be changed", warned == f"Le fichier des réglages ne peut pas être lu : Kitokey ne l’écrit pas tant qu’il n’est pas corrigé. {which}" and locked, warned)
check("it is left as it was", window.file.read_text() == f'sessions = "{broken}"\nwelcomed = true\nkeep_audio = 0\n')
# The shell itself refuses, not only the page.
refused = browser.execute_async_script(
Expand Down
2 changes: 1 addition & 1 deletion modules/shell/src/autostart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn carry_over(before: &Path, entry: &Path) -> io::Result<bool> {
/// At a start: the entry written when the settings say it never was, and that it was, kept in
/// them. True when it was written now. A settings file that cannot be read writes nothing.
pub fn first(entry: &Path, settings_file: &Path) -> io::Result<bool> {
let mut settings = settings::read(settings_file).map_err(|why| io::Error::new(io::ErrorKind::InvalidData, why))?;
let mut settings = settings::read(settings_file).map_err(|why| io::Error::new(io::ErrorKind::InvalidData, why.detail))?;
if settings.autostart.is_some() {
return Ok(false);
}
Expand Down
31 changes: 20 additions & 11 deletions modules/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,15 @@ impl Shell {
/// Reads the settings file again — the user may have changed it by hand — and holds what it
/// says; a file that cannot be read is said, by its name and not its path, and what was held
/// stays.
fn reread(&self) -> Result<Settings, String> {
fn reread(&self) -> Result<Settings, settings::Unread> {
let read = settings::file().map_or_else(
|| Ok(Settings::default()),
|file| settings::read(&file).map_err(|why| settings::unnamed(&why, &file)),
|file| {
settings::read(&file).map_err(|why| settings::Unread {
detail: settings::unnamed(&why.detail, &file),
..why
})
},
);
if let Ok(settings) = &read {
*self.settings.lock().unwrap() = settings.clone();
Expand Down Expand Up @@ -266,7 +271,7 @@ impl Shell {

/// The settings read again for a command.
fn read_or_told(&self) -> Result<Settings, Told> {
self.reread().map_err(|why| self.told(Failure::SettingsUnread, why))
self.reread().map_err(|why| self.told(Failure::SettingsUnread(why.refused), why))
}

/// The settings written for a command.
Expand Down Expand Up @@ -585,7 +590,11 @@ fn main() {
let refused = licence::refused(&licence, &sessions, seconds_now());
tracing::info!(licence = %answer, refused, "shell.licence_read");
if let Err(why) = read {
tell(app.handle(), &words::trouble(&Trouble::Settings(why), language));
// The sentence of `settings.rs` to the log, by the file's name; the user is told which
// setting and what to do (#783).
let detail = settings::file().map_or_else(|| why.detail.clone(), |file| settings::unnamed(&why.detail, &file));
tracing::warn!(%detail, "shell.settings_unread");
tell(app.handle(), &words::trouble(&Trouble::Settings(why.refused), language));
}
// A recording a Kitokey ended before this one left running: shown, and stopped from here (#773).
found(app.handle());
Expand Down Expand Up @@ -672,7 +681,7 @@ fn offer_recording(app: &AppHandle, application: String) {
tracing::info!("shell.offer_off");
let shell = app.state::<Shell>();
let _saving = shell.saving.lock().unwrap();
let saved = shell.reread().and_then(|mut settings| {
let saved = shell.reread().map_err(|why| why.detail).and_then(|mut settings| {
settings.offer = false;
let file = settings::file().ok_or("this system names no folder for settings")?;
settings::write(&file, &settings).map_err(|error| error.to_string())?;
Expand Down Expand Up @@ -732,7 +741,7 @@ fn show_welcome(app: &AppHandle) {
let shell = app.state::<Shell>();
{
let _saving = shell.saving.lock().unwrap();
let written = shell.reread().and_then(|mut settings| {
let written = shell.reread().map_err(|why| why.detail).and_then(|mut settings| {
settings.welcomed = true;
let file = settings::file().ok_or("this system names no folder for settings")?;
settings::write(&file, &settings).map_err(|error| error.to_string())?;
Expand Down Expand Up @@ -1699,7 +1708,7 @@ fn models_offered(shell: State<'_, Shell>, name: Option<String>) -> Result<Model
// Settings unreadable: offered from those in memory, and said — the panel still opens.
let (settings, unreadable) = match shell.reread() {
Ok(settings) => (settings, None),
Err(why) => (shell.settings(), Some(shell.told(Failure::SettingsLocked, why))),
Err(why) => (shell.settings(), Some(shell.told(Failure::SettingsLocked(why.refused), why))),
};
let (mut chosen, gone, confidential) = match &name {
Some(name) => {
Expand Down Expand Up @@ -2384,7 +2393,7 @@ async fn settings_shown(app: AppHandle, shell: State<'_, Shell>) -> Result<Setti
let (autostart, autostart_offered, autostart_held) = startup_shown();
let (settings, unreadable) = match shell.reread() {
Ok(settings) => (settings, None),
Err(why) => (shell.settings(), Some(shell.told(Failure::SettingsLocked, why))),
Err(why) => (shell.settings(), Some(shell.told(Failure::SettingsLocked(why.refused), why))),
};
let models = settings::whisper_models(&models_folder(), &settings)
.into_iter()
Expand Down Expand Up @@ -3290,8 +3299,8 @@ fn write_minutes_from(
let settings = match shell.reread() {
Ok(settings) => settings,
Err(why) => {
refused(why.clone());
return tell(app, &words::trouble(&Trouble::Settings(why), shell.language()));
refused(why.detail);
return tell(app, &words::trouble(&Trouble::Settings(why.refused), shell.language()));
}
};
let named = settings.minutes_provider.clone().zip(settings.minutes_model.clone());
Expand Down Expand Up @@ -3924,7 +3933,7 @@ fn retranscribe(app: &AppHandle, folder: PathBuf, again: Again, cancel: Cancel)
return Ok(());
}
shell.transcripts_tried.lock().unwrap().insert(folder.clone(), Some(again.clone()));
let read = shell.reread().map_err(|why| (Failure::SettingsUnread, why))?;
let read = shell.reread().map_err(|why| (Failure::SettingsUnread(why.refused), why.detail))?;
// The models this computer lists, as Settings name theirs: a Refaire… may pick Settings' own.
let listed = settings::whisper_models(&models_folder(), &read);
let settings = own(&read, &folder);
Expand Down
157 changes: 143 additions & 14 deletions modules/shell/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,31 +249,108 @@ struct Written {
microphone_description: Option<String>,
}

/// What in a settings file Kitokey refuses, as the user is told it (#783): which setting, on which
/// line. A key is one of the file's own (`KEYS`), never what the user typed in its place.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Refused {
/// The file is there and cannot be opened: its permissions, a folder in its place.
Unopened,
/// A line that is not a setting as TOML writes one, or a setting whose value is not of its kind.
Unparsed { line: usize, key: Option<&'static str> },
/// `sessions`: not a folder's whole path.
SessionsNotWhole { line: usize },
/// `model`: not a file's whole path.
ModelNotWhole { line: usize },
/// `keep_audio`: neither "always" nor a number of days from 1 to 36,500.
KeepAudio { line: usize },
}

/// A settings file refused: what the user is told, and the sentence the log and developer mode
/// hold — which names the file by its whole path until `unnamed` is given it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Unread {
pub refused: Refused,
pub detail: String,
}

impl std::fmt::Display for Unread {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.detail)
}
}

/// The keys a settings file may hold: those a refusal names.
const KEYS: [&str; 25] = [
"reminder",
"sessions",
"transcript",
"after",
"model",
"engine",
"transcription_provider",
"transcription_model",
"transcription_agreed",
"minutes_provider",
"minutes_model",
"meeting_language",
"minutes_agreed",
"keep_audio",
"developer",
"offer",
"autostart",
"window",
"log",
"welcomed",
"folded",
"bar_at",
"language",
"microphone",
"microphone_description",
];

/// Reads the settings. No file is no choice made: the defaults. A file that cannot be read as
/// settings is said in one sentence — which file, which line, and what in it — and nothing of
/// it is used.
pub fn read(path: &Path) -> Result<Settings, String> {
pub fn read(path: &Path) -> Result<Settings, Unread> {
let unread = |refused, detail| Unread { refused, detail };
let text = match fs::read_to_string(path) {
Ok(text) => text,
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(Settings::default()),
Err(error) => return Err(format!("{} cannot be read ({error})", path.display())),
Err(error) => return Err(unread(Refused::Unopened, format!("{} cannot be read ({error})", path.display()))),
};
// The line a place of the file is on: one more than the line ends before it.
let line = |at: usize| text[..at.min(text.len())].matches('\n').count() + 1;
// The key a line sets, when it is one of the file's own.
let key = |at: usize| {
let start = text[..at.min(text.len())].rfind('\n').map_or(0, |end| end + 1);
let (named, _) = text[start..].split_once('=')?;
// A key written in quotes, as TOML allows, is the same key.
let named = named.trim().trim_matches(|c| c == '"' || c == '\'');
KEYS.into_iter().find(|key| *key == named)
};
let written: Written = toml::from_str(&text).map_err(|error| match error.span() {
Some(span) => format!("{}, line {}: {}", path.display(), line(span.start), error.message()),
None => format!("{}: {}", path.display(), error.message()),
Some(span) => unread(
Refused::Unparsed {
line: line(span.start),
key: key(span.start),
},
format!("{}, line {}: {}", path.display(), line(span.start), error.message()),
),
None => unread(
Refused::Unparsed { line: 1, key: None },
format!("{}: {}", path.display(), error.message()),
),
})?;
// A path written as people write it: from their home, with a tilde — or from the root.
let whole = |key: &str, what: &str, written: toml::Spanned<PathBuf>| {
let whole = |key: &str, what: &str, refused: fn(usize) -> Refused, written: toml::Spanned<PathBuf>| {
let at = line(written.span().start);
let named = from_home(written.into_inner());
if named.is_absolute() {
Ok(named)
} else {
Err(format!(
"{}, line {at}: {key} is {what} whole path, from the root or from ~",
path.display()
Err(unread(
refused(at),
format!("{}, line {at}: {key} is {what} whole path, from the root or from ~", path.display()),
))
}
};
Expand Down Expand Up @@ -310,18 +387,18 @@ pub fn read(path: &Path) -> Result<Settings, String> {
toml::Value::String(always) if always == "always" => KeepAudio::Always,
toml::Value::Integer(days) if (1..=36_500).contains(days) => KeepAudio::Days(*days as u32),
_ => {
return Err(format!(
"{}, line {at}: keep_audio is \"always\" or a number of days",
path.display()
return Err(unread(
Refused::KeepAudio { line: at },
format!("{}, line {at}: keep_audio is \"always\" or a number of days", path.display()),
));
}
};
}
if let Some(sessions) = written.sessions {
settings.sessions = whole("sessions", "the folder's", sessions)?;
settings.sessions = whole("sessions", "the folder's", |line| Refused::SessionsNotWhole { line }, sessions)?;
}
if let Some(model) = written.model {
settings.model = whole("model", "the file's", model)?;
settings.model = whole("model", "the file's", |line| Refused::ModelNotWhole { line }, model)?;
}
Ok(settings)
}
Expand All @@ -345,7 +422,7 @@ pub fn write(path: &Path, settings: &Settings) -> io::Result<()> {
let refused = |why: String| io::Error::new(io::ErrorKind::InvalidData, why);
// Through a link, the file it points to.
let path = &fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
let before = read(path).map_err(refused)?;
let before = read(path).map_err(|why| refused(why.detail))?;
let mut document = match fs::read_to_string(path) {
Ok(text) => text.parse::<DocumentMut>().map_err(|error| refused(error.to_string()))?,
Err(error) if error.kind() == io::ErrorKind::NotFound => DocumentMut::new(),
Expand Down Expand Up @@ -471,3 +548,55 @@ pub fn write(path: &Path, settings: &Settings) -> io::Result<()> {
let _ = fs::remove_file(&draft);
})
}

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

/// `KEYS` names each of `Written`'s fields, and nothing else (#813): a setting added to the file
/// is named by a refusal. The pattern lists every field — one added or taken out fails to compile
/// here — and the names compared are the pattern's own.
#[test]
fn the_keys_a_refusal_names_are_the_files_fields() {
macro_rules! fields {
($($field:ident),* $(,)?) => {{
#[allow(dead_code)]
fn every(written: Written) {
let Written { $($field: _),* } = written;
}
[$(stringify!($field)),*]
}};
}
let mut fields = fields!(
reminder,
sessions,
transcript,
after,
model,
engine,
transcription_provider,
transcription_model,
transcription_agreed,
minutes_provider,
minutes_model,
meeting_language,
minutes_agreed,
keep_audio,
developer,
offer,
autostart,
window,
log,
welcomed,
folded,
bar_at,
language,
microphone,
microphone_description,
);
let mut keys = KEYS;
fields.sort_unstable();
keys.sort_unstable();
assert_eq!(keys, fields);
}
}
Loading
Loading