{"file":"worker/project/sync.ts","version":318,"total":97,"from":1,"to":97,"lines":[{"n":1,"text":"import { View } from \"../../src/engine/index.ts\";","atom":"a1360","author":"codex-capacity-chair","version":143},{"n":2,"text":"// Move the agent's base to its space's newest version. Writes go through","atom":"a0","author":"init","version":0},{"n":3,"text":"// SyncHost; today the host is Project.","atom":"a0","author":"init","version":0},{"n":4,"text":"","atom":"a0","author":"init","version":0},{"n":5,"text":"import type { AtomId, Graph, ReadView } from \"../../src/engine/index.ts\";","atom":"a1360","author":"codex-capacity-chair","version":143},{"n":6,"text":"import { ProjectError } from \"./project-error.ts\";","atom":"a0","author":"init","version":0},{"n":7,"text":"import type { AgentState, Entry, MergedLine, SyncAnswer } from \"./project-types.ts\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { last, SHARED, type Space } from \"./spaces.ts\";","atom":"a0","author":"init","version":0},{"n":9,"text":"","atom":"a0","author":"init","version":0},{"n":10,"text":"/** What a sync needs from a project. */","atom":"a0","author":"init","version":0},{"n":11,"text":"export interface SyncHost {","atom":"a0","author":"init","version":0},{"n":12,"text":"\treadonly graph: Graph;","atom":"a0","author":"init","version":0},{"n":13,"text":"\treadonly labels: ReadonlyMap<string, readonly number[]>;","atom":"a0","author":"init","version":0},{"n":14,"text":"\tagent(name: string, entries: Entry[]): AgentState;","atom":"a0","author":"init","version":0},{"n":15,"text":"\tspaceOf(agent: AgentState): Space;","atom":"a0","author":"init","version":0},{"n":16,"text":"\tagentView(agent: AgentState): ReadView;","atom":"a1360","author":"codex-capacity-chair","version":143},{"n":17,"text":"\tcaptureAgentView?(agent: AgentState): () => ReadView;","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":18,"text":"\tat(space: Space, version: number): ReadonlySet<AtomId>;","atom":"a0","author":"init","version":0},{"n":19,"text":"\tdraft(agent: AgentState): AtomId[];","atom":"a0","author":"init","version":0},{"n":20,"text":"\tstrandedFiles(draft: readonly AtomId[], set: ReadonlySet<AtomId>): string[];","atom":"a0","author":"init","version":0},{"n":21,"text":"\tapply(entry: Entry): void;","atom":"a0","author":"init","version":0},{"n":22,"text":"\tflush(entries: Entry[]): void;","atom":"a0","author":"init","version":0},{"n":23,"text":"\tmergeIdentical(","atom":"a0","author":"init","version":0},{"n":24,"text":"\t\tagent: AgentState,","atom":"a0","author":"init","version":0},{"n":25,"text":"\t\tbefore: ReadView,","atom":"a1360","author":"codex-capacity-chair","version":143},{"n":26,"text":"\t\toldBase: ReadonlySet<AtomId>,","atom":"a0","author":"init","version":0},{"n":27,"text":"\t\toldVersion: number,","atom":"a0","author":"init","version":0},{"n":28,"text":"\t\ttime: number,","atom":"a0","author":"init","version":0},{"n":29,"text":"\t\tentries: Entry[],","atom":"a0","author":"init","version":0},{"n":30,"text":"\t): MergedLine[];","atom":"a0","author":"init","version":0},{"n":31,"text":"\tchangesSince(agent: AgentState, before: ReadView): SyncAnswer;","atom":"a1360","author":"codex-capacity-chair","version":143},{"n":32,"text":"}","atom":"a0","author":"init","version":0},{"n":33,"text":"","atom":"a0","author":"init","version":0},{"n":34,"text":"/**","atom":"a0","author":"init","version":0},{"n":35,"text":" * Move the agent's base to its space's newest version. Returns every file","atom":"a0","author":"init","version":0},{"n":36,"text":" * whose text in its view changes (null when it's gone), and the collisions","atom":"a0","author":"init","version":0},{"n":37,"text":" * it now has to settle. A first sync returns every file (that's how a","atom":"a0","author":"init","version":0},{"n":38,"text":" * folder joins).","atom":"a0","author":"init","version":0},{"n":39,"text":" */","atom":"a0","author":"init","version":0},{"n":40,"text":"export function sync(host: SyncHost, agentName: string, options: { label?: string; full?: boolean } = {}): SyncAnswer {","atom":"a0","author":"init","version":0},{"n":41,"text":"\tconst entries: Entry[] = [];","atom":"a0","author":"init","version":0},{"n":42,"text":"\tconst agent = host.agent(agentName, entries);","atom":"a0","author":"init","version":0},{"n":43,"text":"\tconst space = host.spaceOf(agent);","atom":"a0","author":"init","version":0},{"n":44,"text":"\tlet target = last(space);","atom":"a0","author":"init","version":0},{"n":45,"text":"\tif (options.label !== undefined) {","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\t// Follow a label (#10): the newest version of shared that carries it.","atom":"a0","author":"init","version":0},{"n":47,"text":"\t\tif (space.name !== SHARED)","atom":"a0","author":"init","version":0},{"n":48,"text":"\t\t\tthrow new ProjectError(\"bad-request\", \"labels mark versions of shared; switch to shared to follow one\");","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\tconst versions = host.labels.get(options.label);","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\tif (!versions)","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\t\tthrow new ProjectError(\"bad-request\", `no version of shared has the label ${JSON.stringify(options.label)}`);","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\ttarget = versions[versions.length - 1]!;","atom":"a0","author":"init","version":0},{"n":53,"text":"\t}","atom":"a0","author":"init","version":0},{"n":54,"text":"\tconst reopenBefore = agent.synced ? host.captureAgentView?.(agent) : undefined;","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":55,"text":"\tconst before = agent.synced ? host.agentView(agent) : new View(host.graph, []);","atom":"a0","author":"init","version":0},{"n":56,"text":"\tconst set = host.at(space, target);","atom":"a0","author":"init","version":0},{"n":57,"text":"\tconst stranded = host.strandedFiles(host.draft(agent), set);","atom":"a0","author":"init","version":0},{"n":58,"text":"\tif (stranded.length > 0) {","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\thost.flush(entries);","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\tthrow new ProjectError(","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\t\"conflict\",","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t\ttarget === last(space)","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t\t\t? `your unpushed changes to ${stranded.join(\", \")} build on lines a drop took out of shared; ` +","atom":"a879","author":"rename","version":100},{"n":64,"text":"\t\t\t\t\t\t`restore those files (abso restore ${stranded.join(\" \")}) and pull again`","atom":"a879","author":"rename","version":100},{"n":65,"text":"\t\t\t\t: `your unpushed changes to ${stranded.join(\", \")} build on lines version ${target} doesn't have yet; ` +","atom":"a879","author":"rename","version":100},{"n":66,"text":"\t\t\t\t\t\t`push or restore them before following label ${options.label}`,","atom":"a879","author":"rename","version":100},{"n":67,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":68,"text":"\t}","atom":"a0","author":"init","version":0},{"n":69,"text":"\t// Moving back to a labeled version: the agent's own newer published work must not build on what that version lacks.","atom":"a0","author":"init","version":0},{"n":70,"text":"\tconst mineAfter = agent.mine.filter((id) => !set.has(id));","atom":"a0","author":"init","version":0},{"n":71,"text":"\tconst lacking = host.strandedFiles(mineAfter, set);","atom":"a0","author":"init","version":0},{"n":72,"text":"\tif (lacking.length > 0) {","atom":"a0","author":"init","version":0},{"n":73,"text":"\t\thost.flush(entries);","atom":"a0","author":"init","version":0},{"n":74,"text":"\t\tthrow new ProjectError(","atom":"a0","author":"init","version":0},{"n":75,"text":"\t\t\t\"conflict\",","atom":"a0","author":"init","version":0},{"n":76,"text":"\t\t\t`your pushed changes to ${lacking.join(\", \")} build on versions after ${target}, so you can't move back to it`,","atom":"a879","author":"rename","version":100},{"n":77,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":78,"text":"\t}","atom":"a0","author":"init","version":0},{"n":79,"text":"\tconst oldBase = host.at(space, agent.base);","atom":"a0","author":"init","version":0},{"n":80,"text":"\tconst oldVersion = agent.base;","atom":"a0","author":"init","version":0},{"n":81,"text":"\tentries.push({ type: \"sync\", agent: agent.name, version: target });","atom":"a0","author":"init","version":0},{"n":82,"text":"\thost.apply(entries[entries.length - 1]!);","atom":"a0","author":"init","version":0},{"n":83,"text":"\t// News about versions the agent has now synced past is moot: the sync answer lists what's still open (#37).","atom":"a0","author":"init","version":0},{"n":84,"text":"\tif (agent.news.some((t) => !t.startsWith(\"Announcement from \"))) {","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":85,"text":"\t\tconst heard: Entry = { type: \"heard\", agent: agent.name, stale: true };","atom":"a0","author":"init","version":0},{"n":86,"text":"\t\tentries.push(heard);","atom":"a0","author":"init","version":0},{"n":87,"text":"\t\thost.apply(heard);","atom":"a0","author":"init","version":0},{"n":88,"text":"\t}","atom":"a0","author":"init","version":0},{"n":89,"text":"\tconst merged = host.mergeIdentical(agent, before, oldBase, oldVersion, Date.now(), entries);","atom":"a0","author":"init","version":0},{"n":90,"text":"\t// full (#37, a partial join): every file in the view, as for a first sync, whatever the folder had.","atom":"a468","author":"trials","version":51},{"n":91,"text":"\tconst answer = host.changesSince(","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":92,"text":"\t\tagent,","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":93,"text":"\t\toptions.full ? new View(host.graph, []) : reopenBefore ? reopenBefore() : before,","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":94,"text":"\t);","atom":"a1784","author":"codex-capacity-chair","version":163},{"n":95,"text":"\thost.flush(entries);","atom":"a0","author":"init","version":0},{"n":96,"text":"\treturn merged.length > 0 ? { ...answer, merged } : answer;","atom":"a0","author":"init","version":0},{"n":97,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a468","author":"trials","message":"","time":1791580983829,"timeIso":"2026-10-09T21:23:03.829Z","publish":{"draft":null,"version":51,"agent":"trials","message":"Drop a seat name from notes on who reported things\n\nNine comments and test names named the person who reported a #37 case. The notes keep the case and drop the name. Only comments and test names change.","time":1791581042507,"timeIso":"2026-10-09T21:24:02.507Z"}},{"atom":"a879","author":"rename","message":"","time":1791659799126,"timeIso":"2026-10-10T19:16:39.126Z","publish":{"draft":null,"version":100,"agent":"rename","message":"abso publish is now abso push, abso sync is now abso pull (abso 427)\n\nCommands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; \"shared\" stays the noun (\"Pushed version N\"). No aliases, no notices. A queued push that was \"pulled\" is now \"turned back\", so pull means one thing.\n\npush -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch.\n\nKept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.","time":1791659833853,"timeIso":"2026-10-10T19:17:13.853Z"}},{"atom":"a1360","author":"codex-capacity-chair","message":"","time":1791854964720,"timeIso":"2026-10-13T01:29:24.720Z","publish":{"draft":null,"version":143,"agent":"codex-capacity-chair","message":"Add inactive disk projection provider and verified transactional readers (#16)","time":1791855032023,"timeIso":"2026-10-13T01:30:32.023Z"}},{"atom":"a1784","author":"codex-capacity-chair","message":"","time":1791948048631,"timeIso":"2026-10-14T03:20:48.631Z","publish":{"draft":null,"version":163,"agent":"codex-capacity-chair","message":"Integrate reviewed disk-backed operations, queue and bounded read caches","time":1791949753900,"timeIso":"2026-10-14T03:49:13.900Z"}}]}