- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/check-clash.ts?version=133&format=json
52 linesFirst import 75% · codex-capacity-chair 12% · engine 8% · infra-split 4% · rename 2%Last change codex-capacity-chair in version 133, 5 versions changed it
You're reading version 133. The newest is 318, and 1 version since then changed this file.
1// Refuse work whose paths would clash in shared. Reads go through
2// CheckClashHost; today the host is Project.
4import type { AtomId, View } from "../../src/engine/index.ts";
5import { unionOverlay } from "../../src/engine/state-source.ts";
6import { ProjectError } from "./project-error.ts";
7import { configProblem, PROJECT_FILES } from "./project-helpers.ts";
8import type { Space } from "./spaces.ts";
9import { clashIn } from "./spelling.ts";
11/** What the spelling clash check needs from a project. */
12export interface CheckClashHost {
13 shared(): Space;
14 setOf(space: Space): ReadonlySet<AtomId>;
15 view(set: ReadonlySet<AtomId>): View;
16 sharedView(): View;
17 touchedFiles(ids: Iterable<AtomId>, views: readonly View[]): Set<string>;
18}
20/**
21 * Refuse work whose paths would clash in shared (#49), before anything of it
22 * is written.
23 */
24export function checkClash(
25 host: CheckClashHost,
26 changes: readonly AtomId[],
27 ahead: ReadonlySet<AtomId> = new Set(),
28): void {
29 if (changes.length === 0) return;
30 let view: View;
31 let now: View;
32 try {
33 // Publishes queued ahead (#39) land first, so they count as shared.
34 const base = host.setOf(host.shared());
35 const queued = unionOverlay(base, ahead);
36 view = host.view(unionOverlay(queued, changes));
37 now = ahead.size === 0 ? host.sharedView() : host.view(queued);
38 } catch (e) {
39 if ((e as { code?: string }).code === "not-closed") return; // stranded by a drop: the publish says so itself
40 throw e;
41 }
42 const touched = host.touchedFiles(changes, [view]);
43 const why = clashIn(view, touched, now);
44 if (why) throw new ProjectError("conflict", why);
45 // A broken project file would quietly switch off files kept whole, the queue and reviewers.
46 for (const name of PROJECT_FILES) {
47 if (!touched.has(name) || !view.hasFile(name)) continue;
48 const bad = configProblem(view.text(name));
49 if (bad)
50 throw new ProjectError("conflict", `${name} ${bad}. Shared keeps the one it has; fix yours and push again.`);
51 }
52}