Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/image-paste/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ export default function imagePaste(
);

pi.on("session_start", (_event, ctx) => {
attachments.clearDraft();
installImagePasteEditor(pi, ctx, attachments);
});

Expand Down
28 changes: 27 additions & 1 deletion tests/extensions/image-paste/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
Loading