Documentation
¶
Overview ¶
Package io provides clipboard, AI watcher, file watcher, and cron scheduler types.
Public types: ClipboardMonitor, AIComment, AIWatcher, FileEvent, WatcherConfig, FileWatcher, SingleFileWatcher, CronJob, CronScheduler, CronExpr, ClipboardBridge.
Public functions: NewClipboardMonitor, ReadClipboard, WriteClipboard, DetectContentType, DetectLanguage, NewAIWatcher, ScanFile, ScanDirectory, BuildPrompt, RemoveComment, NewFileWatcher, WatchSingle, DefaultIgnorePatterns, MatchesPattern, DedupEvents, FormatEvents, NewCronScheduler, ParseCron, IsDue, NextRunTime, SummarizeClipboard, FormatForContext.
Index ¶
- func BuildPrompt(comment AIComment) string
- func DefaultIgnorePatterns() []string
- func DetectContentType(content string) string
- func DetectLanguage(code string) string
- func FormatEvents(events []FileEvent) string
- func FormatForContext(content string, contentType string) string
- func IsDue(job *CronJob, now time.Time) bool
- func MatchesPattern(path string, patterns []string) bool
- func NextRunTime(expr *CronExpr, after time.Time) time.Time
- func ReadClipboard() (string, error)
- func RemoveComment(file string, line int, marker string) error
- func SummarizeClipboard(content string, maxChars int) string
- func WriteClipboard(content string) error
- type AIComment
- type AIWatcher
- type ClipboardBridge
- type ClipboardMonitor
- type CronExpr
- type CronJob
- type CronScheduler
- func (cs *CronScheduler) AddJob(name, schedule, command string) (*CronJob, error)
- func (cs *CronScheduler) FormatJobs() string
- func (cs *CronScheduler) ListJobs() []*CronJob
- func (cs *CronScheduler) PauseJob(id string) error
- func (cs *CronScheduler) RemoveJob(id string) error
- func (cs *CronScheduler) ResumeJob(id string) error
- func (cs *CronScheduler) Start(ctx context.Context, execFn func(string) (string, error))
- func (cs *CronScheduler) Stop()
- type FileEvent
- type FileWatcher
- type SingleFileWatcher
- type WatcherConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPrompt ¶
BuildPrompt constructs a prompt for the AI agent based on the detected comment.
func DefaultIgnorePatterns ¶
func DefaultIgnorePatterns() []string
DefaultIgnorePatterns returns standard patterns to ignore during watching.
func DetectContentType ¶
DetectContentType classifies clipboard content into a category. Returns one of: "code", "diff", "url", "path", "error", "text".
func DetectLanguage ¶
DetectLanguage performs heuristic language detection from code content. Returns the detected language name or "" if unknown.
func FormatEvents ¶
FormatEvents produces a human-readable summary of file events.
func FormatForContext ¶
FormatForContext wraps content appropriately for injection into agent context based on its detected content type.
func MatchesPattern ¶
MatchesPattern checks if a path matches any of the given glob patterns.
func NextRunTime ¶
NextRunTime calculates the next time after `after` that matches the cron expression.
func ReadClipboard ¶
ReadClipboard reads the current system clipboard content. It uses platform-specific commands:
- macOS: pbpaste
- Linux: xclip -selection clipboard -o (falls back to xsel)
- Windows: powershell Get-Clipboard
func RemoveComment ¶
RemoveComment removes the AI comment from the specified file at the given line. It matches the marker string to ensure the correct line is removed.
func SummarizeClipboard ¶
SummarizeClipboard truncates large clipboard content for display, showing the first and last few lines with an omission indicator.
func WriteClipboard ¶
WriteClipboard writes the given content to the system clipboard. It uses platform-specific commands:
- macOS: pipe to pbcopy
- Linux: pipe to xclip -selection clipboard (falls back to xsel)
- Windows: pipe to powershell Set-Clipboard
Types ¶
type AIComment ¶
type AIComment struct {
File string // relative file path
Line int // 1-based line number
Comment string // the instruction text after "ai:"
Language string // detected language (go, python, js, etc.)
Context string // surrounding 10 lines of code (5 before, 5 after)
Marker string // the full comment line for removal after completion
}
AIComment represents a detected AI instruction comment in a source file.
func ScanDirectory ¶
ScanDirectory walks a directory tree and scans all files matching the given patterns for AI comments.
type AIWatcher ¶
type AIWatcher struct {
RootDir string
Patterns []string // file glob patterns to watch (e.g., "*.go", "*.py")
Debounce time.Duration
OnComment func(comment AIComment)
// contains filtered or unexported fields
}
AIWatcher monitors a directory tree for AI instruction comments and fires a callback when new ones are detected.
func NewAIWatcher ¶
NewAIWatcher creates a new AIWatcher for the given directory and file patterns. If patterns is empty, defaults to common source file patterns.
type ClipboardBridge ¶
type ClipboardBridge struct{}
ClipboardBridge enables paste-from-browser workflows. Paste code/errors from browser, hawk processes them as context.
func (*ClipboardBridge) IsCode ¶
func (cb *ClipboardBridge) IsCode(content string) bool
IsCode heuristically detects if clipboard content is code vs prose.
func (*ClipboardBridge) ReadClipboard ¶
func (cb *ClipboardBridge) ReadClipboard() (string, error)
ReadClipboard returns the current clipboard content.
func (*ClipboardBridge) WriteClipboard ¶
func (cb *ClipboardBridge) WriteClipboard(content string) error
WriteClipboard sets the clipboard content.
type ClipboardMonitor ¶
type ClipboardMonitor struct {
Enabled bool
PollInterval time.Duration
OnPaste func(content string)
// contains filtered or unexported fields
}
ClipboardMonitor watches the system clipboard for changes and fires a callback when new content is detected. Inspired by Aider's copypaste feature.
func NewClipboardMonitor ¶
func NewClipboardMonitor() *ClipboardMonitor
NewClipboardMonitor creates a new ClipboardMonitor with sensible defaults.
func (*ClipboardMonitor) Start ¶
func (cm *ClipboardMonitor) Start(ctx context.Context) error
Start begins polling the clipboard at PollInterval. When content changes and passes validation (>20 chars, <50000 chars), the OnPaste callback is fired. The monitor runs until Stop() is called or the context is cancelled.
func (*ClipboardMonitor) Stop ¶
func (cm *ClipboardMonitor) Stop()
Stop halts the clipboard polling loop.
type CronJob ¶
type CronJob struct {
ID string
Name string
Schedule string
Command string
Enabled bool
LastRun *time.Time
NextRun *time.Time
RunCount int
LastResult string
LastError string
CreatedAt time.Time
}
CronJob represents a scheduled recurring task.
type CronScheduler ¶
type CronScheduler struct {
Jobs map[string]*CronJob
Running bool
// contains filtered or unexported fields
}
CronScheduler manages scheduled cron jobs and executes them when due.
func NewCronScheduler ¶
func NewCronScheduler() *CronScheduler
NewCronScheduler creates an initialized CronScheduler.
func (*CronScheduler) AddJob ¶
func (cs *CronScheduler) AddJob(name, schedule, command string) (*CronJob, error)
AddJob parses the schedule expression and registers a new job.
func (*CronScheduler) FormatJobs ¶
func (cs *CronScheduler) FormatJobs() string
FormatJobs returns a human-readable representation of all scheduled jobs.
func (*CronScheduler) ListJobs ¶
func (cs *CronScheduler) ListJobs() []*CronJob
ListJobs returns all jobs as a slice.
func (*CronScheduler) PauseJob ¶
func (cs *CronScheduler) PauseJob(id string) error
PauseJob disables a job so it won't be executed.
func (*CronScheduler) RemoveJob ¶
func (cs *CronScheduler) RemoveJob(id string) error
RemoveJob deletes a job by ID.
func (*CronScheduler) ResumeJob ¶
func (cs *CronScheduler) ResumeJob(id string) error
ResumeJob re-enables a paused job and recalculates its next run time.
type FileEvent ¶
type FileEvent struct {
Path string
Type string // "create", "modify", "delete", "rename"
Time time.Time
Size int64
}
FileEvent represents a single file system change event.
func DedupEvents ¶
DedupEvents removes duplicate events for the same path within a batch, keeping only the latest event for each path.
type FileWatcher ¶
type FileWatcher struct {
RootDir string
Patterns []string
IgnorePatterns []string
Debounce time.Duration
BatchWindow time.Duration
OnChange func([]FileEvent)
// contains filtered or unexported fields
}
FileWatcher monitors a directory tree for file changes using polling. It supports glob-based inclusion/exclusion patterns, debouncing of rapid changes, and batching of events within a configurable window.
func NewFileWatcher ¶
func NewFileWatcher(rootDir string, config WatcherConfig) *FileWatcher
NewFileWatcher creates a FileWatcher with the given root directory and config. Defaults: Debounce 500ms, BatchWindow 100ms, PollInterval 1s.
func (*FileWatcher) ShouldIgnore ¶
func (fw *FileWatcher) ShouldIgnore(path string) bool
ShouldIgnore checks whether a path matches any of the watcher's ignore patterns.
func (*FileWatcher) Start ¶
func (fw *FileWatcher) Start(ctx context.Context) error
Start begins the polling-based file watcher. It walks the directory at each PollInterval, detects creates/modifies/deletes, batches events within BatchWindow, and debounces rapid changes (only fires OnChange after Debounce duration of quiet). It blocks until ctx is cancelled or Stop is called.
type SingleFileWatcher ¶
type SingleFileWatcher struct {
// contains filtered or unexported fields
}
SingleFileWatcher provides a simpler API for watching a single file.
func WatchSingle ¶
func WatchSingle(path string, onChange func()) *SingleFileWatcher
WatchSingle creates a SingleFileWatcher for monitoring a single file.
func (*SingleFileWatcher) Start ¶
func (sw *SingleFileWatcher) Start(ctx context.Context) error
Start begins polling the single file for changes. Blocks until ctx is cancelled or Stop is called.
func (*SingleFileWatcher) Stop ¶
func (sw *SingleFileWatcher) Stop()
Stop signals the single file watcher to stop.