Skip to content

feat(remend): protect parser-owned literal ranges during repair - #701

Draft
davidfant wants to merge 4 commits into
vercel:mainfrom
davidfant:energy/registered-widget-containers
Draft

davidfant wants to merge 4 commits into
vercel:mainfrom
davidfant:energy/registered-widget-containers

Conversation

@davidfant

@davidfant davidfant commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

Add generic literalRanges support so Remend's built-in repairs preserve parser-owned opaque source while retaining normal whole-document Markdown context.

Zero Streamdown package changes. No container grammar, tag registration, renderer, dependency, lockfile or default Streamdown behavior changes. This draft supersedes the broader container proposal, preserved on its archival branch.

Before / After / Why

Before: callers cannot protect exact literal payloads while retaining ordinary incomplete-Markdown repair. Repair can consume literal content or treat its punctuation as surrounding Markdown.

After: an optional callback supplies sorted non-overlapping UTF-16 {start,end} intervals (exclusive end). Built-in repairs respect literal markers, whitespace, edit boundaries and surrounding context. Without the callback, existing behavior remains covered by the full suite.

Why: disabling repair loses ordinary streaming behavior; masking source or repairing fragments independently adds context-loss workarounds. The caller's existing grammar supplies boundaries. Remend knows nothing about tabs, HTML containers or Energy.

Implementation

  • Existing scanner marks literal regions; callback is recalculated when preceding repair changes source.
  • Scope/cache isolation restored through nested calls and exceptions with try/finally.
  • Edits cannot consume protected spans; trimming/insertion and closing-marker counts respect literal boundaries.
  • User-defined custom handlers still receive the full string and must respect literal source themselves.
  • No source encoding, masking, fragment reparsing, fallback renderer or whole-document repair bypass.

Review corrections

The setext finding and three further review findings were independently reproduced before fixes. Additional audit cases covered HTML deletion across ranges, protected comparison escapes, and literal star/dollar half-closers.

At corrected head ba8b9e7e7061e6b78b0f9f9bcb93daea0ae13e69:

  • Unchanged independent boundary oracle: 13/13 pass after, all13 failed before.
  • Expanded installed-product boundary regressions: 18/18 fail before, pass after.
  • Main Remend suite: 590 tests pass; production JS/types build passes.
  • Product-pinned source:584 tests pass. Main build byte-matches pinned/installed artifacts.
  • Final independent review passes240tests/1510assertions,13immutableboundaryoracles,27installedboundarycases and9000no-ranges differential comparisons. Independent frozen rebuild matches pin/main/installed.
  • Fresh downstream original4E2E,capture/reload2,realpopupincremental2 all pass atproduct3151d86f. Synthetic shared-production renderer/headlessChromium, not installedElectron; popupstaticmode, componenttests covermode transition. No media uploads.

Local upstream Biome remains unavailable because shared tooling lacks ultracite/core; added tests formatted with platform Biome/basic matching configuration. Diff check passes. CI statuses reported separately; earlier unsigned-commit/deployment prerequisites remain external, no key access or deployment authorized.

Downstream integration

Product draft uses unmodified Streamdown2.7.1 and app-owned grammar through existing remark/block/rehype hooks. Generic literal ranges come from that same grammar.

The durable product pin5a192dbfe is based on original2.7.1 source; this PR uses current upstream main. Remend runtime is identical, avoiding unrelated unreleased APIs downstream. Product JS SHA256:e9ffa20dd95ec86ec8c6e5577ad1cff082ab2d9363f3b5aa60a8bf3e3b41ef49.

Lines of code

True base:c6f590577744a6328440019deb6ad6053167eb96. Mutually exclusive categories:

Category Added Deleted Net
Runtime 200 32 +168
Tests 280 0 +280
README and changeset 28 0 +28
Total 508 32 +476

Nothing excluded. No generated/lockfile/media changes and no unrelated deletions.

Models used

Implementation and independent review:OpenAI gpt-6.1-sol. No model override/fallback; reasoning effort not independently verified.

Draft, unmerged.

Final exact-head checks

Atba8b9e7 AgentReviewSUCCESS/zero suggestions,InternalSecuritySUCCESS,bothSocketSUCCESS. Reviewer resolution confirmation. No new findings. DraftOPEN/MERGEABLE/unmerged. Signed-commit policy still fails for4unsignedcommits and Verceldeployment authorization is external. No keys accessed,deployment or merge authorized. Downstream exact3151 OSVfullscan passes; mainCIregistration blocked by staleGitHubtest-merge state, not claimed passing.

