feat(invoke): add --prompt-file and stdin support for long prompts#974
Merged
aidandaly24 merged 2 commits intoaws:mainfrom Apr 27, 2026
Merged
Conversation
Long prompts hit shell argument limits (E2BIG, typically 128KB-2MB) when passed as positional args. This adds two new sources: - --prompt-file <path>: read prompt from a file - piped stdin: when no prompt is given and stdin is not a TTY, read the prompt from stdin Precedence is hybrid and backward-compatible: --prompt > positional > --prompt-file > stdin --prompt-file combined with piped stdin content returns an explicit collision error rather than silently picking one. Closes aws#686
avi-alpert
reviewed
Apr 27, 2026
avi-alpert
approved these changes
Apr 27, 2026
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.
Description
Adds two new prompt sources to
agentcore invoketo work around shell argument length limits (E2BIG, typically 128KB–2MB on macOS/Linux) that block long prompts today:--prompt-file <path>— read the prompt from a fileThis unblocks common AI-agent workflows: passing multi-turn JSON conversations, structured payloads, and chaining
agentcore invokecalls via pipes (jq ... | agentcore invoke, agent-to-agent chaining, etc.).Precedence
Hybrid — backward-compatible with today's
--prompt/positional precedence:--prompt-filecombined with piped stdin content returns an explicit collision error rather than silently picking one, since both are "bulk" sources and silent precedence there would mask user mistakes (e.g. a CI pipeline accidentally piping data while also passing--prompt-file).Examples
Related Issue
Closes #686
Documentation PR
N/A — this change adds a self-documenting CLI flag (shows in
--help). Happy to open a docs PR if the team wants the pipeline/file-input pattern called out in the guide.Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsTesting detail
1. Unit tests — new
resolve-prompt.test.ts(11/11 passing) covering every precedence branch, file read, stdin read, collision error, missing file, trailing-newline trim, and empty-string handling.2. CLI surface —
--prompt-fileappears inagentcore invoke --help:3. End-to-end against a live deployed runtime. I deployed a deterministic echo agent (returns
PROMPT_LEN+SHA256of the received prompt) to AgentCore Runtime inus-east-1and verified byte-exact prompt delivery for each source. Local and agent-returned SHA256 match for all three prompt paths including a 5000-byte random payload:4. Error paths fire correctly against the live runtime (collision returns immediately — no cold-start penalty):
Test matrix
--prompt-file(5KB random)55d75163…e655d75163…e655d75163…e655d75163…e6"quick hello"74336f76…a074336f76…a0"hi"8f434346…a48f434346…a4--prompt-file+ piped stdin{"success":false,"error":"Cannot combine…"}--prompt-filemissing path{"success":false,"error":"Failed to read --prompt-file '…': ENOENT…"}Checklist
Implementation notes for reviewers
src/cli/commands/invoke/resolve-prompt.tsowns source resolution.action.tsis unchanged — it still consumes a plainoptions.prompt: string, so all downstream protocols (non-stream, stream, A2A, AGUI, MCP,--exec) inherit the new behavior automatically.src/test-utils/cli-runner.tsnow spawns withstdio: ['ignore', ...]so the new!process.stdin.isTTYdetection doesn't false-trigger when tests drive the CLI without piping stdin.process.stdin.isTTY === falseis the standard non-interactive-stdin signal; we additionally treat empty stdin (immediate EOF) as "no stdin source" so scripts without piped input fall through to the existing "No prompt provided" error.--prompt-file.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.