The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 13:30 UTC
feat(client): add-project folder search matches substrings and fuzzy subsequences (#26376)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Yash Singh <saiansh2525@gmail.com>
Christoffer Artmann committed
Nov 14, 2026 at 20:21 UTC
752bdaeb708a617323f32722c0692cd75f3d567f
2 files changed
+79
-6
packages/client-runtime/src/state/filesystem.test.ts
+40
@@ -116,6 +116,7 @@ describe("filesystem browse model", () => {
116
exactEntry: null,
117
});
118
expect(filterFilesystemBrowseEntries([entry], "De").visibleEntries).toEqual([entry]);
119
+ expect(filterFilesystemBrowseEntries([entry], "dévpt").visibleEntries).toEqual([entry]);
120
expect(filterFilesystemBrowseEntries([entry], "D\u00e9veloppement").exactEntry).toBe(entry);
121
// Linux keeps both spellings as separate folders; the one typed exactly wins.
122
const composed = { name: "D\u00e9veloppement", fullPath: "/home/me/D\u00e9veloppement" };
@@ -155,3 +156,42 @@ describe("browse navigation", () => {
156
expect(commits).toEqual(["second"]);
157
});
158
});
159
+
160
+describe("browse entry filtering", () => {
161
+ const entries = ["my-t3code", "t3code", "cotton", "T3Code-old", ".t3", "docs"].map((name) => ({
162
+ name,
163
+ fullPath: `~/code/${name}`,
164
+ }));
165
+ const names = (query: string) =>
166
+ filterFilesystemBrowseEntries(entries, query).visibleEntries.map((entry) => entry.name);
167
+
168
+ it("keeps every visible entry in order for an empty query", () => {
169
+ expect(names("")).toEqual(["my-t3code", "t3code", "cotton", "T3Code-old", "docs"]);
170
+ });
171
+
172
+ it("matches substrings and subsequences, best match first", () => {
173
+ expect(names("code")).toEqual(["t3code", "T3Code-old", "my-t3code"]);
174
+ expect(names("t3c")).toEqual(["t3code", "T3Code-old", "my-t3code"]);
175
+ expect(names("tcd")).toEqual(["t3code", "T3Code-old", "my-t3code"]);
176
+ expect(names("xyz")).toEqual([]);
177
+ });
178
+
179
+ it("ranks a word-start match in a long name above any substring match", () => {
180
+ const longName = `${"a".repeat(240)}-foo`;
181
+ const folders = [
182
+ { name: "xfoo", fullPath: "~/xfoo" },
183
+ { name: longName, fullPath: "~/long" },
184
+ ];
185
+ expect(
186
+ filterFilesystemBrowseEntries(folders, "foo").visibleEntries.map((entry) => entry.name),
187
+ ).toEqual([longName, "xfoo"]);
188
+ });
189
+
190
+ it("shows dot folders only when the query starts with a dot", () => {
191
+ expect(names("t3")).not.toContain(".t3");
192
+ expect(filterFilesystemBrowseEntries(entries, ".t3")).toEqual({
193
+ visibleEntries: [entries[4]],
194
+ exactEntry: entries[4],
195
+ });
196
+ });
197
+});
packages/client-runtime/src/state/filesystem.ts
+39
-6
@@ -5,6 +5,7 @@ import {
5
sessionGrantsScope,
6
type SessionGrantInput,
7
} from "@t3tools/contracts";
8
+import { scoreQueryMatch } from "@t3tools/shared/searchRanking";
9
import { Atom } from "effect/reactivity";
10
11
import type {
@@ -79,12 +80,44 @@ export function filterFilesystemBrowseEntries(
80
const lowerQuery = query.toLowerCase();
81
const lowerNormalizedQuery = normalizedQuery.toLowerCase();
82
const showHidden = query.startsWith(".");
82
- const visibleEntries = entries.filter(
83
- (entry) =>
84
- (entry.name.toLowerCase().startsWith(lowerQuery) ||
85
- entry.name.normalize("NFC").toLowerCase().startsWith(lowerNormalizedQuery)) &&
86
- (showHidden || !entry.name.startsWith(".")),
87
- );
83
+ const candidates = entries.filter((entry) => showHidden || !entry.name.startsWith("."));
84
+ const visibleEntries =
85
+ lowerQuery.length === 0
86
+ ? candidates
87
+ : candidates
88
+ .map((entry) => {
89
+ const options = {
90
+ // Position penalties stay under 1000 for 255-character names, so tiers never overlap.
91
+ query: lowerNormalizedQuery,
92
+ exactBase: 0,
93
+ prefixBase: 1000,
94
+ boundaryBase: 2000,
95
+ includesBase: 3000,
96
+ fuzzyBase: 4000,
97
+ boundaryMarkers: [" ", "-", "_", "."],
98
+ };
99
+ const rawScore = scoreQueryMatch({
100
+ ...options,
101
+ value: entry.name.toLowerCase(),
102
+ query: lowerQuery,
103
+ });
104
+ const normalizedScore = scoreQueryMatch({
105
+ ...options,
106
+ value: entry.name.normalize("NFC").toLowerCase(),
107
+ });
108
+ const score =
109
+ rawScore === null
110
+ ? normalizedScore
111
+ : normalizedScore === null
112
+ ? rawScore
113
+ : Math.min(rawScore, normalizedScore);
114
+ return { entry, score };
115
+ })
116
+ .filter((match): match is { entry: FilesystemBrowseEntry; score: number } => {
117
+ return match.score !== null;
118
+ })
119
+ .sort((left, right) => left.score - right.score)
120
+ .map((match) => match.entry);
121
const normalizedMatches = visibleEntries.filter(
122
(entry) => entry.name.normalize("NFC") === normalizedQuery,
123
);