diff --git a/extensions/image-paste/index.ts b/extensions/image-paste/index.ts index 214da4224..b04454fa1 100644 --- a/extensions/image-paste/index.ts +++ b/extensions/image-paste/index.ts @@ -531,6 +531,7 @@ export default function imagePaste( ); pi.on("session_start", (_event, ctx) => { + attachments.clearDraft(); installImagePasteEditor(pi, ctx, attachments); }); diff --git a/tests/extensions/image-paste/index.test.ts b/tests/extensions/image-paste/index.test.ts index 8c509c8ac..1c19ba996 100644 --- a/tests/extensions/image-paste/index.test.ts +++ b/tests/extensions/image-paste/index.test.ts @@ -4,10 +4,15 @@ import { existsSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import test from "node:test"; -import type { KeybindingsManager } from "@earendil-works/pi-coding-agent"; +import type { + ExtensionAPI, + ExtensionContext, + KeybindingsManager, +} from "@earendil-works/pi-coding-agent"; import type { EditorComponent } from "@earendil-works/pi-tui"; import { collapseClipboardPaths, + default as imagePaste, ImageAttachmentEditor, ImageAttachmentStore, } from "../../../extensions/image-paste/index.ts"; @@ -107,6 +112,27 @@ function harness() { return { store, base, editor, submitted }; } +test("new sessions do not retain prior image placeholder mappings", () => { + const store = new ImageAttachmentStore(); + const path = temporaryImage("png", "previous-session"); + store.attachClipboardPath(path, ""); + const hooks = new Map< + string, + (event: unknown, ctx: ExtensionContext) => void + >(); + const api = { + on(name: string, handler: (event: unknown, ctx: ExtensionContext) => void) { + hooks.set(name, handler); + }, + registerMarkdownTransformer() {}, + } as unknown as ExtensionAPI; + + imagePaste(api, store); + hooks.get("session_start")?.({}, { mode: "rpc" } as ExtensionContext); + + assert.equal(store.expandPlaceholders("[Image #1]"), "[Image #1]"); +}); + /** * Mirrors Pi's InteractiveMode.handleFollowUp(): it reads the text through * getExpandedText() *before* choosing a delivery path, and only the idle branch