feat(js-exec): accept node's -e and -p, and give process.argv node's shape - #428
mutewinter wants to merge 3 commits into
Conversation
…shape An agent writes `js-exec -e` by reflex, since that is node's flag, and gets `unrecognized option '-e'`; `-e`/`--eval` now mean `-c`, and `-p`/`--print` print the value of an expression. process.argv was [scriptPath, ...args], so the universal `process.argv.slice(2)` dropped the script's first argument at exit 0. It is now ["js-exec", scriptPath, ...args] for a file and ["js-exec", ...args] for inline code, node's two shapes, with argv0 and execPath alongside.
|
@mutewinter is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
🤖 auto-maintain reviewAutomated, advisory triage for
Review panel: 🟡 medium highest severity just-bash maintainer code review: 🟡 medium
General code review: 🟡 medium
Adversarial security: 🟡 medium
Adversarial security (second opinion): 🟡 medium
Standard Bash and host portability: 🟡 medium
Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call. |
…mments
-p handed its value to console.log, whose JSON formatting printed a RegExp as {} and a Symbol or a function as nothing; a hoisted printer now shows strings as they are and the rest as node inspects them, with objects and arrays staying JSON as they are everywhere in this runtime. A trailing semicolon, line comment, or block comment after the expression is stripped (with a // inside a string left alone), and an empty program prints undefined, as node does. The printer is a declaration below the expression so an error inside the expression is still reported on line 1.
The changeset and the argv comment claimed slice(2) for inline code too; under node that is slice(1), and the note now says so, along with what a script indexing argv directly has to check.
|
All of it held, and the second commit takes each one, with a test per case.
A trailing semicolon, line comment, or block comment after the expression is stripped before wrapping, so The argv claim was wrong as written: for inline code node's own shape is js-exec suite: 329 passed across 14 files, up from 315 with the 14 new |
…he comment scan /https:\/\// ends in \/ followed by /, which the trailing-comment scan took for a line comment and cut, leaving a syntax error; a // whose first slash is escaped is now passed over.
Problem
An agent reaches for
node's flag by reflex:It costs a turn to read
--helpand retry with-c. In a real transcript this was the first of three failures in a five-call attempt to list one directory.The second is silent.
process.argvis[scriptPath, ...args], so the universal idiom drops the first argument at exit 0:Cause
parseArgsinjs-exec.tsknows-calone.run-runtime.tsbuildsconst argv = [options.scriptPath, ...options.scriptArgs], with no executable slot; the existing test only asserts thatfooandbarappear somewhere in the array.Fix
-e/--eval(and--eval=CODE) are-c.-p/--printevaluate one expression and print its value, which is whatnode -pprints for a single expression statement; a multi-statement program under-pis a syntax error, reported as one.process.argvis["js-exec", scriptPath, ...args]for a file and["js-exec", ...args]for inline code, node's two shapes, withargv0andexecPathalongside. The one example that indexedargv[1]now indexesargv[2].Scope
Unchanged:
-c,-m,--strip-types,--, stdin, and the help flag anywhere in the arguments. A script's own-eafter the file name still reaches the script.Not addressed, deliberately:
-pover a statement list (node prints the completion value; this prints an expression). Column offsets in an error from-pcode are shifted by the wrapper.Tests
js-exec.test.ts:-e,--eval,--eval=,-pwith a trailing semicolon,--printpassing arguments through,-eafter-m,-ewith no argument, and a script's own-e; the argv test now asserts both exact shapes. What they cannot prove: that a model finds the flag, which is the point of accepting it. js-exec wasm suite 315 passed across 14 files; the three js-exec security suites 13 passed;tsc, biome, andlint:bannedclean.Authored with Claude Opus 5