Skip to content

Commit e098ad2

Browse files
committed
Merge fix/bun-runtime-result-capture into develop
Second critical bug fix for Bun runtime result capture with MCP integration
2 parents 1774277 + b60603a commit e098ad2

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/runtime/bun-runtime.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,17 @@ __originalConsole.log('__RESULT__', JSON.stringify({
271271
const lines = trimmedCode.split('\n');
272272
const lastLine = lines[lines.length - 1].trim();
273273

274-
// Check if code already contains a return statement
274+
// Check if code already contains a TOP-LEVEL return statement
275275
// (avoid wrapping multi-line returns like: return { ... };)
276-
const hasReturnStatement = trimmedCode.includes('return ');
276+
// NOTE: Don't just check for 'return' anywhere - it might be inside a function!
277+
// Simple heuristic: check if last 3 lines contain a return statement
278+
const hasTopLevelReturn = lines.some((line, idx) => {
279+
if (idx < lines.length - 3) return false; // Only check last few lines
280+
return line.trim().startsWith('return ');
281+
});
277282

278-
// If code already has a return statement, don't modify it
279-
if (hasReturnStatement) {
283+
// If code already has a top-level return statement, don't modify it
284+
if (hasTopLevelReturn) {
280285
wrappedCode = trimmedCode;
281286
} else {
282287
// Check if last line is a bare expression that should become a return

0 commit comments

Comments
 (0)