Skip to content

Commit 0ebb311

Browse files
fix(workspace): compare workspace names by collation, and confirm namesakes on the browser path too
- `sameNamedWorkspace` compares names with a case-insensitive, accent-sensitive Unicode collator (after spelling out ß), instead of chained case mapping that merged dotless ı with i. `Straße`/`STRASSE`, `ẞ`/`SS`, `ΟΔΟΣ`/`οδος` and `finance`/`FINANCE` match; `ı`/`i` and `café`/`cafe` do not. - `altimate-code link` asks before either create path when a namesake is listed, including "Set up in browser", which also starts from the project's name. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0172qrhMa5TQgETASi5hxMqD
1 parent 8fc43d3 commit 0ebb311

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎packages/opencode/src/altimate/workspace/workspace-name.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,30 @@ export function workspaceLabel(name: string, id: string | undefined, budget = MA
4949
}
5050

5151
/** A name as the link pickers compare it: control characters and runs of whitespace
52-
* collapsed, trimmed, case folded. Lower, upper, then lower again, so the expanding
53-
* mappings meet: `Straße` and `STRASSE` compare equal, and so do `ẞ` and `SS`, where
54-
* a single `toLowerCase()` or an upper-then-lower pass would not. This is Unicode
55-
* case mapping, not the complete CaseFolding table. (codex) */
52+
* collapsed, trimmed, and the sharp S spelled out, which collation otherwise keeps
53+
* apart from "ss". */
5654
function comparableName(name: string): string {
5755
return name
5856
.replace(/[\u0000-\u001F\u007F-\u009F\u2028\u2029]+/g, " ")
5957
.replace(/\s+/g, " ")
6058
.trim()
61-
.toLowerCase()
62-
.toUpperCase()
63-
.toLowerCase()
59+
.replace(/[ßẞ]/g, "ss")
6460
}
6561

6662
/** The first listed workspace already named what a quick create would call this
6763
* project, or undefined. The link pickers open on it instead of on "create", and
6864
* creating a second workspace with that name takes a confirmation: two workspaces
69-
* with one name split a team's skills and memory without anyone noticing. */
65+
* with one name split a team's skills and memory without anyone noticing.
66+
*
67+
* Names compare by Unicode collation, ignoring case but not accents: `Straße`
68+
* matches `STRASSE` and `ΟΔΟΣ` matches `οδος`, while `ı` and `i` or `café` and
69+
* `cafe` stay different. (codex) */
7070
export function sameNamedWorkspace<T extends { name: string }>(
7171
list: readonly T[],
7272
proposedName: string,
7373
): T | undefined {
7474
const target = comparableName(proposedName)
7575
if (!target) return undefined
76-
return list.find((workspace) => comparableName(workspace.name) === target)
76+
const collator = new Intl.Collator("und", { sensitivity: "accent", usage: "search" })
77+
return list.find((workspace) => collator.compare(comparableName(workspace.name), target) === 0)
7778
}

‎packages/opencode/src/cli/cmd/link.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,24 @@ export const LinkCommand = cmd({
339339
return
340340
}
341341

342+
// Both create paths start from the project's name, so both confirm a namesake.
343+
if ((pick === SET_UP_IN_BROWSER_SENTINEL || pick === CREATE_NEW_SENTINEL) && namesake) {
344+
const again = await prompts.confirm({
345+
message: `A workspace named "${stripControlChars(namesake.name)}" already exists. Create another one with the same name?`,
346+
initialValue: false,
347+
})
348+
if (prompts.isCancel(again) || !again) {
349+
prompts.outro("No changes.")
350+
return
351+
}
352+
}
353+
342354
if (pick === SET_UP_IN_BROWSER_SENTINEL) {
343355
await runBrowserHandoff(identifier, autoName, args.directory)
344356
return
345357
}
346358

347359
if (pick === CREATE_NEW_SENTINEL) {
348-
if (namesake) {
349-
const again = await prompts.confirm({
350-
message: `A workspace named "${stripControlChars(namesake.name)}" already exists. Create another one with the same name?`,
351-
initialValue: false,
352-
})
353-
if (prompts.isCancel(again) || !again) {
354-
prompts.outro("No changes.")
355-
return
356-
}
357-
}
358360
await createThenBindOrRebind(identifier, autoName, args.directory, existing)
359361
return
360362
}

‎packages/opencode/test/altimate/workspace/same-named-workspace.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ describe("sameNamedWorkspace", () => {
1414
["case differs", [ws(1, "Analytics")], "analytics", 1],
1515
["case differs beyond ASCII: ß and SS", [ws(1, "Straße")], "STRASSE", 1],
1616
["case differs beyond ASCII: capital sharp S and SS", [ws(1, "ẞ")], "SS", 1],
17+
["Greek final sigma", [ws(1, "ΟΔΟΣ")], "οδος", 1],
18+
["a ligature against its letters", [ws(1, "finance")], "FINANCE", 1],
19+
["dotless i stays distinct from i", [ws(1, "ı")], "i", undefined],
20+
["an accent is a different name", [ws(1, "café")], "cafe", undefined],
1721
["surrounding and inner whitespace differ", [ws(1, " data platform ")], "data platform", 1],
1822
["a control character in the listed name", [ws(1, "analy\u0007tics")], "analy tics", 1],
1923
["no workspace has the name", [ws(1, "marketing"), ws(2, "finance")], "analytics", undefined],

0 commit comments

Comments
 (0)