Repository navigation
feat: ✨ mocactl spawn --prompt-file - #638
Conversation
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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)
| // 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); |
There was a problem hiding this comment.
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).
| } | ||
| prompt = readFileSync(fd, 'utf8').trim(); | ||
| } catch (err) { | ||
| io.err(`--prompt-file: cannot read ${promptFile}: ${(err as Error).message}`); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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]>
Signed-off-by: Evaline Ju <[email protected]>
Summary
Add
mocactl spawn --prompt-file FILEto 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 spawncall. 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
git commit -s).make lintand the tests for the touched packages pass.docs/page, with the right maturity label (seedocs/CONTRIBUTING-DOCS.md).make check-linkspasses if any Markdown changed.docs/specs/README.mdordocs/adrs/README.md. - N/A