@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@davidfant is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

❌ Unsigned commits found

4 of 4 commit(s) in this pull request do not have a verified signature. All commits must be signed before this PR can be merged.

Commit Subject Author Reason
21a4671 Support parser-owned literal ranges during Markdown repair davidfant commit is not signed
1b0ac02 test(remend): cover literal range scope isolation davidfant commit is not signed
75896c5 docs(remend): clarify caller-owned literal range parsing davidfant commit is not signed
ba8b9e7 fix(remend): respect opaque boundaries in repair edits davidfant commit is not signed

How to fix

1. Set up commit signing (one-time; SSH shown, GPG and S/MIME also work):

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true

2. Add the key to GitHub as a Signing Key at github.com/settings/ssh/new (an authentication key alone is not enough), and make sure your git config user.email is a verified email on your account.

3. Re-sign the commits on this branch and force-push:

git fetch https://github.com/vercel/streamdown.git main
git rebase --exec 'git commit --amend --no-edit --no-verify -S' $(git merge-base HEAD FETCH_HEAD)
git push --force-with-lease

This check re-runs automatically when you push. See CONTRIBUTING.md for more details.

🤖 Using an AI coding agent? Paste this prompt
My pull request to vercel/streamdown is blocked because some commits are not signed with a verified signature. Please help me fix it:

1. Check whether commit signing is already configured: `git config --get gpg.format`, `git config --get user.signingkey`, `git config --get commit.gpgsign`, and `git config --get user.email`.
2. If signing is not configured, set up SSH commit signing: reuse an existing key in ~/.ssh (for example id_ed25519.pub) or generate one with `ssh-keygen -t ed25519 -C "<my email>"`, then run `git config --global gpg.format ssh`, `git config --global user.signingkey <path to the .pub file>`, and `git config --global commit.gpgsign true`.
3. Tell me to add the public key on GitHub at https://github.com/settings/ssh/new with "Key type" set to "Signing Key" (if `gh` is installed and authenticated with the admin:ssh_signing_key scope, you may run `gh ssh-key add <path to .pub> --type signing` instead). Also confirm that `git config user.email` is a verified email on my GitHub account (https://github.com/settings/emails). Wait for me to confirm before continuing.
4. Re-sign every commit on my branch without changing its content: fetch main from https://github.com/vercel/streamdown.git, then run `git rebase --exec 'git commit --amend --no-edit --no-verify -S' $(git merge-base HEAD FETCH_HEAD)`. Do not rebase onto a newer main, and do not squash, reorder, or edit commits.
5. Verify with `git log --show-signature FETCH_HEAD..HEAD` that every commit shows a good signature.
6. Ask me before running `git push --force-with-lease` to update the pull request branch.

Checked at ba8b9e7.

@davidfant
davidfant force-pushed the energy/registered-widget-containers branch from b271a4b to b57a8e8 Compare October 26, 2026 22:35
Comment thread packages/streamdown/index.tsx Outdated
Comment thread packages/streamdown/lib/remark/registered-containers.ts Outdated
Comment thread packages/streamdown/lib/remark/registered-containers.ts Outdated
@davidfant davidfant changed the title Parse registered widget containers through the Markdown grammar feat(remend): protect parser-owned literal ranges during repair Oct 27, 2026
@davidfant
davidfant force-pushed the energy/registered-widget-containers branch from 9867b51 to 75896c5 Compare October 27, 2026 02:08

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional findings

  1. packages/remend/src/html-tag-handler.ts:45-46 — An incomplete HTML tag immediately following a literal range causes trimEnd() to delete protected trailing whitespace from that range.

    Fix on Vercel

  2. packages/remend/src/link-image-handler.ts:22-30 — An incomplete link or image URL opened before a literal range deletes that protected range and all following prose, including in text-only mode.

    Fix on Vercel

  3. packages/remend/src/emphasis-handlers.ts:634-641 — When underscore emphasis precedes a literal range containing trailing newlines, completion inserts _ inside the protected payload instead of outside the range.

    Fix on Vercel

Comment thread packages/remend/src/index.ts

This branch has not been deployed

No deployments
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