Skip to content

refactor(zalouser): compile blocks from CommonMark IR - #113590

Merged
steipete merged 8 commits into
mainfrom
codex/zz-zalo-commonmark-lists
Jul 25, 2026
Merged

steipete merged 8 commits into
mainfrom
codex/zz-zalo-commonmark-lists

Conversation

@steipete

@steipete steipete commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

ZaloUser still compiled headings, list/container ownership, indentation, and code blocks through a plugin-local scanner after emphasis had moved to the shared CommonMark parser. That duplicated parsing policy and diverged on deep, loose, wide-marker, lazy-continuation, and marker-only lists.

Why This Change Was Made

This extends packages/markdown-core with generic parser-owned block metadata: code origin/closure, container depth, heading ownership, and list marker/content source spans. The metadata is optional and non-enumerable, so the existing public MarkdownIR type, API manifest, serialized IR shape, transcript bytes, and current channel consumers remain unchanged.

ZaloUser now consumes that shared metadata and keeps only transport concerns locally: zca RANGE emission, lst_1/lst_2/ind_$ encoding, Bold+Big heading mapping, and NBSP conversion. The old plugin-local list/fence/heading scanner and NBSP-list fallback path are deleted.

The upstream zca-js style contract was checked at pinned commit 9479746040524a805cf5e9d4f5a5a8156384d3a7.

User Impact

ZaloUser now follows shared CommonMark deep/loose list ownership. The authorized rendering changes are fully enumerated by golden before/after cases:

  1. - parent\n - child: NBSP-prefixed literal child marker -> nested native unordered list.
  2. 1. parent\n 1. child: flat ordered child -> indented native ordered child.
  3. 10. parent\n - child: NBSP-prefixed literal child marker -> ordered parent with nested native unordered child.
  4. - parent\n continuation: separately indented continuation -> continuation owned by the same native list range.
  5. - first\n\n continuation\n- next: loose continuation outside the first range -> continuation owned by the first native item.
  6. - parent\n - [ ] child: literal nested task marker -> indented checkbox fallback without a native bullet.

A standalone top-level four-space list-looking line remains an indented code block. No config, environment, schema, protocol, transcript/model-input, or other channel output changes are introduced.

Evidence

