whiteboard

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendWhiteboardLinks(text, base, threadID string) string

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

func CompressScenes(scenes []Scene) (string, error)

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

func CompressText(s string) string

CompressText returns the compressed (deflate+base64url) form of s, used for the plan text handed to the whiteboard walkthrough.

func LinkFor

func LinkFor(base, threadID, mermaid string) (string, error)

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

func RenderASCII(mermaid string, width int) (out string, err error)

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

func WhiteboardBase(webPort int) string

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).

func ToScene

func ToScene(mermaid, name string) (Scene, bool)

ToScene converts a single Mermaid flowchart into one positioned Scene. ok is false when the input is not a flowchart or cannot be parsed into at least one node — callers should then fall back to the raw-mermaid link.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL