Documentation
¶
Overview ¶
Package whiteboard turns Mermaid diagrams the model emits into two things:
- a terminal-rendered ASCII/Unicode graph (RenderASCII), shown in the TUI in place of the raw ```mermaid source, and
- a link to the browser whiteboard (AppendWhiteboardLinks), where flowcharts are converted to positioned canvas "scenes" and everything else falls back to an in-browser mermaid.js render.
It is imported by both the daemon (link injection) and the TUI (ASCII render), so it lives under internal/ with no dependency on either binary.
Index ¶
- func AppendWhiteboardLinks(text, base, threadID string) string
- func CompressScenes(scenes []Scene) (string, error)
- func CompressText(s string) string
- func LinkFor(base, threadID, mermaid string) (string, error)
- func RenderASCII(mermaid string, width int) (out string, err error)
- func WhiteboardBase(webPort int) string
- type Edge
- type MermaidScene
- type Node
- type Scene
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendWhiteboardLinks ¶
AppendWhiteboardLinks scans text for ```mermaid fenced blocks and inserts a "[See it on the whiteboard](url)" markdown link immediately after each one. It is idempotent: a block that is already followed by such a link is left untouched, so re-finalizing or replaying a message does not duplicate links. When base is "" (web UI disabled) the text is returned unchanged.
func CompressScenes ¶
CompressScenes returns the compressed (deflate+base64url) JSON of scenes, suitable as the value of a ?scenes_z= query parameter on the whiteboard page.
func CompressText ¶
CompressText returns the compressed (deflate+base64url) form of s, used for the plan text handed to the whiteboard walkthrough.
func LinkFor ¶
LinkFor returns the whiteboard URL for a single mermaid diagram: a positioned ?scenes= link when it parses as a flowchart, else a ?mermaid= fallback link.
func RenderASCII ¶
RenderASCII renders a Mermaid diagram to Unicode box-drawing text sized to fit width columns (0 = unconstrained). It returns an error for unsupported or malformed diagrams so callers can fall back to showing the raw source.
The underlying mermaid-ascii renderer panics on some diagram geometries (e.g. an index-out-of-range while drawing edges), so we recover here and surface the panic as an error. A single bad diagram must never take down the TUI.
func WhiteboardBase ¶
WhiteboardBase returns the origin of the local web UI for the given port, or "" when the web UI is disabled (port <= 0), in which case no link is emitted.
Types ¶
type Edge ¶
type Edge struct {
ID string `json:"id"`
From string `json:"from"`
FromHandle string `json:"from_handle"`
To string `json:"to"`
ToHandle string `json:"to_handle"`
Label string `json:"label,omitempty"`
}
Edge mirrors the canvas edge schema. Label is new (rendered at the edge midpoint by CustomEdge) and omitted when empty for compact URLs.
type MermaidScene ¶
type MermaidScene struct {
Name string `json:"name"`
Context string `json:"context"`
Mermaid string `json:"mermaid"`
}
MermaidScene is one authored plan-whiteboard scene: a name, narration context (for the voice agent) and a Mermaid flowchart. It is what the plan workflow's generate step emits, before layout.
type Node ¶
type Node struct {
ID string `json:"id"`
Shape string `json:"shape"`
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
Label string `json:"label"`
Color string `json:"color"`
BorderColor string `json:"border_color"`
TextAlignment string `json:"text_alignment"`
// ParentID is the enclosing group (subgraph) node's id, or "" for a
// top-level node. When set, X/Y are relative to the parent, matching React
// Flow's parent/child coordinate model. Omitted for parent-less nodes so
// pre-subgraph links are byte-identical.
ParentID string `json:"parent_id,omitempty"`
}
Node mirrors the canvas node schema consumed by the web whiteboard (SystemDesignCanvas.__setCanvas). Coordinates and dimensions are assigned by the layout pass; the web canvas sizes each box to Width/Height (falling back to per-shape defaults when absent, for backward compatibility).
type Scene ¶
type Scene struct {
Name string `json:"name"`
Context string `json:"context"`
Nodes []Node `json:"nodes"`
Edges []Edge `json:"edges"`
Code []any `json:"code"`
}
Scene is one canvas the whiteboard page can display. The chat feature emits a single scene; the plan workflow emits several.
func ScenesFromMermaid ¶
func ScenesFromMermaid(items []MermaidScene) []Scene
ScenesFromMermaid converts authored mermaid scenes into positioned canvas scenes. Each flowchart is parsed and laid out; a scene whose mermaid can't be parsed as a flowchart becomes an empty canvas (its name/context are kept so it still appears in the scene list).