output

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package output provides UTF-8-safe byte budgeting, ANSI/CR terminal normalization, and root-cause command output compaction under Antigravity CLI's inline spill threshold.

Index

Constants

View Source
const DefaultInlineMaxBytes = 9600

DefaultInlineMaxBytes stays just below Antigravity CLI's ~9,888-byte inline truncation cliff so MCP responses never spill to output.txt by default.

View Source
const PageBytes = 8000

PageBytes is the default page size for long text: one page plus the response header stays under the 9.6KB inline budget (Antigravity spills larger MCP outputs to output.txt).

Variables

This section is empty.

Functions

func EffectiveInlineMaxBytes

func EffectiveInlineMaxBytes(explicit int) int

EffectiveInlineMaxBytes resolves explicit per-call maxOutputBytes, AGY_PTC_MAX_OUTPUT_BYTES env override, or DefaultInlineMaxBytes.

func FitSectionsToByteBudget

func FitSectionsToByteBudget(sections []string, maxBytes int, sep string) string

FitSectionsToByteBudget distributes maxBytes across sections via water-filling so short sections stay intact.

func FormatCommandOutput

func FormatCommandOutput(p CommandFormatParams) string

FormatCommandOutput formats command execution output cleanly, extracting focused errors on failure.

func HumanBytes

func HumanBytes(n int) string

HumanBytes renders a byte count as B/KB/MB.

func MarshalPretty

func MarshalPretty(val any) string

MarshalPretty renders a value as indented JSON (no HTML escaping) so it pages line by line.

func MarshalResultCompact

func MarshalResultCompact(val any) string

MarshalResultCompact serializes value for budget; uses indented JSON when it fits comfortably and switches to compact JSON before truncating.

func MarshalResultForBudget

func MarshalResultForBudget(val any, budgetBytes int) string

MarshalResultForBudget serializes val as indented JSON if it fits within budgetBytes (and <= 6000 B), otherwise compacts whitespace first so medium-sized payloads fit inline without truncation. Uses SetEscapeHTML(false) so `<`, `>`, and `&` in code/URLs stay literal 1-byte characters instead of `\u003c`/`\u0026`.

func NormalizeTerminalOutput

func NormalizeTerminalOutput(raw string) string

NormalizeTerminalOutput strips ANSI sequences and collapses carriage-return progress bar overwrites.

func PageFooter(p Page, index, total, totalLines, size int, key string) string

PageFooter tells the model where it is and how to continue, e.g. "[page 1/4 · lines 1-212 of 890 · next: print(state.page('__result_1', 2)) · last: state.page('__result_1', -1)]". When key is empty, the footer falls back to the keyless state.page(n) form.

func Shape

func Shape(v any) string

Shape summarizes a value's top-level structure so the model can slice an auto-spilled result precisely next turn, e.g. `{files: array(120) of {path, line}, summary: string(3.2KB), stats: object(5)}`.

func SliceUTF8Bytes

func SliceUTF8Bytes(s string, maxBytes int) string

SliceUTF8Bytes truncates s cleanly on a valid UTF-8 rune boundary at <= maxBytes.

func StripAnsi

func StripAnsi(s string) string

StripAnsi removes CSI/OSC terminal escape codes.

func TruncateHeadTailBytes

func TruncateHeadTailBytes(s string, maxBytes int, hint string) string

TruncateHeadTailBytes keeps both the beginning and end of s within maxBytes.

func TruncateWithByteNotice

func TruncateWithByteNotice(s string, maxBytes int) string

TruncateWithByteNotice truncates s to <= maxBytes UTF-8 bytes, preserving line boundaries when practical.

Types

type CommandFormatParams

type CommandFormatParams struct {
	Stdout   string
	Stderr   string
	ExitCode int
	TimedOut bool
	SpawnErr string
	MaxBytes int
	Compact  bool
}

CommandFormatParams configures command output compaction.

type Page

type Page struct {
	Text      string
	FirstLine int // 1-based
	LastLine  int
}

Page is one line-aligned slice of a long text.

func Paginate

func Paginate(text string, size int) []Page

Paginate splits text into pages of at most size bytes, breaking only between lines (a single line longer than size is split at a UTF-8 boundary).

Jump to

Keyboard shortcuts

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