Merge pull request #18 from tgulacsi/betteralign

Reorder struct fields for better memory alignment
This commit is contained in:
Cheikh Seck authored and GitHub committed 2026-06-06 09:45:23 +00:00
commit 7108bc8ecb
24 files changed
+193 -191

No files matched your search

+1 -1
View File
@@ -588,8 +588,8 @@ promptLoop:
}
type promptResult struct {
input string
err error
input string
}
promptCancelCh := make(chan struct{}, 1)
promptResultCh := make(chan promptResult, 1)
+30 -30
View File
@@ -49,39 +49,39 @@ var commandTips = map[string]string{
}
type promptModel struct {
basePrompt string
contPrompt string
input textinput.Model
lines []string
multiline bool
history []string
historyIndex int
historyDraft string
submitted bool
aborted bool
completions []string
completeSeed string
completeIdx int
showCompletions bool
width int
modelName string
contextUsage int
contextLimit int
historyDB *history.HistoryDB
wd string
searchMode bool
searchInput textinput.Model
searchIndex int
searchResults []string
statusMessage string
commitList []string
scheduleList []string
statusCh <-chan string
delegateCh <-chan hive.HiveStats
delegateCount int
delegateLatest string
statusHidden bool
Cancelled chan struct{}
basePrompt string
contPrompt string
historyDraft string
completeSeed string
modelName string
wd string
statusMessage string
delegateLatest string
lines []string
history []string
completions []string
searchResults []string
commitList []string
scheduleList []string
input textinput.Model
searchInput textinput.Model
historyIndex int
completeIdx int
width int
contextUsage int
contextLimit int
searchIndex int
delegateCount int
multiline bool
submitted bool
aborted bool
showCompletions bool
searchMode bool
statusHidden bool
}
func newPromptModel(prompt string, history []string, modelName string, contextUsage int, contextLimit int, historyDB *history.HistoryDB, wd string, statusCh <-chan string, delegateCh <-chan hive.HiveStats) promptModel {
@@ -844,8 +844,8 @@ type selectOption struct {
type statusMsg string
type delegateMsg struct {
Count int
Latest string
Count int
}
func (m *promptModel) applyStatusMessage(msg statusMsg) {
+8 -8
View File
@@ -19,6 +19,10 @@ type MCPServer struct {
// Provider describes a single LLM provider, referenced from the TUI agent.
type Provider struct {
Temperature *float64 `yaml:"temperature,omitempty"`
MaxToolRounds *int `yaml:"max_tool_rounds,omitempty"`
ToolTimeout *int `yaml:"tool_timeout,omitempty"` // in seconds, default 180
Params map[string]string `yaml:"params,omitempty"`
Name string `yaml:"name"`
Type string `yaml:"type"`
Endpoint string `yaml:"endpoint"`
@@ -26,20 +30,16 @@ type Provider struct {
Description string `yaml:"description,omitempty"`
APIKey string `yaml:"api_key,omitempty"`
APIKeyEnv string `yaml:"api_key_env,omitempty"`
Temperature *float64 `yaml:"temperature,omitempty"`
MaxToolRounds *int `yaml:"max_tool_rounds,omitempty"`
ToolTimeout *int `yaml:"tool_timeout,omitempty"` // in seconds, default 180
ContextLimit int `yaml:"context_limit,omitempty"`
Params map[string]string `yaml:"params,omitempty"`
MCPServers []MCPServer `yaml:"mcp_servers,omitempty"`
LlamaServerURL string `yaml:"-"` // CLI override for external llama.cpp server (not persisted)
MCPServers []MCPServer `yaml:"mcp_servers,omitempty"`
ContextLimit int `yaml:"context_limit,omitempty"`
}
// Config is a list of providers, with a default provider name for the CLI.
type Config struct {
Providers []Provider `yaml:"providers"`
DefaultProvider string `yaml:"default_provider,omitempty"`
VisionEnabled *bool `yaml:"vision_enabled,omitempty"`
DefaultProvider string `yaml:"default_provider,omitempty"`
Providers []Provider `yaml:"providers"`
VisionCLIDownloaded bool `yaml:"vision_cli_downloaded,omitempty"`
}
+4 -4
View File
@@ -19,18 +19,18 @@ type HistoryDB struct {
}
type Entry struct {
ID int64
Timestamp time.Time
WD string
Command string
Timestamp time.Time
ID int64
}
type Commit struct {
ID int64
CreatedAt time.Time
WD string
Ref string
Message string
CreatedAt time.Time
ID int64
}
func New(dbPath string) (*HistoryDB, error) {
+12 -12
View File
@@ -23,34 +23,34 @@ const (
)
type Instance struct {
StartedAt time.Time `json:"started_at"`
ID string `json:"id"`
Name string `json:"name"`
Model string `json:"model"`
WorkingDir string `json:"working_dir"`
MCPServers []string `json:"mcp_servers"`
MaxTokens int `json:"max_tokens"`
Port int `json:"port"`
StartedAt time.Time `json:"started_at"`
PID int `json:"pid"`
MCPServers []string `json:"mcp_servers"`
WorkingDir string `json:"working_dir"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
}
type Manager struct {
listener net.Listener
statusCh chan<- string
handler func(context.Context, string) (string, error)
srv *http.Server
closed chan struct{}
results chan HiveResult
statsCh chan HiveStats
stats HiveStats
codeHash string
code string
baseDir string
instance Instance
statusCh chan<- string
handler func(context.Context, string) (string, error)
srv *http.Server
listener net.Listener
closeOnce sync.Once
closed chan struct{}
results chan HiveResult
statsMu sync.Mutex
statsCh chan HiveStats
stats HiveStats
}
type HiveResult struct {
@@ -61,8 +61,8 @@ type HiveResult struct {
}
type HiveStats struct {
DelegatedCount int
LatestCommand string
DelegatedCount int
}
func (m *Manager) Status(msg string) {
+9 -9
View File
@@ -22,18 +22,18 @@ var runCmdMu sync.Mutex
// Job represents a running background job managed by a goroutine
type Job struct {
ID string
Command string
PID int
ExitedAt time.Time
Started time.Time
Ctx context.Context
Cancel context.CancelFunc
Done chan struct{}
ID string
Command string
Output strings.Builder
Mu sync.Mutex
PID int
ExitCode int
Mu sync.Mutex
Exited bool
ExitedAt time.Time
Started time.Time
}
// JobTracker manages all background jobs
@@ -169,13 +169,13 @@ func (t *JobTracker) JobStatus(id string) (string, bool) {
}
type BashServer struct {
jobTracker *JobTracker
allowedPaths []string
tools []Tool
jobTracker *JobTracker
autoConfirm bool
failedStarts []string
mu sync.RWMutex
failedMu sync.Mutex
failedStarts []string
autoConfirm bool
}
var (
+9 -8
View File
@@ -29,15 +29,16 @@ type Tool struct {
InputSchema json.RawMessage
}
type MCPToolExecutor struct {
serverName string
server MCPServer
mcpClient *client.Client
tools []Tool
workingDir string
type MCPToolExecutor struct { //betteralign:ignore
lastRequestID int64 // Must be first for 64-bit alignment on 32-bit platforms - it's accessed atomically
mcpClient *client.Client
serverName string
workingDir string
lastRequestID int64
requestIDMu sync.Mutex
server MCPServer
tools []Tool
requestIDMu sync.Mutex
}
func NewMCPServer(ctx context.Context, server MCPServer, workingDir string) (*MCPToolExecutor, error) {
+6 -6
View File
@@ -34,15 +34,15 @@ type schedulerExt struct {
}
type TaskInfo struct {
ID string `json:"id"`
Prompt string `json:"prompt"`
IntervalSec int `json:"interval_sec"`
RunAt string `json:"run_at"`
IsRepeating bool `json:"is_repeating"`
CreatedAt time.Time `json:"created_at"`
LastRun time.Time `json:"last_run"`
RunCount int `json:"run_count"`
ID string `json:"id"`
Prompt string `json:"prompt"`
RunAt string `json:"run_at"`
LastError string `json:"last_error"`
IntervalSec int `json:"interval_sec"`
RunCount int `json:"run_count"`
IsRepeating bool `json:"is_repeating"`
}
func NewSchedulerServer(scheduler interface {
+4 -4
View File
@@ -16,18 +16,18 @@ import (
)
type cacheEntry struct {
html string
expiresAt time.Time
html string
}
type WebScraperServer struct {
allowedURLs []string
tools []Tool
browserCtx context.Context
browserCancel context.CancelFunc
autoConfirm bool
cache map[string]cacheEntry
allowedURLs []string
tools []Tool
cacheMu sync.Mutex
autoConfirm bool
}
func NewWebScraperServer(allowedURLs []string, autoConfirm bool) *WebScraperServer {
+2 -2
View File
@@ -20,8 +20,8 @@ type hfRepoInfo struct {
}
type hfFileInfo struct {
Size int64 `json:"size"`
BlobHTTPURL string `json:"blobHTTPURL"`
Size int64 `json:"size"`
}
func getGGUFFiles(ctx context.Context, modelID string) ([]string, error) {
@@ -90,9 +90,9 @@ func getDownloadURL(modelID, filename string) string {
}
type DownloadProgress struct {
Filename string
Downloaded int64
Total int64
Filename string
}
var quantOrder = map[string]int{
+5 -5
View File
@@ -18,17 +18,17 @@ const DefaultGeminiModel = "gemini-2.5-flash"
type geminiProvider struct {
client *genai.Client
cfg *config.Provider
model string
temperature *float64
cancelMu sync.Mutex
mu sync.Mutex
cancelFunc context.CancelFunc
statusCh chan<- string
model string
messages []Message
cancelGen uint64
contextLimit int
promptTokens int
completionTokens int
messages []Message
statusCh chan<- string
cancelMu sync.Mutex
mu sync.Mutex
}
func init() {
+6 -6
View File
@@ -18,17 +18,17 @@ import (
const defaultHFBaseURL = "https://router.huggingface.co/v1"
type huggingfaceProvider struct {
temperature *float64
client *http.Client
cancelFunc context.CancelFunc
statusCh chan<- string
baseURL string
model string
apiKey string
temperature *float64
client *http.Client
cancelMu sync.Mutex
cancelFunc context.CancelFunc
cancelGen uint64
messages []Message
cancelGen uint64
cancelMu sync.Mutex
mu sync.Mutex
statusCh chan<- string
}
func init() {
+29 -28
View File
@@ -37,37 +37,38 @@ func llamaDebug(format string, args ...any) {
}
type llamaProvider struct {
baseURL string
model string
modelIsHF bool
cfg *config.Provider
temperature *float64
client *http.Client
messages []map[string]any
mu sync.Mutex
sendMu sync.Mutex
OnThink func(string)
cancelFunc context.CancelFunc
cancelGen uint64
contextLimit int
promptTokens int
completionTokens int
statusCh chan<- string
tools []map[string]any
pendingToolCalls map[string]string
serverCmd *exec.Cmd
serverProcess *os.Process
serverPort int
serverPath string
tokenizePath string
externalServer bool
serverMu sync.Mutex
serverReady bool
serverStarted bool
startMu sync.Mutex
serverCmd *exec.Cmd
serverProcess *os.Process
OnDownloadProgress func(DownloadProgress)
baseURL string
model string
serverPath string
tokenizePath string
messages []map[string]any
tools []map[string]any
cancelGen uint64
contextLimit int
promptTokens int
completionTokens int
serverPort int
mu sync.Mutex
sendMu sync.Mutex
serverMu sync.Mutex
startMu sync.Mutex
modelIsHF bool
externalServer bool
serverReady bool
serverStarted bool
}
var (
@@ -475,10 +476,10 @@ func setCachedQuantization(modelID, quant string) {
type progressWriter struct {
w io.Writer
progressCh chan<- DownloadProgress
filename string
total int64
written int64
filename string
progressCh chan<- DownloadProgress
}
func (pw *progressWriter) Write(p []byte) (int, error) {
@@ -1325,13 +1326,13 @@ func (p *llamaProvider) TokenUsage() (int, int) {
}
type slotInfo struct {
ID int `json:"id"`
IsProcessing bool `json:"is_processing"`
NCtx int `json:"n_ctx"`
IDTask int `json:"id_task"`
NextToken []struct {
NextToken []struct {
NDecoded int `json:"n_decoded"`
} `json:"next_token"`
ID int `json:"id"`
NCtx int `json:"n_ctx"`
IDTask int `json:"id_task"`
IsProcessing bool `json:"is_processing"`
}
func (p *llamaProvider) countTokens(text string) int {
+8 -8
View File
@@ -25,22 +25,22 @@ const (
)
type ollamaProvider struct {
baseURL string
model string
cfg *config.Provider
temperature *float64
client *http.Client
systemPrompt string
messages []map[string]string
mu sync.Mutex
sendMu sync.Mutex
OnThink func(string)
cancelFunc context.CancelFunc
statusCh chan<- string
baseURL string
model string
systemPrompt string
messages []map[string]string
cancelGen uint64
contextLimit int
promptTokens int
completionTokens int
statusCh chan<- string
mu sync.Mutex
sendMu sync.Mutex
visionChecked bool
visionSupported bool
}
@@ -403,8 +403,8 @@ func (o *ollamaProvider) doSend(ctx context.Context, endpoint string, payload []
}
type ollamaError struct {
statusCode int
message string
statusCode int
}
func (e *ollamaError) Error() string {
+12 -12
View File
@@ -31,13 +31,13 @@ func getMaxHistoryMessages() int {
}
type openRouterModelInfo struct {
ID string `json:"id"`
CanonicalSlug string `json:"canonical_slug"`
Name string `json:"name"`
ContextLength float64 `json:"context_length"`
ID string `json:"id"`
CanonicalSlug string `json:"canonical_slug"`
Name string `json:"name"`
Architecture struct {
InputModalities []string `json:"input_modalities"`
} `json:"architecture"`
ContextLength float64 `json:"context_length"`
}
type openRouterModelsResponse struct {
@@ -67,26 +67,26 @@ type reasoningDetail struct {
}
type openRouterProvider struct {
temperature *float64
client *http.Client
pendingToolCalls map[string]string // tool_call_id -> function_name for tracking
cancelFunc context.CancelFunc
OnThink func(string)
statusCh chan<- string
baseURL string
model string
apiKey string
temperature *float64
client *http.Client
systemPrompt string
messages []map[string]any
pendingToolCalls map[string]string // tool_call_id -> function_name for tracking
tools []map[string]any
cancelMu sync.Mutex
cancelFunc context.CancelFunc
cancelGen uint64
contextLimit int
promptTokens int
completionTokens int
cancelMu sync.Mutex
mu sync.Mutex
visionChecked bool
visionSupported bool
OnThink func(string)
mu sync.Mutex
statusCh chan<- string
}
func (p *openRouterProvider) emitStatus(msg string) {
+1 -1
View File
@@ -12,9 +12,9 @@ var DebugMode bool
// Tool represents an executable tool.
type Tool struct {
InputSchema map[string]any
Name string
Description string
InputSchema map[string]any
}
type Message struct {
+1 -1
View File
@@ -13,9 +13,9 @@ const globalCacheLimit = 1000
var globalCache = RegexpCache{m: make(map[string]*regexp.Regexp, globalCacheLimit), limit: globalCacheLimit}
type RegexpCache struct {
mu sync.RWMutex
m map[string]*regexp.Regexp
limit int
mu sync.RWMutex
}
func (c *RegexpCache) MustCompile(pattern string) *regexp.Regexp {
+15 -15
View File
@@ -21,38 +21,38 @@ import (
)
type ScheduledTask struct {
ID string `json:"id"`
Prompt string `json:"prompt"`
IntervalSec int `json:"interval_sec"`
RunAt string `json:"run_at"`
IsRepeating bool `json:"is_repeating"`
WorkingDir string `json:"working_dir"`
CreatedAt time.Time `json:"created_at"`
LastRun time.Time `json:"last_run"`
RunCount int `json:"run_count"`
ID string `json:"id"`
Prompt string `json:"prompt"`
RunAt string `json:"run_at"`
WorkingDir string `json:"working_dir"`
LastError string `json:"last_error"`
LastOutput string `json:"last_output"`
ProviderType string `json:"provider_type"`
ProviderName string `json:"provider_name"`
ProviderModel string `json:"provider_model"`
IntervalSec int `json:"interval_sec"`
RunCount int `json:"run_count"`
IsRepeating bool `json:"is_repeating"`
}
type Scheduler struct {
provider ProviderGetter
db *sql.DB
tasks map[string]*ScheduledTask
taskMu sync.RWMutex
running map[string]context.CancelFunc
runMu sync.RWMutex
stopCh chan struct{}
wg sync.WaitGroup
provider ProviderGetter
servers []ToolServer
onTaskFinished func(*ScheduledTask)
maxRounds int
toolTimeout int
statusCh chan string
wd string
os string
statusCh chan string
servers []ToolServer
wg sync.WaitGroup
maxRounds int
toolTimeout int
taskMu sync.RWMutex
runMu sync.RWMutex
}
type ProviderGetter interface {
+7 -7
View File
@@ -17,17 +17,17 @@ type searchResultMsg struct {
}
type modelSelectModel struct {
textInput textinput.Model
results []modelquery.Model
cursor int
loading bool
searchCancel context.CancelFunc
provider modelquery.Provider
searchDebounce time.Duration
done bool
result string
defaultValue string
currentQuery string
searchCancel context.CancelFunc
results []modelquery.Model
textInput textinput.Model
cursor int
searchDebounce time.Duration
loading bool
done bool
pendingSearch bool
}
+3 -3
View File
@@ -349,10 +349,10 @@ type selectOption struct {
}
type selectModel struct {
result string
options []selectOption
cursor int
done bool
result string
allowCancel bool
}
@@ -437,8 +437,8 @@ func selectPrompt(title string, options []selectOption, defaultVal string, allow
}
type multiSelectModel struct {
options []selectOption
selected map[int]bool
options []selectOption
cursor int
done bool
allowCancel bool
@@ -584,9 +584,9 @@ func openBrowser(urlStr string) error {
}
type oauthCallback struct {
code string
err error
done chan struct{}
code string
received bool
}
+4 -4
View File
@@ -14,16 +14,16 @@ type GeminiModelsResponse struct {
// GeminiModel represents a model from the Gemini API.
type GeminiModel struct {
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"topP,omitempty"`
TopK *int `json:"topK,omitempty"`
Name string `json:"name"`
Version string `json:"version"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
SupportedGenerationMethods []string `json:"supportedGenerationMethods"`
InputTokenLimit int `json:"inputTokenLimit"`
OutputTokenLimit int `json:"outputTokenLimit"`
SupportedGenerationMethods []string `json:"supportedGenerationMethods"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"topP,omitempty"`
TopK *int `json:"topK,omitempty"`
}
// listGeminiModels queries Google's Gemini API for available models.
+6 -6
View File
@@ -14,16 +14,16 @@ type HuggingFaceModel struct {
Author string `json:"author"`
CreatedAt string `json:"createdAt"`
LastModified string `json:"lastModified"`
Private bool `json:"private"`
Downloads int `json:"downloads"`
Guarded bool `json:"guarded"`
Likes int `json:"likes"`
Tags []string `json:"tags"`
PipelineTag string `json:"pipeline_tag"`
Autotemp string `json:"__variant"`
Tags []string `json:"tags"`
Siblings []struct {
Rfilename string `json:"rfilename"`
} `json:"siblings"`
Autotemp string `json:"__variant"`
Downloads int `json:"downloads"`
Likes int `json:"likes"`
Private bool `json:"private"`
Guarded bool `json:"guarded"`
}
// HuggingFaceResponse represents the response from HuggingFace API.
+2 -2
View File
@@ -15,19 +15,19 @@ type OllamaTagsResponse struct {
type OllamaModel struct {
Name string `json:"name"`
Model string `json:"model"`
Size int64 `json:"size"`
Digest string `json:"digest"`
ModifiedAt string `json:"modified_at"`
Details OllamaModelDetails `json:"details"`
Size int64 `json:"size"`
}
// OllamaModelDetails contains additional details about an Ollama model.
type OllamaModelDetails struct {
Format string `json:"format"`
Family string `json:"family"`
Families []string `json:"families"`
ParameterSize string `json:"parameter_size"`
QuantizationLevel string `json:"quantization_level"`
Families []string `json:"families"`
}
// listOllamaModels queries a local Ollama instance for available models.
+9 -9
View File
@@ -13,26 +13,26 @@ type OpenRouterModelsResponse struct {
// OpenRouterModel represents a model from the OpenRouter API.
type OpenRouterModel struct {
DefaultParams map[string]interface{} `json:"default_parameters"`
Pricing OpenRouterPricing `json:"pricing"`
Architecture OpenRouterArchitecture `json:"architecture"`
ID string `json:"id"`
CanonicalSlug string `json:"canonical_slug"`
Name string `json:"name"`
Created int64 `json:"created"`
Description string `json:"description"`
ContextLength int `json:"context_length"`
Architecture OpenRouterArchitecture `json:"architecture"`
Pricing OpenRouterPricing `json:"pricing"`
TopProvider OpenRouterTopProvider `json:"top_provider"`
SupportedParams []string `json:"supported_parameters"`
DefaultParams map[string]any `json:"default_parameters"`
ExpirationDate string `json:"expiration_date"`
SupportedParams []string `json:"supported_parameters"`
TopProvider OpenRouterTopProvider `json:"top_provider"`
Created int64 `json:"created"`
ContextLength int `json:"context_length"`
}
// OpenRouterArchitecture describes the model's technical capabilities.
type OpenRouterArchitecture struct {
InputModalities []string `json:"input_modalities"`
OutputModalities []string `json:"output_modalities"`
Tokenizer string `json:"tokenizer"`
InstructType string `json:"instruct_type"`
InputModalities []string `json:"input_modalities"`
OutputModalities []string `json:"output_modalities"`
}
// OpenRouterPricing contains pricing information for the model.