summaryrefslogtreecommitdiff
path: root/internal/tmuxedit/run.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-17 11:28:19 +0200
committerPaul Buetow <paul@buetow.org>2026-03-17 11:28:19 +0200
commit6f1c8bf7a36eb7044ed7aad30f84664cbbf0d303 (patch)
treedd2ac6e1433177fb59c167a12fa0b4b91132f34a /internal/tmuxedit/run.go
parent10562cc510f64d5ac38aeb76f03e18eb76cca40f (diff)
Fix bugs, remove duplication, and clean up code quality issues
- Log swallowed JSON unmarshal errors in stats and LSP handlers - Fix debug log file handle leak in tmuxedit (return closer from initDebugLog) - Check f.Close() errors on write paths in promptstore and tmuxedit - Fix cacheGet TOCTOU race by using single write lock - Fix readInput to use passed stdin reader instead of os.Stdin.Stat() - Remove 45 'moved to' comment tombstones from lsp/handlers.go - Deduplicate canonicalProvider wrappers (use llmutils.CanonicalProvider directly) - Remove SetWindow side effect from stats.TakeSnapshot (pure read now) - Move duplicated splitLines to textutil.SplitLinesBytes - Collapse StatusSink.SetGlobal 10 params into GlobalStatus struct - Simplify LRU touchLocked to in-place delete-and-append Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'internal/tmuxedit/run.go')
-rw-r--r--internal/tmuxedit/run.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/internal/tmuxedit/run.go b/internal/tmuxedit/run.go
index efa503b..da484df 100644
--- a/internal/tmuxedit/run.go
+++ b/internal/tmuxedit/run.go
@@ -112,22 +112,23 @@ func loadConfig(configPath string) appconfig.App {
var debugLog *log.Logger
// initDebugLog creates a debug log file in the state directory
-// (~/.local/state/hexai/hexai-tmux-edit.log). Returns an error if the
-// state directory cannot be resolved. Silently skips logging if the
-// log file itself cannot be opened.
-func initDebugLog() error {
+// (~/.local/state/hexai/hexai-tmux-edit.log). Returns a closer for the
+// log file handle and an error if the state directory cannot be resolved.
+// Silently skips logging (returns a no-op closer) if the log file cannot
+// be opened.
+func initDebugLog() (func(), error) {
stateDir, err := appconfig.StateDir()
if err != nil {
- return fmt.Errorf("cannot create state directory: %w", err)
+ return nil, fmt.Errorf("cannot create state directory: %w", err)
}
logPath := filepath.Join(stateDir, "hexai-tmux-edit.log")
f, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
- return nil
+ return func() {}, nil
}
debugLog = log.New(f, "", log.LstdFlags|log.Lmicroseconds)
- return nil
+ return func() { _ = f.Close() }, nil
}
func dbg(format string, args ...any) {
@@ -140,9 +141,11 @@ func dbg(format string, args ...any) {
// It resolves the agent (by name or auto-detect), extracts the current
// prompt, opens the editor popup, then clears and sends the result.
func runWithConfig(opts Options, cfg appconfig.App) error {
- if err := initDebugLog(); err != nil {
+ closeLog, err := initDebugLog()
+ if err != nil {
return fmt.Errorf("init debug log: %w", err)
}
+ defer closeLog()
dbg("=== hexai-tmux-edit start ===")
dbg("opts: pane=%q agent=%q config=%q", opts.Pane, opts.Agent, opts.ConfigPath)