Skip to content

codemode: declaring tools or console fails with a bare 'invalid redefinition of parameter name' #375

Backlog

Description

@alfonso-noriega

What happens

A codemode script that declares a variable named tools (or console) fails before it runs, with only:

SyntaxError: invalid redefinition of parameter name
    at codemode.js:1:41

Nothing says which name collided or that the sandbox reserves it. In one long-running monorepo session this hit 3 times (two of them in one read-only dream pass); const tools = … is a natural name in a script that lists or groups tool calls. Reproduced just now on build af3d8e0e with const tools = 1; return tools and const console = 1.

Why

pi-codemode wraps the script as a function whose parameters are the injected names: vm.evalCode(\(async (tools, console) => {${data.code}\n})`, "codemode.js") (@earendil-works/pi-codemode1.5.2,dist/runtime/vm.js:274). A top-level const/let of a parameter name is a syntax error. (ultimate, text, store` etc. are globals, so shadowing them works.)

Expected

Either the name is usable, or the error says what to do.

Suggested fix

  • Cheapest, in Ultimate: in extensions/codemode/server.ts where the failure text is built (L692, const error = result.error.stack ?? …), when the message is invalid redefinition of parameter name, append "tools and console are the sandbox's parameters; rename your variable". Optionally add "never redeclare tools/console" to the tool description (L481).
  • Upstream in pi-codemode: wrap the body one level deeper ((async (tools, console) => { return (async () => {${code}\n})() })), so a top-level declaration shadows the parameter instead of failing. Line numbers stay intact if the prefix stays on line 1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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