LOC (git diff --numstat origin/main...HEAD): production +2227/-555; tests +1108/-173; total +3335/-728 across 12 files. This capability batch is intentionally net-positive under the markdown-unification clean-architecture exception; it removes the old Zalo scanner path and adds shared generic metadata plus exhaustive golden coverage.

  • Exact corrected head 73e272788c7500805746d3bbb2ec889773fb0d23: Blacksmith Testbox tbx_01kycc47ghy5z6j91dk63mjtzb passed the complete markdown-core suite (223 tests), all 13 cross-channel formatter/chunking shards, and the full ZaloUser suite (26 files / 269 tests) in run 30154038529.
  • Exact-head GitHub CI run 30154022410 passed, along with CodeQL, CodeQL Critical Quality, Dependency Guard, Security Sensitive Guard, OpenGrep, Workflow Sanity, and periphery checks on the same SHA.
  • Fresh full-branch autoreview found and drove two final Zalo regressions to closure: extra blockquote padding before nested headings/quotes now remains structural based on parser-owned depth, and marker-only Unicode continuation content is projected through parser-owned list spans before restoration. Focused regression tests cover both cases; the follow-up uncommitted autoreview is clean.
  • node scripts/run-vitest.mjs packages/markdown-core/src plus node scripts/run-vitest.mjs packages/markdown-core/src/ir.block-metadata.test.ts: 22 files, 223 tests passed.
  • node scripts/run-vitest.mjs extensions/zalouser/src/text-styles.test.ts extensions/zalouser/src/text-styles-blocks.test.ts extensions/zalouser/src/text-styles-containers.test.ts packages/markdown-core/src/ir.block-metadata.test.ts: 104 tests passed after the fresh-main rebase.
  • pnpm test extensions/zalouser on Blacksmith Testbox tbx_01kyc8181qt8t2hnwftfm3gxap: 26 files, 268 tests passed (run 30152066394).
  • Production formatter transcript on Blacksmith Testbox tbx_01kyc9gkj84e9sh8v5msctfgdd: directly imported extensions/zalouser/src/text-styles.ts (no test harness) and printed the six authorized runtime outputs, including native lst_1/lst_2 plus nested ind_$ ranges (run 30152786812). The formatter is the complete touched runtime boundary; network delivery and zca authentication are unchanged.
  • Cross-channel formatter/chunking matrix on the same Testbox: 13 Vitest shards passed. Byte-neutral existing-channel coverage: Telegram, Slack, Signal, Matrix, Discord, Feishu, WhatsApp, QQ, iMessage, LINE, SMS, Google Chat, Teams, ClickClack, and Nextcloud Talk; ZaloUser passed its intended golden changes in the same run.
  • Exact matrix command: node scripts/run-vitest.mjs extensions/telegram/src/format.test.ts extensions/telegram/src/format.wrap-md.test.ts extensions/telegram/src/send.chunks.test.ts extensions/slack/src/format.test.ts extensions/signal/src/format.test.ts extensions/signal/src/format.chunking.test.ts extensions/matrix/src/matrix/format.test.ts extensions/discord/src/chunk.test.ts extensions/discord/src/draft-chunking.test.ts extensions/feishu/src/markdown.test.ts extensions/feishu/src/docx-markdown.test.ts extensions/feishu/src/media-chunk-idle.test.ts extensions/whatsapp/src/text-runtime.test.ts extensions/qqbot/src/engine/utils/format.test.ts extensions/qqbot/src/engine/messaging/markdown-table-chunking.test.ts extensions/imessage/src/markdown-format.test.ts extensions/line/src/markdown-to-line.test.ts extensions/googlechat/src/format.test.ts extensions/msteams/src/format.test.ts extensions/clickclack/src/outbound.test.ts extensions/nextcloud-talk/src/send.cfg-threading.test.ts extensions/nextcloud-talk/src/send.fetch-timeout.test.ts extensions/sms/src/send.test.ts extensions/zalouser/src/text-styles.test.ts extensions/zalouser/src/text-styles-blocks.test.ts extensions/zalouser/src/text-styles-containers.test.ts.
  • node scripts/check-changed.mjs on Blacksmith Testbox tbx_01kyc6v5q2tfpwnts05dwxndq3: all core/extension typecheck, lint, API-manifest, boundary, ratchet, and guard lanes passed (run 30151478133).
  • pnpm deadcode:dependencies && pnpm deadcode:exports on Blacksmith Testbox tbx_01kyc94xbcfxjn4g7wn2h2brzx: all production/full-tree/script unused-export scans passed with 0 entries after removing two stale split-module exports (run 30152609340).
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted: clean, no accepted/actionable findings; rerun after each review-triggered correction.
  • Final .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main: clean on the complete final diff, no accepted/actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added channel: zalouser Channel integration: zalouser size: XL maintainer Maintainer-authored PR labels Jul 25, 2026
@steipete
steipete marked this pull request as ready for review July 25, 2026 09:03
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 25, 2026, 6:18 AM ET / 10:18 UTC.

ClawSweeper review

What this changes

The PR replaces ZaloUser’s local Markdown block scanner with CommonMark parser metadata so headings, lists, containers, indentation, and code blocks render from one shared interpretation.

Merge readiness

⚠️ Needs maintainer review before merge - 5 items remain

Keep this PR open: its runtime rendering proof and broad validation are strong, but the proposed ZaloUser formatter still depends on hidden parser fields that are deliberately absent from the public Markdown IR contract. Likely related people: steipete is the visible author of the parser/ZaloUser refactor sequence (medium confidence).

Priority: P2
Reviewed head: 73e272788c7500805746d3bbb2ec889773fb0d23
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The behavior proof is strong, but a P1 compatibility-boundary defect prevents this otherwise well-validated refactor from being merge-ready.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR supplies after-fix Testbox evidence that directly imports the production ZaloUser formatter and prints the six intended outputs; tests and cross-channel checks supplement that runtime proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR supplies after-fix Testbox evidence that directly imports the production ZaloUser formatter and prints the six intended outputs; tests and cross-channel checks supplement that runtime proof.
Evidence reviewed 5 items Hidden metadata is outside the exported IR contract: The patch keeps MarkdownIR public while defining internal MarkdownIRWithMetadata and attaching optional non-enumerable blocks and enriched list-item fields; ZaloUser recreates that hidden shape locally rather than receiving it through a supported seam.
ZaloUser asserts a parallel local contract: The new bundled transport view extends the public MarkdownIR type with parser-private block and list metadata. This duplicates a core-owned contract inside the plugin and gives future parser changes no typed compatibility signal.
Prior review identified the same unresolved boundary: The supplied previous ClawSweeper review at head fa3d5e2 required a supported plugin seam or explicitly owned bundled-only facade. The follow-up keeps a local structural view, so the central boundary concern remains.
Findings 1 actionable finding [P1] Expose parser metadata through an owned plugin seam
Security None None.

How this fits together

packages/markdown-core parses Markdown into the IR consumed through the plugin SDK’s text-chunking surface. ZaloUser’s formatter then converts that parsed content into Zalo native range styles before outbound channel delivery.

flowchart LR
  A[Markdown input] --> B[CommonMark parser]
  B --> C[Markdown IR]
  C --> D[Plugin SDK text chunking]
  D --> E[ZaloUser formatter]
  E --> F[Zalo native style ranges]
  F --> G[Outbound Zalo message]
Loading

Decision needed

Question Recommendation
Should ZaloUser consume CommonMark block metadata through a bundled-only core-owned facade, or should this metadata become a supported plugin-SDK capability? Add a bundled-only parser facade: Provide a typed, core-owned facade for bundled transports so ZaloUser does not recreate parser-private metadata locally.

Why: The patch intentionally preserves the existing public MarkdownIR shape while making a bundled plugin depend on additional runtime fields; selecting the permanent compatibility boundary requires maintainer intent.

Before merge

  • Expose parser metadata through an owned plugin seam (P1) - MarkdownIRWithBlockMetadata recreates fields that packages/markdown-core deliberately keeps outside the public MarkdownIR contract. ZaloUser therefore relies on hidden runtime behavior with no typed compatibility signal; move this behind a core-owned bundled facade or an approved SDK accessor before merge.
  • Resolve merge risk (P1) - Merging leaves ZaloUser coupled to non-enumerable parser internals that are intentionally excluded from the public Markdown IR and plugin-SDK contract; a future parser or SDK refactor can silently regress channel formatting.
  • Resolve merge risk (P1) - The correct long-lived boundary is unresolved: a generic supported capability and an explicitly owned bundled-only bridge have different compatibility and ownership commitments.
  • Complete next step (P2) - A maintainer must choose the permanent parser-to-plugin compatibility seam; this is not a safe mechanical repair until that boundary is decided.

Findings

  • [P1] Expose parser metadata through an owned plugin seam — extensions/zalouser/src/text-styles-shared.ts:20-34
Agent review details

Security

None.

PR surface

Source +1672, Tests +935. Total +2607 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 8 2227 555 +1672
Tests 4 1108 173 +935
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 3335 728 +2607

Review metrics

None.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/markdown-core/src/ir.block-metadata.test.ts, vector/embedding metadata: packages/markdown-core/src/ir.block-metadata.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Move metadata access behind an owned facade (recommended)
    Replace the plugin-local structural cast with a core-owned bundled-only typed bridge and add a focused contract test for the fields ZaloUser consumes.
  2. Approve a public metadata capability
    If external plugins need the same facts, define and document a stable plugin-SDK accessor instead of relying on hidden IR properties.
  3. Pause the refactor
    Keep the current scanner until maintainers choose a compatibility boundary for parser-owned block metadata.

