Documentation
¶
Index ¶
- Variables
- func ContextRatio(est, window int) float64
- func ContextShare(lastInputTokens, contextWindow int) string
- func ContextUsage(lastInputTokens, contextWindow int) (used, window, share int, ok bool)
- func DeniedLine(sessionID string, result personal.RunResult, ...) map[string]any
- func ErrorLine(sessionID string, runErr error, result personal.RunResult, ...) map[string]any
- func EventLine(event personal.Event) (line map[string]any, ok bool)
- func NudgeLine(rule, kind, action, evidence string) map[string]any
- func OutputLimitNotice(tr i18n.Translator, limit int) string
- func ResultLine(sessionID string, result personal.RunResult, ...) map[string]any
- func ResultLineWithContext(sessionID string, result personal.RunResult, contextWindow int, ...) map[string]any
- func RetryNotice(tr i18n.Translator, event personal.Event) string
- func SessionLine(sessionID string) map[string]any
- func ToolResultSummary(content string) string
- func VerifyLine(round int, command string, exitCode int, passed bool, duration time.Duration) map[string]any
- func WithApprovalMode(line map[string]any, mode string) map[string]any
- func WithContext(line map[string]any, result personal.RunResult, contextWindow int, ...) map[string]any
- func WithModel(line map[string]any, model string) map[string]any
- func WithOutputSchema(line map[string]any, rep personal.ContractReport) map[string]any
- func WithUsage(line map[string]any, result personal.RunResult, ...) map[string]any
- func WithVerify(line map[string]any, passed bool, rounds int) map[string]any
- func WrapUpNotice(tr i18n.Translator, reason string, maxSteps int) string
- func WrapUpTruncatedNotice(tr i18n.Translator, limit int) string
- func YieldedLine(sessionID string, result personal.RunResult, ...) map[string]any
- type CodeBlock
- type LiveText
- func (l *LiveText) Answer(text string)
- func (l *LiveText) CodeBlocks() []chatui.CodeBlock
- func (l *LiveText) Finish() bool
- func (l *LiveText) Handle(event personal.Event) bool
- func (l *LiveText) SetCode(highlight bool, maxLines, width int)
- func (l *LiveText) SetMarkdown(color bool)
- func (l *LiveText) SetMarkdownTheme(theme string)
- func (l *LiveText) SetTranslator(tr i18n.Translator)
- func (l *LiveText) SetWholeLines(on bool)
- type MDTerm
Constants ¶
This section is empty.
Variables ¶
var NewMDTerm = chatui.NewMDTerm
Functions ¶
func ContextRatio ¶ added in v0.52.0
ContextRatio is est/window rounded to 3 decimals, the share of the context a request occupies (0 when the window is unknown).
func ContextShare ¶
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 ¶
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 ¶
EventLine maps a runner event to its stream-json line; ok is false for events that have no stream-json representation.
func NudgeLine ¶
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 ¶
SessionLine is the first stream-json line of a run.
func ToolResultSummary ¶
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 WithApprovalMode ¶ added in v0.55.0
WithApprovalMode records the start-up approval tier (--approve/--yolo) on the session line; an empty mode (the entry point's default) leaves the line as it is, so runs without the flags keep their output byte-for-byte.
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 ¶
WithModel adds the "model" field ("provider/model") to a stream-json line; an empty model leaves the line as it is.
func WithOutputSchema ¶
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 ¶
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 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 ¶
NewLiveText returns a LiveText writing to w.
func NewPrefixedLiveText ¶
NewPrefixedLiveText marks each model message with prefix (chat uses "▣ ").
func (*LiveText) Answer ¶
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 ¶
CodeBlocks returns the code blocks of the most recent rendered message, for chat's :code command (nil without markdown rendering).
func (*LiveText) Handle ¶
Handle prints a text delta or closes the line on message_stop; it reports whether the event was a streaming event.
func (*LiveText) SetCode ¶
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 ¶
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 ¶
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 ¶
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.
Source Files
¶
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. |