Repository navigation
Assistant: place images, diagrams, references and child notes by paragraph - #202
Merged
Merged
Conversation
…graph A block-inserting action could only be placed against a heading, so "in the second chapter, add an image above every paragraph" put every image directly beneath the chapter title. The model had no way to say "next to this paragraph". generate_image, create_diagram, add_reference and create_child_note now take three optional placement fields: - anchorText: the opening words of an existing paragraph, list item, quote or other block; the new block goes directly before or after it - position: "before" / "after" (default) relative to the anchor; with only a section, "after" (beneath the heading), "before" (above it) or "end" (after the section's last block). Synonyms like above/below are folded in. - section: narrows the anchor search to that section, or places relative to the heading on its own (the previous behaviour) Anchors are matched through the Markdown the model copies (emphasis, link syntax, escapes, bullets, trailing ellipsis), preferring a whole-block match, then a block that starts with the snippet, then one that contains it. A target that cannot be found degrades to the section, then the end of the note, and the run summary says so. create_diagram previously always appended to the end; it now honours placement too. The planner prompt gains a "Placing blocks" rule with the per-paragraph example, and both parsers (TS and Python) validate and label the new fields identically — checked with tools/plan_parse_diff (57/57 agree). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fym1mUkgMQ1jAexC6D6zmK
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
A request like "In the second chapter, add an image above every paragraph that describes the paragraph" put every image at the start of the chapter.
generate_imagecould only take a heading (section) and always inserted atheading + 1, so N images stacked under the chapter title (in reverse order). The model had no way to express "next to this paragraph".create_diagramwas worse: it always appended to the end of the note.Fix
The four actions that insert a single block (
generate_image,create_diagram,add_reference,create_child_note) now accept three optional placement fields:anchorTextpositionbefore/after(default). Section only:after(under heading, default — old behaviour),before(above heading),end(after the section's last block).above/below/under/beneathfold onto thesesectionExecutor (
executor.py): newresolve_placement/find_anchor_index. Anchors match through the Markdown the model copies (emphasis,[link](url), escapes, bullets, trailing…), and link text inside link nodes is now included (the oldblock_textskipped it). Tightest match wins: whole block → starts-with → contains → nested child (resolved to its top-level ancestor so the block isn't indented under a list item). If a target can't be found it falls back to the section, then the end of the note, and the run summary says so instead of failing a paid image generation.section_endwas pulled out ofedit_sectionand shared.Prompt (
aiPlan.ts): new "Placing blocks" rule with the per-paragraph example spelled out, updated action signatures, and the Images rule now points at paragraph anchoring.Parsers: TS
validateActionand Pythonvalidate_actionboth carry the new fields;add_referencealso acceptssection(folded ontoinsertAfterSection) so every block action uses the same vocabulary. Labels in the review modal say where a block will land ("Generate image above “Storm clouds…” in …").Testing
['Chapter 2', 'image', 'image', 'Storm clouds…', 'The crew…']. With this change they land above their paragraphs.before/end, diagrams/references/child notes, Markdown-tolerant matching, nested anchors).tsc --noEmitclean, vitest 204 passed (new placement parse/label tests).tools/plan_parse_diff: added 3 corpus samples; 57/57 agree between TS and Python on plan, labels and prompts.Notes
PLAN_INSTRUCTIONSinvalidates the Anthropic prompt-cache prefix once after deploy.edit_section(rewrite of the whole section); not changed here.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fym1mUkgMQ1jAexC6D6zmK
Generated by Claude Code