output

package
v0.54.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewMDTerm = chatui.NewMDTerm

Functions

func ContextRatio added in v0.52.0

func ContextRatio(est, window int) float64

ContextRatio is est/window rounded to 3 decimals, the share of the context a request occupies (0 when the window is unknown).

func ContextShare

func ContextShare(lastInputTokens, contextWindow int) string

ContextShare renders the last model request's context usage as "ctx 55%". It is empty when the model window or the request size is unknown. The ratio is intentionally not clamped, so an oversized request remains visible as >100%.

func ContextUsage

func ContextUsage(lastInputTokens, contextWindow int) (used, window, share int, ok bool)

ContextUsage returns the last request's context size, model window and integer percentage. The result is absent when either input is unknown; callers should omit context information in that case.

func DeniedLine

func DeniedLine(sessionID string, result personal.RunResult, budget ...*personal.BudgetSnapshot) map[string]any

DeniedLine is the input_required line of a finished turn that had refused tool calls.

func ErrorLine

func ErrorLine(sessionID string, runErr error, result personal.RunResult, budget ...*personal.BudgetSnapshot) map[string]any

ErrorLine is the stream-json line for a failed run. error_kind (when the failure was a provider error, see personal.RunResult.ErrorKind) tells a transient one - a cut stream whose retries ran out - from an unusable provider answer, so the caller can decide whether continuing makes sense. reset_at is the quota reset time a provider named for an exhausted quota (llm.ResetAt), so the caller can say when trying again makes sense.

func EventLine

func EventLine(event personal.Event) (line map[string]any, ok bool)

EventLine maps a runner event to its stream-json line; ok is false for events that have no stream-json representation.

func NudgeLine

func NudgeLine(rule, kind, action, evidence string) map[string]any

NudgeLine is the stream-json line of one hit rule of the "stopped too early" check: rule is the rule's name, kind one of promise/unverified_write/ plan_open, action says what happened (pushed, hinted, recorded) and evidence is the one-line reason.

func OutputLimitNotice

func OutputLimitNotice(tr i18n.Translator, limit int) string

OutputLimitNotice is the text-mode stderr line of a turn whose answer was cut off at the model's output token limit (personal.RunResult.Truncated): the answer just stops, and the reason (a limit the configuration may raise) is invisible in the text itself. limit is how many tokens were allowed; 0 means neither the configuration nor the provider named one (an OpenAI-compatible server's own default applied). tr is the startup-resolved host catalog.

host.output.truncated* is this whole sentence with the remedy, not the chat status line's short segment (status.turn.truncated*, internal/chat/layout.go): the two are deliberately kept apart, since a status line shares its row with the other turn fields.

func ResultLine

func ResultLine(sessionID string, result personal.RunResult, budget ...*personal.BudgetSnapshot) map[string]any

ResultLine is the final stream-json line of a successful run. A wrap-up answer (result.WrapUp, e.g. "max_steps") carries its reason as "wrap_up", so a caller can tell an answer cut short by a limit from a finished one; a normal answer leaves the field out. An answer cut off at the output token limit is marked the same way, with the limit as "output_limit".

func ResultLineWithContext

func ResultLineWithContext(sessionID string, result personal.RunResult, contextWindow int, occupancy *personal.ContextOccupancy, budget ...*personal.BudgetSnapshot) map[string]any

ResultLineWithContext is ResultLine with the optional context usage object used by the CLI's final result event. occupancy is the turn's context occupancy of its last request (the same figure turn_end carried).

func RetryNotice

func RetryNotice(tr i18n.Translator, event personal.Event) string

RetryNotice is the one-line notice for a "retry" event; tr is the startup-resolved host catalog.

func SessionLine

func SessionLine(sessionID string) map[string]any

SessionLine is the first stream-json line of a run.

func ToolResultSummary

func ToolResultSummary(content string) string

ToolResultSummary condenses a tool result for stream-json. Secrets are redacted first and the result truncated afterwards, so a cut can never leave a partially redacted credential behind.

func VerifyLine

func VerifyLine(round int, command string, exitCode int, passed bool, duration time.Duration) map[string]any

VerifyLine is the stream-json line of one --verify check: round counts from 0 (the check that follows the first turn), command is the caller's command (secrets masked) and passed is what its exit code says.

func WithContext

func WithContext(line map[string]any, result personal.RunResult, contextWindow int, occupancy *personal.ContextOccupancy) map[string]any

WithContext adds the optional context usage object to a stream-json line. used is the latest model request's input token count, including cache tokens; window is the effective model context window and share is its integer percent. occupancy is the turn's own estimate of that request (the figure the context trace event carries): when it is present, its window wins and est_tokens plus the 3-decimal ratio are added, so a caller can compute how full the context is without the estimate being a second, differently rounded figure.

func WithModel

func WithModel(line map[string]any, model string) map[string]any

WithModel adds the "model" field ("provider/model") to a stream-json line; an empty model leaves the line as it is.

func WithOutputSchema

func WithOutputSchema(line map[string]any, rep personal.ContractReport) map[string]any

WithOutputSchema adds the run's --output-schema outcome to the closing result line (design 2026-10-22 4.4): checked:false with a reason when the turn's end left nothing to judge, else passed/rounds/source plus the errors of a failure or the checked value of a pass. A run without --output-schema leaves the line exactly as it was.

