- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/overlaps.ts --version 55 --json
- JSON
- /christopher/abso-core/blame/worker/project/overlaps.ts?version=55&format=json
106 linesFirst import 91% · engine 8% · infra-split 2%Last change engine in version 55,
106 lines from 3 changes in 3 versions.
2// the news when a draft first touches one. Reads and news writes go through
3// OverlapHost; today the host is Project. overlapsOf is the pure match.
5import { type AtomId, type Graph, isStartNode, type View } from "../../src/engine/index.ts";
6import { matchesPattern, pathsInText, patternsMeet } from "./globs.ts";
7import { type NewsItem, overlapItems } from "./news.ts";
8import type { AgentState, Entry, Overlap, Starting } from "./project-types.ts";
10/** Another agent in the same space, as overlaps see it. */
11export interface OverlapPeer {
12 name: string;
13 /** Files its unpublished changes touch. */
14 files: ReadonlySet<string>;
15 /** How many of its unpublished changes touch `file`. */
16 changesIn: (file: string) => number;
17 /** Its live starting note. */
18 note: Starting | undefined;
19}
21/** What draft-file overlaps and their news need from a project. */
22export interface OverlapHost {
23 readonly graph: Graph;
24 readonly agents: ReadonlyMap<string, AgentState>;
25 agentView(agent: AgentState): View;
26 draft(agent: AgentState): readonly AtomId[];
engine55Issue 6: status no longer builds every agent's view. On abso's log (13,148 entries, 48 agents) status went from about 330 ms to 1 ms median (30 ms max) in Node.
- markedCollisions skips the view when the agent has no marked files (most have none). This was most of the cost.
- draftFiles skips the view when the draft is empty, and Project keeps each agent's draft files under their view key plus the draft, so they're worked out again only when either moves. Overlaps and overlap news use the kept ones too.
- New test (draft-files-kept): status from a warm project equals a cold load after every step, in shared and with two agents in one named draft (Pinch's case). A weaker key fails it.Compare27 /** draftFiles below, kept per agent by the host. */
28 draftFiles(agent: AgentState): Set<string>;
30 queueNews(agent: AgentState, items: readonly NewsItem[], entries: Entry[]): void;
31}
33/** What a starting note can name: its files (globs included) and the paths written in its text. */
34export const notePatterns = (note: Starting | undefined): string[] =>
35 note ? [...new Set([...note.files, ...pathsInText(note.text)])] : [];
37/**
38 * Peers with unpublished changes in a file `patterns` match, or a starting
infra-split37Comments and test names give each reason in plain words, without naming who raised it
Notes like "(#37, Builder 5)" or "(AVCS - Security)" become "(#37)" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.Compare39 * note that can name the same file (#37: notes name files by glob,
41 */
42export function overlapsOf(peers: readonly OverlapPeer[], patterns: readonly string[]): Overlap[] {
43 if (patterns.length === 0) return [];
44 const out: Overlap[] = [];
45 for (const other of peers.toSorted((a, b) => (a.name < b.name ? -1 : 1))) {
46 const found = new Map<string, Overlap>();
47 for (const file of [...other.files].toSorted()) {
48 if (!patterns.some((p) => matchesPattern(p, file))) continue;
49 found.set(file, { agent: other.name, file, changes: other.changesIn(file) });
50 }
51 for (const theirs of notePatterns(other.note)) {
52 for (const p of patterns) {
53 if (!patternsMeet(p, theirs)) continue;
54 // Name the file as plainly as either side gives it.
55 const file = /[*?]/.test(p) ? theirs : p;
56 found.set(file, found.get(file) ?? { agent: other.name, file });
57 }
58 }
59 for (const o of [...found.values()].toSorted((a, b) => (a.file < b.file ? -1 : 1))) {
60 out.push({ ...o, ...(other.note ? { starting: other.note.text } : {}) });
61 }
62 }
63 return out;
64}
66/** The files the agent's unpublished changes touch, in its own view. */
67export function draftFiles(host: OverlapHost, agent: AgentState): Set<string> {
68 const files = new Set<string>();
engine55Issue 6: status no longer builds every agent's view. On abso's log (13,148 entries, 48 agents) status went from about 330 ms to 1 ms median (30 ms max) in Node.
- markedCollisions skips the view when the agent has no marked files (most have none). This was most of the cost.
- draftFiles skips the view when the draft is empty, and Project keeps each agent's draft files under their view key plus the draft, so they're worked out again only when either moves. Overlaps and overlap news use the kept ones too.
- New test (draft-files-kept): status from a warm project equals a cold load after every step, in shared and with two agents in one named draft (Pinch's case). A weaker key fails it.Compare69 const draft = host.draft(agent);
70 // No draft, no view to build: most agents in a big project have nothing unpublished.
71 if (draft.length === 0) return files;
engine55Issue 6: status no longer builds every agent's view. On abso's log (13,148 entries, 48 agents) status went from about 330 ms to 1 ms median (30 ms max) in Node.
- markedCollisions skips the view when the agent has no marked files (most have none). This was most of the cost.
- draftFiles skips the view when the draft is empty, and Project keeps each agent's draft files under their view key plus the draft, so they're worked out again only when either moves. Overlaps and overlap news use the kept ones too.
- New test (draft-files-kept): status from a warm project equals a cold load after every step, in shared and with two agents in one named draft (Pinch's case). A weaker key fails it.Compare73 for (const id of draft) {
75 for (const run of atom.inserts) files.add(isStartNode(run.parent) ? run.file : view.fileOf(run.parent));
76 for (const line of atom.deletes) files.add(view.fileOf(line));
77 for (const m of atom.moves ?? []) files.add(view.fileOf(m.line));
78 }
79 return files;
80}
82/** Other agents in the agent's space whose unpublished changes or starting note meet `patterns`. */
83export function overlaps(host: OverlapHost, agent: AgentState, patterns: readonly string[]): Overlap[] {
84 if (patterns.length === 0) return [];
85 const peers = [...host.agents.values()]
86 .filter((other) => other !== agent && other.space === agent.space)
87 .map((other) => ({
88 name: other.name,
engine55Issue 6: status no longer builds every agent's view. On abso's log (13,148 entries, 48 agents) status went from about 330 ms to 1 ms median (30 ms max) in Node.
- markedCollisions skips the view when the agent has no marked files (most have none). This was most of the cost.
- draftFiles skips the view when the draft is empty, and Project keeps each agent's draft files under their view key plus the draft, so they're worked out again only when either moves. Overlaps and overlap news use the kept ones too.
- New test (draft-files-kept): status from a warm project equals a cold load after every step, in shared and with two agents in one named draft (Pinch's case). A weaker key fails it.Compare89 files: host.draftFiles(other),
init0Start the project90 changesIn: (file: string) => host.draft(other).filter((id) => host.graph.filesOf(id).includes(file)).length,
91 note: host.liveNote(other),
92 }));
93 return overlapsOf(peers, patterns);
94}
96/**
97 * News the first time a draft touches a file someone else in its space has
infra-split37Comments and test names give each reason in plain words, without naming who raised it
Notes like "(#37, Builder 5)" or "(AVCS - Security)" become "(#37)" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.Compare98 * unpublished changes in, or a starting note on (#37): one line per file and agent, once per draft. It tells; it never stops
100 */
101export function overlapNews(host: OverlapHost, agent: AgentState, before: ReadonlySet<string>, entries: Entry[]): void {
engine55Issue 6: status no longer builds every agent's view. On abso's log (13,148 entries, 48 agents) status went from about 330 ms to 1 ms median (30 ms max) in Node.
- markedCollisions skips the view when the agent has no marked files (most have none). This was most of the cost.
- draftFiles skips the view when the draft is empty, and Project keeps each agent's draft files under their view key plus the draft, so they're worked out again only when either moves. Overlaps and overlap news use the kept ones too.
- New test (draft-files-kept): status from a warm project equals a cold load after every step, in shared and with two agents in one named draft (Pinch's case). A weaker key fails it.Compare102 const now = host.draftFiles(agent);
104 if (fresh.length === 0) return;
105 host.queueNews(agent, overlapItems(host.draft(agent)[0] ?? "", overlaps(host, agent, fresh)), entries);
106}