Skip to content

Conversation

@alexhancock
Copy link
Collaborator

@alexhancock alexhancock commented Jan 5, 2026

Improves the quality of how we have the rust part of the code execution extension collect results from JS execution

Per this comment initially #6030 (comment) I should have gotten to it on initial implementation

This should avoid the need for improvements and tweaks to the __result__ handling #6267

Demo:

Screenshot 2026-01-05 at 4 50 43 PM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves code execution result recording by replacing the implicit __result__ global variable with an explicit record_result() function. This change eliminates complex code-wrapping logic and provides a cleaner, more explicit API for users to return values from JavaScript execution. Additionally, the Node.js version constraint is loosened from an exact version to a minimum version requirement.

  • Replaces implicit __result__ global with explicit record_result() function
  • Removes complex code wrapping logic that attempted to automatically capture the last expression
  • Updates documentation and examples to reflect the new explicit API

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
ui/desktop/package.json Changes Node.js version constraint from exact (^22.17.1) to minimum (>=22.17.1)
ui/desktop/package-lock.json Updates lockfile to match package.json Node.js version constraint
crates/goose/src/agents/code_execution_extension.rs Replaces __result__ global with record_result() function, removes code wrapping logic, updates documentation and examples
Files not reviewed (1)
  • ui/desktop/package-lock.json: Language not supported

Copy link
Contributor

@rabi rabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

SYNTAX:
- Import: import { tool1, tool2 } from "serverName";
- Call: toolName({ param1: value, param2: value })
- Result: record_result(value) - call this to return a value from the script
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah , looks simpler and better. However, I've seen at times smaller models ignore these type of instructions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do something similar for the main agent for the final result (in the context of recipes). there we check whether the call was actually made and if not, just remind the model to do it if it doesn't. we could add that here too - have the model generate the code, run the code, see that it doesn't call record, stick the js back into the model saying, you said this, but you didn't call record.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously for a follow up

.map_err(|e| format!("Failed to register __result__: {e}"))?;
let record_result = NativeFunction::from_copy_closure(|_this, args, _ctx| {
let value = args.first().cloned().unwrap_or(JsValue::undefined());
RESULT_CELL.with(|cell| *cell.borrow_mut() = Some(value.display().to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value.display() doesn't properly serialize arrays/objects as JSON. Maybe I'll propose a followup later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposed #6495

@alexhancock alexhancock force-pushed the alexhancock/code-mode-results branch from c851871 to fd051c6 Compare January 6, 2026 17:12
Copilot AI review requested due to automatic review settings January 6, 2026 18:12
@alexhancock alexhancock force-pushed the alexhancock/code-mode-results branch from fd051c6 to c20e214 Compare January 6, 2026 18:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • ui/desktop/package-lock.json: Language not supported

@block block deleted a comment from Copilot AI Jan 6, 2026
@block block deleted a comment from Copilot AI Jan 6, 2026
@block block deleted a comment from Copilot AI Jan 6, 2026
@alexhancock alexhancock force-pushed the alexhancock/code-mode-results branch from c20e214 to 8b68944 Compare January 6, 2026 20:10
SYNTAX:
- Import: import { tool1, tool2 } from "serverName";
- Call: toolName({ param1: value, param2: value })
- Result: record_result(value) - call this to return a value from the script
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do something similar for the main agent for the final result (in the context of recipes). there we check whether the call was actually made and if not, just remind the model to do it if it doesn't. we could add that here too - have the model generate the code, run the code, see that it doesn't call record, stick the js back into the model saying, you said this, but you didn't call record.

SYNTAX:
- Import: import { tool1, tool2 } from "serverName";
- Call: toolName({ param1: value, param2: value })
- Result: record_result(value) - call this to return a value from the script
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously for a follow up

@alexhancock alexhancock merged commit c222bde into main Jan 13, 2026
20 checks passed
@alexhancock alexhancock deleted the alexhancock/code-mode-results branch January 13, 2026 19:35
wpfleger96 added a commit that referenced this pull request Jan 13, 2026
* main: (41 commits)
  Allow customizing the new line keybinding in the CLI (#5956)
  Ask for permission in the CLI (#6475)
  docs: add Ralph Loop tutorial for multi-model iterative development (#6455)
  Remove gitignore fallback from gooseignore docs (#6480)
  fix: clean up result recording for code mode (#6343)
  fix(code_execution): handle model quirks with tool calls (#6352)
  feat(ui): support prefersBorder option for MCP Apps (#6465)
  fixed line breaks (#6459)
  Use Intl.NumberFormat for token formatting in SessionsInsights (#6466)
  feat(ui): format large and small token counts for readability (#6449)
  fix: apply subrecipes when using slash commands (#6460)
  Fix: exclude platform_schedule_tool in CLI (#6442)
  Fix: Small update in how ML-based prompt injection determines final result (#6439)
  docs: remove SSE transport and rename to Streamable HTTP (#6319)
  fix: correct Cloudinary extension command and env variable (#6453)
  fix: add gap between buttons in MacDesktopInstallButtons.js (#6452)
  refactor: include hidden dotfiles folders in file picker search (#6315)
  upgraded safe npm packages (#6450)
  chore(deps): bump react-router and react-router-dom in /ui/desktop (#6408)
  chore(deps): bump lru from 0.12.5 to 0.16.3 (#6379)
  ...
lifeizhou-ap added a commit that referenced this pull request Jan 14, 2026
* main:
  fix: require auth when running goose on non loopback address (#6478)
  chore(deps): bump hono from 4.11.3 to 4.11.4 in /ui/desktop (#6485)
  feat(cli): graceful fallback for keyring failures (#5808)
  fix: support global .gooseignore and negation patterns (#6157)
  docs: manual config for jetbrains (#6490)
  fix: Recipe slash command doesn't work with single optional parameter (#6235)
  fix(openrouter): Handle Gemini thoughtSignature for tool calls (#6370)
  docs: fix extensions page (#6484)
  Allow customizing the new line keybinding in the CLI (#5956)
  Ask for permission in the CLI (#6475)
  docs: add Ralph Loop tutorial for multi-model iterative development (#6455)
  Remove gitignore fallback from gooseignore docs (#6480)
  fix: clean up result recording for code mode (#6343)
  fix(code_execution): handle model quirks with tool calls (#6352)
  feat(ui): support prefersBorder option for MCP Apps (#6465)
  fixed line breaks (#6459)
  Use Intl.NumberFormat for token formatting in SessionsInsights (#6466)
  feat(ui): format large and small token counts for readability (#6449)
  fix: apply subrecipes when using slash commands (#6460)
ThanhNguyxn pushed a commit to ThanhNguyxn/goose that referenced this pull request Jan 14, 2026
zanesq added a commit that referenced this pull request Jan 14, 2026
…ased

* 'main' of github.com:block/goose:
  fix(code_execution): serialize record_result output as JSON (#6495)
  perf(google): avoid accumulating thoughtSignatures across conversation history (#6462)
  fix(openai): make tool_call arguments optional and fix silent stream termination (#6309)
  fix: Improve error messages for invalid tool calls (#6483)
  fix: require auth when running goose on non loopback address (#6478)
  chore(deps): bump hono from 4.11.3 to 4.11.4 in /ui/desktop (#6485)
  feat(cli): graceful fallback for keyring failures (#5808)
  fix: support global .gooseignore and negation patterns (#6157)
  docs: manual config for jetbrains (#6490)
  fix: Recipe slash command doesn't work with single optional parameter (#6235)
  fix(openrouter): Handle Gemini thoughtSignature for tool calls (#6370)
  docs: fix extensions page (#6484)
  Allow customizing the new line keybinding in the CLI (#5956)
  Ask for permission in the CLI (#6475)
  docs: add Ralph Loop tutorial for multi-model iterative development (#6455)
  Remove gitignore fallback from gooseignore docs (#6480)
  fix: clean up result recording for code mode (#6343)
  fix(code_execution): handle model quirks with tool calls (#6352)
  feat(ui): support prefersBorder option for MCP Apps (#6465)
  fixed line breaks (#6459)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants