diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-10 09:52:34 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-10 09:52:34 +0200 |
| commit | 5bc2723325131e8432ad5a47d5e9cb245e9f0b28 (patch) | |
| tree | c18bb5dafdcab806b3d8bb0912d083b28741d24c /internal/tmuxedit/run.go | |
| parent | 17220d71f2af54f875ba1a86f489e5af6d7ad189 (diff) | |
Add tmux popup history storage and consolidate state files to XDG_STATE_HOMEv0.19.0
- Add StateDir() helper function respecting XDG_STATE_HOME (~/.local/state/hexai/)
- Implement JSONL-based history storage for tmux popup submissions
- New history.go with AppendHistory() and GetHistory() functions
- Store timestamp, agent name, cwd, and submitted text
- Comprehensive unit tests for history functionality
- Integrate history append into tmux edit workflow after successful submission
- Move logs from /tmp/ to persistent state directory:
- hexai-lsp.log: ~/.local/state/hexai/hexai-lsp.log
- hexai-tmux-edit.log: ~/.local/state/hexai/hexai-tmux-edit.log
- Update README.md with File Locations section documenting XDG directories
- Fix pre-existing test failures by isolating project config in unit tests
- Panic on state directory creation failure instead of silent fallback
All unit tests pass. Follows XDG Base Directory Specification for proper
state file management with persistence across reboots.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/tmuxedit/run.go')
| -rw-r--r-- | internal/tmuxedit/run.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/internal/tmuxedit/run.go b/internal/tmuxedit/run.go index 8c98ded..a156e5f 100644 --- a/internal/tmuxedit/run.go +++ b/internal/tmuxedit/run.go @@ -5,6 +5,7 @@ import ( "log" "os" "os/exec" + "path/filepath" "strings" "codeberg.org/snonux/hexai/internal/appconfig" @@ -111,8 +112,18 @@ func loadConfig(configPath string) appconfig.App { var debugLog *log.Logger // initDebugLog creates a debug log file at /tmp/hexai-tmux-edit.log. +// initDebugLog creates a debug log file in the state directory (~/.local/state/hexai/hexai-tmux-edit.log). +// Falls back to /tmp if state directory cannot be created. +// initDebugLog creates a debug log file in the state directory (~/.local/state/hexai/hexai-tmux-edit.log). +// Panics if the state directory cannot be created. func initDebugLog() { - f, err := os.OpenFile("/tmp/hexai-tmux-edit.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644) + stateDir, err := appconfig.StateDir() + if err != nil { + panic(fmt.Sprintf("cannot create state directory: %v", 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 } @@ -181,6 +192,20 @@ func runWithConfig(opts Options, cfg appconfig.App) error { dbg("SendText error: %v", err) return err } + + // Append to history (log errors but don't fail the operation) + cwd, err := os.Getwd() + if err != nil { + cwd = "unknown" + dbg("os.Getwd error (using 'unknown'): %v", err) + } + if err := AppendHistory(text, agent.Name(), cwd); err != nil { + dbg("AppendHistory error: %v", err) + // Non-fatal: log but continue + } else { + dbg("appended to history: agent=%q cwd=%q len=%d", agent.Name(), cwd, len(text)) + } + dbg("=== done ===") return nil } |
