chatops

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package chatops holds CLI helpers shared between the `prune` and `compact` subcommands: the interactive agent picker, styled output (tables, disclaimer and zen boxes), confirmation prompts, and path-safety checks.

Index

Constants

This section is empty.

Variables

View Source
var (
	ColDanger      = lipgloss.Color("#F38BA8")
	ColWarn        = lipgloss.Color("#FAB387")
	ColZen         = lipgloss.Color("#A6E3A1")
	ColZenAccent   = lipgloss.Color("#94E2D5")
	ColPrimary     = lipgloss.Color("#B4BEFE")
	ColTextBright  = lipgloss.Color("#CDD6F4")
	ColTextSubtle  = lipgloss.Color("#94A3B8")
	ColTextDim     = lipgloss.Color("#6C7086")
	ColBorderDim   = lipgloss.Color("#45475A")
	ColHighlightBg = lipgloss.Color("#313244")
	ColDarkText    = lipgloss.Color("#1E1E2E")
	ColKeyBg       = lipgloss.Color("#585B70")

	StyleTableHeader = lipgloss.NewStyle().Bold(true).Foreground(ColPrimary)
	StyleAgent       = lipgloss.NewStyle().Foreground(lipgloss.Color("#89B4FA"))
	StyleCount       = lipgloss.NewStyle().Foreground(lipgloss.Color("#F9E2AF")).Bold(true)
	StyleMuted       = lipgloss.NewStyle().Foreground(ColTextDim)
	StyleFooter      = lipgloss.NewStyle().Italic(true).Foreground(ColTextSubtle)
	StyleBorder      = lipgloss.NewStyle().Foreground(ColBorderDim)
)

Shared palette. Kept small on purpose: individual commands can layer extra colors on top, but anything that ends up on both prune and compact lives here so the two subcommands look like siblings.

View Source
var StdoutIsTTY = isatty.IsTerminal(os.Stdout.Fd())

StdoutIsTTY is true when stdout is a real terminal. Callers use this to degrade styling for piped/redirected output (e.g. drop borders).

Functions

func Confirm

func Confirm(prompt string) bool

Confirm reads a y/N answer from stdin. Any input other than "y"/"yes" (case-insensitive) — including read errors — is treated as a no.

func EnsureWithin

func EnsureWithin(target string, roots []string) error

EnsureWithin returns nil only if target resolves to a path inside one of the given roots. It guards against deleting or mutating files outside the known agent directories (e.g. a rogue JSONLPath or a symlink escape).

func HumanBytes

func HumanBytes(n int64) string

HumanBytes renders a byte count with a binary suffix (KiB/MiB/GiB/…).

func IsBelowAny

func IsBelowAny(path string, roots []string) bool

IsBelowAny returns true if path lives inside any of roots (excluding the roots themselves). Used when garbage-collecting empty project dirs.

func NewTable

func NewTable() *table.Table

NewTable returns a lipgloss table pre-wired with the shared style. Callers set headers and rows, then pass to fmt.Println. When stdout is not a tty the border is hidden for cleaner piped output.

func PickAgents

func PickAgents(agents []Agent, title, subtitle string) ([]string, error)

PickAgents runs a bordered multi-select picker. It returns the chosen Agent.Key values. `subtitle` lets callers vary the helper text between prune and compact (e.g. "Only agents with plain-text file storage").

func PrintDestructiveDisclaimer

func PrintDestructiveDisclaimer(title string, body string)

PrintDestructiveDisclaimer prints a prominent red/orange warning box before the user is asked to confirm a destructive action. The title and body are caller-provided so `prune` and `compact` can vary the language.

func PrintZenBox

func PrintZenBox(title, body, quote string)

PrintZenBox prints a calm green panel. Used as the "nothing to do" state where no candidates matched the filters.

Types

type Agent

type Agent struct {
	Key   string         // machine id, e.g. "claude"
	Label string         // human label, e.g. "Claude Code"
	Color lipgloss.Color // identity dot color
}

Agent describes a selectable entry in the interactive picker.

type Choice

type Choice struct {
	Kind  ChoiceKind
	Index int
}

Choice is the result of ConfirmOrPick. Index is populated only when Kind == ChoiceIndex.

func ConfirmOrPick

func ConfirmOrPick(prompt string, maxIndex int) Choice

ConfirmOrPick prompts the user with y / N / row-number semantics.

"y" / "yes"                → ChoiceAll
an integer in [1, maxIndex] → ChoiceIndex
anything else / empty / EOF → ChoiceAbort

Inputs are trimmed and lowercased. Out-of-range integers are treated as Abort — the caller decides whether to retry; in practice the user re-runs the command.

type ChoiceKind

type ChoiceKind int

ChoiceKind categorises the result of ConfirmOrPick.

const (
	// ChoiceAbort: user said no / empty line / unparseable / read error.
	ChoiceAbort ChoiceKind = iota
	// ChoiceAll: user said yes — act on every candidate.
	ChoiceAll
	// ChoiceIndex: user entered a valid 1-based row number.
	ChoiceIndex
)

Jump to

Keyboard shortcuts

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