fix(engines): stop a nested moshcode child opening a second TUI#40
Merged
ralyodio merged 1 commit intoJul 26, 2026
Merged
Conversation
A CLI verb called from a script (run(), install(), agents(), upgrade()) spawns `moshcode <verb>` with stdio inherited, so the child sees a TTY whenever a human runs the script from a terminal. At the end of the verb the child called backToPit(), printed the banner and blocked on its own `mosh >` prompt, so the parent script never resumed. Mark spawned children with MOSHCODE_NESTED=1 and treat that like a non-TTY in backToPit, so a nested run exits and hands control back. Same fix for the moshscript shim, which made an executable .mosh file land in a TUI instead of returning to the user's shell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling any CLI verb from a moshscript (
run(),install(),agents(),upgrade()) hangs the script on a terminal, and an executable.moshfile never returns to your shell.Reproduce
parent afternever runs. The script is now sitting in a second mosh pit that shares the parent's TTY.The same happens via the documented shebang path:
./deploy.moshlands in a TUI instead of exiting to your shell.Cause
cliVerbspawns the child withstdio: "inherit"(src/cli.mjs:44), so the child inherits a TTY stdin whenever a human runs the script from a terminal. At the end of the verb the child reachesbackToPit(bin/moshcode.mjs:320), whose only guard isisTTY(bin/moshcode.mjs:59):That guard is right for the top-level process but wrong for a spawned child: "has a TTY" is not the same as "is the session the user is driving".
The existing tests miss it because
test/run-options.test.mjsfeeds stdin from a file, so the child is never a TTY.Fix
Mark spawned children with
MOSHCODE_NESTED=1and treat that like a non-TTY inbackToPit. Three call sites:bin/moshcode.mjs:59,src/cli.mjs:44,bin/moshscript.mjs:17.The parent's own drop into the mosh pit after the script finishes is unchanged — that is intended interactive behaviour.
Verification
Added
run() marks the nested moshcode child as nestedtotest/run-options.test.mjs, which asserts the child sees the flag. It fails on main (not ok 89) and passes with the fix. Full suite: 146/146 pass, up from 145 baseline.