Skip to content

feat: ✨ mocactl spawn --prompt-file - #638

Merged
evaline-ju merged 7 commits into
rossoctl:mainfrom
evaline-ju:prompt-file
Oct 27, 2026
Merged

evaline-ju merged 7 commits into
rossoctl:mainfrom
evaline-ju:prompt-file

Conversation

@evaline-ju

Copy link
Copy Markdown
Contributor

Summary

Add mocactl spawn --prompt-file FILE to read the prompt from a file instead of positional argv. Mutually exclusive with an inline prompt.

Chained-subagent flows inline a prior leaf's final message into the next mocactl spawn call. Claude Code 2.x's Bash static safety check refuses argv containing #, $(...), heredocs, or multi-line quoted content independent of the permission allow-list.

Assisted-By: Claude (Anthropic AI) [email protected]

Closes #637

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass.
  • Docs: changed behavior, flags or environment variables are reflected in the relevant README or
    docs/ page, with the right maturity label (see docs/CONTRIBUTING-DOCS.md).
  • Docs: make check-links passes if any Markdown changed.
  • A new spec or ADR is registered in docs/specs/README.md or docs/adrs/README.md. - N/A

Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
@evaline-ju
evaline-ju requested a review from pdettori as a code owner October 27, 2026 17:07
Comment thread packages/mocactl/src/cli.ts Fixed
Signed-off-by: Evaline Ju <[email protected]>
@evaline-ju evaline-ju added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 27, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-tested addition: mocactl spawn --prompt-file FILE reads the prompt from a regular file, mutually exclusive with an inline prompt and refused outside spawn. It opens once and uses fstat + read on the same fd with O_NOFOLLOW (which addresses the CodeQL CWE-367 note), closes the fd on every path, and keeps the 64 KiB cap enforced in cmdSpawn. There are tests for the happy path, the mutex, missing/empty/directory/symlink, solve composition, and outside-spawn. The docs (CLI reference, README, spec) are updated consistently.

Non-blocking: a FIFO path blocks in open(2) before the regular-file check can refuse it (verified locally, Node 26), and a symlink refusal surfaces as a raw ELOOP message that the docs don't mention. One nit on reading oversized files fully into memory before the cap check.

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl CLI), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 5 commits, all signed-off: yes
CI status: passing (all 15 checks green)

Comment thread packages/mocactl/src/cli.ts Outdated
// path cannot redirect the read elsewhere between stat and read (CodeQL CWE-367).
let fd: number | undefined;
try {
fd = openSync(promptFile, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: open(2) on a FIFO with O_RDONLY blocks until a writer appears, so --prompt-file some.fifo (or a named pipe left over from a chained flow) hangs mocactl here, before the isFile() check can refuse it. I verified on Node 26: the plain open times out, while with O_NONBLOCK it returns at once and fstatSync(fd).isFile() is false. Adding fsConstants.O_NONBLOCK to the flags has no effect on regular-file reads, and it makes the "not a regular file" refusal reachable for FIFOs too (character devices are already refused after open).

Comment thread packages/mocactl/src/cli.ts Outdated
}
prompt = readFileSync(fd, 'utf8').trim();
} catch (err) {
io.err(`--prompt-file: cannot read ${promptFile}: ${(err as Error).message}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a symlinked prompt file comes back as --prompt-file: cannot read X: ELOOP: too many symbolic links encountered, which reads like a filesystem loop, not a deliberate refusal. /dev/stdin and /dev/fd/N (process substitution) hit the same path. Consider mapping ELOOP to something like X is a symlink; pass the target path, and adding "symlinks refused" to the README / cli-mocactl.md wording (currently only "must be a regular file").

io.err(`--prompt-file: ${promptFile} is not a regular file`);
return 2;
}
prompt = readFileSync(fd, 'utf8').trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the whole file is read into memory before cmdSpawn applies the 64 KiB cap, so pointing at a large file by mistake (a log, a binary) reads all of it only to refuse it. You already have the fstat result, so a st.size > 64 KiB early refusal (the error could reuse the cap message) would avoid that. Low stakes for a CLI.

Signed-off-by: Evaline Ju <[email protected]>
@evaline-ju
evaline-ju merged commit 4206293 into rossoctl:main Oct 27, 2026
15 checks passed
@evaline-ju
evaline-ju deleted the prompt-file branch October 27, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: mocactl spawn --prompt-file FILE for multi-line prompts coding-agent shells refuse

3 participants