-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Code execution extension produces syntax errors for multi-line JavaScript expressions #6266
Description
Describe the bug
When the LLM generates JavaScript code with multi-line expressions (like objects or function calls spanning multiple lines), the code execution extension's result wrapping logic fails, producing invalid JavaScript syntax and causing parse errors.
To Reproduce
Steps to reproduce the behavior:
- Configure an external MCP extension (e.g., kiteextension)
- Ask Goose to perform a task that requires calling multiple tools and aggregating results
The LLM generates code like:
import { get_holdings, get_margins } from "kiteextension"; const holdings = get_holdings({}); const margins = get_margins({}); console.log(JSON.stringify({ holdings, margins, total: holdings.length }));
Expected behavior
The code executes successfully and returns the result.
Actual behavior
Error: Parse error: SyntaxError: expected token '(', got 'result' in method definition at line 35, col 1
The tool call fails and the agent retries with the same code, creating an infinite loop.
Root Cause
The run_js_module function wraps user code to capture results in a result variable. It only examines the last line of code. When code ends with:
}));
The wrapping logic transforms it to:
result = }));
This is invalid JavaScript syntax.