Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions scripts/amp-reply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,27 @@ source "${SCRIPT_DIR}/amp-helper.sh"
# Parse arguments
MESSAGE_ID=""
REPLY_MESSAGE=""
BODY_FILE=""
BODY_STDIN=false
PRIORITY=""
TYPE="response"
ATTACH_FILES=()

show_help() {
echo "Usage: amp-reply <message-id> <reply-message> [options]"
echo " amp-reply <message-id> --body-file PATH [options]"
echo " amp-reply <message-id> --body-stdin [options]"
echo ""
echo "Reply to a message."
echo ""
echo "Arguments:"
echo " message-id The message ID to reply to"
echo " reply-message Your reply message"
echo " reply-message Your reply message (omit if using --body-file or --body-stdin)"
echo ""
echo "Options:"
echo " --body-file PATH Read reply body from a file (avoids shell escaping"
echo " issues with backticks, code blocks, box-drawing chars)"
echo " --body-stdin Read reply body from stdin"
echo " --priority, -p PRIORITY Override priority (default: same as original)"
echo " --type, -t TYPE Message type (default: response)"
echo " --attach, -a FILE Attach a file (can be repeated)"
Expand All @@ -55,6 +62,8 @@ show_help() {
echo " amp-reply msg_1234567890_abc \"Got it, working on it\""
echo " amp-reply msg_1234567890_abc \"Urgent update\" --priority urgent"
echo " amp-reply msg_1234567890_abc \"See attached\" --attach report.pdf"
echo " amp-reply msg_1234567890_abc --body-file reply.md"
echo " cat reply.md | amp-reply msg_1234567890_abc --body-stdin"
}

# Parse positional and optional arguments
Expand All @@ -73,6 +82,14 @@ while [[ $# -gt 0 ]]; do
ATTACH_FILES+=("$2")
shift 2
;;
--body-file)
BODY_FILE="$2"
shift 2
;;
--body-stdin)
BODY_STDIN=true
shift
;;
--id)
shift 2 # Already handled in pre-source parsing
;;
Expand All @@ -92,16 +109,42 @@ while [[ $# -gt 0 ]]; do
esac
done

# Check positional arguments
if [ ${#POSITIONAL[@]} -lt 2 ]; then
echo "Error: Missing required arguments."
# Resolve body source: positional arg, file, or stdin (mutually exclusive)
_body_sources=0
[ -n "$BODY_FILE" ] && _body_sources=$((_body_sources + 1))
[ "$BODY_STDIN" = true ] && _body_sources=$((_body_sources + 1))
[ ${#POSITIONAL[@]} -ge 2 ] && _body_sources=$((_body_sources + 1))

if [ $_body_sources -gt 1 ]; then
echo "Error: provide reply body via exactly one of: positional arg, --body-file, --body-stdin"
exit 1
fi

if [ ${#POSITIONAL[@]} -lt 1 ]; then
echo "Error: Missing message-id."
echo ""
show_help
exit 1
fi

MESSAGE_ID="${POSITIONAL[0]}"
REPLY_MESSAGE="${POSITIONAL[1]}"

if [ -n "$BODY_FILE" ]; then
if [ ! -f "$BODY_FILE" ]; then
echo "Error: --body-file path not found: $BODY_FILE"
exit 1
fi
REPLY_MESSAGE=$(cat "$BODY_FILE")
elif [ "$BODY_STDIN" = true ]; then
REPLY_MESSAGE=$(cat)
elif [ ${#POSITIONAL[@]} -ge 2 ]; then
REPLY_MESSAGE="${POSITIONAL[1]}"
else
echo "Error: Missing reply body. Provide as positional arg, --body-file PATH, or --body-stdin."
echo ""
show_help
exit 1
fi

# Validate message ID
validate_message_id "$MESSAGE_ID" || {
Expand Down
53 changes: 48 additions & 5 deletions scripts/amp-send.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ source "${SCRIPT_DIR}/amp-helper.sh"
RECIPIENT=""
SUBJECT=""
MESSAGE=""
BODY_FILE=""
BODY_STDIN=false
PRIORITY="normal"
TYPE="notification"
REPLY_TO=""
Expand All @@ -45,15 +47,20 @@ ATTACH_FILES=()

show_help() {
echo "Usage: amp-send <recipient> <subject> <message> [options]"
echo " amp-send <recipient> <subject> --body-file PATH [options]"
echo " amp-send <recipient> <subject> --body-stdin [options]"
echo ""
echo "Send a message to another agent."
echo ""
echo "Arguments:"
echo " recipient Agent address (e.g., alice, bob@tenant.provider)"
echo " subject Message subject"
echo " message Message body"
echo " message Message body (omit if using --body-file or --body-stdin)"
echo ""
echo "Options:"
echo " --body-file PATH Read message body from a file (avoids shell escaping"
echo " issues with backticks, code blocks, box-drawing chars)"
echo " --body-stdin Read message body from stdin"
echo " --priority, -p PRIORITY low|normal|high|urgent (default: normal)"
echo " --type, -t TYPE request|response|notification|task|status (default: notification)"
echo " --reply-to, -r ID Message ID this is replying to"
Expand All @@ -73,6 +80,8 @@ show_help() {
echo " amp-send alice \"Hello\" \"How are you?\""
echo " amp-send backend-api \"Deploy\" \"Ready\" --priority high"
echo " amp-send bob@acme.crabmail.ai \"Help\" \"Need assistance\" --type request"
echo " amp-send alice \"Report\" --body-file report.md"
echo " cat reply.md | amp-send alice \"Reply\" --body-stdin"
}

# Parse positional and optional arguments
Expand Down Expand Up @@ -103,6 +112,14 @@ while [[ $# -gt 0 ]]; do
ATTACH_FILES+=("$2")
shift 2
;;
--body-file)
BODY_FILE="$2"
shift 2
;;
--body-stdin)
BODY_STDIN=true
shift
;;
--id)
shift 2 # Already handled in pre-source parsing
;;
Expand All @@ -122,17 +139,43 @@ while [[ $# -gt 0 ]]; do
esac
done

# Check positional arguments
if [ ${#POSITIONAL[@]} -lt 3 ]; then
echo "Error: Missing required arguments."
# Resolve body source: positional, file, or stdin (mutually exclusive)
_body_sources=0
[ -n "$BODY_FILE" ] && _body_sources=$((_body_sources + 1))
[ "$BODY_STDIN" = true ] && _body_sources=$((_body_sources + 1))
[ ${#POSITIONAL[@]} -ge 3 ] && _body_sources=$((_body_sources + 1))

if [ $_body_sources -gt 1 ]; then
echo "Error: provide message body via exactly one of: positional arg, --body-file, --body-stdin"
exit 1
fi

if [ ${#POSITIONAL[@]} -lt 2 ]; then
echo "Error: Missing recipient or subject."
echo ""
show_help
exit 1
fi

RECIPIENT="${POSITIONAL[0]}"
SUBJECT="${POSITIONAL[1]}"
MESSAGE="${POSITIONAL[2]}"

if [ -n "$BODY_FILE" ]; then
if [ ! -f "$BODY_FILE" ]; then
echo "Error: --body-file path not found: $BODY_FILE"
exit 1
fi
MESSAGE=$(cat "$BODY_FILE")
elif [ "$BODY_STDIN" = true ]; then
MESSAGE=$(cat)
elif [ ${#POSITIONAL[@]} -ge 3 ]; then
MESSAGE="${POSITIONAL[2]}"
else
echo "Error: Missing message body. Provide as positional arg, --body-file PATH, or --body-stdin."
echo ""
show_help
exit 1
fi

# Validate priority
if [[ ! "$PRIORITY" =~ ^(low|normal|high|urgent)$ ]]; then
Expand Down