Repository navigation
fix(file-explorer): sort numbered file names naturally across every listing surface - #11576
Conversation
The File Explorer compared names with bare localeCompare, so numbered files listed 100, 200 before 99. Hoist the numeric collator Source Control file rows already use (#10850) into src/shared and apply it to the local and runtime directory listings, the name-filtered view, and Source Control directory nodes, which were inconsistent with the file rows one line below (#11426).
Adversarial-review round 1 rework:
- Both readDir funnels short-circuited to the SSH filesystem provider
before the patched sort, so SSH workspaces kept lexicographic order;
re-sort locally after the provider returns (the remote relay may be an
older build), and fix the relay's own comparator for relay-native
consumers.
- sortDirEntries (shared, unit-tested) owns the directories-first +
natural-order listing contract used by every funnel.
- compareFileNames breaks numeric-collation ties ('2' vs '02') by code
units so sibling order stays total instead of readdir order, and pins
the collator locale to 'en' so every host produces one order.
- The SSH folder browser and runtime server dir picker now match the
Explorer they browse into.
- Ordering pinned by tests at the relay, source-control tree, and shared
helper.
Mobile re-sorted host readDir results with bare localeCompare, undoing the host funnel's natural order (round-2 review). Reuse the shared comparator and pin the order in the mobile suite.
…ining ties Round-3 review: the remote-runtime RPC and paired-web routes return the host's order verbatim, so re-sort in readFileExplorerDirectory where every desktop route converges; pin the SSH funnel with a handler-level test; and route Source Control path compares through compareFileNames so numeric-collation ties share one total order with the Explorer.
Greptile SummaryThis PR centralises all file-explorer sort logic into a new
Confidence Score: 5/5Safe to merge — the change is a well-scoped sort-algorithm replacement with no effect on IPC shapes, auth, or data integrity. All nine previously independent sort comparators now delegate to a single, well-tested shared module. The max-heap in quick-open-search is correct (total-order comparator, proper sift-up/sift-down, max at root), and the shared Intl.Collator singleton is correctly hoisted. Re-sorting at every funnel closes the version-skew gap for older relays. Files Needing Attention: No files require special attention. The mobile import path crossing package boundaries warrants a device spot-check on the Files panel, as noted in the PR.
|
| Filename | Overview |
|---|---|
| src/shared/file-name-sort.ts | New shared module: hoisted Intl.Collator singleton, compareFileNames with code-unit tie-break, sortDirEntries with directories-first contract. Well-commented, tested, and correctly structured. |
| src/renderer/src/components/quick-open-search.ts | Replaces sorted-insertion with a correct max-heap for O(N log K) top-N selection; compareRankedResult gains natural-path tie-breaker; finalizeResults sorts heap output ascending for best-first display. Implementation is correct. |
| src/main/ipc/filesystem.ts | SSH provider branch now re-sorts via sortDirEntries; local readdir branch replaces inline comparator. Both paths consistently produce directories-first natural order. |
| src/relay/fs-handler.ts | Inline sort replaced by sortDirEntries. Relay now produces natural order; test updated to pin exact numeric ordering. |
| src/renderer/src/components/right-sidebar/file-explorer-directory-listing.ts | Renderer choke-point re-sorts backend results; paired-web and remote-runtime routes now produce consistent order even when the host relay is an older build. |
| src/renderer/src/components/right-sidebar/source-control-tree.ts | Directory name sort upgraded from bare localeCompare to compareFileNames; removes now-unused sourceControlPathCollator import. Tree and flat-list now agree on numeric order. |
| src/renderer/src/components/right-sidebar/source-control-file-filter.ts | Adds filterAndSortSourceControlPathEntries (spread copy + compareFileNames sort); original filterSourceControlPathEntries left intact. Non-mutating by design. |
| mobile/src/files/file-tree.ts | compareDirectoryEntries switches from bare localeCompare to compareFileNames, bringing mobile ordering in line with desktop. |
| src/renderer/src/runtime/runtime-server-directory-browser.ts | browseRuntimeServerDirectory now re-sorts the RPC result before returning, ensuring natural order regardless of host runtime version. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Directory listing requested] --> B{Route type}
B -->|Local fs:readDir| C[Node.js readdir]
B -->|SSH connectionId| D[SSH filesystem provider]
B -->|Remote-runtime RPC| E[callRuntimeRpc]
B -->|Relay handler| F[FsHandler readDir]
B -->|SSH folder browser| G[runBrowseCommand]
B -->|Mobile file tree| H[flattenDirectoryCache]
C --> SORT1[sortDirEntries]
D --> SORT2[sortDirEntries re-sort locally]
E --> SORT3[sortDirEntries renderer choke-point]
F --> SORT4[sortDirEntries relay-side]
G --> SORT5[sortDirEntries in-place]
H --> SORT6[compareFileNames]
SORT1 --> OUT[Directories-first natural numeric order]
SORT2 --> OUT
SORT3 --> OUT
SORT4 --> OUT
SORT5 --> OUT
SORT6 --> OUT
subgraph shared [src/shared/file-name-sort.ts]
SC[fileNameCollator Intl.Collator en+numeric]
SC --> CF[compareFileNames + code-unit tie-break]
CF --> SDE[sortDirEntries dirs-first contract]
end
Reviews (2): Last reviewed commit: "fix(file-listings): cover remaining natu..." | Re-trigger Greptile
|
Warning Review limit reached
Next review available in: 34 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughAdds shared natural filename comparison with deterministic tie-breaking and directory-first sorting. The helper is applied to local and remote filesystem listings, SSH browsing, runtime directory reads, mobile file trees, renderer explorer projections, and source-control trees and status entries. Tests cover numeric filename ordering, embedded numeric segments, directory grouping, remote filesystem responses, explorer listings, and source-control tree flattening. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6b460ae3-1360-4d39-82d6-1e4def10c6ec
📒 Files selected for processing (18)
mobile/src/files/file-tree.test.tsmobile/src/files/file-tree.tssrc/main/ipc/filesystem.test.tssrc/main/ipc/filesystem.tssrc/main/ipc/ssh-browse.tssrc/main/runtime/orca-runtime-files.tssrc/main/runtime/orca-runtime.tssrc/relay/fs-handler.test.tssrc/relay/fs-handler.tssrc/renderer/src/components/right-sidebar/file-explorer-directory-listing.test.tssrc/renderer/src/components/right-sidebar/file-explorer-directory-listing.tssrc/renderer/src/components/right-sidebar/file-explorer-name-filter-projection.tssrc/renderer/src/components/right-sidebar/source-control-status-sort.test.tssrc/renderer/src/components/right-sidebar/source-control-status-sort.tssrc/renderer/src/components/right-sidebar/source-control-tree.test.tssrc/renderer/src/components/right-sidebar/source-control-tree.tssrc/shared/file-name-sort.test.tssrc/shared/file-name-sort.ts
| vi.mock('./file-explorer-operation-owner', () => ({ | ||
| getFileExplorerOperationOwner: () => ({ kind: 'local' }), | ||
| getFileExplorerOperationRoute: () => ({ settings: null, connectionId: null }), | ||
| getFileExplorerOwnerUnresolvedMessage: () => 'unresolved' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Make the route mock match the test’s stated coverage.
The mocks always return { kind: 'local' }, so this test never exercises the remote-runtime or paired-web routes named on Line 16. Parameterize the route mock for those owners, or rename the test to avoid implying coverage it does not provide.
Also applies to: 16-16
…isting surface (stablyai#11576) * fix(file-explorer): sort numbered file names naturally The File Explorer compared names with bare localeCompare, so numbered files listed 100, 200 before 99. Hoist the numeric collator Source Control file rows already use (stablyai#10850) into src/shared and apply it to the local and runtime directory listings, the name-filtered view, and Source Control directory nodes, which were inconsistent with the file rows one line below (stablyai#11426). * fix(file-explorer): natural sort on SSH funnels, relay, and pickers Adversarial-review round 1 rework: - Both readDir funnels short-circuited to the SSH filesystem provider before the patched sort, so SSH workspaces kept lexicographic order; re-sort locally after the provider returns (the remote relay may be an older build), and fix the relay's own comparator for relay-native consumers. - sortDirEntries (shared, unit-tested) owns the directories-first + natural-order listing contract used by every funnel. - compareFileNames breaks numeric-collation ties ('2' vs '02') by code units so sibling order stays total instead of readdir order, and pins the collator locale to 'en' so every host produces one order. - The SSH folder browser and runtime server dir picker now match the Explorer they browse into. - Ordering pinned by tests at the relay, source-control tree, and shared helper. * fix(mobile): natural sort in the mobile file explorer Mobile re-sorted host readDir results with bare localeCompare, undoing the host funnel's natural order (round-2 review). Reuse the shared comparator and pin the order in the mobile suite. * fix(file-explorer): natural sort at the renderer choke point and remaining ties Round-3 review: the remote-runtime RPC and paired-web routes return the host's order verbatim, so re-sort in readFileExplorerDirectory where every desktop route converges; pin the SSH funnel with a handler-level test; and route Source Control path compares through compareFileNames so numeric-collation ties share one total order with the Explorer. * docs(file-name-sort): state the real perf baseline in the hoist comment * refactor(source-control): drop the dead collator export; pin the test oracle locale * fix(file-listings): cover remaining natural-sort surfaces







Summary
Fixes #11426 (Linear STA-2950). The File Explorer sorted names lexicographically, so numbered files listed
100, 200before99. Every directory-listing funnel now sorts directories-first in natural (numeric-aware) name order via one shared comparator: localfs:readDir, the SSH short-circuits (re-sorted locally so an older remote relay can't leak lexicographic order), the relay's own handler, the remote-runtime RPC / paired-web routes (re-sorted at the renderer choke point), the SSH folder browser and runtime server dir pickers, the name-filtered view, Source Control directory nodes, and the mobile file explorer.ELI5: computers sort text character-by-character, so "100" comes before "99" (because "1" < "9") — like shelving "Chapter 100" before "Chapter 99". This teaches Orca's file lists to read whole numbers inside names the way Finder and Explorer do, so
9,99,100shelve in the order you'd expect.Live before/after (real dev app, right-sidebar File Explorer):
Before — lexicographic (
1, 100, 2, 200, 409, 41, 410, 9, 99):After — natural (
1, 2, 9, 41, 99, 100, 200, 409, 410), re-verified on the final build:Screenshots
See before/after above.
Testing
pnpm lintpnpm typecheckpnpm test— targeted instead: affected desktop suites (182 files / 1699 passed, incl. new ordering tests at the relay, SSHfs:readDirhandler branch, renderer choke point, source-control tree, shared helper) plusmobile/src/files/file-tree.test.ts(8 passed, mobile vitest config). A reviewer's broader sweep of src/main+relay+shared hit only two known local-environment artifacts (GIT_CONFIG env leak; load-dependent timeout), both green when re-run isolated.pnpm build— left to CI.AI Review Report
Adversarial review loop: 4 rounds with a fresh reviewer each round; round 4 came back clean (zero blocker/major).
2vs02, which would otherwise fall back to readdir order); pinned the collator locale to'en'so every host produces one order; patched the SSH folder browser and runtime dir pickers that would have disagreed with the Explorer.localeCompare, undoing the host's order — fixed with the shared comparator + mobile test.Cross-platform: explicitly reviewed for macOS/Linux/Windows — the comparator is pure JS with no path-separator or shell assumptions; verified
/terminates ICU numeric runs so digits never merge across path segments; SSH, WSL (routes through main's patched local readdir), remote-runtime, paired-web, relay version-skew (older remote sends lexicographic order → local re-sort corrects it), and mobile (Hermes ships Intl on RN 0.83 for both platforms; Metro already watchessrc/shared) were each traced. Performance review (perf skill): pass-with-notes — numeric collation costs ~5x barelocaleCompare(~5ms extra on a 10,000-entry directory; invisible at realistic sizes), the hoisted collator avoids a 68x naive form, re-sorting an already-sorted SSH response is near-free (V8 adaptive sort, n−1 comparisons), and one collator instance was deduped.Security Audit
No input handling, command execution, auth, secrets, or dependency changes. The comparator is pure string comparison; no user input reaches
Intl.Collatoroptions. IPC surface unchanged (same handlers, same payload shapes — only result ordering). The relay change affects ordering only, not path resolution or authorization;resolveAuthorizedPathchecks are untouched and still precede every local readdir.Notes
'en'-pinned) — for locales whose collation differs from English (sv/cs/da) the list can reorder relative to the old OS-locale behavior; accepted for cross-host consistency and repo precedent (skill-freshness pins'en'). (2) Zero-padded numeric ties (2vs02) now order deterministically by code units instead of readdir order.numeric: truecollation in three modules, so risk is bounded — a device spot-check of the Files panel with9/99/100-style names would close it.CombinedDiffViewer's flat view still sorts by barelocaleComparewhile its tree view now uses the shared collator; three mobile modules use the slow per-calllocaleCompare(x, undefined, {numeric:true})form that the new shared module makes a one-line fix each.