Changesets · Branches · Tags · Compare
| Changeset | 78eef004d40052bbea7c48dfb37c091ea11f5a858cd13fac9772e0ce71f1316d |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-31 18:59 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-31 18:59 -07:00 |
| Parents | cc1185a06b7b |
3 files changed
modified extensions/cli/src/ui/TextBuffer.ts +29 −0
| @@ -2,6 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | export const COLLAPSE_SIZE = 800; // Characters threshold for collapsing pasted content |
| 4 | 4 | export const RAPID_INPUT_THRESHOLD = 200; // Minimum characters to trigger rapid input detection |
| 5 | +export const MAX_IMAGE_SIZE = 10 * 1024 * 1024; // 10MB per image | |
| 6 | +export const MAX_IMAGE_COUNT = 20; // Maximum number of images | |
| 7 | +export const MAX_TOTAL_IMAGE_MEMORY = 50 * 1024 * 1024; // 50MB total image memory | |
| 5 | 8 | |
| 6 | 9 | export class TextBuffer { |
| 7 | 10 | private _text: string = ""; |
| @@ -195,6 +198,32 @@ | ||
| 195 | 198 | |
| 196 | 199 | // Add image to buffer and return placeholder |
| 197 | 200 | addImage(imageBuffer: Buffer): string { |
| 201 | + // Validate image size | |
| 202 | + if (imageBuffer.length > MAX_IMAGE_SIZE) { | |
| 203 | + throw new Error( | |
| 204 | + `Image size ${(imageBuffer.length / 1024 / 1024).toFixed(1)}MB exceeds maximum allowed size of ${MAX_IMAGE_SIZE / 1024 / 1024}MB`, | |
| 205 | + ); | |
| 206 | + } | |
| 207 | + | |
| 208 | + // Check image count limit | |
| 209 | + if (this._imageMap.size >= MAX_IMAGE_COUNT) { | |
| 210 | + throw new Error(`Cannot add more than ${MAX_IMAGE_COUNT} images`); | |
| 211 | + } | |
| 212 | + | |
| 213 | + // Check total memory usage | |
| 214 | + const currentMemoryUsage = Array.from(this._imageMap.values()).reduce( | |
| 215 | + (total, buffer) => total + buffer.length, | |
| 216 | + 0, | |
| 217 | + ); | |
| 218 | + | |
| 219 | + if (currentMemoryUsage + imageBuffer.length > MAX_TOTAL_IMAGE_MEMORY) { | |
| 220 | + const currentUsageMB = (currentMemoryUsage / 1024 / 1024).toFixed(1); | |
| 221 | + const maxUsageMB = MAX_TOTAL_IMAGE_MEMORY / 1024 / 1024; | |
| 222 | + throw new Error( | |
| 223 | + `Adding image would exceed total memory limit. Current usage: ${currentUsageMB}MB, Maximum: ${maxUsageMB}MB`, | |
| 224 | + ); | |
| 225 | + } | |
| 226 | + | |
| 198 | 227 | this._imageCounter++; |
| 199 | 228 | const placeholder = `[Image #${this._imageCounter}]`; |
| 200 | 229 | this._imageMap.set(placeholder, imageBuffer); |
modified extensions/cli/src/ui/components/MemoizedMessage.formatDisplay.test.tsx +4 −3
| @@ -126,9 +126,10 @@ | ||
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | 128 | const output = lastFrame(); |
| 129 | - expect(output).toContain("Start"); | |
| 130 | - expect(output).toContain("end"); | |
| 131 | - expect(output).toContain('{"type":"unknown","data":{"some":"data"}}'); | |
| 129 | + // Verify whitespace preservation - trailing space after "Start" and leading space before "end" | |
| 130 | + expect(output).toContain( | |
| 131 | + 'Start {"type":"unknown","data":{"some":"data"}} end', | |
| 132 | + ); | |
| 132 | 133 | }); |
| 133 | 134 | |
| 134 | 135 | it("should handle non-array non-string content by converting to JSON", () => { |
modified extensions/cli/src/ui/hooks/useUserInput.ts +1 −1
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 | } else if (platform === "win32") { |
| 84 | 84 | // Windows: Use PowerShell to save clipboard image |
| 85 | 85 | await execAsync( |
| 86 | - `powershell -command "Get-Clipboard -Format Image | Set-Content -Path '${tempImagePath}' -Encoding Byte"`, | |
| 86 | + `powershell -command "$image = Get-Clipboard -Format Image; if ($image) { $image.Save('${tempImagePath}') }"`, | |
| 87 | 87 | ); |
| 88 | 88 | } else if (platform === "linux") { |
| 89 | 89 | // Linux: Use xclip to save clipboard image |