Technical review

Best possible solution:

Keep the parser metadata owned by markdown-core, but expose ZaloUser’s required block/list view through an explicitly owned bundled-only facade or a deliberately approved typed SDK capability with focused contract coverage.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a defect report: the supplied production formatter transcript demonstrates the intended after-change ZaloUser behavior, while the remaining concern is a code-boundary contract rather than a failing user scenario.

Is this the best way to solve the issue?

No. Replacing duplicate parsing is the right direction, but the local structural view of deliberately hidden metadata is not the narrowest maintainable boundary; use an owned facade or explicitly approved SDK capability.

Full review comments:

  • [P1] Expose parser metadata through an owned plugin seam — extensions/zalouser/src/text-styles-shared.ts:20-34
    MarkdownIRWithBlockMetadata recreates fields that packages/markdown-core deliberately keeps outside the public MarkdownIR contract. ZaloUser therefore relies on hidden runtime behavior with no typed compatibility signal; move this behind a core-owned bundled facade or an approved SDK accessor before merge.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against faaab9bd4819.

Labels

Label justifications:

  • P2: This is a bounded channel-rendering refactor with a concrete compatibility-contract blocker, not an urgent production outage.
  • merge-risk: 🚨 compatibility: The formatter reads parser metadata intentionally omitted from the public Markdown IR and plugin-SDK contract, so future changes can break it without a typed compatibility signal.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR supplies after-fix Testbox evidence that directly imports the production ZaloUser formatter and prints the six intended outputs; tests and cross-channel checks supplement that runtime proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies after-fix Testbox evidence that directly imports the production ZaloUser formatter and prints the six intended outputs; tests and cross-channel checks supplement that runtime proof.

Evidence

What I checked:

  • Hidden metadata is outside the exported IR contract: The patch keeps MarkdownIR public while defining internal MarkdownIRWithMetadata and attaching optional non-enumerable blocks and enriched list-item fields; ZaloUser recreates that hidden shape locally rather than receiving it through a supported seam. (packages/markdown-core/src/ir.ts:130, 73e272788c75)
  • ZaloUser asserts a parallel local contract: The new bundled transport view extends the public MarkdownIR type with parser-private block and list metadata. This duplicates a core-owned contract inside the plugin and gives future parser changes no typed compatibility signal. (extensions/zalouser/src/text-styles-shared.ts:20, 73e272788c75)
  • Prior review identified the same unresolved boundary: The supplied previous ClawSweeper review at head fa3d5e2 required a supported plugin seam or explicitly owned bundled-only facade. The follow-up keeps a local structural view, so the central boundary concern remains. (extensions/zalouser/src/text-styles-shared.ts:20, 73e272788c75)
  • Real runtime formatter proof is present: The PR body and follow-up comment cite a Testbox run that directly imports the production formatter and prints the intended nested-list and continuation outputs; the supplied checks also show the relevant quality and boundary lanes passing. (extensions/zalouser/src/text-styles.ts:1, 73e272788c75)
  • Refactor provenance: The supplied commit sequence shows steipete carrying the CommonMark-IR refactor from the initial ZaloUser change through internalization and nested-container fixes, making them the clearest available routing contact for the proposed boundary design. (packages/markdown-core/src/ir.ts:130, 73e272788c75)

