Draft
Conversation
Implements a new TypeAgent agent (excalidraw-agent) that uses an LLM to convert source materials (markdown, plain text, Visio XML, Mermaid, and architecture descriptions) into valid Excalidraw JSON diagrams. Includes createDiagram and exportDiagram actions, with output defaulting to the user's Documents folder. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the lossy 2-phase Mermaid intermediate approach with a typed DiagramPlan IR and an iterative LLM correction loop (up to 3 passes) backed by deterministic programmatic validation. Adds explicit support for nested/grouped objects and plan-to-element traceability via stable ID conventions. - diagramPlan.ts: typed IR with parentGroupId/childNodeIds for nesting - prompts.ts: plan extraction, generation, and correction prompt builders - diagramValidator.ts: 8-category deterministic validator (no LLM) - excalidrawActionHandler.ts: rewritten iterative pipeline - test/: 24-test suite covering validation and prompt correctness - excalidraw_agent_design.md: architecture design document Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…agent Remove hardcoded max_tokens overrides (8000/16000) that exceeded the configured model's 4096 token limit, causing "max_tokens is too large" errors. The API now uses the model's default maximum. Also add stripMarkdownFences() to handle models that emit markdown code fences even in json_object mode, and improve parse error messages to include response context for debugging. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document the max_tokens fix, JSON parse robustness improvements, and better error diagnostics added in the previous commit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LLM sometimes omits childNodeIds or childGroupIds arrays from PlanGroup objects. Added normalization in the plan post-parse step and defensive null-coalescing in the validator to prevent .includes() on undefined. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d generation Large diagrams (16+ nodes) caused LLM output to exceed token limits, producing truncated JSON (e.g., "Unterminated string in JSON at position 12564"). This adds a 3-layer defense: (1) compact output via default field omission with programmatic injection post-parse, reducing output ~40%; (2) chunked generation splitting Phase 2 into 3 sequential LLM calls (groups, nodes, edges) for diagrams with >12 plan items; (3) truncation recovery as a last-ditch salvage mechanism. Adds 30 new tests (54 total). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…with deterministic expansion LLM now generates a compact MinimalDiagram (~7 fields/element) instead of verbose Excalidraw JSON (~20+ fields/element). New expandToExcalidraw() function deterministically adds all required Excalidraw fields in TypeScript, eliminating reliance on LLM to omit default fields. A 31-element diagram now produces well under 4000 chars of LLM output vs ~12,761 chars previously. Correction loop also updated to work in minimal format. 81 tests pass (27 new). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…re flow - Add normalizeLayout() pre-processing pass in expandToExcalidraw() - Group frames sized by 2^N multiplier where N = max child nesting depth (cap 4) - Frames re-flow children along dominant axis (LR if wider, TD if taller) - Frames grow by 50% when children don't fit, propagating up ancestor chain - resolveOverlaps() pushes siblings along parent frame's dominant axis - Snap all coordinates to 20px grid for clean alignment - Increase prompt spacing: 100px row gap, 60px within-group, 80px group top padding - Fix group label text: small strip at top-left instead of spanning full frame - Debug error message includes raw response preview for parse failures Co-Authored-By: Claude Sonnet 4.6 <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.
Add Excalidraw Agent for AI-Powered Diagram Generation
Summary
Adds a new excalidraw TypeAgent that converts documentation, markdown, Visio XML exports, Mermaid
diagrams, and plain-text architecture descriptions into https://excalidraw.com/ diagram files using
AI. The agent integrates with the existing TypeAgent dispatcher and agent provider infrastructure.
What's Changed
New package: ts/packages/agents/excalidraw/
architecture), optional diagramTitle, and optional outputPath
instructs the LLM to output valid Excalidraw JSON (type, version, elements[], appState). Writes the
resulting .excalidraw file to the user-specified path, or defaults to ~/Documents/ with a timestamped
filename.
Agent registration: ts/packages/defaultAgentProvider/
Usage Examples
▎ "Create an Excalidraw diagram from this architecture document"
▎ "Convert this Mermaid diagram to an Excalidraw file and save it to C:\diagrams\arch.excalidraw"
▎ "Turn this Visio XML into an Excalidraw diagram"
Testing
Notes
(cross-platform: works on Windows and Unix)
arrows, colors, layout) to maximize diagram quality