<feed xmlns='http://www.w3.org/2005/Atom'>
<title>newos4/modules/test/test-shell-script.js, branch main</title>
<subtitle>newOS4 - the browser terminal that runs WebX11 user spaces</subtitle>
<id>https://newos.webx11.duckdns.org/newos4/atom?h=main</id>
<link rel='self' href='https://newos.webx11.duckdns.org/newos4/atom?h=main'/>
<link rel='alternate' type='text/html' href='https://newos.webx11.duckdns.org/newos4/'/>
<updated>2026-10-27T16:10:40+00:00</updated>
<entry>
<title>fix(newos4): `if test …` was always false and `for` items never globbed</title>
<updated>2026-10-27T16:10:40+00:00</updated>
<author>
<name>Agando</name>
<email>roduccomm@gmail.com</email>
</author>
<published>2026-10-27T16:10:40+00:00</published>
<link rel='alternate' type='text/html' href='https://newos.webx11.duckdns.org/newos4/commit/?id=b78eba08d320a58c4cd793cf4811444e351ffa17'/>
<id>urn:sha1:b78eba08d320a58c4cd793cf4811444e351ffa17</id>
<content type='text'>
Found by running the shipped runner the way a user would, not by re-reading it.

- _evalTest() stripped [ ] but not the `test` keyword, so `if test -f /work/alpha.txt` evaluated
  the word "test" as an operator, returned false, and every such branch took the else arm —
  measured live: "alpha missing" for a file that exists. Both spellings work now
  (`test -f x`, `[ -f x ]`), plus `-d`, `-e`, `-z`, `-n`, `!` and the = / != comparisons.
- `for f in /work/*.txt` ran ONCE with $f set to the literal pattern, because only command
  arguments went through _expandGlobs. Loop items are expanded per iteration now, so the body runs
  once per matched file with the real path.
- _expandGlobs() falls back to readDir() when a fs has no ls(), so the helper works against either
  shape instead of silently returning the literal pattern.

Verification, live on v4.6.119:
- for+glob: "--- /work/alpha.txt / 3 /work/alpha.txt / --- /work/beta.txt / 1 /work/beta.txt"
  (6 statements, exit 0) — previously one iteration printing the pattern.
- conditionals: "alpha exists", "nope missing", grep + $? intact.
- end-to-end /work/report.sh (loop + glob + &gt;&gt; append + test -f) wrote a correct log:
  "start / file: /work/alpha.txt / 3 /work/alpha.txt / file: /work/beta.txt / 1 /work/beta.txt …".
- unknown command still reports "command not found" and never calls the AI.
- test-shell-script.js 27 -&gt; 35 asserts.

Retracted: I reported `echo x &gt; file` as broken. It was my probe monkey-patching terminal.print,
which bypassed the capture stack the redirect uses. Both paths write correctly:
direct helper -&gt; "direct-call", prompt -&gt; "prompt-call\n".
</content>
</entry>
<entry>
<title>feat(newos4): the script runner runs scripts — control flow, variables, globs, redirects, stdin</title>
<updated>2026-10-27T15:23:21+00:00</updated>
<author>
<name>Agando</name>
<email>roduccomm@gmail.com</email>
</author>
<published>2026-10-27T15:23:21+00:00</published>
<link rel='alternate' type='text/html' href='https://newos.webx11.duckdns.org/newos4/commit/?id=cd71cc814f0d51c2d71fca4231690228a1e1da83'/>
<id>urn:sha1:cd71cc814f0d51c2d71fca4231690228a1e1da83</id>
<content type='text'>
MAINT-021 and MAINT-017, executed from .hermes/plans/2026-10-27_145500-newos4-script-runner.md.

- shell.js: new block parser (_parseBlocks) and executor (_runInstructions/_runSimple/_runCommand/
  _dispatchOne). `for`/`while`/`if` bodies now run, including one-line `if [ -f x ]; then y; fi`.
  Variables expand through _expandVars ($VAR, ${VAR}, $?, single quotes literal), globs expand
  through _expandGlobs (unquoted args only, per-command), and `&gt;`/`&gt;&gt;` capture the command's output
  into the VFS instead of being passed to the command as text.
- shell.js: a script never answers an unknown command by calling the AI any more. It prints
  `script:&lt;path&gt;:&lt;line&gt;: &lt;cmd&gt;: command not found` and sets $? — the AI fallback stays for typing.
- shell.js: unclosed blocks and bad `for` headers surface as `Script &lt;path&gt; failed: …` (the parse
  used to sit outside the try, so a bad script crashed the runner).
- shell.js: interactive path gets the same treatment — prompt globbing and `echo hi &gt; /f` now work.
  Cause of the asymmetry: the two code paths had separate dispatch.
- shell.js: `_isPipeAware` no longer injects the __pipebuf__ file into wc (it reads _pipeInput), and
  the module registers itself with a versioned URL and calls its own init() — registerModule() does
  not call init(), so the executeCommand wrapper was never installed from the boot bundle.
- module-fs.js: wc/head/tail/grep read piped stdin when no file operand is given; `cat` accepts
  several operands (`cat *.txt`); `ls &lt;file&gt;` names the file instead of printing "(empty)".
- main.html: shell.js removed from the extension list — it is already inside
  critical-ext-bundle.js, and loading it twice produced two ShellModule instances that could
  disagree about their version.

Verification:
- test-shell-script.js 27 asserts (parser, variables, globs, executor, redirect, command-not-found,
  one-line if, parse error). RED on HEAD: `TypeError: shell._parseBlocks is not a function`.
- test-shell-stdin.js 16 asserts (added by a subagent): wc -l/-c, head -n, tail -n over stdin, and
  the file-argument path unchanged.
- Suite 18/18 files; maintain --fix "node tests 18/18 pass".
- Live on v4.6.115, through the real executeCommand:
  `ls /n*.txt` -&gt; /n1.txt · `cat /n*.txt` -&gt; one|two · `echo hi &gt; /r.txt` then `cat /r.txt` -&gt; hi ·
  `cat /probe.txt | wc -l` -&gt; 3 (bare, no __pipebuf__) ·
  `script /run.sh` -&gt; item 1 / item 2 / item 3 / exists / command not found, exit 1, no AI routing.
</content>
</entry>
</feed>
