Skip to content

fix: decode MECP with the top-level 1.4.0 message pattern - #495

Merged
Avi0n merged 1 commit into
Avi0n:devfrom
Blake-Latchford:fix/mecp-message-pattern
Nov 20, 2026
Merged

Avi0n merged 1 commit into
Avi0n:devfrom
Blake-Latchford:fix/mecp-message-pattern

Conversation

@Blake-Latchford

@Blake-Latchford Blake-Latchford commented Nov 19, 2026 •

Copy link
Copy Markdown

Description

First PR in a series for #494, covering its first three sections. MC1's decoder now uses the MECP 1.4.0 §6.1 message pattern, so strings the spec defines as not MECP stay plain text and MECP read from a serial or text source keeps its codes.

Overview of Changes

  • Reject a bunch of formatting failures that the spec defines as 'not MECP'.
  • Strip a trailing newline on decode.
  • Free text is returned unmodified, so runs of spaces are no longer collapsed.

MECPDecode.decode replaces the token scan with one regex, matched by Unicode scalar so that a CRLF is two scalars, as it is in other languages. Callers that get nil already show the raw text, so a rejected string still appears in the chat as plain text.

Testing

  • MECPDecodeTests covers each example in MECP 1.4.0 Support #494's first three sections, plus tabs, a non-breaking space, a code-shaped word that is not a whole code, every Unicode line break, and repeated trailing line endings.
  • Ran the MECP decode and catalog tests with swift test in the swift:6.2 Docker image on Linux. All decode tests pass. The one failure is pack choice uses the first preferred localization, which fails on Linux before any MECP code runs because Linux Foundation resolves zh-Hans to en. It is unrelated to this change.
  • swiftlint lint is clean on both changed files.

I don't have access to an Apple device on which to test my code. However, I have tested the unit tests on linux/docker with the command below.

docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp \
  -v "$REPO":"$REPO":ro -v "$HERE":"$HERE" -w "$HERE" \
  swift:6.2 swift test "$@"

Tested on

  • iOS [version]
  • iPadOS [version]
  • macOS [version]

Checklist

  • This PR was discussed with the maintainer either via GitHub issue or other means (Also check the box if this PR is small enough not to need discussion e.g. typo fix)
  • I have read CONTRIBUTING.md
  • Testing steps are documented above.
  • This change is not low effort and I took the time to test it

🤖 Generated with Claude Code

- Reject a bunch of formatting failures that the spec defines as 'not MECP'.
- Strip a trailing newline on decode.
- Free text is returned unmodified, so runs of spaces are no longer collapsed.

First commit in a series for issue Avi0n#494
@Blake-Latchford
Blake-Latchford marked this pull request as ready for review November 19, 2026 19:00
@Avi0n

Avi0n commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Looks good, thanks!

@Avi0n
Avi0n merged commit 2a3c22c into Avi0n:dev Nov 20, 2026
9 of 11 checks passed
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.

2 participants