display

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultThresholdWarm = 500
	DefaultThresholdCold = 2000
)

Default thresholds for state transitions.

View Source
const ProtocolHeader = "#!SOV/1"

ProtocolHeader is the versioned prefix for the Sovereign Context Protocol.

Variables

View Source
var (
	HeaderStyle  = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12"))
	SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
	ErrorStyle   = lipgloss.NewStyle().Foreground(lipgloss.Color("9"))
	DimStyle     = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
	StatStyle    = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("14"))
	WarnStyle    = lipgloss.NewStyle().Foreground(lipgloss.Color("11"))
	GreenStyle   = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
	YellowStyle  = lipgloss.NewStyle().Foreground(lipgloss.Color("11"))
	RedStyle     = lipgloss.NewStyle().Foreground(lipgloss.Color("9"))
)

Functions

func ColorBar

func ColorBar(value, maxVal, width int) string

ColorBar returns a colored impact bar (green filled, dim empty). Guarantees at least 1 filled block when value > 0.

func ColorSavings

func ColorSavings(pct float64) string

ColorSavings returns a savings percentage string colored by tier. ≥70% green, 30-70% yellow, <30% red.

func ColorTier

func ColorTier(tier string) string

ColorTier returns a tier label colored by level.

func ComputeULMENHash

func ComputeULMENHash(symbols []store.Symbol) string

ComputeULMENHash generates a deterministic SHA-256 hash for a set of symbols.

func ExportMermaid

func ExportMermaid(calls []store.Call, title string) string

ExportMermaid formats a slice of calls into a Mermaid graph string.

func FormatBar

func FormatBar(value, maxVal, width int) string

FormatBar renders a horizontal bar proportional to value/maxVal.

func FormatSeparator

func FormatSeparator(width int) string

FormatSeparator returns a horizontal separator line.

func FormatSparkline

func FormatSparkline(values []float64) string

FormatSparkline renders a sparkline from a slice of values. Uses Unicode block characters ▁▂▃▄▅▆▇█.

func FormatTable

func FormatTable(headers []string, rows [][]string) string

FormatTable formats data as a simple aligned table. Handles ANSI-colored cells correctly for alignment.

func IsTerminal

func IsTerminal() bool

IsTerminal returns true if stdout is a TTY.

func PrintError

func PrintError(msg string)

PrintError prints a styled error to stderr.

func PrintFiltered

func PrintFiltered(output string, verbose int)

PrintFiltered prints filtered output with optional verbosity header.

func PrintFlows

func PrintFlows(w io.Writer, symbol string, flows []store.Flow)

PrintFlows displays data flow origins in a styled table.

func RunGain

func RunGain(tracker *telemetry.Tracker, args []string) error

RunGain executes the gain (token savings report) command.

func TierLabel

func TierLabel(pct float64) string

TierLabel returns an efficiency tier label based on savings percentage.

func ValidateULMENHash

func ValidateULMENHash(hash string, symbols []store.Symbol) bool

ValidateULMENHash checks if a given hash matches the current state of symbols.

Types

type ACCP

type ACCP struct {
	ThresholdWarm int
	ThresholdCold int
	TotalTokens   int
	Frames        []ContextFrame
}

ACCP (Adaptive Context Compression Protocol) manages token density and state transitions.

func NewACCP

func NewACCP(warm, cold int) *ACCP

NewACCP creates a new ACCP engine with the specified token thresholds.

func (*ACCP) DetermineState

func (a *ACCP) DetermineState(tokens int) SovereignState

DetermineState returns the appropriate SovereignState based on the provided token count.

func (*ACCP) RegisterFrame

func (a *ACCP) RegisterFrame(path string, tokens int)

RegisterFrame adds a new frame to the ACCP window and updates the total token count.

type ContextFrame

type ContextFrame struct {
	Path   string
	Tokens int
}

ContextFrame represents a unit of context (e.g., a file) in the sliding window.

type DefaultPresenter added in v1.1.0

type DefaultPresenter struct{}

DefaultPresenter implements the Presenter interface.

func NewDefaultPresenter added in v1.1.0

func NewDefaultPresenter() *DefaultPresenter

NewDefaultPresenter creates a new DefaultPresenter.

func (*DefaultPresenter) FormatError added in v1.1.0

func (p *DefaultPresenter) FormatError(err error) *mcp.CallToolResult

FormatError creates an MCP error result.

func (*DefaultPresenter) FormatResult added in v1.1.0

func (p *DefaultPresenter) FormatResult(thought string, data interface{}) (*mcp.CallToolResult, error)

FormatResult wraps the output data in a JSON string, prepended by the thought block.

func (*DefaultPresenter) FormatTextResult added in v1.1.0

func (p *DefaultPresenter) FormatTextResult(thought string, text string) *mcp.CallToolResult

FormatTextResult wraps the text output, prepended by the thought block.

type GainStats

type GainStats struct {
	TotalSaved     int
	AvgSavings     float64
	TotalCommands  int
	HoursReclaimed float64
}

GainStats holds high-level metrics for the Gain dashboard.