func WithUsage

func WithUsage(line map[string]any, result personal.RunResult, budget ...*personal.BudgetSnapshot) map[string]any

WithUsage adds usage to a stream-json line: "usage" is this run's total (observe layer: every model call including compaction and failed attempts that reported usage, plus tool_calls), the same value as the last "usage" line; "session_usage" is the session-cumulative total. Both use the reported accounting (input_tokens excludes cache; see personal.ReportUsage), identical on the result, input_required and error lines. A budget snapshot is optional and is omitted for the historical no-budget path.

func WithVerify

func WithVerify(line map[string]any, passed bool, rounds int) map[string]any

WithVerify adds the run's --verify outcome to the closing result line: how many checks ran and whether the last one passed. A run without --verify leaves the line exactly as it was.

func WrapUpNotice

func WrapUpNotice(tr i18n.Translator, reason string, maxSteps int) string

WrapUpNotice is the text-mode stderr line of a turn whose answer was a wrap-up (result.WrapUp) rather than a normal one; it is empty for a normal answer. It names the real limit, because the answer itself is short for a reason a reader cannot see: without this line a wrapped-up answer is easily taken for a timeout or a finished task. stdout keeps the answer text only.

func WrapUpTruncatedNotice

func WrapUpTruncatedNotice(tr i18n.Translator, limit int) string

WrapUpTruncatedNotice calls out the less obvious combination where the budget's final wrap-up answer was itself cut by the per-request output cap.

func YieldedLine

func YieldedLine(sessionID string, result personal.RunResult, budget ...*personal.BudgetSnapshot) map[string]any

YieldedLine is the input_required line of a run that stopped for more input.

Types

type CodeBlock

type CodeBlock = chatui.CodeBlock

type LiveText

type LiveText struct {
	// contains filtered or unexported fields
}

LiveText prints a turn's text deltas as they stream in. Each model message ends on its own line, so commentary before a tool call and the final answer do not run together.

func NewLiveText

func NewLiveText(w io.Writer) *LiveText

NewLiveText returns a LiveText writing to w.

func NewPrefixedLiveText

func NewPrefixedLiveText(w io.Writer, prefix string) *LiveText

NewPrefixedLiveText marks each model message with prefix (chat uses "▣ ").

func (*LiveText) Answer

func (l *LiveText) Answer(text string)

Answer prints the final text of a turn that was not streamed: with markdown on it goes through the renderer of the streamed text (a multi-line answer would otherwise show its raw markers), otherwise the prefix and the text are one line. The prefix goes out with a line whoever owns it: the markdown renderer while whole lines are on (it may not leave as a write of its own), this text otherwise.

func (*LiveText) CodeBlocks

func (l *LiveText) CodeBlocks() []chatui.CodeBlock

CodeBlocks returns the code blocks of the most recent rendered message, for chat's :code command (nil without markdown rendering).

func (*LiveText) Finish

func (l *LiveText) Finish() bool

Finish ends the turn's output and reports whether anything was streamed.

func (*LiveText) Handle

func (l *LiveText) Handle(event personal.Event) bool

Handle prints a text delta or closes the line on message_stop; it reports whether the event was a streaming event.

func (*LiveText) SetCode

func (l *LiveText) SetCode(highlight bool, maxLines, width int)

SetCode configures the code blocks of the markdown renderer: highlighting by the fence's language, the fold limit of a block (chat.code_*) and the terminal width a table is kept within. A LiveText without markdown rendering ignores it.

func (*LiveText) SetMarkdown

func (l *LiveText) SetMarkdown(color bool)

SetMarkdown renders the streamed text as terminal markdown, line by line, instead of printing the deltas as they are (chat). color styles the rendered lines; without it the markers are still replaced, but nothing is colored.

func (*LiveText) SetMarkdownTheme

func (l *LiveText) SetMarkdownTheme(theme string)

SetMarkdownTheme picks the palette the markdown renderer paints with (chat.theme: "dark" or "light"; anything else keeps the dark default). A LiveText without markdown rendering ignores it.

func (*LiveText) SetTranslator

func (l *LiveText) SetTranslator(tr i18n.Translator)

SetTranslator installs the host UI catalog of the notices this text prints itself (the retry line through RetryNotice, the folded-code line of the markdown renderer); nil keeps the historical Chinese text.

func (*LiveText) SetWholeLines

func (l *LiveText) SetWholeLines(on bool)

SetWholeLines makes the streamed text wait for line ends: only complete lines are written, the unfinished rest stays buffered until its newline or the end of the message (closeLine). chat turns it on while it keeps an input line on screen during a turn (chat.steering): the line editor repaints its line after every write, so a partial line would be left on screen next to the line being edited. With markdown on the renderer is already line based; it then prints the message prefix itself, since the prefix may not leave as a write of its own.

type MDTerm

type MDTerm = chatui.MDTerm

Markdown types are kept as aliases for the non-chat output callers while the reusable implementation lives in pkg/chatui.

Directories

Path Synopsis
Package termtext removes terminal control sequences from text that came from a model, a tool or another external source before chat writes it to a terminal.
Package termtext removes terminal control sequences from text that came from a model, a tool or another external source before chat writes it to a terminal.

Jump to

Keyboard shortcuts

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