Repository navigation
fix: flatten markdown tables in imessage replies - #47860
winnythedev wants to merge 1 commit into
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change fills a missing step in iMessage's own flattener by reusing the shared WhatsApp reduction, and Notes
[DESIGN-REVIEWED] aebf50a Description read[DESCRIPTION-READ] 943312e808c954f88f067006987b286efe936b423d76d9e0aaeaffd727d4e2e7 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix reuses the shared What this change shipsInventory (4 items) — 4 justifiedIntent: iMessage users get bot replies with tables as readable rows instead of raw pipe source. This is a FIX (#47825; the module docstring already promised it).
[FIRST-PRINCIPLES-REVIEWED] aebf50a Description read[DESCRIPTION-READ] 24203782490872f3643c1a5997ecc48133839ee5d2647388fe88ecc319e46515 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
iMessage renders no markup, and to_plaintext flattened headings, bullets, quotes, links and emphasis but had no table step, so a reply holding a pipe table arrived as its raw source, separator row included. WhatsApp, which has the same limits, already reduces each table to one labelled line per row. to_plaintext now runs the shared flatten_pipe_tables over the text outside code fences before its line pass, so the cells' markup is flattened with the rest of the reply. A table inside a fence, prose with pipes and an [OPTIONS: ...] footer reach the chat unchanged. Fixes #47825
0cf12c3 to
aebf50a
Compare
Problem / Motivation
Goal: A Bot's reply that holds a markdown table reaches iMessage as one readable line per row, the way it already reaches WhatsApp, instead of as raw table source.
On iMessage a reply with a pipe table arrived as written: every row with its pipes, and the
|---|---|separator row under the header. The same reply reaches WhatsApp as one labelled line per row (- Name: a.py | Size: 10 | Owner: ann).Why it matters
Bots answer with tables often (file lists, comparisons, status rows). On iMessage, which renders no markup, those answers were hard to read on a phone: the separator row and pipes took up the screen and the columns wrapped into ragged text. The module that flattens iMessage replies already says it flattens pipe tables, so a reader of the code expects this to work.
Not a goal
flatten_pipe_tables(messaging/markup.py) orrewrite_outside_fences(messaging/split.py).plaintext.py's own fence regex with the shared CommonMark fence machine (see the review section).What changed (motivation → approach → change)
to_plaintext(src/kiro_crew/imessage/plaintext.py), whichIMessageRenderer.delivery_textruns on every reply, flattens headings, rules, bullets, numbers, quotes, links, images and emphasis line by line but had no table step.IMESSAGE_CAPABILITIESkeepstable_mode="off", and no renderer step converts tables on its own.to_plaintextnow runsrewrite_outside_fences(text, flatten_pipe_tables), the same reduction WhatsApp applies. The table becomes markdown bullets with bold labels, and the existing line pass then flattens those bullets and the cells' own markup (bold, links, inline code) like the rest of the reply. Fenced content is untouched. Splitting still runs last, on the flat text.to_plaintext: the module's other importers (chat titles, computer-use output and others) only use its grapheme helpers, and importingmessaging.splitcosts them about 70-90 ms for nothing.docs/system-specs/modules/messaging.md(iMessage, "Rendering.").Backwards compatibility
Compatible: only the plain text iMessage receives changes, and only for lines that form a pipe table (a header row followed by a separator row) outside a fence. Nothing that is accepted today is rejected.
Removes nothing: the change adds a rendering step; no key, path, record or function is removed.
Tests
test/test_imessage_tables.py, each case through the realIMessageRenderer(on_text_chunk,on_done) into a fake client:test_a_table_is_sent_as_one_labelled_line_per_row: a 3-column table between two paragraphs.test_cell_markup_is_flattened_too: cells holding bold, a link and inline code.test_a_cjk_table_is_flattened: a CJK table.test_choices_under_a_table_stay_choices: an[OPTIONS: ...]footer right under a table stays numbered choices (expected footer taken from the renderer itself).test_a_table_inside_a_code_fence_is_left_alone,test_a_table_inside_a_tilde_fence_is_left_alone,test_prose_with_pipes_is_left_alone: guarded inputs that must not change.On main the first four fail and the last three pass; with the fix all seven pass.
Proof: PROVEN test/test_imessage_tables.py::test_a_table_is_sent_as_one_labelled_line_per_row, test/test_imessage_tables.py::test_cell_markup_is_flattened_too, test/test_imessage_tables.py::test_a_cjk_table_is_flattened, test/test_imessage_tables.py::test_choices_under_a_table_stay_choices (head cb85afd68abb)
Local gates on Linux x86_64:
scripts/local-gate.py --base upstream/main --tree-scansran the related set (7,745 passed) and both tree-scan shards (57,738 passed); 11 tree-scan tests failed only for host reasons: their child Python cannot loadlibffi.so.6on this host, or (test_browser_harness_supervisor.py,test_mcp_footprint_stub_probe.py) they probe host-installed tools and stub children; none imports the iMessage code.mypy src/kiro_crewreports 6 errors, all in files this PR does not touch (missing library stubs and an aiohttp version in the local venv); none inimessage/; black, isort, flake8, subprocess-encoding, comment-history, brand-name, agent-SDK boundary and file-line-cap checks pass;test/test_flake_pattern_ratchet.pyandtest/test_wait_discipline_ratchet.pypass;./scripts/docs-lint.shpasses.semgrep scan --config semgrep/ --baseline-commit <merge-base> --error(1.78.0): 0 findings.Inputs probed by hand through
to_plaintext, not kept as cases: a bullet list followed by a table (both flattened, blank line kept), a fence followed by a table and the reverse, a fence left open before a table (table stays raw), a*inside a cell (2*3,a * b: unchanged), an escaped\|and a pipe inside inline code (cell text, not a boundary), a header with no data rows (left as written). Not tested: a table longer than one iMessage message (flattening runs beforechunk_plaintext, which splits the flat text as before).Review (multi-model interrogate)
Three independent reviewers read the full diff against CI's own lane contracts; all three passed it.
plaintext.py's fence regex accepts two openers the shared CommonMark machine rejects (a tab-indented fence, or a backtick inside a backtick fence's info string). For such a block the table is flattened and then shipped as "code", so literal**labels show. Dismissed for this PR: both openers are rare in model output, the damage is cosmetic, and the real fix is to drive the line pass fromiter_fence_spansso one fence rule exists, which is a separate change. The opposite disagreement (a two-word info string) keeps the table raw, as on main.**pairs with the label's bold markers. This is the sharedflatten_pipe_tablesoutput format, unchanged here and the same on WhatsApp.Manual verification
N/A: no live iMessage account and no gateway were used. The bridge needs macOS, but this is platform-independent text code, so the tests above drive the real renderer on Linux and Linux CI verifies it.
Real-machine verification
Machine: own computer, Linux x86_64.
Before (main e392fe2):
python -m pytest -n0 test/test_imessage_tables.py-> 4 failed, 3 passed (the table, cell-markup, CJK and options-footer cases show raw pipes).After (head aebf50a):
python -m pytest -n0 test/test_imessage_tables.py-> 7 passed.Cleanup: own computer, nothing to delete. No live iMessage account was used: the run goes through the real
IMessageRendererinto a fake client.Related Issues
Fixes #47825
Overlap: PR #47847 (merged) changed the single-star emphasis pattern in the same file (
_EMPHASIS_RES) and added an iMessage sentence tomessaging.md. This branch is rebased on it: the spec paragraph keeps both sentences, and table cells go through that emphasis rule like prose (| 2 * 3 * 4 | */5 * * * * |arrives as• Expr: 2 * 3 * 4 | Cron: */5 * * * *). PR #47803 also editsmessaging.md(the empty-turn notice) andimessage/renderer.py, notplaintext.py.Sibling sweep
Swept: git grep -n -i -E "table_mode|render_tables|flatten_pipe_tables|native_tables" -- src/kiro_crew/
Sibling: src/kiro_crew/whatsapp/renderer.py -- not affected -- already flattens each table outside a fence with flatten_pipe_tables
Sibling: src/kiro_crew/weixin/transport.py -- not affected -- declares native tables, keeps markdown on purpose
Sibling: src/kiro_crew/wecom/renderer.py -- not affected -- renders tables through render_tables_for_target by its own policy
Sibling: src/kiro_crew/teams/renderer.py -- not affected -- converts tables through render_tables_for_target
Sibling: src/kiro_crew/webex/renderer.py -- not affected -- converts tables through render_tables_for_target
Sibling: src/kiro_crew/feishu/client.py -- not affected -- sends replies as text with no markdown pass at all, a wider gap than a missing table step
Pattern harvest
Not generalizable: a channel converter that skipped one markdown construct its own docstring promised; the shared reduction already existed and is now called.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributed under the project's Apache-2.0 license.