- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/spelling.ts?version=278&format=json
79 linesFirst import 86% · capacity 5% · codex-capacity-chair 4% · rename 4% · infra-split 1%Last change capacity in version 278, 5 versions changed it
You're reading version 278. The newest is 318, and 1 version since then changed this file.
1// Spellings (#49), moved out of project.ts (abso issue 46): whether paths
2// would make two spellings of one name live at once, and which spelling a
3// path has in a view. Plain functions of views; the project calls them.
5import type { ReadView } from "../../src/engine/index.ts";
6import { pathKey } from "./pathkey.ts";
8/**
9 * Whether paths entering shared would make two spellings of one name live
10 * at once (#49): two
11 * files whose names differ only in case or Unicode form, or a file and a
12 * folder with one name. No disk holds both, and the git copy can't either.
13 * `touched` are the paths the work changes; `now` is shared as it is, so a
14 * clash shared already holds isn't charged to this work. The answer is the
15 * refusal's reason, or undefined.
16 */
17export function clashIn(view: ReadView, touched: Iterable<string>, now: ReadView): string | undefined {
18 const byKey = new Map<string, string[]>();
19 // Every path the graph has ever had, sorted, not the view's known paths (abso Capacity, prod abso 2026-10-15): those
20 // read every atom's file list, over half of a publish on abso. Each use below keeps only paths the view has a file
21 // at, and a path the view never had has none, so the answers are the same.
22 for (const p of [...view.graph.knownFiles()].sort()) {
23 const k = pathKey(p);
24 const list = byKey.get(k);
25 if (list) list.push(p);
26 else byKey.set(k, [p]);
27 }
28 const liveAs = (key: string, but?: string) => byKey.get(key)?.find((q) => q !== but && view.hasFile(q));
29 const old = (a: string, b: string) => now.hasFile(a) && now.hasFile(b);
30 for (const p of [...touched].sort()) {
31 if (!view.hasFile(p)) continue;
32 const key = pathKey(p);
33 const twin = liveAs(key, p);
34 if (twin !== undefined && !old(p, twin))
35 return `${p} and ${twin} would both be in shared, but they're one file, spelled two ways (case or Unicode form). Keep one: abso mv ${p} ${twin}, or put your change into ${twin}, then push again.`;
36 const parts = p.split("/");
37 for (let i = 1; i < parts.length; i++) {
38 const file = liveAs(pathKey(parts.slice(0, i).join("/")));
39 if (file !== undefined && !old(p, file))
40 return `${p} puts a file in folder ${parts.slice(0, i).join("/")}, but ${file} is a file of that name in shared, and no disk holds both. Move one of them (abso mv), then push again.`;
41 }
42 for (const [k, qs] of byKey) {
43 if (!k.startsWith(`${key}/`)) continue;
44 const under = qs.find((q) => view.hasFile(q));
45 if (under !== undefined && !old(p, under))
46 return `${p} is a file, but ${under} makes a folder of that name in shared, and no disk holds both. Move one of them (abso mv), then push again.`;
47 }
48 }
49 return undefined;
50}
52/** The same check for a list of paths alone (init, a git commit): the first clash among them. */
53export function clashInPaths(paths: readonly string[]): string | undefined {
54 const files = new Map<string, string>();
55 for (const p of paths) {
56 const twin = files.get(pathKey(p));
57 if (twin !== undefined && twin !== p)
58 return `${twin} and ${p} are one file, spelled two ways (case or Unicode form); keep one`;
59 files.set(pathKey(p), p);
60 }
61 for (const p of paths) {
62 const parts = p.split("/");
63 for (let i = 1; i < parts.length; i++) {
64 const file = files.get(pathKey(parts.slice(0, i).join("/")));
65 if (file !== undefined)
66 return `${file} is a file, and ${p} puts a file in a folder of that name; no disk holds both`;
67 }
68 }
69 return undefined;
70}
72/** The spelling a path has in this view: itself, or the one existing file it matches by pathKey (case and Unicode form ignored). */
73export function spellingOf(view: ReadView, path: string): string {
74 if (view.hasFile(path)) return path;
75 const key = pathKey(path);
76 // Known paths first, by key, then only those laid out (#46).
77 const twins = view.knownPaths().filter((p) => pathKey(p) === key && view.hasFile(p));
78 return twins.length === 1 ? twins[0]! : path;
79}