Repository navigation
feat(applets): agents revise applets with edits, and applet source stays out of other models' context - #1828
Merged
Merged
Conversation
…ith edits
- publish_applet takes edits ({part, old_str, new_str}, each matching once,
applied in order, all or none) against appletId at expectedRevision. Fields
left out keep the revision's values. A stale revision, a second revision of
the same applet in one response and an edit that does not match are tool
errors when the call is made, not a failed publication at the end.
- New read_applet tool: the sizes of an applet's parts, a bounded page of one
part, or the lines containing a text, for a revision a shown reply carries.
Threads only; not bots.
- Handoffs, a run's result (what a parent and thread_wait read) and
thread_read give a published applet as one line instead of its source. The
stored reply keeps its fence for recovery and bots' chats.
- A fork no longer lists its parent's applets, which it cannot open.
- The applet guidance tells agents to revise with edits and read with
read_applet, not to look for source in the conversation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- publish_applet revises only an applet whose newest revision a shown reply carries, so a revision an Undo hid is neither named in an error nor built on. - A run's result is built after publication: published applets read as their reference line, and an applet the model wrote as a fence no longer passes its source to the parent. - A remote subagent's result reads its reply the same way. - A bot's thread_read summary previews the reply with its applets as lines. - read_applet search cuts a long excerpt around the match and keeps all matches within one page. - The guidance asks for read_applet only where it is usable (not bots). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheAnimatrix
force-pushed
the
applet-source-out-of-context
branch
from
November 24, 2026 15:05
9e9136e to
a61b0d5
Compare
A remote subagent whose applet failed to publish now returns a line naming the applet, as a local run does. read_applet sizes data as the pretty JSON its pages return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_applet by bytes - A valid applet that failed to publish reads as [Applet: title] in handoffs, thread_read and a run's result, not as its source. - A stopped run's result names an applet it streamed whole but never published. - read_applet pages stop at 64 KiB of UTF-8 as well as at limit characters, and never split a character; search matches together stay within 64 KiB, and a search is at most 1,024 characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on as written - A tool-staged applet after a reply that left a code block open now closes that block first, so the applet publishes and reads as its line instead of being held as text with its source. - A person's message reaches other models as written: only a model's replies have their applet fences named. - read_applet counts the bytes its JSON result adds (escaped tabs, quotes, control characters) toward a page, and an offset inside an emoji starts at the emoji. - A schema version given with edits is validated, not replaced with 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… past the publication cap - A code block an earlier reply row leaves open no longer decides how the turn's last row is closed: the last row is judged on its own, so a tool-staged applet after it publishes and reads as its line. - Naming applets for other models reads every valid fence in a reply, also past the three a reply may publish, so a fourth one is never passed on as source. - read_applet search excerpts never cut an emoji at either end. - A null schemaVersion given with edits is validated, not replaced with 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n one line - A run's result names each earlier reply row's applets on that row alone, so a code block one row leaves open no longer hides a later row's fence and passes its source on. - Naming reads past a block left open, which publication reads as text. - A title's line breaks become spaces in its reference line, so they can't start a line that reads as a code fence. - A revision with edits keeps every field the call gives, so a null title or a misspelled field is refused as in a full submission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
master added the line to the instructions without updating this snapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Model-facing text (a run's result, a handoff, thread_read, a remote subagent's reply) no longer reuses the publication parser to hide applet source. A separate redactor cuts every applet fence, valid or not, from its opening line to where publication would end it or to the end of the text, and names it on one line. It ignores other code blocks, counts, sizes and validity, and sees openings at every line start publication sees. A stored reply's parts are read one by one, so a reference line is never read again as text, and a reference line's title stays on one line for U+2028 and U+2029 too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… one - The redactor finds an applet opening anywhere on a line, since a stopped run's rows can join without a line break. It ends a fence only at a closing line after a real line break, so it never cuts less than publication reads. It names a fence only by its body's top-level title. - A stored reply is redacted whole, with its published applets as reference lines, so a fence a part leaves open is cut as in the text the model wrote. - Tool-staged applets join the last row before a code block it leaves open, instead of closing that block, so an unfinished applet fence stays unpublished. Their JSON escapes U+2028 and U+2029, so backticks after one in a string no longer end the fence early. - The viewport sizing message quotes at most 60 characters of source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Model-facing text now always comes from the reply as the model wrote it, never from the stored presentation parts. Publication adds diagnostic text to those parts, which could end a cut early. Published applets are matched to their fences by title, in order, and named by their reference lines. Any published applet not matched follows the text. - A turn's result redacts the whole turn's text after publication too, so a fence one row opens and a later row continues is cut. - A definition run's result is redacted like a turn's. - An applet opening is tried only where a run of backticks or tildes starts, so a long divider line is scanned once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tool-staged applets join the last row at its end or before a code block it leaves open, and now never inside an applet fence as redaction reads one. There, their closing line could end the fence's cut early and pass the rest of its source to a model. They go before the line that fence opens on. A reference line's title no longer holds a run of three backticks or tildes, so redacting a result again leaves it as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…el's text - Tool-staged applets go after everything the model wrote, as on master, so they never fall inside an applet fence as redaction reads one. A code block the reply leaves open is closed first, unless an applet fence is left open, so an unfinished applet never publishes. - A run's result is the text the model wrote with its applet fences cut, then the staged applets by title or, once published, by reference line. Text added for publication is never read with it. - A bot's thread summary reads replies from the newest back and stops at the first with text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- An action block no longer takes the backticks that open the next block (```mousse-applet) as its closing fence, which left the applet's source as text without its opening. - A stopped run whose result is only its open row, and a definition run whose result is its last row, now cut that row as part of the turn's whole text, so a fence an earlier row opened is cut. - A tool-staged applet that failed to publish is still named in the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- An action block that overlaps an applet fence stays, so stripping it cannot take the fence's opening or leave a line that closes it early. - A stopped run's and a definition run's last row are cut as part of the turn's rows joined as they streamed, with nothing trimmed or put between them, so no row closes a fence that the original text did not (redactAppletTail). - Staged applets' publications are matched from the end, where their fences are, so one the cap refused is still named when a reply's own applet shares its title. - A published applet's reference line goes to a fence with all three parts, never to an earlier invalid fence with its title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Published applets are placed by where their fence opens, read as publication read the stored reply (its parts map one to one onto the parsed reply). No title matching is left: a refused fence with a published applet's title, or a staged applet the cap refused, no longer takes its reference. References that cannot be placed follow the text. - A completed run's result is the turn's text with the staged fences, which follow everything the model wrote, so their publications are placed there too. - A last row that is the exact end of a turn's rows keeps its white space. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s lazily - Stored parts place a published applet's reference on a fence only when that fence's applet has the reference's title; stale parts of the same shape put their references after the text. - thread_read's short views read each message's model-facing text only when a view asks for it, so a recent view of one turn does not read every older applet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an agent builds an applet, its source (up to 512 KiB, roughly 100k+ tokens) keeps reaching models after it is published:
thread_read.Change
Revise with edits.
publish_applettakesedits: [{part, old_str, new_str}]withappletIdandexpectedRevision, like Claude Code's artifact edits:old_strmust match exactly once. Edits apply in order, all or none.read_applet. It returns one of three things for a revision a shown reply carries:search(at most 1,024 characters), the lines that contain a text, cut around the match on a long minified line, all matches together within 64 KiBIt is for threads, not bots.
One line instead of source. Handoffs, a run's result (what a parent and
thread_waitread, from a completed, stopped or definition run, also from a subagent on another computer) andthread_readshow a published applet as[Applet: title (appletId …, revision …)], and any other applet fence, valid or not, as[Applet: title]([Applet]when no title can be read). The stored reply keeps its fence, which crash recovery and a bot's chat match on. A person's message is passed on as written.How fences are cut. A redactor separate from the publication parser cuts every applet fence and fails closed. It finds an opening anywhere on a line and ignores other code blocks, the three-per-reply cap, size and validity. It ends a fence only at a closing line after a real line break, never earlier than publication would, and runs an unclosed fence to the end of the text. A published applet's reference line goes on the fence that published it, found by reading the stored reply as publication read it. A stopped or definition run reads its last row together with the turn's earlier rows. Tool-staged applets join the reply after everything the model wrote.
Related fixes. An action block no longer takes the backticks that open the next block as its closing fence, and one that overlaps an applet fence stays. Tool-staged JSON escapes U+2028 and U+2029. The viewport-sizing error quotes at most 60 characters of source.
Forks. A fork no longer lists its parent's applets, which it cannot open.
Guidance. Agents now revise with edits and read with
read_appletwhere it is usable. The SPEC describes both tools under "Applet source stays out of context".Out of scope: a runtime's own session (Claude Code, Codex, Pi) keeps what the model wrote there. Writing an applet still costs its tokens once.
Verification
tests/appletSource.test.ts(new) is a table of the edit and read rules: order, all or none, no match, two matches, inherited and overridden fields, edits given beside parts or paths, paging bounds, search.tests/run/appToolApplets.test.tscovers a vendor turn calling the MCP tools. A later turn reads the published applet in pages, searches it, is refused for a stale revision, an edit that doesn't match, edits given besidehtmland a second revision in one response, and publishes a revision from edits. Title, data and state version carry over.tests/appletsOrchestrator.test.tscovers a tool-published applet. The run's result, the handoff transcript and an agent'sthread.messagespage carry the reference line and not the source. The stored reply still has the fence. A second test does the same for an applet the model wrote as a fence: the run's result isBefore, the line,After.tests/run/remoteSubagents.test.ts: a remote subagent's result reads its reply with the applet as a line, also when the applet failed to publish. That second test fails without the fix.tests/applets.test.tsholds the redaction rules. A marker string inside every odd reply never comes through: an applet after an open code block, a fourth fence, an oversized, invalid or unclosed fence, one opening mid-line or after U+2028 or a lone\r, nested fences, CRLF, and a failed publication as the reply shows it. Redacting twice changes nothing. Published references are checked against a real publication.tests/appletsOrchestrator.test.tscovers the run result of a stopped run, of rows split around tool calls, of a staged applet the cap refused, and of a staged applet beside an unfinished fence.3bb54e0(master merged in),node scripts/verify.mjswith the 24 affected test files and--typecheck all: 447 of 449 tests pass, and typecheck passes for node and web.EPERMerrors when a test deletes its temp folder:tests/appletsOrchestrator.test.ts› "publishes completed native fences in order…" andtests/threadPaging.test.ts› "does not load a thread with nothing queued". They fail the same way on master on this machine, and which of these cleanup tests fail varies from run to run.tests/run/__snapshots__/toolAuthorityParity.jsonwas regenerated.read_appletis listed whereverpublish_appletis, plus read-only subagents, and never for bots.editsin a live turn.Council review
The design was reviewed before implementation by GPT-6.2 Astra, Claude Fable 5.2 and Gemini 4 Neon. All three found that rewriting history inside Mousse would save nothing, because every runtime keeps its own session. They pointed to edits,
read_appletand the handoff and run-result paths, which is what this PR does.Rounds: 16 (final review by GPT-6.2 Astra)
Round 1 findings, all fixed: a revision hidden by Undo could be named and edited; a fence the model wrote passed its source to the parent; a remote subagent's result passed raw source.
Round 2 findings, all fixed: a remote subagent's applet that failed to publish still passed its source on;
read_appletsized data as compact JSON while its pages return pretty JSON.Round 3 findings, fixed: an applet that failed to publish, and one a stopped run streamed whole, passed their source on;
read_appletpages and searches were bounded by characters, not bytes.Round 4 findings, fixed: a staged applet after an open code block was held as text with its source; a person's pasted fence was replaced by a line. The JSON escapes a page adds, an offset inside an emoji and an edit's schema version were also fixed.
Round 5 findings, fixed: an earlier row's open block, or three malformed fences, hid a staged applet's source from naming. A null schema version and search excerpts cutting an emoji were also fixed.
Round 6 findings, fixed: an earlier row's open block hid a later row's applet; a multiline title opened a code block in a reference line; an unfinished applet could publish. A null title and misspelled fields with edits were also fixed.
Round 7 findings, fixed: a stopped run's joined rows, a U+2028 title and an oversized failed publication still leaked through the strict parser. A design review with Gemini 4 Neon replaced naming through the publication parser with the fail-closed redactor.
Round 8 findings, fixed: rows joined mid-line; a published applet inside a malformed outer fence; a staged applet whose source held U+2028 and backticks; the viewport error quoting CSS; a title read from nested data; closing an open block that published an unfinished applet.
Round 9 findings, fixed: publication's added text ending a cut early; a fence continued across a tool call; a slow scan of long tilde lines. Definition-run results are now redacted too.
Round 10 findings, fixed: a staged applet inserted inside an applet fence ended its cut early. Reference titles no longer hold fence markers.
Round 11 findings, fixed: staged applets placed mid-reply ended a cut early or stopped publishing; they now follow the reply.
Round 12 findings, fixed: an action block took the backticks of a following applet opener; stopped and definition runs read only their last row.
Round 13 findings, fixed: action stripping, trimmed rows and row joins changed where a fence closed; a staged applet the cap refused lost its name.
Round 14 findings, fixed: a staged applet the cap refused, or a refused fence, took a published applet's reference; references are now placed by position.
Round 15 findings: no blocking findings. Stale stored parts could place a reference, and a recent view read every older applet; both fixed.
Round 16 findings: no blocking findings. A fence marker quoted mid-line in prose hides the rest of that reply from the next model, which is the fail-closed cost; a
thread_readpage redacts its first row twice.Findings left as follow-ups are listed in Notes.
Notes
Follow-ups:
publish_applet) can still name a revision an Undo hid as itsexpectedRevision.thread_searchsnippets can quote applet source around a match.thread_read, a handoff or a remote result reads one stored row of such a fence on its own. This costs tokens, not a secret."~~~mousse-applet") hides the rest of that reply from the next model. Redaction fails closed, so it hides too much rather than too little.thread_readmessages page redacts its first row twice.No issue
🤖 Generated with Claude Code