Add consistent, configurable image placeholders (#442)

* Add consistent, configurable image placeholders

* Kill the placeholders
This commit is contained in:
Armin Ronacher 2026-01-04 18:12:55 +01:00 committed by GitHub
parent 36e774282d
commit 5b95ccf830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 26 deletions

View file

@ -143,10 +143,6 @@ export class InteractiveMode {
// Custom tools for custom rendering
private customTools: Map<string, LoadedCustomTool>;
// Clipboard image tracking: imageId -> temp file path
private clipboardImages = new Map<number, string>();
private clipboardImageCounter = 0;
// Convenience accessors
private get agent() {
return this.session.agent;
@ -847,35 +843,19 @@ export class InteractiveMode {
}
// Write to temp file
const imageId = ++this.clipboardImageCounter;
const tmpDir = os.tmpdir();
const fileName = `pi-clipboard-${crypto.randomUUID()}.png`;
const filePath = path.join(tmpDir, fileName);
fs.writeFileSync(filePath, Buffer.from(imageData));
// Store mapping and insert marker
this.clipboardImages.set(imageId, filePath);
this.editor.insertTextAtCursor(`[image #${imageId}]`);
// Insert file path directly
this.editor.insertTextAtCursor(filePath);
this.ui.requestRender();
} catch {
// Silently ignore clipboard errors (may not have permission, etc.)
}
}
/**
* Replace [image #N] markers with actual file paths and clear the image map.
*/
private replaceImageMarkers(text: string): string {
let result = text;
for (const [imageId, filePath] of this.clipboardImages) {
const marker = `[image #${imageId}]`;
result = result.replace(marker, filePath);
}
this.clipboardImages.clear();
this.clipboardImageCounter = 0;
return result;
}
private setupEditorSubmitHandler(): void {
this.editor.onSubmit = async (text: string) => {
text = text.trim();
@ -1003,9 +983,6 @@ export class InteractiveMode {
}
// If streaming, use prompt() with steer behavior
// Replace image markers with actual file paths
text = this.replaceImageMarkers(text);
// This handles hook commands (execute immediately), slash command expansion, and queueing
if (this.session.isStreaming) {
this.editor.addToHistory(text);