toolutil

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package toolutil provides utilities used by tools.

Index

Constants

View Source
const (
	// TruncateMaxLines is the maximum number of lines before truncation
	TruncateMaxLines = 2000
	// TruncateMaxBytes is the maximum bytes before truncation (50KB)
	TruncateMaxBytes = 50 * 1024
)

Variables

View Source
var FileTime = &FileTimeTracker{
	sessions: make(map[string]map[string]time.Time),
}

FileTime is the global file time tracker instance.

Functions

func GenerateDiff

func GenerateDiff(filename, oldContent, newContent string) string

GenerateDiff creates a unified diff between old and new content

func TrimDiff

func TrimDiff(diff string, maxLines int) string

TrimDiff trims a diff to a reasonable size for display

Types

type AutoAnswerHandler

type AutoAnswerHandler struct{}

AutoAnswerHandler automatically answers questions with empty responses.

func (*AutoAnswerHandler) Ask

func (h *AutoAnswerHandler) Ask(ctx context.Context, questions []bus.QuestionInfo) ([][]string, error)

type FileTimeTracker

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

FileTimeTracker manages file read timestamps per session. This prevents overwriting files that have been modified externally since they were last read by the agent.

func (*FileTimeTracker) Assert

func (ft *FileTimeTracker) Assert(sessionID, filepath string) error

Assert checks that a file hasn't been modified since it was last read. Returns an error if: - The file was never read (must read before writing) - The file was modified after it was read

func (*FileTimeTracker) Clear

func (ft *FileTimeTracker) Clear(sessionID string)

Clear removes all tracked files for a session

func (*FileTimeTracker) Get

func (ft *FileTimeTracker) Get(sessionID, filepath string) (time.Time, bool)

Get returns when a file was last read in a session

func (*FileTimeTracker) Read

func (ft *FileTimeTracker) Read(sessionID, filepath string)

Read records the current time as when a file was read

type QuestionHandler

type QuestionHandler interface {
	// Ask presents questions to the user and returns their answers
	Ask(ctx context.Context, questions []bus.QuestionInfo) ([][]string, error)
}

QuestionHandler handles question requests.

type ScriptedQuestionHandler

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

ScriptedQuestionHandler answers questions from a predefined queue. Used for replay testing with pre-recorded answers.

func NewScriptedQuestionHandler

func NewScriptedQuestionHandler(answers []string) *ScriptedQuestionHandler

NewScriptedQuestionHandler creates a handler with queued answers. Each answer should be either a 1-based option index ("1", "2", etc.) or a custom text answer.

func (*ScriptedQuestionHandler) Ask

func (h *ScriptedQuestionHandler) Ask(ctx context.Context, questions []bus.QuestionInfo) ([][]string, error)

type StdioQuestionHandler

type StdioQuestionHandler struct {
	Reader io.Reader
	Writer io.Writer
}

StdioQuestionHandler prompts the user via stdin/stdout.

func NewStdioQuestionHandler

func NewStdioQuestionHandler(r io.Reader, w io.Writer) *StdioQuestionHandler

NewStdioQuestionHandler creates a new stdio question handler.

func (*StdioQuestionHandler) Ask

func (h *StdioQuestionHandler) Ask(ctx context.Context, questions []bus.QuestionInfo) ([][]string, error)

type TruncateOptions

type TruncateOptions struct {
	MaxLines  int
	MaxBytes  int
	Direction string // "head" or "tail"
}

TruncateOptions configures truncation behavior

type TruncateResult

type TruncateResult struct {
	Content    string
	Truncated  bool
	OutputPath string
}

TruncateResult contains the result of truncation

func TruncateOutput

func TruncateOutput(text string, opts TruncateOptions) TruncateResult

TruncateOutput truncates output that exceeds limits and saves full output to file

Jump to

Keyboard shortcuts

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