Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(transcript-index): keep Turkish İ matching an i in the query

review14356a559224
diff --git a/CLAUDE.md b/CLAUDE.md
index 2f4c86b4f..227978303 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -9247,7 +9247,9 @@ script (`fetch('http://localhost:9333/json')`, then a WebSocket to the page):
lowered every entry per keystroke: 20-52 ms and 7-15 MB garbage per search on a 16 MB index,
vs 2-13 ms and 0 MB as one `RegExp(escaped, 'iu')`. A stored lowered copy would retain +32 MB.
`iu`, not `i`: `i` loses hits `toLowerCase` found (Kelvin K, Å, ẞ); escape only SyntaxCharacters
- and `/` (`\-` is a SyntaxError in `u` mode). The snippet uses the same matcher. The index file
+ and `/` (`\-` is a SyntaxError in `u` mode). Even `iu` loses Turkish İ (it lowers to `i` +
+ U+0307, so `türki` matched `TÜRKİYE`), so each i/I of the escaped query is widened to `[iİ]`.
+ The snippet uses the same matcher. The index file
persists through `writeFileAtomic` (0600), only when a `dirty` flag says the file is behind.
## SSH projects on Windows: the in-process transport
diff --git a/src/core/transcript-index-core.test.ts b/src/core/transcript-index-core.test.ts
index a7e1654f5..a5f933fe5 100644
--- a/src/core/transcript-index-core.test.ts
+++ b/src/core/transcript-index-core.test.ts
@@ -99,6 +99,20 @@ describe('searchEntries matching (RegExp iu, audit #5)', () => {
expect(hit('Deseret \u{10400}', 't \u{10428}')).toBe(true) // astral case pair
})
+ it('Turkish İ: an i in the query still matches the dotted capital, as toLowerCase did', () => {
+ // 'İ'.toLowerCase() is 'i' + U+0307, so the old lowered copy matched 'türki' inside 'TÜRKİYE';
+ // under `iu` İ folds only to itself, so the query's i/I are widened to also take İ.
+ expect(hit('Merhaba TÜRKİYE', 'türki')).toBe(true)
+ expect(hit('İstanbul trafiği', 'istanbul')).toBe(true)
+ expect(hit('İSTANBUL', 'ISTANBUL')).toBe(true)
+ // A whole word now matches too (the old copy had U+0307 between the i and the rest).
+ expect(hit('TÜRKİYE', 'türkiye')).toBe(true)
+ // …and nothing that was a miss before turns into a hit on a different letter.
+ expect(hit('TÜRKAYE', 'türki')).toBe(false)
+ const [h] = searchEntries(one('z'.repeat(400) + ' TÜRKİYE ' + 'z'.repeat(400)), 'türki')
+ expect(h.snippet).toContain('TÜRKİYE')
+ })
+
it('treats regex metacharacters in the query literally', () => {
expect(hit('axb', 'a.b')).toBe(false)
expect(hit('see a.b here', 'A.B')).toBe(true)
diff --git a/src/core/transcript-index-core.ts b/src/core/transcript-index-core.ts
index ccfd9cae8..df977bfd1 100644
--- a/src/core/transcript-index-core.ts
+++ b/src/core/transcript-index-core.ts
@@ -53,11 +53,15 @@ export function extractEntryFields(rawText: string): { cwd: string; title: strin
// match the old code found is lost". Over every BMP case pair, plain `i` disagreed 160 times and
// LOST hits (Kelvin sign K, Ångström Å, ẞ, Ohm Ω all stopped matching k/å/ß/ω); `iu` disagreed 94
// times, every one an EXTRA hit (ſ~s, µ~μ, Greek symbol variants, final ς~σ), and also folds astral
-// pairs (Deseret) that `i` misses. Turkish İ (one char lowering to two) diverges under all three.
+// pairs (Deseret) that `i` misses. Turkish İ (U+0130) is the one LOST hit `iu` still has: it
+// lowers to `i` + U+0307, so the old copy matched `türki` in `TÜRKİYE`, while case folding maps İ
+// only to itself. Every i/I of the escaped query is therefore widened to `[iİ]` (safe: the escape
+// below never emits a letter, so each i/I in its output is a literal one).
// The escape set is exactly SyntaxCharacter plus `/` — the only identity escapes `u` mode accepts;
// escaping anything else (`-`, say) is a SyntaxError there. No `g`: `test` would turn stateful.
export function queryRegExp(query: string): RegExp {
- return new RegExp(query.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'), 'iu')
+ const escaped = query.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')
+ return new RegExp(escaped.replace(/[iI]/g, '[iİ]'), 'iu')
}
export function makeSnippet(text: string, query: string | RegExp): string {