From 2709b2fe4963c680a083502abf1d6f33dac3d5e2 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 24 Mar 2026 18:40:26 +0100 Subject: [PATCH] feat: make buffer size limits configurable via environment variables Allow overriding MAX_TERMINAL_BUFFER_SIZE, TRIM_TERMINAL_TO, MAX_TEXT_OUTPUT_SIZE, TRIM_TEXT_TO, and MAX_MESSAGES via CODEMAN_* env vars, falling back to existing defaults. Enables users with fewer sessions or more RAM to tune buffer sizes without patching source. Closes #48 Co-Authored-By: Claude Opus 4.6 --- src/config/buffer-limits.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/config/buffer-limits.ts b/src/config/buffer-limits.ts index 921e5f79..4a44ac6d 100644 --- a/src/config/buffer-limits.ts +++ b/src/config/buffer-limits.ts @@ -22,14 +22,16 @@ * Maximum terminal buffer size in characters. * Contains raw terminal output with ANSI escape sequences. * Reduced from 5MB to 2MB for better render performance. + * Override: CODEMAN_MAX_TERMINAL_BUFFER (bytes) */ -export const MAX_TERMINAL_BUFFER_SIZE = 2 * 1024 * 1024; // 2MB +export const MAX_TERMINAL_BUFFER_SIZE = parseInt(process.env.CODEMAN_MAX_TERMINAL_BUFFER || '') || 2 * 1024 * 1024; /** * Size to trim terminal buffer to when max is exceeded. * Keeps the most recent portion to preserve context. + * Override: CODEMAN_TRIM_TERMINAL_TO (bytes) */ -export const TRIM_TERMINAL_TO = 1.5 * 1024 * 1024; // 1.5MB +export const TRIM_TERMINAL_TO = parseInt(process.env.CODEMAN_TRIM_TERMINAL_TO || '') || 1.5 * 1024 * 1024; // ============================================================================ // Text Output Buffer Limits @@ -38,13 +40,15 @@ export const TRIM_TERMINAL_TO = 1.5 * 1024 * 1024; // 1.5MB /** * Maximum text output buffer size in characters. * Contains ANSI-stripped text for search and analysis. + * Override: CODEMAN_MAX_TEXT_OUTPUT (bytes) */ -export const MAX_TEXT_OUTPUT_SIZE = 1 * 1024 * 1024; // 1MB +export const MAX_TEXT_OUTPUT_SIZE = parseInt(process.env.CODEMAN_MAX_TEXT_OUTPUT || '') || 1 * 1024 * 1024; /** * Size to trim text output buffer to when max is exceeded. + * Override: CODEMAN_TRIM_TEXT_TO (bytes) */ -export const TRIM_TEXT_TO = 768 * 1024; // 768KB +export const TRIM_TEXT_TO = parseInt(process.env.CODEMAN_TRIM_TEXT_TO || '') || 768 * 1024; // ============================================================================ // Message Buffer Limits @@ -53,8 +57,9 @@ export const TRIM_TEXT_TO = 768 * 1024; // 768KB /** * Maximum number of Claude JSON messages to keep in memory per session. * Older messages are discarded when limit is exceeded. + * Override: CODEMAN_MAX_MESSAGES (count) */ -export const MAX_MESSAGES = 1000; +export const MAX_MESSAGES = parseInt(process.env.CODEMAN_MAX_MESSAGES || '') || 1000; // ============================================================================ // Line Buffer Limits