A2: disk-conflict banner, overwrite question and Local History dialog

- Banner inside the editor pane for a dirty tab whose file changed
  (Reload (discard mine) / Keep mine / Compare) or was deleted (Keep as
  unsaved / Close); state in stores/diskConflicts.ts, the old notice is gone.
- Save and save all ask Overwrite / Cancel when the engine refuses with
  disk_changed.
- Diff tabs against the disk text (file.readDisk) and a Local History
  entry (history.read); "Revert to This" in the caption.
- Show Local History dialog (history.show: tree context menu, palette,
  File menu) with Show Diff and an undoable Revert to This.
- History failures warn once until a snapshot works again.
- Docs: docs/local-history.md, G2 in gaps.md, ui-parity, architecture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-08 12:23:14 +01:00
parent dfe2f19ca5
commit d2344bf216
29 changed files with 1999 additions and 52 deletions

View file

@ -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-11-02
> **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); files changed on disk and Local History (C10 A2) · **Last updated:** 2026-11-08
## Overview
@ -117,9 +117,9 @@ Theme tokens are defined in Rust (`lutra_engine::theme`) and rendered as CSS cus
### Events
`lutra_engine::Event`, serialised as `{"kind": "<camelCase>", ...}`: `projectOpened {root, name}`, `projectClosed`, `treeChanged {dir}`, `bufferOpened {id, path}`, `bufferFocused {id}` (M1.13), `bufferChanged {id, version}`, `dirtyChanged {id, dirty}`, `bufferClosed {id}`, `fileChangedOnDisk {path, id, removed}`, `watchFailed {message}`, `recoveryAvailable {entries}` (M1.7, see Recovery journal), `uiCommand {id, params}` (M1.8, see UI commands), `recoveryResolved {paths}` (M1.15, see Recovery journal), `searchResults {searchId, path, matches}` and `searchDone {searchId, files, matches, truncated, cancelled, elapsedMs}` (M2.3, see Search), `terminalOutput {terminalId, data}` and `terminalExited {terminalId, code}` (M3.6, see Terminal). Events say what changed; clients fetch data with `project.children` and `buffer.get`. `file.open` on a file whose buffer is already open returns that buffer and emits `bufferFocused {id}` instead of `bufferOpened` (M1.13): a separate event, so that `bufferOpened` keeps meaning "a new buffer exists" (the host's `engine_ready` replay and other clients rely on that) while every client, including the editor, still learns that the user asked to see that buffer and activates its tab.
`lutra_engine::Event`, serialised as `{"kind": "<camelCase>", ...}`: `projectOpened {root, name}`, `projectClosed`, `treeChanged {dir}`, `bufferOpened {id, path}`, `bufferFocused {id}` (M1.13), `bufferChanged {id, version}`, `dirtyChanged {id, dirty}`, `bufferClosed {id}`, `fileChangedOnDisk {path, id, removed}`, `diskConflictResolved {id}` (C10 A2), `watchFailed {message}`, `recoveryAvailable {entries}` (M1.7, see Recovery journal), `uiCommand {id, params}` (M1.8, see UI commands), `recoveryResolved {paths}` (M1.15, see Recovery journal), `searchResults {searchId, path, matches}` and `searchDone {searchId, files, matches, truncated, cancelled, elapsedMs}` (M2.3, see Search), `terminalOutput {terminalId, data}` and `terminalExited {terminalId, code}` (M3.6, see Terminal). Events say what changed; clients fetch data with `project.children` and `buffer.get`. `file.open` on a file whose buffer is already open returns that buffer and emits `bufferFocused {id}` instead of `bufferOpened` (M1.13): a separate event, so that `bufferOpened` keeps meaning "a new buffer exists" (the host's `engine_ready` replay and other clients rely on that) while every client, including the editor, still learns that the user asked to see that buffer and activates its tab.
Changes on disk reach the engine through `Engine::pump_vfs()`, which hosts call regularly (the desktop's pump thread every 100 ms; tests call it directly). It maps VFS events to `treeChanged` for the parent directories, reloads a clean buffer whose file changed (unless the file already matches, as after our own save) with `bufferChanged`, and reports `fileChangedOnDisk` for a dirty buffer, which keeps its text, or for a removed file. At most 10,000 VFS events are handled per pump.
Changes on disk reach the engine through `Engine::pump_vfs()`, which hosts call regularly (the desktop's pump thread every 100 ms; tests call it directly). It maps VFS events to `treeChanged` for the parent directories, reloads a clean buffer whose file changed (unless the file already matches, as after our own save) with `bufferChanged`, and reports `fileChangedOnDisk` for a dirty buffer, which keeps its text, or for a removed file. C10 A2: every event for a path only means "look again", so a delete followed by a create (git checkout, atomic saves) reloads instead of reporting a removal; a removed file's buffer becomes dirty; a save checks the file's mtime and hash and fails with `disk_changed` over a newer file; Local History snapshots are taken on save, reload, deletion, rename and file-changing git commands. See `docs/local-history.md`. At most 10,000 VFS events are handled per pump.
Watched directories: the VFS watcher is non-recursive, so `project.children` watches each directory it lists. At most 256 directories besides the root are watched natively and 32 when polling (each polled directory is rescanned every 100 ms); beyond that the least recently listed directory is unwatched, and listing it again re-watches it. Expanding a deep `vendor/` therefore costs at most 256 native watches; changes in directories that dropped out are not reported until they are listed again. `node_modules`, ignored and hidden directories are never watched. The parent directory of every open buffer is pinned (M1.13, `workspace::sync_buffer_dirs`, run by `Engine::execute` after every command): it is watched even if the tree never listed it, so reloads and `fileChangedOnDisk` arrive for files opened by path from never-expanded folders. Pinned directories count against the cap but are never evicted while a buffer in them is open (with more pinned directories than the cap, the watched set exceeds it); after the last buffer in a directory closes, it ages out like a listed one. A buffer inside an ignored or hidden directory is still not watched.
@ -133,7 +133,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
### Tabs and editor (M1.6)
- `ui/src/stores/editor.ts` holds the tabs (buffer id, path, dirty, notice), the active tab and the close question. It adds a tab from the `file.open` result (opened from the tree) or, for a `bufferOpened` event it did not cause (control channel, replay after a reload), from `buffer.get`. `bufferClosed`, `dirtyChanged`, `fileChangedOnDisk` and project open/close update it; `bufferFocused` activates the tab and outranks adoptions still fetching, so the most recent open wins. The project tree ends a directory the engine listed only partly (`truncated`) with a note row (`project.tree.truncated`). `ui/src/components/editor/engineEvents.ts` checks event fields before the store sees them.
- `ui/src/stores/editor.ts` holds the tabs (buffer id, path, dirty, notice), the active tab and the close question. It adds a tab from the `file.open` result (opened from the tree) or, for a `bufferOpened` event it did not cause (control channel, replay after a reload), from `buffer.get`. `bufferClosed`, `dirtyChanged` and project open/close update it (files changed on disk: `ui/src/stores/diskConflicts.ts`, C10 A2); `bufferFocused` activates the tab and outranks adoptions still fetching, so the most recent open wins. The project tree ends a directory the engine listed only partly (`truncated`) with a note row (`project.tree.truncated`). `ui/src/components/editor/engineEvents.ts` checks event fields before the store sees them.
- One `BufferSync` per tab (`ui/src/components/editor/bufferSync.ts`) owns the tab's CodeMirror `EditorState`; one `EditorView` shows the active tab's state, so undo history and selection survive tab switches. Every transaction goes through the sync. Local changes are sent with `buffer.edit` against the confirmed version, one call in flight, later keystrokes composed into the next call. On `stale_version`, or a `bufferChanged` with a newer version than ours, the sync fetches `buffer.get`, diffs it against the confirmed text, rebases unsent local changes over that diff (CodeMirror change-set mapping) and applies the remote part to the editor without adding it to undo history. A refused edit (other than stale) is reported and the editor returns to the engine text.
- Line breaks: the engine keeps text as on disk and counts `\r\n` as two UTF-16 units; CodeMirror counts every break as one position. `EngineText` remembers which breaks are `\r\n` and converts positions when building edits; inserted breaks are sent with the buffer's line ending, so a CRLF file stays CRLF in memory. Text without `\r\n` (the common case) needs no table.
- Save, save all and close run from the engine's default shortcuts (`file.save` `Mod+S`, `file.saveAll` `Mod+Alt+S`, `buffer.close` `Mod+W`), loaded with `listCommands` and matched by key code, with the active buffer as context; since M1.8 through the global keymap (see UI commands, palette and keymap). Saving and closing wait until the sync has no pending edits.

View file

@ -1,13 +1,13 @@
# Gaps
> **Status:** M0 closed G1; G2 under way (text buffer, engine buffers, tabs and editor in the app, recovery journal, autosave); G3 M1 part done (project tree, palette, settings dialog with string and path controls, themes) plus the app menu (M3.9); G4 under way (tree-sitter outline and folding library, Lezer highlighting, Structure tool window); G5 under way (search backend, Find tool window, symbol index, go-to popup); G6 under way (LSP client library, PHP detection, Phpactor download, engine wiring and diagnostics, completion and hover, definition, references and rename, Phpactor dies with Lutra, faster indexing, progress and messages, `php -l` on Windows); G7 under way (`lutra` CLI and single instance, MCP server, integrated terminal); G8 under way (Git backend, M4.1; Changes window, M4.2; gutter markers and status colours, M4.4; diff viewer, M4.3; branch widget and popup, M4.5; merge conflicts, M4.8; remotes, M4.10; stash, M4.9; chunk staging, C8 C3); G14 English UI catalog in place · **Last updated:** 2026-11-06
> **Status:** M0 closed G1; G2 under way (text buffer, engine buffers, tabs and editor in the app, recovery journal, autosave, files changed on disk and Local History); G3 M1 part done (project tree, palette, settings dialog with string and path controls, themes) plus the app menu (M3.9); G4 under way (tree-sitter outline and folding library, Lezer highlighting, Structure tool window); G5 under way (search backend, Find tool window, symbol index, go-to popup); G6 under way (LSP client library, PHP detection, Phpactor download, engine wiring and diagnostics, completion and hover, definition, references and rename, Phpactor dies with Lutra, faster indexing, progress and messages, `php -l` on Windows); G7 under way (`lutra` CLI and single instance, MCP server, integrated terminal); G8 under way (Git backend, M4.1; Changes window, M4.2; gutter markers and status colours, M4.4; diff viewer, M4.3; branch widget and popup, M4.5; merge conflicts, M4.8; remotes, M4.10; stash, M4.9; chunk staging, C8 C3); G14 English UI catalog in place · **Last updated:** 2026-11-08
Every known shortfall, ranked. This is the work list: unless the owner gives a task, take the highest open gap. Hours are agent wall-clock hours for one agent, all estimated.
| # | Gap | Milestone | Estimate (one agent) |
|---|---|---|---|
| G1 | ~~Foundation: workspace, quality gate, command registry, guard, control channel~~ closed 2026-10-14 | M0 | done (~2 h measured) |
| G2 | Editor core: ~~engine buffers, save~~ (M1.3), ~~editor UI with tabs, undo, multi-caret~~ (M1.6, CodeMirror basics), ~~recovery journal~~ (M1.7), ~~tab management (preview, pin, split, close others, reopen)~~ (C10 A1), conflict UI for files changed on disk, ~~autosave~~ (M3.10), local history | M1 | ~10 h |
| G2 | Editor core: ~~engine buffers, save~~ (M1.3), ~~editor UI with tabs, undo, multi-caret~~ (M1.6, CodeMirror basics), ~~recovery journal~~ (M1.7), ~~tab management (preview, pin, split, close others, reopen)~~ (C10 A1), ~~conflict UI for files changed on disk~~ (C10 A2), ~~autosave~~ (M3.10), ~~local history~~ (C10 A2, v1) | M1 | ~10 h |
| G3 | Project model: ~~VFS~~ (M1.2: listing, ignore rules, native file watching with polling fallback, safe file IO), ~~project tree wiring~~ (M1.5 UI, M1.3 engine, M1.4 bridge: folder picker, live tree), tree toolbar and options, ~~showing truncated listings~~ (M1.13), ~~error notifications for the folder picker~~ (M1.12), ~~tabs~~ (M1.6), ~~command palette~~ (M1.8: commands only, global keymap, UI commands over the control channel); ~~settings~~ (backend: M1.9a; dialog with search: M1.9b; string and path controls: H4), ~~theme switching~~ (M1.10: light/dark, live, system mode; picker in the dialog, M1.9b; C9 T1: six built-in themes, picker with live preview, theme file import, editor font family and line height), ~~main menu~~ (M3.9: hamburger dropdown from `menuPath`s; native macOS menu bar: A1 adds the system menus (Lutra, Edit, Window; ⌘W and ⌘Q stay Lutra's), mirroring Lutra's own menus natively and display modes open) | M1 | ~24 h |
| G4 | Syntax and structure: tree-sitter PHP, ~~Lezer highlighting~~ (M2.2: PHP with embedded HTML plus HTML, CSS, JS/TS, JSON, YAML, Markdown; `--lt-syntax-*` tokens; `editor.reveal`), ~~file structure~~ (M2.7: Structure tool window, `syntax.outline`), semantic highlighting, folding in the editor | M2 | ~8 h |
| G5 | Search and navigation: find in files, go to file/class/symbol, first index | M2 | ~35 h |
@ -28,7 +28,7 @@ Every known shortfall, ranked. This is the work list: unless the owner gives a t
| G20 | AI features (chat, inline prompts, commit messages); MCP server is G7/M3 | M9 | ~60 h |
| G21 | Feature breadth: the full PhpStorm help inventory has 155 feature units; ~23 have at least partial support (2026-10-18, estimated). The list lives in `plan/phpstorm/00-feature-inventory.md` with public URLs | ongoing | — |
G2 progress: the engine text buffer landed (M1.1, `crates/text`: rope, UTF-16 and char positions, atomic edit batches, line ending policy). M1.3 added engine buffers with versions, the edit protocol, save and save all, and reloading on external changes. M1.6 added tabs and a CodeMirror 6 editor synced to engine buffers (version-based edits with resync, CRLF-aware offsets), save and save all by engine shortcuts, the Save / Don't Save / Cancel question and a notice for files changed on disk. M1.7 added the crash-recovery journal (debounced atomic entries per dirty buffer, `recovery.*` commands, restore dialog; not yet checked in the running app). M1.13 made re-opening an open file switch to its tab and keeps the folders of open files watched. M3.10 added autosave (window blur, tab switch, after 15 s idle; settings) and `flushDirty()`, the one "save all dirty and wait" entry point for later deployment and run features; autosave skips files in conflict with the disk. C10 A1 added tab management: preview tabs (and their setting), pinning, close others/all/left/right/unmodified with one question for every unsaved file, reopen closed tab with selection and scroll, a second editor group (split right/down, move, focus, unsplit) sharing one engine buffer and undo history, a tab context menu, `tabs.*` commands and the tab layout per project in Lutra's own state file. Left from tab management: drag to reorder or between groups, more than two groups, a tab limit, a recent-files switcher. Still open: a conflict UI (compare and merge with the disk version), local history, editor settings (soft wrap); estimate lowered to ~10 h.
G2 progress: the engine text buffer landed (M1.1, `crates/text`: rope, UTF-16 and char positions, atomic edit batches, line ending policy). M1.3 added engine buffers with versions, the edit protocol, save and save all, and reloading on external changes. M1.6 added tabs and a CodeMirror 6 editor synced to engine buffers (version-based edits with resync, CRLF-aware offsets), save and save all by engine shortcuts, the Save / Don't Save / Cancel question and a notice for files changed on disk. M1.7 added the crash-recovery journal (debounced atomic entries per dirty buffer, `recovery.*` commands, restore dialog; not yet checked in the running app). M1.13 made re-opening an open file switch to its tab and keeps the folders of open files watched. M3.10 added autosave (window blur, tab switch, after 15 s idle; settings) and `flushDirty()`, the one "save all dirty and wait" entry point for later deployment and run features; autosave skips files in conflict with the disk. C10 A1 added tab management: preview tabs (and their setting), pinning, close others/all/left/right/unmodified with one question for every unsaved file, reopen closed tab with selection and scroll, a second editor group (split right/down, move, focus, unsplit) sharing one engine buffer and undo history, a tab context menu, `tabs.*` commands and the tab layout per project in Lutra's own state file. Left from tab management: drag to reorder or between groups, more than two groups, a tab limit, a recent-files switcher. C10 A2 added the conflict UI and Local History v1 (`docs/local-history.md`): a banner in each editor pane for a dirty file changed (Reload (discard mine) / Keep mine / Compare with the disk text in the diff viewer) or deleted on disk (Keep as unsaved / Close); a delete followed by a create (git checkout) reloads instead of losing the buffer; a save never overwrites a newer file silently (mtime + hash check in the engine, `disk_changed`, Overwrite / Cancel); Local History in the data dir (content-addressed, 14 days / 200 MB per project, pruned on open) with snapshots on save, before reloads, on deletion, before rename and file-changing git operations; Show Local History (tree and tab menus, palette, File menu) with Show Diff and an undoable Revert to This. Still open: a merge view against the disk version, Local History labels, folder and project history, editor settings (soft wrap); estimate lowered to ~10 h.
G4 progress: M2.1 added the structural half in `crates/syntax`: tree-sitter PHP parse and incremental reparse, outline (namespaces, class-likes, functions, members, promoted properties, enum cases; anonymous classes marked) and folding ranges, an 8 MiB parse cap, proptests and snapshots. M2.2 made highlighting visible. M2.7 added the Structure tool window: each open PHP buffer keeps a tree-sitter tree, reparsed incrementally on a worker thread off the engine lock (200 ms debounce), `syntax.outline` and `outlineChanged`, and the outline as a tree in the left tool window with jumps through `editor.reveal`. Open in G4: semantic highlighting, folding in the editor, Structure speed search, sorting and filters. Finding: a full parse of 1 MB takes 364–553 ms on the dev machine (target 50 ms; reparse 7–11 ms), so parsing must stay off the engine lock and the index must parse in parallel.
@ -55,6 +55,7 @@ G6 progress: M3.2 landed the LSP client library in `crates/lsp`: JSON-RPC framin
| Date | Change | Summary |
|---|---|---|
| 2026-11-08 | minor | G2 shrunk: conflict UI for files changed on disk and Local History v1 (C10 A2) |
| 2026-11-08 | minor | G2 shrunk: tab management (C10 A1) |
| 2026-11-06 | patch | G17: deployment v2 (C9 D2): remote browser, compare, sync |
| 2026-11-06 | patch | G17: deployment v1 (C9 D1); remote browser, compare and sync left for D2 |

97
docs/local-history.md Normal file
View file

@ -0,0 +1,97 @@
# Files changed on disk and Local History
> **Status:** v1 (C10 A2, owner decision D29) · **Last updated:** 2026-11-08
Lutra never loses a text because another program, a git operation or Lutra itself changed a file. Two parts work together:
- **Files changed on disk:** what an open editor does when its file changes or disappears outside Lutra, and how a save avoids overwriting a newer file.
- **Local History:** copies of file texts that Lutra keeps by itself, per project, so you can compare with and go back to an earlier text, also for files git does not track.
Behaviour comes from Lutra's own design and the public documentation of the feature in other IDEs; wording, icons and shortcuts are Lutra's own (there is no default shortcut).
## Files changed on disk
Lutra watches the folders of every open file (`docs/architecture.md` › VFS). Every change to a file only means "look again": what counts is the file on disk when Lutra looks.
| Situation | What Lutra does |
|---|---|
| The file changed, the tab has no unsaved changes | Reloads it silently. The editor moves onto the new text with the smallest change, so the caret and the scroll position stay where the text around them did not change. |
| The file changed, the tab has unsaved changes | Keeps your text and shows a banner in the editor: **Reload (discard mine)**, **Keep mine**, **Compare**. |
| The file was deleted or renamed away | Keeps the text, marks the tab as unsaved and shows a banner: **Keep as unsaved**, **Close**. Closing the tab later asks as for any unsaved file; saving writes the file again. |
| The file is deleted and created again (a git checkout, an editor that saves by replacing the file) | Treated as a change, not as a loss: the tab reloads (or shows the "changed" banner if it has unsaved changes). A tab that only became unsaved because its file was gone for a moment reloads like a clean one. |
| The file comes back with exactly your text | The banner goes away and the tab is clean again. |
- **Reload (discard mine)** replaces your text with the file's (`file.reload`). Your text goes into the Local History first.
- **Keep mine** hides the banner. The next save asks once more before it overwrites the newer file.
- **Compare** opens a diff tab: the file on disk on the left, your text on the right (`file.readDisk`). You can edit the right side; it is the same buffer as the tab.
- **Close** closes the tab without saving; the text is in the Local History.
### Saving never overwrites a newer file silently
Before every save the engine compares the file's modification time and size with what it recorded when it last read or wrote the file. When they differ it reads the file and compares its hash. A different text means another program changed it:
- `file.save` fails with `disk_changed`, and the editor asks "… was changed by another program since you opened it. Overwrite it with your text?" (**Overwrite** / **Cancel**, Cancel has the focus). Overwrite repeats the save with `overwrite: true`.
- `file.saveAll` saves the others and lists such files under `diskChanged`; the editor asks for each.
- Autosave (`file.saveAll {skipConflicts: true}`) never asks and never overwrites: it leaves these files unsaved.
- A file that was only touched (same text) saves without asking. A file that is gone is written again.
## Local History
### What is kept, and when
| Reason in the list | When |
|---|---|
| Saved | Every save (also save all and autosave) keeps the saved text. |
| Before first save | The first save of a file in a session keeps the text it overwrites, unless the history already has it. |
| Changed by another program | When Lutra sees another program's text for an open file. |
| Before reload from disk | The tab's text before a reload replaces it (silent reload or "Reload (discard mine)"). |
| Deleted on disk | The tab's text when its file disappears. |
| Before refactoring | Every file a rename (`lsp.rename`) changes, before it changes. |
| Before git operation | Every open file before checkout, new branch with checkout, merge, abort merge, stash, apply stash, pull and revert chunk. |
| Before revert | The tab's text before "Revert to This" replaces it. |
A text equal to the file's newest entry is not added again, so repeated saves of the same text cost nothing. Texts over 16 MiB are not kept.
Files that are not open in Lutra are not watched for the history. git protects their local changes itself: checkout, merge and pull refuse to overwrite them, and stash keeps them.
### Using it
- **Show Local History**: in the project tree's context menu (Show Local History), the palette and File › Show Local History (`history.show {path?}`; without a path, the active tab's file). The dialog lists the file's entries newest first with date, time, reason and size.
- **Show Diff** (or Enter, or a double click) opens a diff tab: the entry on the left, the current text on the right.
- **Revert to This** (in the dialog and in the diff tab's caption) puts the entry's text into the editor as an ordinary unsaved change: Undo brings your text back, and nothing is written until you save. A closed file is opened first.
### Storage and limits (D29)
- In Lutra's data directory, per project: `<data dir>/history/<project id>/` (the project id is a hash of the project folder). Never inside the project; if the data directory lies inside the project, the Local History is off and Lutra says so.
- Content-addressed: each text is stored once as `blobs/<first two hex digits>/<SHA-256>`, however many entries refer to it. `index.jsonl` lists the entries.
- Kept for **14 days**, at most **200 MB per project**: when the project opens, older entries are dropped, then the oldest ones while the texts take more than 200 MB, and texts no entry refers to are deleted. A new entry that crosses 200 MB drops the oldest ones at once.
- A damaged index line is skipped; a text whose hash does not match is reported as damaged instead of shown. Failing to write the history never stops a save: Lutra shows one warning.
## Commands
| Command | What it does |
|---|---|
| `file.save {id, overwrite?}` | Saves; `disk_changed` when the file is newer, unless `overwrite`. |
| `file.saveAll {skipConflicts?}` | Saves every unsaved buffer; `diskChanged` lists the ones it left alone. |
| `file.reload {id}` | Replaces the buffer with the file ("Reload (discard mine)"). |
| `file.readDisk {path}` | The file's text on disk, answered like `git.show`. |
| `buffer.get {id}` | Includes `diskConflict`: `null`, `"changed"` or `"removed"`. |
| `history.list {path}` | The file's entries, newest first: `{id, time, reason, size}`. |
| `history.read {path, id}` | One entry's text, answered like `git.show`. |
| `history.revert {path, id}` | Puts an entry's text into the buffer (an undoable `buffer.edit`). |
| `history.show {path?}` | UI command: the dialog. |
Events: `fileChangedOnDisk {path, id, removed}` sets the banner, `diskConflictResolved {id}` removes it.
## Not yet
- Labels (put a name on the current state), history of a folder or of the whole project, recently deleted files.
- History for files changed by tools while they are not open in Lutra.
- A merge view for a changed file (Compare shows both sides; you merge by editing the right side).
- Settings for the 14 days and 200 MB.
## Revision history
| Date | Change | Summary |
|---|---|---|
| 2026-11-08 | major | First version (C10 A2) |

View file

@ -1,6 +1,6 @@
# UI parity checklist
> **Status:** main window layout (M1.5), project tree running against the engine (M1.4), editor tabs with a CodeMirror editor (M1.6), light and dark themes (M1.10), restore dialog for unsaved changes (M1.7), notification toasts (M1.12), command palette and global keymap (M1.8), settings dialog with search (M1.9b), syntax highlighting and `editor.reveal` (M2.2), Find tool window in the bottom panel (M2.4), go-to popup (M2.6), left stripe and Structure tool window (M2.7), app menu (M3.9), Terminal tool window and bottom panel tabs (M3.6), Problems tool window and editor diagnostics (M3.3), completion, quick documentation and parameter info (M3.4), string and path settings with completion and tooltip settings (H4), banner-aligned themes with diagnostic and VCS colours (H5), Changes tool window (M4.2), Git change markers and status colours (M4.4), diff viewer and the project tree's context menu (M4.3), branch widget and popup (M4.5), fetch/pull/push progress, the clone and remotes dialogs (M4.10), four more themes, theme import and editor font settings (C9 T1) · **Last updated:** 2026-11-02
> **Status:** main window layout (M1.5), project tree running against the engine (M1.4), editor tabs with a CodeMirror editor (M1.6), light and dark themes (M1.10), restore dialog for unsaved changes (M1.7), notification toasts (M1.12), command palette and global keymap (M1.8), settings dialog with search (M1.9b), syntax highlighting and `editor.reveal` (M2.2), Find tool window in the bottom panel (M2.4), go-to popup (M2.6), left stripe and Structure tool window (M2.7), app menu (M3.9), Terminal tool window and bottom panel tabs (M3.6), Problems tool window and editor diagnostics (M3.3), completion, quick documentation and parameter info (M3.4), string and path settings with completion and tooltip settings (H4), banner-aligned themes with diagnostic and VCS colours (H5), Changes tool window (M4.2), Git change markers and status colours (M4.4), diff viewer and the project tree's context menu (M4.3), branch widget and popup (M4.5), fetch/pull/push progress, the clone and remotes dialogs (M4.10), four more themes, theme import and editor font settings (C9 T1), files changed on disk and Local History (C10 A2) · **Last updated:** 2026-11-08
- [ ] Main window: tool window stripes, editor area, status bar, navigation bar
- M2.7 (2026-10-17): a left stripe with one tab per left tool window (Project, Structure); the shown one is marked, clicking it again hides the window. Still missing: right docking, several bottom tool windows, drag to rearrange, navigation bar, layout persistence.
@ -15,6 +15,8 @@
- C10 A1 (2026-11-08): **preview tabs**: a single click in the project tree, a Find result or a Go-to choice opens a preview tab (italic title) that the next preview in its group replaces; editing it, opening it for good (double click in the tree), a double click on the tab or "Keep Tab Open" makes it permanent; setting `editor.tabs.preview` turns previews off. **Pinning** (Lucide `pin` icon): pinned tabs sit left and survive every bulk close. **Close actions**: close, close other tabs, close all, close to the left / right, close unmodified; the unsaved files of one action are asked about once with a list (Save All / Don't Save / Cancel). **Reopen Closed Tab**: a stack of the last 30 closed tabs per window, reopened at their place with selection and scroll position. **Split**: Split Right / Split Down add a second editor group (at most two) showing the active tab; Move Tab to Other Group, Focus Other Group, Unsplit; the same file in both groups is one engine buffer with one text, selection and undo history; the focused group is marked. A **tab context menu** (right click) runs all of these. Commands `tabs.*` in the registry (palette, a new Window menu group, agents); no default shortcuts. The layout of each project (groups, tabs, pins, previews, active tabs) is stored in Lutra's own state file (`layout.get` / `layout.set`, `<data_dir>/layout/`) and restored when the project opens. Vitest (model and area tests); live check over `--control` on Windows 11. Missing: reorder by drag, dragging tabs between groups, more than two groups, a tab limit, a recent-files switcher, duplicate-name disambiguation, diff tabs in the second group, per-group scroll for the same file (both groups share one selection).
- [ ] Editor syntax highlighting (Lutra's own colours, no copied scheme)
- M2.2 (2026-10-16): the language is picked from the file extension when a tab opens: PHP (with the HTML, CSS and JavaScript around `<?php` blocks), HTML, CSS, JS/TS, JSON, YAML, Markdown; other files stay plain. Eleven syntax tokens (`--lt-syntax-keyword/string/number/comment/variable/function/type/constant/tag/attribute/operator`) in both themes, each ≥ 4.5:1 on the editor background and the active line. `editor.reveal {path, line, column}` (UI command, palette, control channel) opens the file, activates the tab, places the cursor and centres it. Checked in the app on Windows 11 (bundled UI, control channel): PHP with embedded HTML in dark and light, `editor.reveal` into a closed CRLF file (last line, then line 302 centred). Vitest; keystroke to highlight on a 1 MB PHP file 3.0–11.4 ms median (jsdom, JavaScript work only, measured, not yet in the WebView). Missing: semantic highlighting (from the language server), a colour scheme editor, more languages (XML, SQL, Twig, Blade, .env), font styles (bold/italic) per token.
- [ ] Files changed on disk and Local History
- C10 A2 (2026-11-08): a banner under the tab bar for a tab whose file changed on disk while it had unsaved changes (Reload (discard mine), Keep mine, Compare: disk text left, buffer right in the diff viewer) or was deleted (Keep as unsaved, Close); clean tabs reload silently, keeping the caret; a save over a newer file asks Overwrite / Cancel (Cancel focused), also for save all; Show Local History (project tree and tab context menus, palette, File menu) lists a file's snapshots with date, time, reason and size; Show Diff opens the entry against the current text, Revert to This (dialog and diff caption) is an undoable unsaved edit. Catalog strings, `--lt-*` tokens, Vitest (13 tests), live check over `--control` on Windows 11. Missing: labels, folder and project history, recently deleted files, a merge view. Behaviour and storage: `docs/local-history.md`.
- [ ] Restore dialog for unsaved changes after a crash
- M1.7 (2026-10-16): modal dialog after a project opens when the recovery journal holds unsaved texts: files with the time they were journaled and a hint when the file changed on disk since; Restore All, Restore Selected (the others stay listed), Discard; Escape keeps the journal for the next open; restore failures listed. Catalog strings, `--lt-*` tokens, Vitest (10 tests). Live check pending (gaming mode). Missing: a diff against the disk version, local history. M1.15: a restore or discard from elsewhere (control channel) removes the settled files and closes the dialog when none are left; the dialog waits behind the palette and the settings dialog. Behaviour notes: `plan/phpstorm/04-recovery.md`.
- [ ] Command palette / search everywhere
@ -53,6 +55,7 @@
| Date | Change | Summary |
|---|---|---|
| 2026-11-08 | minor | Banner for files changed on disk, overwrite question, Local History dialog (C10 A2) |
| 2026-11-08 | minor | Tab management: preview, pin, close actions, reopen closed tab, split into two groups, stored layout (C10 A1) |
| 2026-11-02 | minor | Four more themes, theme picker, theme file import, editor font family and line height (C9 T1) |
| 2026-11-01 | patch | Chunk popup from the gutter and the diff viewer, staged markers, partly staged rows (C8 C3) |