type HAKAIEncoder

type HAKAIEncoder struct {
	State SovereignState
	// contains filtered or unexported fields
}

HAKAIEncoder implements the High-density Adaptive Knowledge Atlas Integration format. It provides a high-density, token-efficient wire format for code symbols and relationships.

func NewHAKAIEncoder

func NewHAKAIEncoder(w io.Writer) *HAKAIEncoder

NewHAKAIEncoder creates a new HAKAI encoder writing to w.

func (*HAKAIEncoder) EncodeCall

func (e *HAKAIEncoder) EncodeCall(c store.Call) error

EncodeCall encodes a caller relationship row. Format: C|PathID|CallerName

func (*HAKAIEncoder) EncodeChurn

func (e *HAKAIEncoder) EncodeChurn(path string, churn float64) error

EncodeChurn encodes a churn metric row. Format: K|PathID|Churn

func (*HAKAIEncoder) EncodeCritical

func (e *HAKAIEncoder) EncodeCritical(s store.CriticalSymbol) error

EncodeCritical encodes a critical symbol row. Format: X|PathID|Name|Centrality|Fragility

func (*HAKAIEncoder) EncodeRank

func (e *HAKAIEncoder) EncodeRank(path string, rank float64) error

EncodeRank encodes a Pagerank metric row. Format: R|PathID|Rank

func (*HAKAIEncoder) EncodeSymbol

func (e *HAKAIEncoder) EncodeSymbol(s store.Symbol) error

EncodeSymbol encodes a symbol row. Format: S|PathID|Name|Type|StartLine|StartCol|Signature|Doc

func (*HAKAIEncoder) WriteHeader

func (e *HAKAIEncoder) WriteHeader() error

WriteHeader writes the HAKAI protocol header.

type Presenter added in v1.1.0

type Presenter interface {
	FormatResult(thought string, data interface{}) (*mcp.CallToolResult, error)
	FormatTextResult(thought string, text string) *mcp.CallToolResult
	FormatError(err error) *mcp.CallToolResult
}

Presenter defines the interface for formatting tool responses.

type SovereignContext

type SovereignContext interface {
	io.Writer
	SetState(state SovereignState)
	GetState() SovereignState
	EmitSymbol(s store.Symbol) error
	EmitCall(c store.Call) error
	EmitRank(path string, rank float64) error
	EmitChurn(path string, churn float64) error
}

SovereignContext defines the interface for state-aware context management.

type SovereignState

type SovereignState string

SovereignState defines the data density tier for context frames.

const (
	HOT  SovereignState = "HOT"
	WARM SovereignState = "WARM"
	COLD SovereignState = "COLD"
)

type SovereignWrapper

type SovereignWrapper struct {
	Writer  io.Writer
	Encoder *HAKAIEncoder
	State   SovereignState
	ACCP    *ACCP
	// contains filtered or unexported fields
}

SovereignWrapper wraps an io.Writer to provide state-aware context generation.

func NewSovereignWrapper

func NewSovereignWrapper(w io.Writer) *SovereignWrapper

NewSovereignWrapper creates a new wrapper around the provided writer.

func (*SovereignWrapper) EmitCall

func (s *SovereignWrapper) EmitCall(c store.Call) error

EmitCall emits a call relationship according to the current state.

func (*SovereignWrapper) EmitChurn

func (s *SovereignWrapper) EmitChurn(path string, churn float64) error

EmitChurn emits a churn metric if the state is not COLD.

func (*SovereignWrapper) EmitRank

func (s *SovereignWrapper) EmitRank(path string, rank float64) error

EmitRank emits a Pagerank metric if the state is not COLD.

func (*SovereignWrapper) EmitSymbol

func (s *SovereignWrapper) EmitSymbol(sym store.Symbol) error

EmitSymbol emits a symbol according to the current state.

func (*SovereignWrapper) Flush

func (s *SovereignWrapper) Flush() error

Flush emits all buffered COLD hashes.

func (*SovereignWrapper) GetState

func (s *SovereignWrapper) GetState() SovereignState

GetState returns the current context state.

func (*SovereignWrapper) SetACCP

func (s *SovereignWrapper) SetACCP(accp *ACCP)

SetACCP attaches an ACCP engine to the wrapper.

func (*SovereignWrapper) SetState

func (s *SovereignWrapper) SetState(state SovereignState)

SetState updates the current context state and synchronizes the encoder.

func (*SovereignWrapper) TrackTokens

func (s *SovereignWrapper) TrackTokens(count int)

TrackTokens updates the ACCP engine with the number of tokens emitted and adjusts the state if necessary.

func (*SovereignWrapper) Write

func (s *SovereignWrapper) Write(p []byte) (n int, err error)

Write implements io.Writer by delegating to the underlying writer. It updates the internal token count to prevent seal bypasses using a lossless accumulator.

func (*SovereignWrapper) WriteHeader

func (s *SovereignWrapper) WriteHeader() error

WriteHeader writes the Sovereign protocol header and current state.

Directories

Path Synopsis
tui

Jump to

Keyboard shortcuts

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