{"file":"client/src/drafts.ts","version":318,"total":172,"from":1,"to":172,"lines":[{"n":1,"text":"// abso switch, land and draft-sync: named drafts (#10, #22).","atom":"a0","author":"init","version":0},{"n":2,"text":"//","atom":"a0","author":"init","version":0},{"n":3,"text":"// Each agent has its own unpublished draft in each space (shared, or a named","atom":"a0","author":"init","version":0},{"n":4,"text":"// draft). Switching parks the draft on the server in the space it leaves and","atom":"a0","author":"init","version":0},{"n":5,"text":"// brings back what was parked in the space it moves to, so nothing needs","atom":"a0","author":"init","version":0},{"n":6,"text":"// publishing first. `switch -c <name>` instead takes the current unpublished","atom":"a0","author":"init","version":0},{"n":7,"text":"// changes into a new named draft.","atom":"a0","author":"init","version":0},{"n":8,"text":"","atom":"a0","author":"init","version":0},{"n":9,"text":"import { readFileSync } from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":10,"text":"import { bool, type Parsed, str, UsageError } from \"./args.ts\";","atom":"a0","author":"init","version":0},{"n":11,"text":"import {","atom":"a0","author":"init","version":0},{"n":12,"text":"\tapplyAnswer,","atom":"a0","author":"init","version":0},{"n":13,"text":"\tchangedFilesText,","atom":"a0","author":"init","version":0},{"n":14,"text":"\tcollisionsHeading,","atom":"a0","author":"init","version":0},{"n":15,"text":"\tcollisionText,","atom":"a0","author":"init","version":0},{"n":16,"text":"\ttype Env,","atom":"a0","author":"init","version":0},{"n":17,"text":"\tEXIT,","atom":"a0","author":"init","version":0},{"n":18,"text":"\tmergedLinesText,","atom":"a0","author":"init","version":0},{"n":19,"text":"\ttype Output,","atom":"a0","author":"init","version":0},{"n":20,"text":"\topen,","atom":"a0","author":"init","version":0},{"n":21,"text":"\tplural,","atom":"a0","author":"init","version":0},{"n":22,"text":"\tpullAnswer,","atom":"a2757","author":"pinch","version":280},{"n":23,"text":"\tpullWritten,","atom":"a2757","author":"pinch","version":280},{"n":24,"text":"\trecordedFirst,","atom":"a0","author":"init","version":0},{"n":25,"text":"\trecordFolder,","atom":"a0","author":"init","version":0},{"n":26,"text":"} from \"./commands.ts\";","atom":"a0","author":"init","version":0},{"n":27,"text":"import { isLocalOnly } from \"./core.ts\";","atom":"a0","author":"init","version":0},{"n":28,"text":"import { absolute } from \"./folder.ts\";","atom":"a0","author":"init","version":0},{"n":29,"text":"import { refusedText } from \"./safety.ts\";","atom":"a0","author":"init","version":0},{"n":30,"text":"","atom":"a0","author":"init","version":0},{"n":31,"text":"/** The name that means shared, not a named draft. */","atom":"a0","author":"init","version":0},{"n":32,"text":"const SHARED = \"shared\";","atom":"a0","author":"init","version":0},{"n":33,"text":"","atom":"a0","author":"init","version":0},{"n":34,"text":"function draftName(raw: string): string {","atom":"a0","author":"init","version":0},{"n":35,"text":"\tif (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(raw))","atom":"a0","author":"init","version":0},{"n":36,"text":"\t\tthrow new UsageError(`draft names are letters, digits, dot, dash and underscore (got ${JSON.stringify(raw)})`);","atom":"a0","author":"init","version":0},{"n":37,"text":"\treturn raw;","atom":"a0","author":"init","version":0},{"n":38,"text":"}","atom":"a0","author":"init","version":0},{"n":39,"text":"","atom":"a0","author":"init","version":0},{"n":40,"text":"export async function runSwitch(args: Parsed, env: Env): Promise<Output> {","atom":"a0","author":"init","version":0},{"n":41,"text":"\tif (args.positionals.length !== 1)","atom":"a0","author":"init","version":0},{"n":42,"text":"\t\tthrow new UsageError(","atom":"a0","author":"init","version":0},{"n":43,"text":"\t\t\t\"switch takes one name: abso switch <draft>, abso switch -c <new draft>, or abso switch shared\",","atom":"a0","author":"init","version":0},{"n":44,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":45,"text":"\tconst raw = args.positionals[0]!;","atom":"a0","author":"init","version":0},{"n":46,"text":"\tconst carry = bool(args, \"carry\");","atom":"a0","author":"init","version":0},{"n":47,"text":"\tconst name = raw === SHARED ? null : draftName(raw);","atom":"a0","author":"init","version":0},{"n":48,"text":"\tif (carry && name === null)","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\tthrow new UsageError(\"-c starts a new named draft; shared already exists (use: abso switch shared)\");","atom":"a0","author":"init","version":0},{"n":50,"text":"\tconst { root, api } = open(env);","atom":"a0","author":"init","version":0},{"n":51,"text":"\t// Folder-only edits must be on the server first, or the new view would overwrite them instead of parking them.","atom":"a0","author":"init","version":0},{"n":52,"text":"\tconst recorded = await recordFolder(root, api);","atom":"a0","author":"init","version":0},{"n":53,"text":"\t// What the folder held before, for each file the switch or the sync touches, so only the net change is reported.","atom":"a0","author":"init","version":0},{"n":54,"text":"\tconst before = new Map<string, string | null>();","atom":"a0","author":"init","version":0},{"n":55,"text":"\tconst note = (files: Readonly<Record<string, unknown>>): void => {","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\tfor (const rel of Object.keys(files)) if (!before.has(rel)) before.set(rel, onDisk(root, rel));","atom":"a0","author":"init","version":0},{"n":57,"text":"\t};","atom":"a0","author":"init","version":0},{"n":58,"text":"\tconst answer = await api.switchDraft(name, carry);","atom":"a0","author":"init","version":0},{"n":59,"text":"\tnote(answer.files);","atom":"a0","author":"init","version":0},{"n":60,"text":"\tconst switched = await applyAnswer(root, api, answer);","atom":"a0","author":"init","version":0},{"n":61,"text":"\t// The switch brings back the space as it was when parked; sync straight away so the folder shows it as it is now (#22).","atom":"a0","author":"init","version":0},{"n":62,"text":"\tconst syncAnswer = await pullAnswer(root, api);","atom":"a2757","author":"pinch","version":280},{"n":63,"text":"\tnote(syncAnswer.files);","atom":"a0","author":"init","version":0},{"n":64,"text":"\tconst synced = await applyAnswer(root, api, syncAnswer);","atom":"a0","author":"init","version":0},{"n":65,"text":"\tpullWritten(root);","atom":"a2757","author":"pinch","version":280},{"n":66,"text":"\tconst touched = new Set([...switched.written, ...switched.deleted, ...synced.written, ...synced.deleted]);","atom":"a0","author":"init","version":0},{"n":67,"text":"\tconst written: string[] = [];","atom":"a0","author":"init","version":0},{"n":68,"text":"\tconst deleted: string[] = [];","atom":"a0","author":"init","version":0},{"n":69,"text":"\tfor (const rel of [...touched].sort()) {","atom":"a0","author":"init","version":0},{"n":70,"text":"\t\tconst now = onDisk(root, rel);","atom":"a0","author":"init","version":0},{"n":71,"text":"\t\tif (now === before.get(rel)) continue;","atom":"a0","author":"init","version":0},{"n":72,"text":"\t\t(now === null ? deleted : written).push(rel);","atom":"a0","author":"init","version":0},{"n":73,"text":"\t}","atom":"a0","author":"init","version":0},{"n":74,"text":"\tconst where = answer.draft === null ? \"shared\" : `draft ${answer.draft}`;","atom":"a0","author":"init","version":0},{"n":75,"text":"\tconst kept = [...new Set([...switched.kept, ...synced.kept])];","atom":"a0","author":"init","version":0},{"n":76,"text":"\tconst dropped = [...new Set([...switched.dropped, ...synced.dropped])];","atom":"a0","author":"init","version":0},{"n":77,"text":"\tconst collisions = [...switched.collisions, ...synced.collisions];","atom":"a0","author":"init","version":0},{"n":78,"text":"\tconst lines = [","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\t...recordedFirst(recorded),","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\tcarry","atom":"a0","author":"init","version":0},{"n":81,"text":"\t\t\t? `Started ${where}, carrying your unpushed changes into it.`","atom":"a840","author":"rename","version":100},{"n":82,"text":"\t\t\t: `Switched to ${where}. Your unpushed changes where you were are parked there, and come back when you switch back.`,","atom":"a840","author":"rename","version":100},{"n":83,"text":"\t\t`It is at version ${synced.version}. ${written.length + deleted.length === 0 ? \"No files changed in this folder.\" : `${plural(written.length, \"file\")} updated, ${deleted.length} deleted:`}`,","atom":"a0","author":"init","version":0},{"n":84,"text":"\t\t...changedFilesText(\"switch\", written, deleted, [], bool(args, \"verbose\")),","atom":"a0","author":"init","version":0},{"n":85,"text":"\t\t...refusedText([...switched.refused, ...synced.refused]),","atom":"a0","author":"init","version":0},{"n":86,"text":"\t\t...mergedLinesText([...switched.merged, ...synced.merged]),","atom":"a0","author":"init","version":0},{"n":87,"text":"\t\t...(kept.length > 0 ? [`Left alone because they changed while switching (run abso pull): ${kept.join(\", \")}`] : []),","atom":"a840","author":"rename","version":100},{"n":88,"text":"\t\t...(dropped.length > 0 ? [`Dropped from your draft, kept on disk (these stay local): ${dropped.join(\", \")}`] : []),","atom":"a0","author":"init","version":0},{"n":89,"text":"\t\t...(collisions.length > 0 ? [collisionsHeading(collisions), ...collisions.map(collisionText)] : []),","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\t...(answer.draft !== null","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\t\t? ['Push into this draft with abso push; land it in shared with abso land -m \"why\".']","atom":"a840","author":"rename","version":100},{"n":92,"text":"\t\t\t: []),","atom":"a0","author":"init","version":0},{"n":93,"text":"\t];","atom":"a0","author":"init","version":0},{"n":94,"text":"\treturn {","atom":"a0","author":"init","version":0},{"n":95,"text":"\t\ttext: lines.join(\"\\n\"),","atom":"a0","author":"init","version":0},{"n":96,"text":"\t\tjson: {","atom":"a0","author":"init","version":0},{"n":97,"text":"\t\t\tdraft: answer.draft,","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\t\tversion: synced.version,","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\t\tcarried: carry,","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\t\trecorded: recorded.sent,","atom":"a0","author":"init","version":0},{"n":101,"text":"\t\t\twritten,","atom":"a0","author":"init","version":0},{"n":102,"text":"\t\t\tdeleted,","atom":"a0","author":"init","version":0},{"n":103,"text":"\t\t\tkept,","atom":"a0","author":"init","version":0},{"n":104,"text":"\t\t\tdropped,","atom":"a0","author":"init","version":0},{"n":105,"text":"\t\t\tcollisions,","atom":"a0","author":"init","version":0},{"n":106,"text":"\t\t},","atom":"a0","author":"init","version":0},{"n":107,"text":"\t};","atom":"a0","author":"init","version":0},{"n":108,"text":"}","atom":"a0","author":"init","version":0},{"n":109,"text":"","atom":"a0","author":"init","version":0},{"n":110,"text":"/** A file's bytes as text, or null when there is no file. */","atom":"a0","author":"init","version":0},{"n":111,"text":"function onDisk(root: string, rel: string): string | null {","atom":"a0","author":"init","version":0},{"n":112,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":113,"text":"\t\treturn readFileSync(absolute(root, rel), \"latin1\");","atom":"a0","author":"init","version":0},{"n":114,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":115,"text":"\t\treturn null;","atom":"a0","author":"init","version":0},{"n":116,"text":"\t}","atom":"a0","author":"init","version":0},{"n":117,"text":"}","atom":"a0","author":"init","version":0},{"n":118,"text":"","atom":"a0","author":"init","version":0},{"n":119,"text":"export async function runLand(args: Parsed, env: Env): Promise<Output> {","atom":"a0","author":"init","version":0},{"n":120,"text":"\tconst message = str(args, \"message\");","atom":"a0","author":"init","version":0},{"n":121,"text":"\tif (!message) throw new UsageError('say why with -m \"<message>\"');","atom":"a0","author":"init","version":0},{"n":122,"text":"\tconst { root, api } = open(env);","atom":"a0","author":"init","version":0},{"n":123,"text":"\tconst recorded = await recordFolder(root, api);","atom":"a0","author":"init","version":0},{"n":124,"text":"\tconst answer = await api.land(message);","atom":"a0","author":"init","version":0},{"n":125,"text":"\tconst pre = recordedFirst(recorded);","atom":"a0","author":"init","version":0},{"n":126,"text":"\tif (answer.ok) {","atom":"a0","author":"init","version":0},{"n":127,"text":"\t\tconst what =","atom":"a0","author":"init","version":0},{"n":128,"text":"\t\t\tanswer.changes === 0","atom":"a0","author":"init","version":0},{"n":129,"text":"\t\t\t\t? `Nothing to land: the draft has nothing shared doesn't. Shared is at version ${answer.version}.`","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\t\t\t: `Landed in shared as version ${answer.version}.`;","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\treturn {","atom":"a0","author":"init","version":0},{"n":132,"text":"\t\t\ttext: [...pre, what].join(\"\\n\"),","atom":"a0","author":"init","version":0},{"n":133,"text":"\t\t\tjson: { version: answer.version, changes: answer.changes ?? null, recorded: recorded.sent },","atom":"a0","author":"init","version":0},{"n":134,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":135,"text":"\t}","atom":"a0","author":"init","version":0},{"n":136,"text":"\tconst collisions = (answer.collisions ?? []).filter((c) => !isLocalOnly(c.file));","atom":"a0","author":"init","version":0},{"n":137,"text":"\treturn {","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\texit: EXIT.refused,","atom":"a0","author":"init","version":0},{"n":139,"text":"\t\ttext: [","atom":"a0","author":"init","version":0},{"n":140,"text":"\t\t\t...pre,","atom":"a0","author":"init","version":0},{"n":141,"text":"\t\t\t`Not landed: ${plural(collisions.length, \"collision\")} with work that landed in shared since the draft's base.`,","atom":"a0","author":"init","version":0},{"n":142,"text":"\t\t\t...collisions.map(collisionText),","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\t\t\"Run abso draft-pull to move the draft onto shared, settle those lines in the draft, push, then land again.\",","atom":"a840","author":"rename","version":100},{"n":144,"text":"\t\t].join(\"\\n\"),","atom":"a0","author":"init","version":0},{"n":145,"text":"\t\tjson: { collisions, recorded: recorded.sent },","atom":"a0","author":"init","version":0},{"n":146,"text":"\t};","atom":"a0","author":"init","version":0},{"n":147,"text":"}","atom":"a0","author":"init","version":0},{"n":148,"text":"","atom":"a0","author":"init","version":0},{"n":149,"text":"export async function runDraftSync(_args: Parsed, env: Env): Promise<Output> {","atom":"a0","author":"init","version":0},{"n":150,"text":"\tconst { root, api } = open(env);","atom":"a0","author":"init","version":0},{"n":151,"text":"\tconst moved = await api.draftSync();","atom":"a0","author":"init","version":0},{"n":152,"text":"\t// Bring the moved draft's new view into this folder straight away.","atom":"a0","author":"init","version":0},{"n":153,"text":"\tconst recorded = await recordFolder(root, api);","atom":"a0","author":"init","version":0},{"n":154,"text":"\tconst applied = await applyAnswer(root, api, await pullAnswer(root, api));","atom":"a2757","author":"pinch","version":280},{"n":155,"text":"\tpullWritten(root);","atom":"a2757","author":"pinch","version":280},{"n":156,"text":"\tconst lines = [","atom":"a0","author":"init","version":0},{"n":157,"text":"\t\t`Moved draft ${moved.draft} onto shared version ${moved.sharedBase} (the draft is at version ${moved.version}).`,","atom":"a0","author":"init","version":0},{"n":158,"text":"\t\t...recordedFirst(recorded),","atom":"a0","author":"init","version":0},{"n":159,"text":"\t\tapplied.written.length + applied.deleted.length === 0","atom":"a0","author":"init","version":0},{"n":160,"text":"\t\t\t? \"No files changed in this folder.\"","atom":"a0","author":"init","version":0},{"n":161,"text":"\t\t\t: `${plural(applied.written.length, \"file\")} updated, ${applied.deleted.length} deleted.`,","atom":"a0","author":"init","version":0},{"n":162,"text":"\t\t...refusedText(applied.refused),","atom":"a0","author":"init","version":0},{"n":163,"text":"\t\t...mergedLinesText(applied.merged),","atom":"a0","author":"init","version":0},{"n":164,"text":"\t\t...(applied.collisions.length > 0","atom":"a0","author":"init","version":0},{"n":165,"text":"\t\t\t? [","atom":"a0","author":"init","version":0},{"n":166,"text":"\t\t\t\t\t`${plural(applied.collisions.length, \"collision\")} to settle in the draft before it lands:`,","atom":"a0","author":"init","version":0},{"n":167,"text":"\t\t\t\t\t...applied.collisions.map(collisionText),","atom":"a0","author":"init","version":0},{"n":168,"text":"\t\t\t\t]","atom":"a0","author":"init","version":0},{"n":169,"text":"\t\t\t: []),","atom":"a0","author":"init","version":0},{"n":170,"text":"\t];","atom":"a0","author":"init","version":0},{"n":171,"text":"\treturn { text: lines.join(\"\\n\"), json: { ...applied, ...moved } };","atom":"a0","author":"init","version":0},{"n":172,"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":"a840","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":"a2757","author":"pinch","message":"","time":1792113682010,"timeIso":"2026-10-16T01:21:22.010Z","publish":{"draft":null,"version":280,"agent":"pinch","message":"A pull whose answer never arrives no longer leaves the folder behind\n\nThe server moves the agent's base when it answers a pull, and later pulls send only what changed since that base. When the answer was lost (a timeout on a slow server), the files it carried were never written, and every later pull, status, restore and export agreed the folder was current.\n\nNow the client notes a pull in .abso/pulling.json before asking, and takes the note away once the answer is written. While the note is there, abso status says a pull didn't finish, and the next pull asks for every file in the view (as pull --full does) and writes the ones that differ, keeping work done in the folder meanwhile, as every pull does. follow, draft switching and draft-pull pull the same way. A server without full pulls gets a plain pull.\n\nTests: client/test/lost-pull.test.ts (a fake server that carries out a pull and drops its answer), plus held-push, join-signed-out and record-batches: 19 pass. tsc and Biome clean.","time":1792113718029,"timeIso":"2026-10-16T01:21:58.029Z"}}]}