You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
codemode: declaring tools or console fails with a bare 'invalid redefinition of parameter name' #375
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