Likely related people:

  • steipete: The supplied eight-commit PR sequence spans both the markdown-core metadata implementation and ZaloUser’s formatter migration, including the latest nested-container repair. (role: parser and ZaloUser refactor author; confidence: medium; commits: c9f96228c7ce, 840c78788859, 73e272788c75; files: packages/markdown-core/src/ir.ts, extensions/zalouser/src/text-styles.ts, extensions/zalouser/src/text-styles-shared.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Replace the local hidden-metadata view with an owned bundled facade or approved SDK accessor.
  • Add focused contract coverage for the supported metadata access path.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-07-25T09:08:08.483Z sha 3f3fcbbbfd8b149c6cdb36c34fd401a17de60ea7 :: needs real behavior proof before merge. :: [P1] Expose block metadata through the plugin SDK
  • reviewed 2026-07-25T09:54:16.431Z sha fa3d5e2 :: found issues before merge. :: [P1] Expose block metadata through a supported plugin seam

@steipete
steipete force-pushed the codex/zz-zalo-commonmark-lists branch from 3f3fcbb to fa3d5e2 Compare July 25, 2026 09:47
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the latest ClawSweeper review on the corrected head:

  • Real behavior proof: Testbox run 30152786812 directly imports the production ZaloUser formatter (not a test harness) and prints all six authorized nested-list/continuation outputs with their native lst_1, lst_2, and ind_$ ranges. The PR body now records this transcript. Network delivery and zca authentication are unchanged by this transport-render-only patch.
  • SDK-boundary move: intentionally not widening the public MarkdownIR contract in this batch. The commissioned hard gates require additive non-enumerable runtime metadata while preserving the existing public IR/API-manifest shape and prohibit baseline edits. This uses the review's documented option 2: the bundled transport view is explicitly recorded at text-styles-shared.ts and must stay in lockstep with markdown-core. A public SDK capability would require a separate contract/baseline decision outside this batch.
  • The reported persistent/vector data-model signal is a filename classifier false positive: ir.block-metadata.test.ts contains formatter IR metadata tests only; this PR has no storage, SQLite, vector, embedding, schema, or migration changes.
  • The CI dead-code failure was fixed by making two split-module helpers internal. Both exact checks pass with zero entries in Testbox run 30152609340.

The maintainer decision for this batch remains the shared CommonMark IR approach; there is no remaining product decision in the scoped behavior.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 25, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper publisher exception for the final head 73e272788c7500805746d3bbb2ec889773fb0d23:

  • The exact-head ClawSweeper worker run 30154176512 completed successfully with no failed jobs.
  • Its durable PR comment remained an unchanged review started placeholder after completion plus an additional 60-second publisher grace period, so no exact-head Rank-up moves: payload was published.
  • Per the markdown-unification fleet precedent, I am documenting this congested-publisher stall publicly and proceeding.

The last published substantive moves were not skipped silently: production Zalo formatter output is linked in the PR body, the bundled non-enumerable metadata coupling and lifecycle are documented at the type site, the public SDK/baseline widening was explicitly declined because it violates this batch's hard gates, and the false-positive storage/vector signal was explained. Since then, fresh full-branch autoreview found two real container regressions; both were fixed with focused tests, exact-head CI is green, the complete 13-shard channel matrix is green, full ZaloUser is green, and the final full-branch autoreview is clean.

@steipete
steipete merged commit 589ac03 into main Jul 25, 2026
130 checks passed
@steipete
steipete deleted the codex/zz-zalo-commonmark-lists branch July 25, 2026 10:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 26, 2026
* refactor(zalouser): compile blocks from commonmark ir

* refactor(markdown-core): keep block metadata internal

* test(markdown-core): type hidden block metadata

* refactor(zalouser): drop split-module leftovers

* test(markdown-core): assert serialized metadata shape

* refactor(zalouser): satisfy formatter lint contracts

* refactor(zalouser): internalize source span helpers

* fix(zalouser): preserve nested container semantics
threely-lab pushed a commit to threely-lab/openclaw that referenced this pull request Jul 27, 2026
* refactor(zalouser): compile blocks from commonmark ir

* refactor(markdown-core): keep block metadata internal

* test(markdown-core): type hidden block metadata

* refactor(zalouser): drop split-module leftovers

* test(markdown-core): assert serialized metadata shape

* refactor(zalouser): satisfy formatter lint contracts

* refactor(zalouser): internalize source span helpers

* fix(zalouser): preserve nested container semantics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: zalouser Channel integration: zalouser maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant