Skip to content

Message directive embeds render as literal text when prose follows ::name{…} on the same line #4409

Closed

Description

@MacHatter1

Summary

When an assistant message has prose on the same line right after a plugin message directive, like ::browser-preview{session="…"}Next I'll load the page., the embed never mounts. The directive source shows up as literal text instead. I expected the embed to mount with the prose rendered after it. This affects every app.slots.messageDirective() embed (browser-preview, inline-vis, …), not one plugin.

Versions and environment

  • bb 0.43.4 (desktop app), macOS 26.6
  • claude-code, Claude Code 2.1.280
  • Also reproduced from source on main at a19b3ed (renderer level, see steps)

Steps to reproduce

Renderer level, on main at a19b3ed4f:

  1. Render MarkdownPreview with a registered inline-vis message directive and this content:
    ::inline-vis{file="demo.html"}Next I will load the thread.
    
  2. No directive mounts. The whole line renders as a literal paragraph.
  3. Put a newline after } (::inline-vis{file="demo.html"}\nNext I will load the thread.). It mounts.

In the app: any assistant message where a registered ::name{...} is followed by prose on the same line. I saw this live with ::browser-preview (see Evidence).

Did not reproduce with the directive on its own line, or with a single \n right after }. A space after } still fails.

Expected vs actual

Input:    ::inline-vis{file="demo.html"}Next I will load the thread.
Actual:   literal paragraph "::inline-vis{file="demo.html"}Next I will load the thread.", 0 mounts
Expected: inline-vis embed (file=demo.html), then the paragraph "Next I will load the thread."
Before (main) Expected
Glued directive renders as literal text and nothing mounts Embed mounts and the trailing prose renders below it

Look at the first line of each: on main it's raw ::inline-vis{…} text. The "Expected" shot comes from a patched build.

Evidence

Observed in thread thr_pdjcruqnvf (project proj_hmikzjrmwn, provider claude-code). bb browser-automation open returned a valid ready session every time. The agent then wrote the directive with prose glued on in 3 of 4 messages, and only the standalone one mounted:

seq 447   '::browser-preview{session="1cc01f18-…"}The browser is open (live view above). Next I'll check …'   -> literal
seq 554   '::browser-preview{session="b901eef9-…"}'                                                           -> mounted
seq 639   '::browser-preview{session="79ad152b-…"}The aggregator has just started, so I'll switch back …'  -> literal
seq 1660  '::browser-preview{session="94327984-…"}Next I'll load the `/moa` thread you pointed at, …'       -> literal

For seq 1660, the directive and the prose arrived as separate deltas (1657, 1658) and were joined into one agentMessage with no separator. I haven't established whether the model emitted them back to back or the join dropped a newline. Either way the text reaches the renderer glued.

Root cause: [email protected] only emits a leafDirective when ::name{...} is the last thing on its line. Checked directly against the parser:

'::browser-preview{session="x"}Next'      -> paragraph (text)
'::browser-preview{session="x"} Next'     -> paragraph (text)
'::browser-preview{session="x"}\nNext'    -> leafDirective + paragraph
'::browser-preview{session="x"}\n\nNext'  -> leafDirective + paragraph

So remarkMessageDirectives() never sees a directive node for the glued form, and it renders as text:

export function remarkMessageDirectives(args: {
indexBase: number;
limit: number;
mounts: MountedMessageDirective[];
registry: MessageDirectiveRegistry;
}) {
const { indexBase, limit, mounts, registry } = args;
return (tree: Nodes, file: RemarkMessageDirectiveFile): void => {
const markdownSource =
typeof file.value === "string" ? file.value : String(file.value ?? "");
mounts.length = 0;
visit(tree, (node, index, parent: Parent | undefined) => {
const directive = asDirectiveNode(node);
if (directive === null || parent === undefined || index === undefined) {
return;
}
const marker = DIRECTIVE_MARKERS[directive.type];
const name = typeof directive.name === "string" ? directive.name : "";
const attributes = normalizeDirectiveAttributes(directive.attributes);
const source = directiveSourceFromNode(
directive,
markdownSource,
name,
attributes,
marker,
);
const entry = registry.get(name);
if (
directive.type !== "leafDirective" ||
name.length === 0 ||
entry === undefined ||
entry.status === "collision" ||
mounts.length >= limit
) {
return spliceLiteralDirective(parent, index, directive.type, source);
}
const mountIndex = indexBase + mounts.length;
mounts.push({
attributes,
index: mountIndex,
slot: entry.slot,
source,
});
parent.children.splice(index, 1, messageDirectiveMountNode(mountIndex));
return index;
});
};

The browser-automation skill already says to emit the directive "exactly once as a standalone line" (SKILL.md#L75), but agents still glue prose to it often. A prompt-only fix won't cover every plugin or provider.

What you ruled out

Suggested priority and effort

Medium. It hits every plugin message-directive embed whenever an agent continues on the same line, which happens often. The only workaround is agent formatting, and no data is lost. Effort is probably low: a tolerant fallback in remarkMessageDirectives().

Checks

  • I reproduced this on main (a19b3ed).
  • I searched open and closed issues for the same problem.

Activity

  1. added a commit that references this issue on Sep 29, 2026
    c78badf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions