Skip to content

feat: add --message-file flag to openclaw message send#79225

Closed
BigBot-ironlogic wants to merge 3 commits into
openclaw:mainfrom
BigBot-ironlogic:feat/message-file-flag
Closed

feat: add --message-file flag to openclaw message send#79225
BigBot-ironlogic wants to merge 3 commits into
openclaw:mainfrom
BigBot-ironlogic:feat/message-file-flag

Conversation

@BigBot-ironlogic

Copy link
Copy Markdown

Summary

Adds first-class file input to openclaw message send to fix agent completion message corruption when reports contain shell metacharacters.

Closes #79182

Problem

Agent completion reports passed via --message "$(cat file.txt)" are silently corrupted or dropped when the file contains:

  • $ (variable expansion)
  • Backticks (command substitution)
  • Quotes
  • JSON
  • Markdown code fences

This caused multiple silent failures in production builds.

Solution

New --message-file <path> flag reads UTF-8 content from a file without shell interpolation.

New flags

  • --message-file <path> — read message body from file
  • --allow-empty — allow sending empty file (default: error)

Mutual exclusion

  • --message and --message-file are mutually exclusive (error if both supplied)
  • Neither supplied: existing downstream validation handles it unchanged

Safe agent completion pattern

REPORT_FILE="$(mktemp)"
cat > "$REPORT_FILE" << 'EOF'
Done: summary here

- Fix 1: description
- Fix 2: description
EOF
openclaw message send --channel telegram --target 8611381068 --message-file "$REPORT_FILE"
rm -f "$REPORT_FILE"

Changes

  • src/cli/program/message/register.send.ts — adds --message-file and --allow-empty options
  • src/cli/program/message/helpers.ts — adds resolveMessageFromFile(), wired into runMessageAction
  • src/cli/program/message/register.send.message-file.test.ts — 10 new vitest tests

Tests

  • 10 new tests covering: simple file, multiline, special chars ($, backticks, quotes, JSON, code fences), missing file, empty file, both flags, neither flag, key stripping, path resolution
  • 35/35 total tests passing (25 existing + 10 new)
  • TypeScript: no errors (pnpm tsgo)
  • Formatter: clean (oxfmt)

Adds first-class file input support to avoid shell expansion corruption
when agent completion reports contain $, backticks, quotes, JSON, or
markdown code fences.

New flags:
  --message-file <path>   Read UTF-8 message body from file
  --allow-empty           Allow sending empty file (default: error)

Behaviour:
- Reads file content without shell interpolation
- Fails clearly if file not found or empty (unless --allow-empty)
- Mutually exclusive with --message (error if both supplied)
- Strips messageFile/allowEmpty from opts before downstream call
- No logging of message body content

Safe agent completion pattern:
  REPORT_FILE="$(mktemp)"
  cat > "$REPORT_FILE" << 'EOF'
  Done: summary
  EOF
  openclaw message send --channel telegram --target <t> --message-file "$REPORT_FILE"
  rm -f "$REPORT_FILE"

Tests: 10 new vitest tests + 25 existing passing (35/35 total)
TypeScript: no errors (pnpm tsgo)

Closes #79182
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 8, 2026
@clawsweeper

clawsweeper Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: feat: add --message-file flag to openclaw message send This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@Joseff531

Copy link
Copy Markdown

This PR is duplicated with #79200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: openclaw message send --message-file <path>

2 participants