Repository navigation
feat: favourite directories with a star in the path line - #84
Conversation
Pull the read-once, validate-both-ways, write-through-a-temp-file logic out of RecentSessionStore into JsonFileStore, with the text-cleaning helpers next to it. The favourites store builds on it next. This also removes the duplication SonarCloud flagged on #83. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A star beside the path line stars the focused pane's directory, and a menu next to it lists every favourite in two groups. Favourites the focused pane can reach are a `cd` through openDirectory, so they get the same quoting, WSL translation and busy-pane refusal as the directory browser. Favourites on another machine open a new local or WSL pane already in that directory. SSH favourites on another host are listed but not opened yet. Each row can be removed from the menu. The directory browser's header has a star for the folder being browsed, and starred folders are marked in its list. Each favourite records the machine it belongs to (this computer, a WSL distribution, or an SSH host) and, for local ones, the shell it was starred from, because a path means nothing on another machine. Only absolute paths can be starred, because `~` does not expand inside a quoted `cd`. Saved in favourite-directories.json. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
There was a problem hiding this comment.
Review Summary
This PR adds a well-structured favourites feature with solid validation on both sides of the IPC boundary, atomic file writes, and good test coverage. The architecture (machine-aware favourites, path-style matching, the planJump split) is clean.
Blocking issues found:
-
JsonFileStore.ensureLoadedrace condition (src/main/json-file-store.tsline 50-60):this.loaded = trueis set before the asyncreadFileresolves. A concurrentsave()call (e.g. the renderer callingsaveFavouritesimmediately after mount beforeloadFavouritesreturns) will seeloaded === true, skip the read, and overwrite in-memory state before the disk data has landed — silently discarding the user's stored favourites. Fix: store the load promise itself rather than a boolean flag. -
safeTextsurrogate-pair slicing (src/main/json-file-store.tsline 79-87):out.trim().slice(0, limit)slices by code units, so an emoji or other supplementary character near the limit boundary can be split into a lone surrogate. Lone surrogates in a JSON string produce malformed output on some runtimes. Fix: slice by code points using[...out].slice(0, limit).join(''). -
WSL favourite
planJumpmissing distribution guard (src/renderer/favourites.tsline 145-147):favourite.wslDistributionis typed asstring | undefined, yet it's passed directly toCreateLocalRequest.wslDistribution. A WSL session whosewslDistributionisundefined(e.g. if cwd-tracking fires before the WSL distro is known) can produce a WSL pane open request with no distribution, which the main process will attempt to honour with an empty/undefined distro string. Fix: returnunavailablewhen the distribution is absent.
The toggleFavouriteAt error message issue (comment #4) is lower severity — it's a misleading user-visible message rather than a crash, but it's worth fixing for accuracy.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| private async ensureLoaded(): Promise<void> { | ||
| if (this.loaded) return; | ||
| this.loaded = true; | ||
| try { | ||
| const parsed: unknown = JSON.parse(await readFile(this.filePath, 'utf8')); | ||
| const normalized = this.normalize(parsed); | ||
| if (normalized) this.file = normalized; | ||
| } catch { | ||
| this.file = this.empty(); | ||
| } | ||
| } |
There was a problem hiding this comment.
🛑 Logic Error: this.loaded = true is set before the readFile promise resolves. If save() is called while load() is still in flight, ensureLoaded() returns immediately (the flag is already true) and save() overwrites the store's in-memory state before the disk file has been read in. Any data persisted from the previous session is silently discarded.
Replace the flag with a stored promise so concurrent callers all wait for the same read to finish.
private async ensureLoaded(): Promise<void> {
if (this.loadPromise) return this.loadPromise;
this.loadPromise = (async () => {
try {
const parsed: unknown = JSON.parse(await readFile(this.filePath, 'utf8'));
const normalized = this.normalize(parsed);
if (normalized) this.file = normalized;
} catch {
this.file = this.empty();
}
})();
return this.loadPromise;
}
private loadPromise: Promise<void> | null = null;| export function safeText(value: string, limit: number): string { | ||
| let out = ''; | ||
| for (const char of value) { | ||
| const code = char.charCodeAt(0); | ||
| if (code < 0x20 || code === 0x7f) continue; | ||
| out += char; | ||
| } | ||
| return out.trim().slice(0, limit); | ||
| } |
There was a problem hiding this comment.
🛑 Logic Error: safeText applies slice(0, limit) after stripping control characters, but the loop increments one JavaScript code unit at a time via for...of which does iterate full Unicode code points. However, slice(0, limit) on the resulting out string operates on code units, so a supplementary character (e.g. an emoji represented as a surrogate pair) near the limit could be split, leaving a lone leading surrogate at position limit-1. This produces an invalid UTF-16 string that JSON.stringify will encode as the replacement character or malformed JSON on some runtimes.
Use [...out].slice(0, limit).join('') to slice by code points rather than code units.
| export function safeText(value: string, limit: number): string { | |
| let out = ''; | |
| for (const char of value) { | |
| const code = char.charCodeAt(0); | |
| if (code < 0x20 || code === 0x7f) continue; | |
| out += char; | |
| } | |
| return out.trim().slice(0, limit); | |
| } | |
| export function safeText(value: string, limit: number): string { | |
| const chars: string[] = []; | |
| for (const char of value) { | |
| const code = char.codePointAt(0) ?? 0; | |
| if (code < 0x20 || code === 0x7f) continue; | |
| chars.push(char); | |
| } | |
| return chars.slice(0, limit).join('').trim(); | |
| } |
| if (favourite.place === 'wsl') { | ||
| return { kind: 'open-local', request: { name, backend: 'wsl', wslDistribution: favourite.wslDistribution, cwd: favourite.path } }; | ||
| } |
There was a problem hiding this comment.
🛑 Logic Error: When planJump returns kind: 'open-local' for a WSL favourite, favourite.wslDistribution is passed directly into CreateLocalRequest. While normalizeEntry in favourite-store.ts correctly rejects WSL entries missing wslDistribution, the renderer's toggleFavourite can produce WSL entries without a distribution if placeOf returns { place: 'wsl', wslDistribution: undefined } (because session.wslDistribution is optional in SessionInfo). That would produce { backend: 'wsl', wslDistribution: undefined, cwd: ... }, launching a WSL pane with no distribution — which the main process passes to service.createLocal as an empty/undefined distro and may start the wrong shell or error.
Add a guard to return unavailable when wslDistribution is absent.
| if (favourite.place === 'wsl') { | |
| return { kind: 'open-local', request: { name, backend: 'wsl', wslDistribution: favourite.wslDistribution, cwd: favourite.path } }; | |
| } | |
| if (favourite.place === 'wsl') { | |
| if (!favourite.wslDistribution) return { kind: 'unavailable', reason: `The WSL distribution for ${favourite.path} is not recorded.` }; | |
| return { kind: 'open-local', request: { name, backend: 'wsl', wslDistribution: favourite.wslDistribution, cwd: favourite.path } }; | |
| } |
| const toggleFavouriteAt = (session: SessionInfo, path: string) => { | ||
| const wasStarred = Boolean(findFavourite(favourites, session, path)); | ||
| const next = toggleFavourite(favourites, session, path, { now: new Date(), id: crypto.randomUUID() }); | ||
| if (next === favourites) { | ||
| setStatus(`${path} cannot be starred: it is not an absolute path.`); | ||
| return; | ||
| } | ||
| updateFavourites(next); | ||
| setStatus(wasStarred ? `Removed ${path} from favourites` : `Added ${path} to favourites`); |
There was a problem hiding this comment.
🛑 Logic Error: The toggleFavouriteAt path only guards against adding non-absolute paths (if (next === favourites)), but toggleFavourite returns the unchanged file when !isStarrable(path) — not only for non-absolute paths but also when placeOf(session) returns null (e.g. an SSH session with no resolvable host). In that case, next === favourites is true and the status bar incorrectly reports "cannot be starred: it is not an absolute path" even though the problem is the unresolvable host. This misleads users but is the only consequence — the star is a no-op. This is a minor message accuracy issue rather than a crash, but it could confuse users debugging why the star doesn't work for SSH panes.



Summary
cdthroughopenDirectory. That is the directory browser's existing route, so it gets the same per-shell quoting, WSL translation and refusal when the pane is busy.favourite-directories.jsonin the user's profile. Each favourite records its machine (this computer / WSL distribution / SSH host), because a path means nothing elsewhere. Local favourites also record their shell, and a pane can onlycdto a path in its own style (C:\workfor PowerShell,/c/workfor Git Bash).cd '~/x'does not expand~, so the star stays disabled until a pane has reported a real directory. Its tooltip says why.JsonFileStorenow holds the load/save logic the recent-sessions store had, and the favourites store builds on it. This clears the SonarCloud duplication reported on feat: reopen recent sessions at startup, plus PowerShell cwd and long voice fixes #83.Testing
npm run typecheck,npm test(1203 passed, 3 skipped) andnpm run buildpass.tests/favourites.test.ts(11 tests) covers machine identification, toggling, Windows path matching, which favourites a pane can reach, jump plans (cd, new pane, unavailable) and store validation.Not yet checked in the running app: starring from the path line and the browser, jumping within a pane, and opening a WSL favourite from a PowerShell pane.
Not included
labelfield, but there is no way to edit it yet.cd.🤖 Generated with Claude Code