cmd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 70 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version = "dev"
	Commit  = "none"
	Date    = "unknown"
)

Build-time variables injected by goreleaser/ldflags.

Functions

func ApplyPowerLevel

func ApplyPowerLevel(sess *engine.Session, level int)

ApplyPowerLevel configures a session based on power level.

func BuildResearchPrompt

func BuildResearchPrompt(cfg ResearchConfig) string

BuildResearchPrompt generates the full autonomous research prompt based on Karpathy's autoresearch program.md pattern.

func DescribePower

func DescribePower(level int) string

DescribePower returns a human-readable description of what a power level does.

func DetectRunCommand

func DetectRunCommand(dir string) string

DetectRunCommand auto-detects the project's test/build command by looking for well-known build files in the given directory.

func Execute

func Execute() error

Execute runs the root command.

func ExportContext

func ExportContext(dir string, focus string) (string, error)

ExportContext generates a comprehensive context document about the current project. Output is optimized for pasting into any LLM chat.

func ExportContextToFile

func ExportContextToFile(dir, focus, outputPath string) error

ExportContextToFile writes context to a .md file.

func FormatReviewReport

func FormatReviewReport(findings []ReviewFinding) string

FormatReviewReport formats findings as a readable report grouped by severity.

func GenerateAgentsTemplate

func GenerateAgentsTemplate(projectType string) string

GenerateAgentsTemplate returns an AGENTS.md template for the given project type.

func GenerateManPage

func GenerateManPage() string

GenerateManPage produces a man page in roff format for hawk.

func RenderBreakdown

func RenderBreakdown(tb TokenBreakdown, windowSize int) string

RenderBreakdown produces a multi-line token breakdown for /context command.

func SetBuildDate

func SetBuildDate(d string)

SetBuildDate sets the build date from main.

func SetVersion

func SetVersion(v string)

SetVersion sets the version string from main.

func ShortVersion

func ShortVersion() string

ShortVersion returns just the version number.

func VersionString

func VersionString() string

VersionString returns the full version string.

func VibeLoop

func VibeLoop(ctx context.Context, sess *engine.Session, prompt string, config VibeConfig) error

VibeLoop runs the vibe coding loop: edit -> run -> check -> fix -> repeat.

1. Send prompt to LLM 2. Auto-apply all file changes (no permission prompt) 3. Run RunCommand 4. If passes: done, print success 5. If fails: send error output back to LLM, ask it to fix 6. Repeat until passes or MaxIterations reached

Types

type AIDirective

type AIDirective struct {
	Path        string
	Line        int
	Instruction string
	Mode        string // "!" (do) or "?" (ask)
}

AIDirective represents a found AI comment directive in a source file.

type CommandState

type CommandState struct {
	Type     CommandType
	Op       Operator
	Count    int
	Digits   string
	FindType byte // f, F, t, T
	Scope    byte // i (inner), a (around)
}

CommandState tracks the in-progress vim command.

type CommandType

type CommandType int

CommandType represents what the command state is waiting for.

const (
	CmdIdle CommandType = iota
	CmdCount
	CmdOperator
	CmdFind
	CmdOperatorFind
	CmdOperatorTextObj
	CmdReplace
)

type ContextState

type ContextState int

ContextState represents the urgency level of context usage.

const (
	ContextNormal   ContextState = iota
	ContextWarning               // approaching compact threshold
	ContextError                 // approaching blocking
	ContextBlocking              // at capacity
)

type ContextVisualization

type ContextVisualization struct {
	ContextWindowSize int
	CurrentTokens     int
	CompactThreshold  int
	WarningThreshold  int
	BlockingThreshold int
}

ContextVisualization renders token usage as a visual bar in the TUI.

func NewContextVisualization

func NewContextVisualization(windowSize int) *ContextVisualization

NewContextVisualization creates a visualization with default thresholds.

func (*ContextVisualization) PercentUsed

func (cv *ContextVisualization) PercentUsed() float64

PercentUsed returns the percentage of context window used.

func (*ContextVisualization) Render

func (cv *ContextVisualization) Render(width int) string

Render produces a styled context bar for the TUI status line.

func (*ContextVisualization) State

func (cv *ContextVisualization) State() ContextState

State returns the current warning state.

