Elffuss BraidHub

kikocis/continue public

fix: address feedback
Changeset78eef004d40052bbea7c48dfb37c091ea11f5a858cd13fac9772e0ce71f1316d
AuthorNate <sestinj@gmail.com> · 2025-08-31 18:59 -07:00
CommitterNate <sestinj@gmail.com> · 2025-08-31 18:59 -07:00
Parentscc1185a06b7b

Browse the files at this changeset

3 files changed

modified extensions/cli/src/ui/TextBuffer.ts +29 −0
@@ -2,6 +2,9 @@
22
33 export const COLLAPSE_SIZE = 800; // Characters threshold for collapsing pasted content
44 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
58
69 export class TextBuffer {
710 private _text: string = "";
@@ -195,6 +198,32 @@
195198
196199 // Add image to buffer and return placeholder
197200 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+
198227 this._imageCounter++;
199228 const placeholder = `[Image #${this._imageCounter}]`;
200229 this._imageMap.set(placeholder, imageBuffer);
modified extensions/cli/src/ui/components/MemoizedMessage.formatDisplay.test.tsx +4 −3
@@ -126,9 +126,10 @@
126126 );
127127
128128 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+ );
132133 });
133134
134135 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 @@
8383 } else if (platform === "win32") {
8484 // Windows: Use PowerShell to save clipboard image
8585 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}') }"`,
8787 );
8888 } else if (platform === "linux") {
8989 // Linux: Use xclip to save clipboard image