Documentation
¶
Overview ¶
Package blocks prepares the structured, non-Markdown conversation blocks in mecatui's conversation view.
It is an internal package, but its boundary is intentionally stable enough for other UI components and contributors to use. Blocks is a pure presentation layer: callers provide immutable snapshots and resolved presentation inputs; preparation returns final block-local lines plus lockstep structural rows. It does not know about conversations, session events, viewports, Bubble Tea models, block identity, or cache lifetime.
The major pieces are:
- Prepared and Row: final lines and their semantic provenance. A Row has the semantic region, visible-text offset, fallback row, leading column, and grapheme span needed by the parent UI to build frame provenance without parsing decorated output.
- styled_tool.go and styled_tool_rows.go: the framed tool-card compiler and its layout/provenance reconciliation for headers, arguments, results, artifacts, diffs, and delegation output.
- plain.go and plain_cards.go: shared plain-card width and terminal-safety handling plus User, Notice, Hook, Delivery, and TurnStat preparation.
- error_cards.go: transient and permanent error presentation, including the collapsed permanent-error summary and expanded raw payload.
The parent ui package owns the rest of the rendering pipeline. Conversation mutation advances each block's content revision; the renderer combines that revision with shared view context (width, expansion, and rendering dialect) to decide cache reuse. After a cache miss, it adapts Prepared.Rows into its document-local frame by attaching block identity, indentation, kind, and inter-block separators.
Package blocks prepares stateless, structured conversation-block snapshots.
It deliberately has no knowledge of the conversation, renderer cache, viewport, or Bubble Tea model. The parent ui package attaches document-local identity and frame ownership when it adapts a Prepared value into its rendered frame.
Index ¶
- func CollapseErrorSummary(s string) string
- func DeliveryBodyForDisplay(raw string) string
- func PermanentErrorSummary(raw string) string
- func SanitizePlain(s string) string
- type DeliveryInput
- type DeliverySnapshot
- type ErrorInput
- type ErrorSnapshot
- type HookInput
- type HookSnapshot
- type NoticeInput
- type NoticeSnapshot
- type PermanentErrorInput
- type PermanentErrorSnapshot
- type PlainLayout
- type PlainLayoutInput
- type Prepared
- func PrepareDelivery(in DeliverySnapshot, layout PlainLayout, theme Theme) Prepared
- func PrepareError(in ErrorSnapshot, layout PlainLayout, theme Theme) Prepared
- func PrepareHook(in HookSnapshot, layout PlainLayout, theme Theme) Prepared
- func PrepareNotice(in NoticeSnapshot, layout PlainLayout, theme Theme) Prepared
- func PreparePermanentError(in PermanentErrorSnapshot, layout PlainLayout, theme Theme) Prepared
- func PrepareStyledTool(input StyledToolSnapshot, theme Theme) Prepared
- func PrepareTurnStat(in TurnStatSnapshot, layout PlainLayout, theme Theme) Prepared
- func PrepareUser(in UserSnapshot, layout PlainLayout, theme Theme) Prepared
- type Region
- type Row
- type StyledSectionInput
- type StyledToolInput
- type StyledToolSnapshot
- type Theme
- type TurnStatInput
- type TurnStatSnapshot
- type UserInput
- type UserSnapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollapseErrorSummary ¶
CollapseErrorSummary rewrites a legacy SDK-shaped provider error.
func DeliveryBodyForDisplay ¶
DeliveryBodyForDisplay strips only the recognized delivery fence and header.
func PermanentErrorSummary ¶
PermanentErrorSummary preserves compatibility with legacy SDK-shaped errors.
func SanitizePlain ¶
SanitizePlain removes terminal controls from plain card text while preserving layout newlines and tabs. Markdown must not pass through this function.
Types ¶
type DeliveryInput ¶
type DeliveryInput struct{ ScheduleName, FireID, Text string }
DeliveryInput is caller-owned scheduled-delivery content.
type DeliverySnapshot ¶
type DeliverySnapshot struct {
// contains filtered or unexported fields
}
DeliverySnapshot is an immutable delivery snapshot.
func SnapshotDelivery ¶
func SnapshotDelivery(in DeliveryInput) DeliverySnapshot
SnapshotDelivery owns a scheduled-delivery input.
type ErrorInput ¶
type ErrorInput struct{ Text string }
ErrorInput is caller-owned transient-error content.
type ErrorSnapshot ¶
type ErrorSnapshot struct {
// contains filtered or unexported fields
}
ErrorSnapshot is an immutable transient-error snapshot.
func SnapshotError ¶
func SnapshotError(in ErrorInput) ErrorSnapshot
SnapshotError owns a transient-error input.
type HookInput ¶
type HookInput struct{ Text, Phase, Tool, Decision string }
HookInput is caller-owned structured hook content.
type HookSnapshot ¶
type HookSnapshot struct {
// contains filtered or unexported fields
}
HookSnapshot is an immutable hook snapshot.
func SnapshotHook ¶
func SnapshotHook(in HookInput) HookSnapshot
SnapshotHook owns a structured hook input.
type NoticeInput ¶
NoticeInput is caller-owned notice content.
type NoticeSnapshot ¶
type NoticeSnapshot struct {
// contains filtered or unexported fields
}
NoticeSnapshot is an immutable notice snapshot.
func SnapshotNotice ¶
func SnapshotNotice(in NoticeInput) NoticeSnapshot
SnapshotNotice owns a notice input.
type PermanentErrorInput ¶
type PermanentErrorInput struct{ Text string }
PermanentErrorInput is caller-owned permanent-error content.
type PermanentErrorSnapshot ¶
type PermanentErrorSnapshot struct {
// contains filtered or unexported fields
}
PermanentErrorSnapshot is an immutable permanent-error snapshot.
func SnapshotPermanentError ¶
func SnapshotPermanentError(in PermanentErrorInput) PermanentErrorSnapshot
SnapshotPermanentError owns a permanent-error input.
type PlainLayout ¶
type PlainLayout struct {
// contains filtered or unexported fields
}
PlainLayout is an immutable geometry snapshot.
func SnapshotPlainLayout ¶
func SnapshotPlainLayout(in PlainLayoutInput) PlainLayout
SnapshotPlainLayout detaches plain-card preparation from renderer state.
type PlainLayoutInput ¶
PlainLayoutInput is the caller-owned geometry used by non-Markdown cards.
type Prepared ¶
Prepared is the complete output of one stateless preparation.
func PrepareDelivery ¶
func PrepareDelivery(in DeliverySnapshot, layout PlainLayout, theme Theme) Prepared
PrepareDelivery prepares a scheduled-delivery card.
func PrepareError ¶
func PrepareError(in ErrorSnapshot, layout PlainLayout, theme Theme) Prepared
PrepareError prepares a transient error.
func PrepareHook ¶
func PrepareHook(in HookSnapshot, layout PlainLayout, theme Theme) Prepared
PrepareHook prepares a decision-specific hook notice.
func PrepareNotice ¶
func PrepareNotice(in NoticeSnapshot, layout PlainLayout, theme Theme) Prepared
PrepareNotice prepares an ordinary or recovery notice.
func PreparePermanentError ¶
func PreparePermanentError(in PermanentErrorSnapshot, layout PlainLayout, theme Theme) Prepared
PreparePermanentError prepares collapsed or expanded permanent-error content.
func PrepareStyledTool ¶
func PrepareStyledTool(input StyledToolSnapshot, theme Theme) Prepared
PrepareStyledTool produces the actual main-conversation block lines and their structural provenance in one stateless operation.
func PrepareTurnStat ¶
func PrepareTurnStat(in TurnStatSnapshot, layout PlainLayout, theme Theme) Prepared
PrepareTurnStat prepares a turn-stat line.
func PrepareUser ¶
func PrepareUser(in UserSnapshot, layout PlainLayout, theme Theme) Prepared
PrepareUser prepares a user-prompt block.
type Region ¶
type Region uint8
Region identifies a block-local semantic area. It has no document identity.
const ( // RegionChrome identifies frame and header rows without visible semantic text. RegionChrome Region = iota // RegionBody identifies visible non-tool card text. RegionBody // RegionArguments identifies visible tool-argument text. RegionArguments // RegionResult identifies visible tool-result text. RegionResult )
type Row ¶
type Row struct {
Region Region
Text bool
SourceOffset int
FallbackRow int
LeadingColumn int
GraphemeSpan int
}
Row is the structural provenance for one final card-local line. It carries no semantic source text; the frame remains the owner of rendered strings.
type StyledSectionInput ¶
StyledSectionInput is one already width-bounded semantic section of a real tool card. Text may contain ANSI styling, but all dynamic text has been wrapped before that styling was applied.
type StyledToolInput ¶
type StyledToolInput struct {
Sections []StyledSectionInput
}
StyledToolInput is the caller-owned input for the main-conversation tool card.
type StyledToolSnapshot ¶
type StyledToolSnapshot struct {
// contains filtered or unexported fields
}
StyledToolSnapshot owns the strings used by a tool-card preparation.
func SnapshotStyledTool ¶
func SnapshotStyledTool(input StyledToolInput) StyledToolSnapshot
SnapshotStyledTool detaches preparation from the mutable conversation block.
type Theme ¶
type Theme struct {
UserLabel lipgloss.Style
UserBody lipgloss.Style
Muted lipgloss.Style
Warning lipgloss.Style
Error lipgloss.Style
HookModified lipgloss.Style
HookAdvisory lipgloss.Style
DeliveryHead lipgloss.Style
ToolCard lipgloss.Style
}
Theme contains the resolved semantic styles required to prepare conversation blocks. The UI maps its stylesheet roles to this value at the package boundary.
type TurnStatInput ¶
type TurnStatInput struct{ Text string }
TurnStatInput is caller-owned turn-stat content.
type TurnStatSnapshot ¶
type TurnStatSnapshot struct {
// contains filtered or unexported fields
}
TurnStatSnapshot is an immutable turn-stat snapshot.
func SnapshotTurnStat ¶
func SnapshotTurnStat(in TurnStatInput) TurnStatSnapshot
SnapshotTurnStat owns a turn-stat input.
type UserSnapshot ¶
type UserSnapshot struct {
// contains filtered or unexported fields
}
UserSnapshot is an immutable user-prompt snapshot.
func SnapshotUser ¶
func SnapshotUser(in UserInput) UserSnapshot
SnapshotUser owns a user-prompt input.