func (*ContextVisualization) Update

func (cv *ContextVisualization) Update(tokens int)

Update sets the current token count.

type ExecResult

type ExecResult struct {
	SessionID  string `json:"session_id"`
	Response   string `json:"response"`
	ExitCode   int    `json:"exit_code"`
	TokensIn   int    `json:"tokens_in,omitempty"`
	TokensOut  int    `json:"tokens_out,omitempty"`
	TurnsTaken int    `json:"turns_taken"`
	Duration   string `json:"duration"`
	Model      string `json:"model,omitempty"`
	Worktree   string `json:"worktree,omitempty"`
	Branch     string `json:"branch,omitempty"`
}

ExecResult is the structured output for --output-format json.

type FileWatcher

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

FileWatcher watches a directory tree for file changes, debounces them, computes a git diff, and calls an onChange callback.

func NewFileWatcher

func NewFileWatcher(dir string, ignore []string, onChange func(string, string)) *FileWatcher

NewFileWatcher creates a new FileWatcher. ignore is a list of path substrings to skip (e.g. ".git", "node_modules"). onChange is called with the changed file path and the git diff for that file.

func (*FileWatcher) Start

func (fw *FileWatcher) Start(ctx context.Context) error

Start begins watching for file changes. It blocks until ctx is cancelled or Stop is called.

func (*FileWatcher) Stop

func (fw *FileWatcher) Stop()

Stop signals the watcher to shut down.

type Operator

type Operator int

Operator represents a vim operator (d, c, y).

const (
	OpNone Operator = iota
	OpDelete
	OpChange
	OpYank
)

type PersistentState

type PersistentState struct {
	LastFind     byte
	LastFindType byte
	Register     string
	RegisterLine bool
	LastChange   *RecordedChange
	Recording    *RecordedChange
}

PersistentState survives across commands.

type PowerConfig

type PowerConfig struct {
	Level           int
	Model           string
	MaxTokens       int
	ContextWindow   int
	Temperature     float64
	MaxTurns        int
	ToolParallelism int
	ReviewDepth     string // "none", "quick", "thorough"
	AutoApply       bool
	BudgetUSD       float64
}

PowerConfig maps a power level (1-10) to all relevant settings.

func PowerPreset

func PowerPreset(level int) PowerConfig

PowerPreset returns the configuration for a given power level (1-10).

1-2: haiku/flash, 4K context, fast, no review, $0.05 budget -- quick questions 3-4: sonnet-mini/gpt-4o-mini, 16K context, moderate -- simple tasks 5-6: sonnet/gpt-4o, 64K context, standard -- normal coding (DEFAULT) 7-8: sonnet/opus, 128K context, thorough review -- complex tasks 9-10: opus, 200K context, multi-pass review, council mode -- critical work

type QueryProfile

type QueryProfile struct {
	StartTime time.Time
	TTFT      time.Duration // time to first token
	APICall   time.Duration
	ToolExec  time.Duration
	TotalTime time.Duration
	TokensIn  int
	TokensOut int
	// contains filtered or unexported fields
}

QueryProfile tracks timing for a single query.

func (*QueryProfile) Finish

func (p *QueryProfile) Finish()

Finish completes the profile and records the total time.

func (*QueryProfile) RecordAPICallEnd

func (p *QueryProfile) RecordAPICallEnd()

RecordAPICallEnd marks the end of an API call and accumulates duration.

func (*QueryProfile) RecordAPICallStart

func (p *QueryProfile) RecordAPICallStart()

RecordAPICallStart marks the beginning of an API call.

func (*QueryProfile) RecordTTFT

func (p *QueryProfile) RecordTTFT()

RecordTTFT records the time to first token.

func (*QueryProfile) RecordToolExecEnd

func (p *QueryProfile) RecordToolExecEnd()

RecordToolExecEnd marks the end of a tool execution and accumulates duration.

func (*QueryProfile) RecordToolExecStart

func (p *QueryProfile) RecordToolExecStart()

RecordToolExecStart marks the beginning of a tool execution.

func (*QueryProfile) String

func (p *QueryProfile) String() string

String returns a formatted summary of the profile, suitable for debug output.

type RecordedChange

type RecordedChange struct {
	Type     string // "insert", "operator", "replace", "x", "toggleCase"
	Keys     []tea.KeyMsg
	Text     string
	StartPos int
	EndPos   int
}

RecordedChange stores info needed for dot-repeat.

type ResearchConfig

type ResearchConfig struct {
	MetricCmd    string // command to run the experiment (e.g. "go test -bench .")
	MetricGrep   string // grep pattern to extract the metric (e.g. "^val_bpb:")
	Direction    string // "lower" or "higher" — whether lower or higher metric is better
	Budget       int    // time budget per experiment in minutes (default: 5)
	BranchPrefix string // git branch prefix (default: "autoresearch")
	ResultsFile  string // TSV results file (default: "results.tsv")
}

ResearchConfig controls the autonomous research loop. The loop itself is executed by the LLM agent via the generated prompt.

func DefaultResearchConfig

func DefaultResearchConfig() ResearchConfig

DefaultResearchConfig returns sensible defaults.

type ReviewConcern

type ReviewConcern struct {
	Name   string // "security", "performance", "style", "bugs", "correctness"
	Prompt string // specialized review prompt for this concern
}

ReviewConcern represents one aspect of code review.

func DefaultConcerns

func DefaultConcerns() []ReviewConcern

DefaultConcerns returns standard review concerns.

type ReviewFinding

type ReviewFinding struct {
	Concern  string
	Severity string // "critical", "high", "medium", "low"
	File     string
	Line     int
	Message  string
	Fix      string // suggested fix
}

ReviewFinding represents one issue found.

func RunReviewPipeline

func RunReviewPipeline(files []string, concerns []ReviewConcern) ([]ReviewFinding, string)

RunReviewPipeline performs multi-concern parallel review. In this implementation, the LLM calls are simulated by building per-concern prompts and collecting placeholder findings. The caller is expected to wire in actual LLM queries. Returns deduplicated findings sorted by severity and a formatted report string.

type StartupWarning

type StartupWarning struct {
	Check   string
	Message string
}

StartupWarning represents a non-fatal startup issue.

func (StartupWarning) String

func (w StartupWarning) String() string

type Tip

type Tip struct {
	ID       string `json:"id"`
	Text     string `json:"text"`
	Category string `json:"category"`
}

Tip represents a single hawk usage tip.

type TokenBreakdown

type TokenBreakdown struct {
	System     int `json:"system"`
	UserMsgs   int `json:"user_messages"`
	Assistant  int `json:"assistant"`
	ToolUse    int `json:"tool_use"`
	ToolResult int `json:"tool_results"`
	Total      int `json:"total"`
}

TokenBreakdown provides a detailed breakdown of token usage by category.

type VibeConfig

type VibeConfig struct {
	Enabled       bool
	AutoApply     bool   // apply file changes without asking
	AutoRun       bool   // run build/test after each change
	RunCommand    string // command to run (default: auto-detect)
	ShowDiffs     bool   // show diffs briefly (default: false in full vibe, true in semi-vibe)
	MaxIterations int    // max auto-fix iterations (default: 10)
}

VibeConfig controls vibe coding behavior.

func DefaultVibeConfig

func DefaultVibeConfig() VibeConfig

DefaultVibeConfig returns the default vibe coding configuration.

type VimMode

type VimMode int

VimMode represents the current vim mode.

const (
	VimInsert VimMode = iota
	VimNormal
)

type VimState

type VimState struct {
	Mode       VimMode
	Command    CommandState
	Persistent PersistentState
	// contains filtered or unexported fields
}

VimState is the full vim state machine.

func NewVimState

func NewVimState() *VimState

NewVimState creates a new vim state starting in insert mode.

func (*VimState) HandleKey

func (v *VimState) HandleKey(msg tea.KeyMsg, text string, cursor int) (string, int, bool)

HandleKey processes a key event and returns the new text, cursor position, and whether the key was consumed by vim.

func (*VimState) IsEnabled

func (v *VimState) IsEnabled() bool

IsEnabled returns whether vim mode is active.

func (*VimState) ModeString

func (v *VimState) ModeString() string

ModeString returns a display string for the current mode.

func (*VimState) SetEnabled

func (v *VimState) SetEnabled(enabled bool)

SetEnabled enables or disables vim mode.

Jump to

Keyboard shortcuts

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