Skip to content

Code execution extension produces syntax errors for multi-line JavaScript expressions #6266

@rabi

Description

@rabi

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:

  1. Configure an external MCP extension (e.g., kiteextension)
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions