Skip to content

feat(memos-cloud-server): add --messages-file flag to add_message CLI - #16

Open
DDmouth wants to merge 1 commit into
MemTensor:mainfrom
DDmouth:feature/messages-file-flag
Open

feat(memos-cloud-server): add --messages-file flag to add_message CLI#16
DDmouth wants to merge 1 commit into
MemTensor:mainfrom
DDmouth:feature/messages-file-flag

Conversation

@DDmouth

@DDmouth DDmouth commented Aug 29, 2026

Copy link
Copy Markdown

Summary

The add_message CLI currently takes the messages payload as a positional argparse argument. On Windows, this fails for any payload larger than ~32KB with Argument list too long (the OS argv limit), breaking long-session backups (e.g. multi-day chat uploads, tool-heavy sessions).

This PR adds --messages-file <path> to load the messages JSON from a UTF-8 file instead, mirroring the existing --stdin pattern on add_kb_doc.

Changes

  • memos_cloud/cli.py
    • Make positional messages optional (nargs="?", default "")
    • Add --messages-file PATH flag
    • Forward messages_file through dispatch()
  • memos_cloud/operations.py
    • add_message() accepts new messages_file: Optional[str] parameter
    • If set, reads UTF-8 contents into messages_json_str before payload construction
    • If both messages_json_str and messages_file are set, the file wins
  • tests/test_cli.py — 2 new tests:
    • test_cli_add_message_with_messages_file — basic file-based loading
    • test_cli_add_message_messages_file_overrides_positional — file takes precedence

All 49 tests pass (47 original + 2 new).

Usage

# Small payload (unchanged)
python3 memos_cloud.py add_message user-1 conv-first-msg \
  '[{"role":"user","content":"hello"}]'

# Large payload via file (new)
python3 memos_cloud.py add_message user-1 conv-first-msg \
  --messages-file /tmp/messages.json --tags backup

# SDK equivalent
from memos_cloud.operations import add_message
add_message(client, "user-1", messages_file="/tmp/messages.json")

Context

Reported by an integration user (Hermes Agent — memos-backup-workflow skill) running on Windows. Real-world failure case: a 158-message / 113KB session upload succeeded via Python SDK but the CLI subcommand path crashed at the OS layer before reaching the API. The fix is local (no behavior change for existing invocations) and additive (existing positional callers keep working).

Backward compatibility

  • The positional messages argument is now nargs="?" instead of required, so existing CLI invocations that already pass it continue to work unchanged.
  • New messages_file parameter defaults to None, so SDK callers see no behavior change.
  • All 47 pre-existing tests still pass without modification.

Allow loading the messages payload from a UTF-8 file path instead of the
positional `messages` arg. This bypasses the Windows ~32KB argv size limit
that breaks large session uploads (e.g. multi-day chat backups).

- cli.py: add --messages-file option; make positional `messages` optional
- operations.py: read messages from file when --messages-file is set
- tests/test_cli.py: 2 new tests covering file path and override behavior

Use case: an Agent persisting a long conversation (e.g. 200+ messages,
50KB+ payload) can write messages to disk and pass the path, avoiding
the OS-dependent 'Argument list too long' failure that breaks
mcporter-style invocations on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant