@selesai/code 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ import { isInstallTelemetryEnabled } from "../../core/telemetry.js";
26
26
  import { hasTrustRequiringProjectResources, ProjectTrustStore } from "../../core/trust-manager.js";
27
27
  import { getChangelogPath, getNewEntries, normalizeChangelogLinks, parseChangelog } from "../../utils/changelog.js";
28
28
  import { copyToClipboard } from "../../utils/clipboard.js";
29
- import { readClipboardImage } from "../../utils/clipboard-image.js";
29
+ import { extensionForImageMimeType, readClipboardImage } from "../../utils/clipboard-image.js";
30
30
  import { parseGitUrl } from "../../utils/git.js";
31
31
  import { formatDimensionNote, resizeImage } from "../../utils/image-resize.js";
32
32
  import { getCwdRelativePath } from "../../utils/paths.js";
@@ -1995,23 +1995,35 @@ export class InteractiveMode {
1995
1995
  try {
1996
1996
  const image = await readClipboardImage();
1997
1997
  if (!image) {
1998
+ this.showWarning("No image found in clipboard");
1998
1999
  return;
1999
2000
  }
2001
+ const tmpDir = os.tmpdir();
2002
+ const ext = extensionForImageMimeType(image.mimeType) ?? "png";
2003
+ const fileName = `pi-clipboard-${Date.now()}-${this.pendingInputImages.length + 1}.${ext}`;
2004
+ const filePath = path.join(tmpDir, fileName);
2005
+ fs.writeFileSync(filePath, Buffer.from(image.bytes));
2000
2006
  let attachment;
2001
2007
  let dimensionNote;
2002
2008
  const autoResizeImages = this.settingsManager.getImageAutoResize();
2003
2009
  if (autoResizeImages) {
2004
- const resized = await resizeImage(image.bytes, image.mimeType);
2010
+ const resized = await resizeImage(image.bytes, image.mimeType).catch(() => null);
2005
2011
  if (!resized) {
2006
- this.showWarning("Clipboard image could not be resized below the inline image size limit.");
2007
- return;
2012
+ this.showWarning("Clipboard image attached without resize");
2013
+ attachment = {
2014
+ type: "image",
2015
+ mimeType: image.mimeType,
2016
+ data: Buffer.from(image.bytes).toString("base64"),
2017
+ };
2018
+ }
2019
+ else {
2020
+ dimensionNote = formatDimensionNote(resized);
2021
+ attachment = {
2022
+ type: "image",
2023
+ mimeType: resized.mimeType,
2024
+ data: resized.data,
2025
+ };
2008
2026
  }
2009
- dimensionNote = formatDimensionNote(resized);
2010
- attachment = {
2011
- type: "image",
2012
- mimeType: resized.mimeType,
2013
- data: resized.data,
2014
- };
2015
2027
  }
2016
2028
  else {
2017
2029
  attachment = {
@@ -2021,14 +2033,12 @@ export class InteractiveMode {
2021
2033
  };
2022
2034
  }
2023
2035
  this.pendingInputImages.push(attachment);
2024
- const label = dimensionNote
2025
- ? `[clipboard image ${this.pendingInputImages.length}: ${dimensionNote}]`
2026
- : `[clipboard image ${this.pendingInputImages.length}]`;
2036
+ const label = dimensionNote ? `${filePath} ${dimensionNote}` : filePath;
2027
2037
  this.editor.insertTextAtCursor?.(label);
2028
2038
  this.ui.requestRender();
2029
2039
  }
2030
- catch {
2031
- // Silently ignore clipboard errors (may not have permission, etc.)
2040
+ catch (error) {
2041
+ this.showWarning(`Failed to paste image: ${error instanceof Error ? error.message : String(error)}`);
2032
2042
  }
2033
2043
  }
2034
2044
  consumePendingInputImages() {