Skip to content

Commit f92e4b3

Browse files
committed
feat: Edit diff preview, error recovery suggestions (v1.3.3)
1 parent b52685f commit f92e4b3

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

dist/agent/loop.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,21 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
330330
await new Promise(r => setTimeout(r, backoffMs));
331331
continue;
332332
}
333-
onEvent({ kind: 'turn_done', reason: 'error', error: errMsg });
333+
// Add recovery suggestions based on error type
334+
let suggestion = '';
335+
if (errLower.includes('429') || errLower.includes('rate')) {
336+
suggestion = '\nTip: Try /model to switch to a different model, or wait a moment and /retry.';
337+
}
338+
else if (errLower.includes('balance') || errLower.includes('insufficient') || errLower.includes('402')) {
339+
suggestion = '\nTip: Run `runcode balance` to check funds. Try /model free for free models.';
340+
}
341+
else if (errLower.includes('timeout') || errLower.includes('econnrefused')) {
342+
suggestion = '\nTip: Check your network connection. Use /retry to try again.';
343+
}
344+
else if (errLower.includes('prompt is too long')) {
345+
suggestion = '\nTip: Run /compact to compress conversation history.';
346+
}
347+
onEvent({ kind: 'turn_done', reason: 'error', error: errMsg + suggestion });
334348
break;
335349
}
336350
onEvent({

dist/tools/edit.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,20 @@ async function execute(input, ctx) {
8282
updated = content.slice(0, firstIdx) + newStr + content.slice(firstIdx + oldStr.length);
8383
}
8484
fs.writeFileSync(resolved, updated, 'utf-8');
85+
// Build a concise diff preview
86+
const oldLines = oldStr.split('\n');
87+
const newLines = newStr.split('\n');
88+
let diffPreview = '';
89+
if (oldLines.length <= 5 && newLines.length <= 5) {
90+
const removed = oldLines.map(l => `- ${l}`).join('\n');
91+
const added = newLines.map(l => `+ ${l}`).join('\n');
92+
diffPreview = `\n${removed}\n${added}`;
93+
}
94+
else {
95+
diffPreview = ` (${oldLines.length} lines → ${newLines.length} lines)`;
96+
}
8597
return {
86-
output: `Updated ${resolved}${matchCount} replacement${matchCount > 1 ? 's' : ''} made.`,
98+
output: `Updated ${resolved}${matchCount} replacement${matchCount > 1 ? 's' : ''} made.${diffPreview}`,
8799
};
88100
}
89101
catch (err) {

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.2",
3+
"version": "1.3.3",
44
"description": "RunCode — AI coding agent powered by 41+ models. Pay per use with USDC.",
55
"type": "module",
66
"bin": {

src/agent/loop.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,18 @@ export async function interactiveSession(
445445
continue;
446446
}
447447

448-
onEvent({ kind: 'turn_done', reason: 'error', error: errMsg });
448+
// Add recovery suggestions based on error type
449+
let suggestion = '';
450+
if (errLower.includes('429') || errLower.includes('rate')) {
451+
suggestion = '\nTip: Try /model to switch to a different model, or wait a moment and /retry.';
452+
} else if (errLower.includes('balance') || errLower.includes('insufficient') || errLower.includes('402')) {
453+
suggestion = '\nTip: Run `runcode balance` to check funds. Try /model free for free models.';
454+
} else if (errLower.includes('timeout') || errLower.includes('econnrefused')) {
455+
suggestion = '\nTip: Check your network connection. Use /retry to try again.';
456+
} else if (errLower.includes('prompt is too long')) {
457+
suggestion = '\nTip: Run /compact to compress conversation history.';
458+
}
459+
onEvent({ kind: 'turn_done', reason: 'error', error: errMsg + suggestion });
449460
break;
450461
}
451462

src/tools/edit.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,20 @@ async function execute(input: Record<string, unknown>, ctx: ExecutionScope): Pro
104104

105105
fs.writeFileSync(resolved, updated, 'utf-8');
106106

107+
// Build a concise diff preview
108+
const oldLines = oldStr.split('\n');
109+
const newLines = newStr.split('\n');
110+
let diffPreview = '';
111+
if (oldLines.length <= 5 && newLines.length <= 5) {
112+
const removed = oldLines.map(l => `- ${l}`).join('\n');
113+
const added = newLines.map(l => `+ ${l}`).join('\n');
114+
diffPreview = `\n${removed}\n${added}`;
115+
} else {
116+
diffPreview = ` (${oldLines.length} lines → ${newLines.length} lines)`;
117+
}
118+
107119
return {
108-
output: `Updated ${resolved}${matchCount} replacement${matchCount > 1 ? 's' : ''} made.`,
120+
output: `Updated ${resolved}${matchCount} replacement${matchCount > 1 ? 's' : ''} made.${diffPreview}`,
109121
};
110122
} catch (err) {
111123
const msg = err instanceof Error ? err.message : String(err);

0 commit comments

Comments
 (0)