graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Preserve edited clipboard exports during draft cleanup
justrach071c8c1de52b
diff --git a/apps/native/electron/attachment-lifetime-frontend.cjs b/apps/native/electron/attachment-lifetime-frontend.cjsindex 55774b29..848fa987 100644--- a/apps/native/electron/attachment-lifetime-frontend.cjs+++ b/apps/native/electron/attachment-lifetime-frontend.cjs@@ -32,6 +32,12 @@ async function runAttachments({win,origin,temp,output,requests,workspace,send,clawait click('[aria-label="Close image preview"]');await click('[aria-label="Remove remove.png"]');await until(()=>!fs.existsSync(removed),'discarded paste file cleanup');+ const edited=await paste('edited.png');+ const changed=fs.readFileSync(edited);changed[changed.length-1]^=1;fs.writeFileSync(edited,changed);+ await click('[aria-label="Remove edited.png"]');+ await until(()=>js(`!document.querySelector('[aria-label="Remove edited.png"]')`),'edited attachment removed from draft');+ await fetch(origin+'/api/attach',{method:'DELETE',headers:{'content-type':'application/json'},body:JSON.stringify({paths:[edited]})});+ assert.deepEqual(fs.readFileSync(edited),changed,'Discard must preserve an in-place edit to exported pixels');await send('Describe the pasted image in one sentence.');await until(()=>js(`document.body.textContent.includes('The pasted image was received.') && !document.querySelector('article[aria-busy="true"]')`),'real image turn completion',25000);const calls=JSON.parse(fs.readFileSync(requests,'utf8'));@@ -92,6 +98,7 @@ async function runAttachments({win,origin,temp,output,requests,workspace,send,classert.ok(fs.existsSync(archivedRotated),'Deleting the original must preserve the archived rotated transcript');assert.ok(fs.existsSync(aged),'An independent archived replay still needs the original image pixels');report.passed.push('real sidebar delete retires its writer and removes checkpoint plus both transcript generations; production archive preserves all replay files');+ report.passed.push('edited clipboard export remains on disk after its draft chip is removed');report.passed.push('synthetic clipboard event through real GUI paste/upload/ACP: aged draft survives, removed and closed drafts release files, sent PNG reaches model and stays available for replay');fs.writeFileSync(path.join(output,'attachment-requests.json'),JSON.stringify(calls,null,2));}diff --git a/apps/native/lib/attachment-store.test.ts b/apps/native/lib/attachment-store.test.tsindex 64d396f8..86466224 100644--- a/apps/native/lib/attachment-store.test.ts+++ b/apps/native/lib/attachment-store.test.ts@@ -60,3 +60,12 @@ test("a failed ownership-record write removes its newly created upload", () => {expect(existsSync(existing)).toBe(true);} finally { chmodSync(records, 0o700); }});++test("an in-place edit is preserved even when the inode and byte count match", () => {+ const {store} = fixture(12345, () => false);+ const edited = store.create("edited.png", new Uint8Array([1,2,3]));+ writeFileSync(edited, new Uint8Array([4,5,6]));+ expect(store.discard(edited)).toBe(false);+ expect(store.sweep()).toBe(0);+ expect(existsSync(edited)).toBe(true);+});diff --git a/apps/native/lib/attachment-store.ts b/apps/native/lib/attachment-store.tsindex 1d709352..e52f8a84 100644--- a/apps/native/lib/attachment-store.ts+++ b/apps/native/lib/attachment-store.ts@@ -1,9 +1,9 @@-import { randomUUID } from "node:crypto";+import { createHash, randomUUID } from "node:crypto";import { mkdirSync, openSync, closeSync, fstatSync, writeFileSync, readFileSync, renameSync, unlinkSync, lstatSync, opendirSync, type Dir } from "node:fs";import os from "node:os";import path from "node:path";-type Record = { version: 1; name: string; owner: number; retained: boolean; dev: number; ino: number };+type Record = { version: 1; name: string; owner: number; retained: boolean; dev: number; ino: number; size?: number; sha256?: string };export const attachmentDirectory = path.join(os.tmpdir(), "graff-native-attachments");function ownerAlive(pid: number): boolean {try { process.kill(pid, 0); return true; }@@ -34,7 +34,8 @@ export class AttachmentStore {const record = JSON.parse(readFileSync(this.recordPath(name), "utf8")) as Record;const file = lstatSync(path.join(this.directory, name));return record.version === 1 && record.name === name && typeof record.retained === "boolean" && file.isFile() &&- file.dev === record.dev && file.ino === record.ino ? record : null;+ file.dev === record.dev && file.ino === record.ino && file.size === record.size &&+ typeof record.sha256 === "string" ? record : null;} catch { return null; }}create(label: string, bytes: Uint8Array): string {@@ -46,7 +47,7 @@ export class AttachmentStore {const file = fstatSync(descriptor);try {writeFileSync(descriptor, bytes);- this.save({ version: 1, name, owner: this.owner, retained: false, dev: file.dev, ino: file.ino });+ this.save({ version: 1, name, owner: this.owner, retained: false, dev: file.dev, ino: file.ino, size: bytes.byteLength, sha256: createHash("sha256").update(bytes).digest("hex") });} catch (error) {try {const current = lstatSync(target);@@ -73,6 +74,7 @@ export class AttachmentStore {if (path.dirname(target) !== this.directory) return false;const record = this.read(path.basename(target));if (!record || record.retained) return false;+ if (createHash("sha256").update(readFileSync(target)).digest("hex") !== record.sha256) return false;unlinkSync(target);try { unlinkSync(this.recordPath(record.name)); } catch {}return true;diff --git a/docs/adr/0117-clipboard-files-follow-consumer-ownership.md b/docs/adr/0117-clipboard-files-follow-consumer-ownership.mdindex 07796e46..a04d2bc0 100644--- a/docs/adr/0117-clipboard-files-follow-consumer-ownership.md+++ b/docs/adr/0117-clipboard-files-follow-consumer-ownership.md@@ -29,7 +29,9 @@ the handoff and allows prompt recall/retry. Unknown or malformed records andchanged exports are preserved. Unsupported locking or unavailable temporarystorage disables recovery registration rather than granting deletion authority.-The native desktop records upload ownership and file identity. Discarding an+The native desktop records upload ownership, file identity, size and a content digest.+Deletion verifies unchanged bytes; replacing or editing an export never grants+cleanup authority. Older records without content identity remain preserved. Discarding anunsent draft releases its recorded upload; accepting a prompt retains referenceduploads before dispatching to ACP. Sent files remain available for replay.Recovery examines a bounded number of ownership records per upload and removes