Skip to content

feat: favourite directories with a star in the path line - #84

Merged
SPhillips1337 merged 2 commits into
mainfrom
feat/favourite-directories
Nov 9, 2026
Merged

SPhillips1337 merged 2 commits into
mainfrom
feat/favourite-directories

Conversation

@SPhillips1337

Copy link
Copy Markdown
Contributor

Summary

  • Star the current directory: a ☆ beside the path line above the panes stars the focused pane's directory. It shows as a yellow ★ when that directory is already a favourite.
  • Favourites menu: the ▾ next to the star lists favourites in two groups.
    • This pane: a cd through openDirectory. 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.
    • Elsewhere: local and WSL favourites open a new pane already in that directory, in the shell they were starred from. SSH favourites on another host are listed but greyed for now.
    • Each row has a remove (×) button, so a favourite can be removed without going to it.
  • Directory browser: a star in the header stars the folder being browsed, and starred folders are marked in the list.
  • Storage: favourite-directories.json in 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 only cd to a path in its own style (C:\work for PowerShell, /c/work for Git Bash).
  • Absolute paths only: a quoted cd '~/x' does not expand ~, so the star stays disabled until a pane has reported a real directory. Its tooltip says why.
  • Refactor: JsonFileStore now 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) and npm run build pass.
  • New 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.
  • The recent-sessions tests still pass on the refactored store.

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

  • Renaming favourites. The data model has a label field, but there is no way to edit it yet.
  • Opening an SSH favourite from a different machine: connect, wait for a prompt, then cd.

🤖 Generated with Claude Code

Stephen Phillips and others added 2 commits November 9, 2026 16:50
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>
@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. JsonFileStore.ensureLoaded race condition (src/main/json-file-store.ts line 50-60): this.loaded = true is set before the async readFile resolves. A concurrent save() call (e.g. the renderer calling saveFavourites immediately after mount before loadFavourites returns) will see loaded === 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.

  2. safeText surrogate-pair slicing (src/main/json-file-store.ts line 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('').

  3. WSL favourite planJump missing distribution guard (src/renderer/favourites.ts line 145-147): favourite.wslDistribution is typed as string | undefined, yet it's passed directly to CreateLocalRequest.wslDistribution. A WSL session whose wslDistribution is undefined (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: return unavailable when 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.

Comment on lines +50 to +60
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();
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 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;

Comment on lines +79 to +87
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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 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.

Suggested change
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();
}

Comment on lines +145 to +147
if (favourite.place === 'wsl') {
return { kind: 'open-local', request: { name, backend: 'wsl', wslDistribution: favourite.wslDistribution, cwd: favourite.path } };
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 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.

Suggested change
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 } };
}

Comment thread src/renderer/main.tsx
Comment on lines +2816 to +2824
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`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 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.

@SPhillips1337
SPhillips1337 merged commit 3950a9d into main Nov 9, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant