- 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=296&format=json
54 linesFirst import 61% · codex-capacity-chair 26% · engine 7% · infra-split 4% · rename 2%Last change codex-capacity-chair in version 143, 6 versions changed it
You're reading version 296. The newest is 318, and no 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, ReadView } 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>): ReadView;
16 sharedView(): ReadView;
17 sharedOverlay?(atoms: readonly AtomId[]): ReadView;
18 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
19}
21/**
22 * Refuse work whose paths would clash in shared (#49), before anything of it
23 * is written.
24 */
25export function checkClash(
26 host: CheckClashHost,
27 changes: readonly AtomId[],
28 ahead: ReadonlySet<AtomId> = new Set(),
29): void {
30 if (changes.length === 0) return;
31 let view: ReadView;
32 let now: ReadView;
33 try {
34 // Publishes queued ahead (#39) land first, so they count as shared.
35 const base = host.setOf(host.shared());
36 const queued = unionOverlay(base, ahead);
37 view = host.sharedOverlay ? host.sharedOverlay([...ahead, ...changes]) : host.view(unionOverlay(queued, changes));
38 now =
39 ahead.size === 0 ? host.sharedView() : host.sharedOverlay ? host.sharedOverlay([...ahead]) : host.view(queued);
40 } catch (e) {
41 if ((e as { code?: string }).code === "not-closed") return; // stranded by a drop: the publish says so itself
42 throw e;
43 }
44 const touched = host.touchedFiles(changes, [view]);
45 const why = clashIn(view, touched, now);
46 if (why) throw new ProjectError("conflict", why);
47 // A broken project file would quietly switch off files kept whole, the queue and reviewers.
48 for (const name of PROJECT_FILES) {
49 if (!touched.has(name) || !view.hasFile(name)) continue;
50 const bad = configProblem(view.text(name));
51 if (bad)
52 throw new ProjectError("conflict", `${name} ${bad}. Shared keeps the one it has; fix yours and push again.`);
53 }
54}