Skip to content

Commit d744d62

Browse files
committed
fix: SSE buffer overflow protection, /model shows current model in terminal (v1.3.8)
1 parent ca59a8f commit d744d62

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

dist/agent/llm.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export class ModelClient {
280280
let buffer = '';
281281
// Persist across read() calls — event: and data: may arrive in separate chunks
282282
let currentEvent = '';
283+
const MAX_BUFFER = 1_000_000; // 1MB buffer cap
283284
try {
284285
while (true) {
285286
if (signal?.aborted)
@@ -288,6 +289,10 @@ export class ModelClient {
288289
if (done)
289290
break;
290291
buffer += decoder.decode(value, { stream: true });
292+
// Safety: if buffer grows too large without newlines, truncate
293+
if (buffer.length > MAX_BUFFER) {
294+
buffer = buffer.slice(-MAX_BUFFER / 2);
295+
}
291296
const lines = buffer.split('\n');
292297
buffer = lines.pop() || '';
293298
for (const line of lines) {

dist/commands/start.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ async function runWithBasicUI(agentConfig, model, workDir) {
170170
if (input.startsWith('/') && ui.handleSlashCommand(input))
171171
continue;
172172
// Handle model switch via /model shortcut
173+
if (input === '/model' || input === '/models') {
174+
console.error(chalk.dim(` Current model: ${agentConfig.model}`));
175+
console.error(chalk.dim(' Switch with: /model <name> (e.g. /model sonnet, /model free)'));
176+
continue;
177+
}
173178
if (input.startsWith('/model ')) {
174179
const newModel = resolveModel(input.slice(7).trim());
175180
agentConfig.model = newModel;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blockrun/runcode",
3-
"version": "1.3.7",
3+
"version": "1.3.8",
44
"description": "RunCode — AI coding agent powered by 41+ models. Pay per use with USDC.",
55
"type": "module",
66
"bin": {

src/agent/llm.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export class ModelClient {
373373
// Persist across read() calls — event: and data: may arrive in separate chunks
374374
let currentEvent = '';
375375

376+
const MAX_BUFFER = 1_000_000; // 1MB buffer cap
376377
try {
377378
while (true) {
378379
if (signal?.aborted) break;
@@ -381,6 +382,10 @@ export class ModelClient {
381382
if (done) break;
382383

383384
buffer += decoder.decode(value, { stream: true });
385+
// Safety: if buffer grows too large without newlines, truncate
386+
if (buffer.length > MAX_BUFFER) {
387+
buffer = buffer.slice(-MAX_BUFFER / 2);
388+
}
384389
const lines = buffer.split('\n');
385390
buffer = lines.pop() || '';
386391

src/commands/start.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ async function runWithBasicUI(
203203
// Handle slash commands in terminal UI
204204
if (input.startsWith('/') && ui.handleSlashCommand(input)) continue;
205205
// Handle model switch via /model shortcut
206+
if (input === '/model' || input === '/models') {
207+
console.error(chalk.dim(` Current model: ${agentConfig.model}`));
208+
console.error(chalk.dim(' Switch with: /model <name> (e.g. /model sonnet, /model free)'));
209+
continue;
210+
}
206211
if (input.startsWith('/model ')) {
207212
const newModel = resolveModel(input.slice(7).trim());
208213
agentConfig.model = newModel;

0 commit comments

Comments
 (0)