diff --git a/crates/engine/src/cmd/buffer.rs b/crates/engine/src/cmd/buffer.rs index 6dae200..8f4f949 100644 --- a/crates/engine/src/cmd/buffer.rs +++ b/crates/engine/src/cmd/buffer.rs @@ -197,7 +197,7 @@ impl Command for Close { fn spec(&self) -> &CommandSpec { &CommandSpec { id: "buffer.close", - label: "Close Buffer", + label: "Close Tab", menu_path: Some("File/Close Tab"), default_shortcut: Some("Mod+W"), params: "{ id: number, force?: bool (discard unsaved changes) }; returns null; fails with unsaved_changes if the buffer is dirty and force is not set", diff --git a/crates/engine/src/engine.rs b/crates/engine/src/engine.rs index 6cf84cb..d6b6cb9 100644 --- a/crates/engine/src/engine.rs +++ b/crates/engine/src/engine.rs @@ -462,6 +462,25 @@ mod tests { ); } + /// The palette label of a menu command starts with the menu item's + /// wording; it may add context the menu gives by its place ("Rename + /// Symbol" for Refactor › Rename…), but never says it differently + /// ("Close Buffer" for File › Close Tab). + #[test] + fn a_command_in_a_menu_has_the_menu_items_wording_in_the_palette() { + let engine = Engine::new().unwrap(); + let differing: Vec = engine + .list_commands() + .iter() + .filter_map(|c| { + let item = c.menu_path.as_deref()?.rsplit('/').next()?; + (!c.label.starts_with(item.trim_end_matches('…'))) + .then(|| format!("{}: {} / {item}", c.id, c.label)) + }) + .collect(); + assert_eq!(differing, Vec::::new()); + } + #[test] fn lists_commands_with_metadata() { let mut engine = Engine::new().unwrap(); diff --git a/crates/search/src/query.rs b/crates/search/src/query.rs index 5cfe997..836c32e 100644 --- a/crates/search/src/query.rs +++ b/crates/search/src/query.rs @@ -44,7 +44,7 @@ impl Search { .dfa_size_limit(REGEX_SIZE_LIMIT) .nest_limit(REGEX_NEST_LIMIT) .build(&query.pattern) - .map_err(|e| SearchError::InvalidPattern(e.to_string()))?; + .map_err(|e| SearchError::InvalidPattern(pattern_error(&e.to_string())))?; Ok(Self { matcher, filter: PathFilter::new(&query.include, &query.exclude)?, @@ -53,6 +53,20 @@ impl Search { } } +/// The reason in a regex error for a person: the regex parser's report +/// spans several lines (the pattern as the matcher wrapped it, a caret, then +/// `error: `), so only the reason is kept; other errors keep their +/// text with line breaks and runs of spaces folded into one space. +pub(crate) fn pattern_error(text: &str) -> String { + if let Some(reason) = text + .lines() + .find_map(|line| line.trim().strip_prefix("error: ")) + { + return reason.trim().to_string(); + } + text.split_whitespace().collect::>().join(" ") +} + /// Include and exclude globs, split by whether they match a name or a path. #[derive(Debug, Clone)] pub(crate) struct PathFilter { diff --git a/crates/search/tests/search.rs b/crates/search/tests/search.rs index dcbe9cc..8396a5c 100644 --- a/crates/search/tests/search.rs +++ b/crates/search/tests/search.rs @@ -81,10 +81,18 @@ fn regex_and_invalid_input() { assert_eq!(files[0].matches[1].length, 5); q.pattern = "(".into(); - assert!(matches!( - Search::new(&q), - Err(SearchError::InvalidPattern(_)) - )); + assert_eq!( + Search::new(&q).unwrap_err().to_string(), + "invalid pattern: unclosed group" + ); + q.pattern = "a{".into(); + let message = Search::new(&q).unwrap_err().to_string(); + assert!( + message.starts_with("invalid pattern: ") + && !message.contains('\n') + && !message.contains("(?:"), + "{message}" + ); q.pattern = String::new(); assert_eq!(Search::new(&q).unwrap_err(), SearchError::EmptyPattern); let mut q = Query::literal("x"); diff --git a/docs/alpha-checklist.md b/docs/alpha-checklist.md index 09759ad..a600854 100644 --- a/docs/alpha-checklist.md +++ b/docs/alpha-checklist.md @@ -1,6 +1,6 @@ # Alpha acceptance checklist -> **Status:** C7 A2, written against main `da58c83` (M0–M4) · **Last updated:** 2026-10-31 +> **Status:** C7 A2, written against main `da58c83` (M0–M4) · **Last updated:** 2026-11-02 The alpha gate ([`roadmap.md`](roadmap.md) › Alpha gate) asks for six workflows to work end to end. This checklist turns them into steps you do by hand, once on Windows and once on macOS. Each step names the action, then what you should see. Plan on 30–45 minutes per platform. @@ -112,7 +112,7 @@ Before this section: `DEMO/shop` has the changes from 1.3, 3.3 and 3.10. The dem | 5.19 | Git › Abort Merge…, confirm. | The merge is undone: `DiscountPolicy.php` is gone, no conflict colour, `main` as before. | [ ] | [ ] | | 5.20 | Git › Merge… `feature/discounts` again, then "Resolve…" on `PriceCalculator.php`. | Three editors: current branch (left), result (middle), merged branch (right), "1 of 1 conflicts open" (or more). | [ ] | [ ] | | 5.21 | "Accept all left". Then, in the middle editor, change `gross(float $net)` to `gross(float $net, float $discount = 0.0)` and `round($net *` to `round(max(0.0, $net - $discount) *`. "Apply and mark resolved". | Apply is enabled once no chunk is open; afterwards the file is saved and the list says no conflicts are left, offering "Commit…". | [ ] | [ ] | -| 5.22 | "Commit…". Keep the prefilled message, Commit. (The conflict warnings from 5.18 and 5.20 stay until you close them with ×; close them if they cover the Commit button.) Then `php public/index.php` in the terminal. | The message box already holds `Merge branch 'feature/discounts'` (git's prepared message). The commit succeeds; the Log shows the merge with two parents; the script still prints `19.88 EUR`. | [ ] | [ ] | +| 5.22 | "Commit…". Keep the prefilled message, Commit. (The conflict warning from 5.18 closes by itself once no conflict is left, and toasts never cover the commit box.) Then `php public/index.php` in the terminal. | The message box already holds `Merge branch 'feature/discounts'` (git's prepared message). The commit succeeds; the Log shows the merge with two parents; the script still prints `19.88 EUR`. | [ ] | [ ] | | 5.23 | Git › Manage Remotes… Add a remote `backup` with the URL of `DEMO/origin.git`; then Remove it (confirm in the row). | `origin` is listed with its URL; `backup` appears and disappears again. | [ ] | [ ] | | 5.24 | Git › Clone Repository…, URL `DEMO/origin.git` (the full path), "Browse…" and choose `DEMO`. | The folder field becomes `DEMO/origin`. Clone shows progress, then the clone opens as the project (tree with `src`, `public`, `CHANGELOG.md`; branch `main`). | [ ] | [ ] | | 5.25 | File › Open Folder… `DEMO/shop`. | The demo project is back, with the Git state from 5.22. | [ ] | [ ] | @@ -187,4 +187,5 @@ When everything is ticked on both platforms, say so in the chat with the build c | Date | Change | Summary | |---|---|---| | 2026-10-31 | new | A2: the six alpha workflows as manual steps, the demo project (`cargo xtask demo-project`), failure reports | +| 2026-11-02 | fix | C9 F1: 5.22 no longer asks to close the conflict warnings | | 2026-11-01 | dry run | C8 C1: corrected after a Windows dry run (release build, control channel, CLI, MCP): 1.15 line break, 2.4 namespace node, 3.4 line 43, 3.7 `round` instead of `format_price`, 3.9 declaration, 5.2 staged label, 5.5 amend takes `.gitignore` along (else 5.16 stashes it), 5.6 own commits' author, 5.9 doc line, 5.13 no upstream next to "current", 5.22 sticky conflict toasts | diff --git a/docs/architecture.md b/docs/architecture.md index b877126..9c64c7a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,6 +1,6 @@ # Architecture -> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented; M2 highlighting and `editor.reveal`, plus the search backend, the Find tool window, the symbol index, the Structure tool window and the go-to popup; M3 CLI and single instance, LSP client library, toolchain (PHP detection, Phpactor download), the app menu, MCP server, autosave and `flushDirty`, integrated terminal; engine ↔ Phpactor wiring and diagnostics (M3.3), pending outcomes (M3.5), completion, hover and signature help (M3.4); C5 child process groups (H1), settings dialog string and path controls and assist settings (H4), the banner-aligned themes and diagnostic/VCS tokens (H5), Phpactor UX: fast tick, messages, progress, `php -l` (H3); Git backend (M4.1), Changes tool window (M4.2); line changes, gutter markers and status colours (M4.4), diff viewer (M4.3), branches (M4.5); remotes: fetch, pull, push, clone and remote management (M4.10); stash (M4.9) · **Last updated:** 2026-10-28 +> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented; M2 highlighting and `editor.reveal`, plus the search backend, the Find tool window, the symbol index, the Structure tool window and the go-to popup; M3 CLI and single instance, LSP client library, toolchain (PHP detection, Phpactor download), the app menu, MCP server, autosave and `flushDirty`, integrated terminal; engine ↔ Phpactor wiring and diagnostics (M3.3), pending outcomes (M3.5), completion, hover and signature help (M3.4); C5 child process groups (H1), settings dialog string and path controls and assist settings (H4), the banner-aligned themes and diagnostic/VCS tokens (H5), Phpactor UX: fast tick, messages, progress, `php -l` (H3); Git backend (M4.1), Changes tool window (M4.2); line changes, gutter markers and status colours (M4.4), diff viewer (M4.3), branches (M4.5); remotes: fetch, pull, push, clone and remote management (M4.10); stash (M4.9) · **Last updated:** 2026-11-02 ## Overview @@ -170,7 +170,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat - `/settings.json`, a flat JSON object of dotted keys, written with `lutra_vfs::write_atomic` on every change. Unknown keys are kept; a stored value that fails validation counts as unset. Read with a 1 MiB cap. - A file that is not a JSON object (invalid JSON, not UTF-8, too large) is renamed to `settings.json.bad-` (with `-n` if taken), the defaults are used and a `notification {level: "warning", messageKey: "notification.settings.corrupt", message, params: {reason, backup}}` is queued. If it cannot be moved, or the directory or file cannot be read, settings stay in memory for the session (`notification.settings.corruptNotMoved`, `notification.settings.unavailable`) so the file is never overwritten. - Keys: `appearance.theme` (`lutra-dark|lutra-light|system`, default `system`), `editor.fontSize` (int 8–48, default 14), `ui.language` (`en`), the autosave keys `editor.autosave.onBlur`, `editor.autosave.onTabSwitch` (bool, default true) and `editor.autosave.idleSeconds` (int 0–600, default 15; M3.10), the assist keys `editor.completion.autoPopup` (bool, default true), `editor.completion.delayMs` (int 0–2000, default 0) and `editor.hover.delayMs` (int 100–3000, default 350; H4). Defined in `lutra_engine::settings::DEFS`. -- Commands: `settings.list` → `[{key, type: enum|int, default, enumValues?, min?, max?, labelKey, descriptionKey, section}]` (catalog keys `settings..label` / `.description`; `section` is an id shown with `settings.section.`), `settings.get {keys?}` → `{values}`, `settings.set {key, value}` → `{value}`, `settings.reset {key}` → `{value}`. Unknown keys and bad values fail with `invalid_params`; a write failure fails with `failed` and changes nothing. +- Commands: `settings.list` → `[{key, type: enum|int|bool|string, default, enumValues?, min?, max?, path?, labelKey, descriptionKey, section}]` (`path: true` marks a file path setting, `Kind::Path`) (catalog keys `settings..label` / `.description`; `section` is an id shown with `settings.section.`), `settings.get {keys?}` → `{values}`, `settings.set {key, value}` → `{value}`, `settings.reset {key}` → `{value}`. Unknown keys and bad values fail with `invalid_params`; a write failure fails with `failed` and changes nothing. - Events: `settingsChanged {keys}` when an effective value changes; `notification {id, level: info|warning|error, messageKey?, message?, params?}` (ids `n1`, `n2`…). ### Notifications (M1.12) @@ -252,7 +252,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat - **Text:** labels, descriptions and section names come from the catalog keys the engine sends (`settings..label`, `.description`, `settings.section.`); enum values use `settings..value.`. A key the catalog lacks shows the setting key (or the raw value). These keys are in the catalog test's runtime list. - **Font size:** `theme.ts` has `setTokenOverride(name, value)`: a value above the theme's that `applyTheme` keeps across theme switches. The store sets `--lt-font-size-editor` to `editor.fontSize` px; the editor reads only that token. - **Dialog:** `ui/src/components/settings/SettingsDialog.vue` (mounted in `App.vue`) provides `settings.open` (`Mod+,`, palette, `uiCommand`). Sections on the left, the chosen section's settings on the right; enum → select, int → number field (min/max, applied when committed; text that is no whole number in range is refused in place with `settings.error.intRange`), bool → switch, string → text field (H4). The theme picker is the `appearance.theme` select; the engine answers with `themeChanged`. - - **String and path settings (H4, `stringSetting.ts`):** every `string` setting from `settings.list` gets a text field, applied when committed, so a new key (M4.1's `git.executable`) needs no UI change. A string setting whose key's last segment ends in `path` or `executable` is a path: it gets "Browse…", which calls the desktop's `pick_file {title}` IPC (the dialog plugin's native file picker, run off the main thread; `ipc.ts › pickFile`) and applies the chosen file through `settings.set`; a path with an empty default shows "Detected automatically" while empty. Checks before `settings.set`, each with its own catalog message: at most 4,096 UTF-8 bytes and no control characters (every string), no surrounding quotes and no spaces at either end (paths). The engine validates everything else. String rows stack the field under the label at full width. `settings.open {section?, query?}` opens on a section or with a search (for agents and live checks). + - **String and path settings (H4, `stringSetting.ts`):** every `string` setting from `settings.list` gets a text field, applied when committed, so a new key (M4.1's `git.executable`) needs no UI change. A string setting that `settings.list` marks with `path: true` (`php.executable`, `phpactor.path`, `git.executable`) is a path: it gets "Browse…", which calls the desktop's `pick_file {title}` IPC (the dialog plugin's native file picker, run off the main thread; `ipc.ts › pickFile`) and applies the chosen file through `settings.set`; a path with an empty default shows "Detected automatically" while empty. Checks before `settings.set`, each with its own catalog message: at most 4,096 UTF-8 bytes and no control characters (strings that are not paths). Paths are checked only by the engine's `settings::check_path` (C9 F1), the one validator for the dialog, agents and the CLI: at most 4,096 bytes, no control characters, no surrounding quotes, no spaces at either end; refused, never trimmed. The dialog shows the engine's reason without the `invalid params for settings.set: : ` prefix (`ipc.ts › userMessage`). A stored path that fails the check counts as unset. The engine validates everything else. String rows stack the field under the label at full width. `settings.open {section?, query?}` opens on a section or with a search (for agents and live checks). - **Search** matches label, description, key and section name (every word, ignoring case); while it has text every match shows, grouped by section, and sections without matches are dimmed. - **Reset to default** per setting, enabled while the value differs from the default. - **Errors** show under the control (`role="alert"`, `aria-invalid`) and keep the typed text until the value changes. @@ -345,6 +345,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat - `Child` dereferences to `std::process::Child`. `Child::kill` replaces the standard `kill` and takes the whole group; `kill_and_wait` also reaps; `Drop` kills the group and reaps. - A child of `spawn` runs for a moment before it joins its job (Windows) or before its watchdog exists (Unix); a grandchild started in those microseconds can escape. Short-lived tools (git, `php -l`, the `php -v` probe) keep this path: git starts hooks long after it is in its job. - `lutra_proc::spawn_suspended` (F3) closes the window on Windows for long-lived children (Phpactor): `CREATE_SUSPENDED | CREATE_NO_WINDOW` (replacing the command's creation flags), assign to the job, then resume the primary thread. std keeps the thread handle to itself, so the thread is found with a Tool Help snapshot (`CreateToolhelp32Snapshot` + `Thread32First/Next`, `OpenThread` + `ResumeThread`). The snapshot covers every thread on the machine. Measured 2026-10-27, debug, 30× `cmd /c exit`, other builds running: std 35–38 ms, std + `CREATE_NO_WINDOW` 54–55 ms, `spawn` 55–65 ms (unchanged from H1), `spawn_suspended` 130–187 ms. That is why git does not use it. On Unix it is `spawn`. +- `lutra_proc::spawn_detached(program, args) -> io::Result` (C9 F1) starts a program that outlives the caller, as the `lutra` CLI starts the desktop: on Windows `CreateProcessW` with `bInheritHandles = FALSE`, null standard handles and `DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP`. The standard library always passes `TRUE`, so the desktop kept every inheritable handle of `lutra`, such as the pipe a script read its output from, and `lutra a.php | cat` returned only when the desktop exited. On Unix a new process group with null stdio. Tests: helper roles `detached-plain` (the pipe stays open) and `detached-proc` (end of file at once). - `lutra_proc::adopt(RawHandle) -> io::Result` (Windows, F3) puts a process someone else started into a new kill-on-close job; dropping the `Guard` or `Guard::kill` ends the process and everything it started since. - Tests: `crates/proc/tests/process_tree.rs` starts `lutra-proc-helper`, which starts a sleeping grandchild holding the test's pipe. A hard kill of the helper (`TerminateProcess` / `SIGKILL`, with and without the helper itself in a group), `Child::kill` and drop each end the tree; the pipe reaches end of file. Without `KILL_ON_JOB_CLOSE` the hard-kill tests fail. The same runs for `spawn_suspended`, and `adopt` is tested with a helper that starts its grandchild only after a line on stdin, i.e. after the adoption (9 tests). - The integrated terminal (portable-pty): on Windows the ConPTY shell is adopted into a job right after it starts (`portable_pty::Child::as_raw_handle`, F3). `Session::kill` and drop kill the job, so processes the shell started (a dev server, `start /b`) end with the terminal tab or with Lutra, even after the shell itself exited. A process the shell starts in the microseconds before the adoption is not in the job; the ConPTY host still ends its console clients when its pipes break. On Unix portable-pty makes the shell a session leader, and closing the PTY master on Lutra's exit hangs it up. @@ -771,6 +772,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat | Date | Change | Summary | |---|---|---| +| 2026-11-02 | minor | C9 F1: `Kind::Path` and `check_path` (one validator for `settings.set` and the dialog, `path` in `settings.list`), `lutra_proc::spawn_detached` for the CLI's desktop start | | 2026-10-31 | minor | C7 B1: app identifier `com.tyrveil.lutra` with the one-time copy from `dev.lutra.desktop`, NSIS and DMG installers, `cargo xtask bundle` | | 2026-10-31 | minor | C7 A3: `git.mergeMessage` and the merge message prefill, `git.ignore` and the Changes context menu, gutter markers kept on their line, per-module `COMMAND_IDS` for the command listing test | | 2026-10-30 | minor | M4.7: blame (`git.blame` with `--contents` from the buffer, the annotation gutter by age, hover with the commit message, `vcs.toggleBlame`, `vcs.showCommit`) | diff --git a/docs/install.md b/docs/install.md index 8c4f0c6..69b1ccd 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,6 +1,6 @@ # Installing Lutra -> **Status:** draft, alpha installers · **Last updated:** 2026-11-01 +> **Status:** draft, alpha installers · **Last updated:** 2026-11-02 Lutra's alpha comes as an installer for Windows (a setup `.exe`) and macOS (a `.dmg`). Both are **not signed yet**, so Windows and macOS warn before the first start; the steps below get past that once. Linux has no installer yet: build it from source ([`development.md`](development.md)). @@ -61,7 +61,7 @@ Since 0.1.0-alpha the finish page starts Lutra through Explorer (`explorer.exe " ### Uninstalling on Windows -Settings → Apps → Installed apps → **Lutra** → … → **Uninstall**, or run `uninstall.exe` in the install folder. The uninstaller removes the app and `lutra.exe`, its shortcuts, its Installed-apps entry, the **Open with** entries and the PATH entry the setup added. Your settings, recovery journal and Phpactor stay unless you tick **Delete the application data**. +Settings → Apps → Installed apps → **Lutra** → … → **Uninstall**, or run `uninstall.exe` in the install folder. The uninstaller removes the app and `lutra.exe`, its shortcuts, its Installed-apps entry, the **Open with** entries and the PATH entry the setup added. Your settings, recovery journal and Phpactor stay unless you tick **Delete the application data**. The taskbar's Jump List (recent and pinned files) stays too: every Lutra install shares one app id (`com.tyrveil.lutra`), so clearing it, as Tauri's template does, would also empty the list of another Lutra still installed. ## macOS @@ -116,4 +116,5 @@ An instance started with `--control PORT` or `--data-dir DIR` keeps its files in |---|---|---| | 2026-10-31 | major | B1: initial version, NSIS setup and DMG, unsigned | | 2026-10-31 | minor | B2: finish-page hang found and fixed, Open with for PHP files, version 0.1.0-alpha | +| 2026-11-02 | minor | C9 F1: the uninstaller keeps the Jump List | | 2026-11-01 | minor | C2: `lutra` CLI in both installers, optional per-user PATH entry on Windows, macOS link step, `xtask bundle` prints the version; the web view's folder holds no user state | diff --git a/docs/localization-parity.md b/docs/localization-parity.md index f3982bd..7113975 100644 --- a/docs/localization-parity.md +++ b/docs/localization-parity.md @@ -1,6 +1,6 @@ # Localization checklist -> **Status:** English catalog covers 100% of UI strings (M1.11); German not started · **Last updated:** 2026-10-16 +> **Status:** English catalog covers 100% of UI strings (M1.11); German not started · **Last updated:** 2026-11-02 | Language | Code | Status | Translated | |---|---|---|---:| @@ -18,6 +18,7 @@ All interface strings go through the message catalog: `t(key, params?)` from `ui - [ ] Engine messages: `EngineError.message` and other texts the engine sends are English only; they need message keys and params (G14) - [x] Setting labels, descriptions, section names and enum value names from `settings.list` in the catalog (M1.9b) - [ ] Language switch through `ui.language`; the catalog becomes reactive (G14) +- [x] One date format everywhere until G14 (C9 F1): `YYYY-MM-DD` and `YYYY-MM-DD HH:mm` in local time (`i18n › formatDate`, `formatDateTime`) in the Log, stash list, blame and the recovery dialog, instead of the system locale's format next to English text - [ ] Plural forms and number/date formatting per locale (G14) - [ ] German catalog (G14) - [ ] Native menus and dialogs of the desktop shell (folder picker title, app menu) (G14) @@ -26,6 +27,7 @@ All interface strings go through the message catalog: `t(key, params?)` from `ui | Date | Change | Summary | |---|---|---| +| 2026-11-02 | minor | C9 F1: one documented date format; path refusals from the engine (two catalog keys removed) | | 2026-10-16 | minor | M1.9b: settings keys, key count 80 | | 2026-10-16 | minor | M1.12: notification keys, key count 46 | | 2026-10-15 | minor | M1.11: English catalog, lint rule, checklist; engine-message gap | diff --git a/ui/src/components/editor/blame.ts b/ui/src/components/editor/blame.ts index 6d3c52d..b1d7e31 100644 --- a/ui/src/components/editor/blame.ts +++ b/ui/src/components/editor/blame.ts @@ -27,7 +27,7 @@ import { RangeSet, RangeSetBuilder, StateEffect, StateField, type EditorState, type Extension, type Text } from "@codemirror/state"; import { EditorView, GutterMarker, ViewPlugin, gutter, showTooltip, type PluginValue, type Tooltip, type ViewUpdate } from "@codemirror/view"; import { runWaiting, type JsonValue } from "../../ipc"; -import { t } from "../../i18n"; +import { formatDate, formatDateTime, t } from "../../i18n"; import type { AssistBuffer } from "./assist"; /** Delay between the last edit and the query. */ @@ -154,18 +154,13 @@ export function ageLevel(iso: string, now: number): number { } /** - * A short local date, `YYYY-MM-DD`. + * A short local date, `YYYY-MM-DD` ({@link formatDate}). * * @param iso - ISO 8601 date. * @returns the date, or the input when it cannot be read. */ export function shortDate(iso: string): string { - const date = new Date(iso); - if (Number.isNaN(date.getTime())) { - return iso; - } - const pad = (n: number): string => String(n).padStart(2, "0"); - return `${String(date.getFullYear())}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`; + return formatDate(iso); } /** The text and look of one annotated line. */ @@ -343,9 +338,7 @@ function hoverCard(line: BlameLine): { dom: HTMLElement; message: HTMLElement } head.textContent = t("editor.blame.notCommitted"); message.textContent = t("editor.blame.notCommittedHint"); } else { - const date = new Date(line.date); - const when = Number.isNaN(date.getTime()) ? line.date : date.toLocaleString(); - head.textContent = t("editor.blame.byLine", { hash: line.hash.slice(0, 8), author: line.author, date: when }); + head.textContent = t("editor.blame.byLine", { hash: line.hash.slice(0, 8), author: line.author, date: formatDateTime(line.date) }); message.textContent = messages.get(line.hash) ?? line.summary; const hint = document.createElement("div"); hint.className = "lt-blame-tooltip__hint"; diff --git a/ui/src/components/recovery/RecoveryDialog.vue b/ui/src/components/recovery/RecoveryDialog.vue index 44fe9a7..7ad300f 100644 --- a/ui/src/components/recovery/RecoveryDialog.vue +++ b/ui/src/components/recovery/RecoveryDialog.vue @@ -8,7 +8,7 @@ * failures, they are listed until the dialog is closed. */ import { nextTick, onMounted, onUnmounted, ref, watch } from "vue"; -import { t } from "../../i18n"; +import { formatDateTime, t } from "../../i18n"; import { useRecoveryStore } from "./recovery"; const recovery = useRecoveryStore(); @@ -55,7 +55,7 @@ watch( * @param savedAt - ms since the Unix epoch. */ function formatTime(savedAt: number): string { - return new Date(savedAt).toLocaleString(); + return formatDateTime(savedAt); } /** diff --git a/ui/src/components/vcs/log/LogToolWindow.vue b/ui/src/components/vcs/log/LogToolWindow.vue index 265fbe2..f87ccc0 100644 --- a/ui/src/components/vcs/log/LogToolWindow.vue +++ b/ui/src/components/vcs/log/LogToolWindow.vue @@ -17,7 +17,7 @@ */ import { RefreshCw, X } from "@lucide/vue"; import { computed, nextTick, onBeforeUnmount, ref } from "vue"; -import { t } from "../../../i18n"; +import { formatDateTime, t } from "../../../i18n"; import { useProjectStore } from "../../../stores/project"; import { SHORT_HASH } from "../changes/changes"; import { refBadges, useLogStore, type CommitFile, type CommitFileStatus } from "./log"; @@ -138,16 +138,12 @@ function rowAt(index: number): GraphRow | null { } /** - * A date for the list: the local date and time, short. + * A date for the list: the local date and time, `YYYY-MM-DD HH:mm`. * * @param iso - ISO 8601 date. */ function shortDate(iso: string): string { - const date = new Date(iso); - if (Number.isNaN(date.getTime())) { - return iso; - } - return date.toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }); + return formatDateTime(iso); } /** Applies the typed filters now. */ diff --git a/ui/src/components/vcs/stash/StashDialog.vue b/ui/src/components/vcs/stash/StashDialog.vue index 78aa910..9fd0d28 100644 --- a/ui/src/components/vcs/stash/StashDialog.vue +++ b/ui/src/components/vcs/stash/StashDialog.vue @@ -22,7 +22,7 @@ import { Archive } from "@lucide/vue"; import { nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue"; import { useModalsStore } from "../../../commands/modals"; import { useCommandsStore } from "../../../commands/store"; -import { t } from "../../../i18n"; +import { formatDateTime, t } from "../../../i18n"; import { useStashStore, type StashEntry } from "./stash"; const stash = useStashStore(); @@ -57,16 +57,12 @@ function refName(entry: StashEntry): string { } /** - * A date for the list: the local date and time, short. + * A date for the list: the local date and time, `YYYY-MM-DD HH:mm`. * * @param iso - ISO 8601 date. */ function shortDate(iso: string): string { - const date = new Date(iso); - if (Number.isNaN(date.getTime())) { - return iso; - } - return date.toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }); + return formatDateTime(iso); } /** diff --git a/ui/src/i18n/index.ts b/ui/src/i18n/index.ts index 709e257..b265942 100644 --- a/ui/src/i18n/index.ts +++ b/ui/src/i18n/index.ts @@ -55,3 +55,55 @@ export function t(key: string, params?: MessageParams): string { return value === undefined ? placeholder : String(value); }); } + +/** + * Two digits, with a leading zero. + * + * @param n - a number from 0 to 99. + */ +function pad(n: number): string { + return String(n).padStart(2, "0"); +} + +/** + * Reads a date: an ISO 8601 text or milliseconds since the Unix epoch. + * + * @param value - the date. + * @returns the date, or null when it cannot be read. + */ +function toDate(value: string | number): Date | null { + const date = new Date(value); + return Number.isNaN(date.getTime()) ? null : date; +} + +/** + * A date as Lutra shows it everywhere: `YYYY-MM-DD` in local time. One + * fixed format instead of the system locale's, so dates read the same in + * every part of the English interface (`01.11.2026` next to English text + * looked broken). G14 may switch to the interface language's format. + * + * @param value - an ISO 8601 text or milliseconds since the Unix epoch. + * @returns the date, or the input as text when it cannot be read. + */ +export function formatDate(value: string | number): string { + const date = toDate(value); + if (!date) { + return String(value); + } + return `${String(date.getFullYear())}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`; +} + +/** + * A date and time as Lutra shows it everywhere: `YYYY-MM-DD HH:mm` in + * local time, 24-hour clock (see {@link formatDate}). + * + * @param value - an ISO 8601 text or milliseconds since the Unix epoch. + * @returns the date and time, or the input as text when it cannot be read. + */ +export function formatDateTime(value: string | number): string { + const date = toDate(value); + if (!date) { + return String(value); + } + return `${formatDate(value)} ${pad(date.getHours())}:${pad(date.getMinutes())}`; +} diff --git a/ui/src/stores/find.ts b/ui/src/stores/find.ts index d35c296..633aedf 100644 --- a/ui/src/stores/find.ts +++ b/ui/src/stores/find.ts @@ -12,7 +12,8 @@ * - **One search at a time:** a new search cancels the running one * (`search.cancel`); the engine does not do that by itself. * - **Errors:** a refused search (`invalid_params` for a bad regex or glob) - * shows its message in the window, not as a toast. + * shows its reason (`userMessage`, without the engine's command prefix) in + * the window, not as a toast. * - **Opening:** `open` shows the panel, takes the query from the params * (an agent's `find.open {query}` searches at once) or from the editor * (selection or word at the cursor) and asks the window to focus its field. @@ -23,7 +24,7 @@ import type { EditorState } from "@codemirror/state"; import { defineStore } from "pinia"; import { computed, ref, shallowRef } from "vue"; import { t } from "../i18n"; -import { onEngineEvent, run, type EngineEventPayload, type JsonValue } from "../ipc"; +import { onEngineEvent, run, userMessage, type EngineEventPayload, type JsonValue } from "../ipc"; import { useEditorStore } from "./editor"; /** One match as the window shows it. */ @@ -351,7 +352,7 @@ export const useFindStore = defineStore("find", () => { early = []; if (!result.ok) { running.value = false; - error.value = result.error.message; + error.value = userMessage(result.error); return; } if (id === null) { diff --git a/ui/tests/find/FindToolWindow.test.ts b/ui/tests/find/FindToolWindow.test.ts index 3c17fc3..b8157dd 100644 --- a/ui/tests/find/FindToolWindow.test.ts +++ b/ui/tests/find/FindToolWindow.test.ts @@ -397,9 +397,9 @@ describe("Find tool window", () => { it("shows a refused regex as an alert", async () => { const { wrapper } = await mountFind(); - findError = { code: "invalid_params", message: "bad regex" }; + findError = { code: "invalid_params", message: "invalid params for search.find: invalid pattern: unclosed group" }; await searchFor(wrapper, "("); - expect(wrapper.get("[data-test=find-error]").text()).toBe("bad regex"); + expect(wrapper.get("[data-test=find-error]").text()).toBe("invalid pattern: unclosed group"); expect(wrapper.get("[data-test=find-query]").attributes("aria-invalid")).toBe("true"); expect(wrapper.get("[data-test=find-status]").text()).toBe(""); }); diff --git a/ui/tests/i18n/catalog.test.ts b/ui/tests/i18n/catalog.test.ts index 617e6a2..c5134da 100644 --- a/ui/tests/i18n/catalog.test.ts +++ b/ui/tests/i18n/catalog.test.ts @@ -1,13 +1,13 @@ /** * Tests of the message catalog: the `t` helper (lookup, interpolation, - * missing keys) and a scan of the frontend source that every literal key + * missing keys), the one date format, and a scan of the frontend source that every literal key * passed to `t` exists in `en.json`. */ import { readdirSync, readFileSync } from "node:fs"; import { join } from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import en from "../../src/i18n/en.json"; -import { hasMessage, t } from "../../src/i18n"; +import { formatDate, formatDateTime, hasMessage, t } from "../../src/i18n"; /** Root of the frontend source tree. */ const SRC = join(import.meta.dirname, "..", "..", "src"); @@ -205,3 +205,15 @@ describe("en.json", () => { expect(Object.keys(en).filter((key) => !used.has(key))).toEqual([]); }); }); + +describe("dates", () => { + it("shows every date as YYYY-MM-DD and times as HH:mm in local time, whatever the system locale", () => { + const local = new Date(2026, 10, 1, 9, 5, 30); + expect(formatDate(local.getTime())).toBe("2026-11-01"); + expect(formatDateTime(local.getTime())).toBe("2026-11-01 09:05"); + expect(formatDateTime("2026-12-24T18:30:00")).toBe("2026-12-24 18:30"); + expect(formatDate("2026-03-07T23:59:00")).toBe("2026-03-07"); + expect(formatDateTime("not a date")).toBe("not a date"); + expect(formatDate("")).toBe(""); + }); +}); diff --git a/ui/tests/menu/AppMenu.test.ts b/ui/tests/menu/AppMenu.test.ts index 9fc76fa..e898e19 100644 --- a/ui/tests/menu/AppMenu.test.ts +++ b/ui/tests/menu/AppMenu.test.ts @@ -29,7 +29,7 @@ import SettingsDialog from "../../src/components/settings/SettingsDialog.vue"; const ENGINE_COMMANDS = [ { id: "app.about", label: "About Lutra", menuPath: "Help/About Lutra", defaultShortcut: null, params: "", enabled: true, ui: false }, { id: "app.quit", label: "Quit", menuPath: "File/Quit", defaultShortcut: "Mod+Q", params: "", enabled: true, ui: false }, - { id: "buffer.close", label: "Close Buffer", menuPath: "File/Close Tab", defaultShortcut: "Mod+W", params: "", enabled: false, ui: false }, + { id: "buffer.close", label: "Close Tab", menuPath: "File/Close Tab", defaultShortcut: "Mod+W", params: "", enabled: false, ui: false }, { id: "buffer.edit", label: "Edit Buffer", menuPath: null, defaultShortcut: null, params: "", enabled: true, ui: false }, { id: "file.save", label: "Save", menuPath: "File/Save", defaultShortcut: "Mod+S", params: "", enabled: true, ui: false }, { id: "file.saveAll", label: "Save All", menuPath: "File/Save All", defaultShortcut: "Mod+Alt+S", params: "", enabled: true, ui: false }, diff --git a/ui/tests/recovery/RecoveryDialog.test.ts b/ui/tests/recovery/RecoveryDialog.test.ts index 746c433..184fa6b 100644 --- a/ui/tests/recovery/RecoveryDialog.test.ts +++ b/ui/tests/recovery/RecoveryDialog.test.ts @@ -112,9 +112,7 @@ describe("RecoveryDialog", () => { "src/b.php", "c.php", ]); - expect(rows[0]?.text()).toContain( - `Saved ${new Date(ENTRIES[0]?.savedAt ?? 0).toLocaleString()}`, - ); + expect(rows[0]?.text()).toMatch(/Saved \d{4}-\d{2}-\d{2} \d{2}:\d{2}/); expect(rows[0]?.find("[data-test=recovery-changed]").exists()).toBe(false); expect(rows[1]?.get("[data-test=recovery-changed]").text()).toBe( "The file changed on disk since then",