Documentation
¶
Overview ¶
Package toolutil provides utilities used by tools.
Index ¶
Constants ¶
const ( // TruncateMaxLines is the maximum number of lines before truncation TruncateMaxLines = 2000 // TruncateMaxBytes is the maximum bytes before truncation (50KB) TruncateMaxBytes = 50 * 1024 )
Variables ¶
var FileTime = &FileTimeTracker{ sessions: make(map[string]map[string]time.Time), }
FileTime is the global file time tracker instance.
Functions ¶
func GenerateDiff ¶
GenerateDiff creates a unified diff between old and new content
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 ¶
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 ¶
TruncateOptions configures truncation behavior
type TruncateResult ¶
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