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/appconfig/config.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/appconfig/config.go')
| -rw-r--r-- | internal/appconfig/config.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go index 63b5ea5..f8c1827 100644 --- a/internal/appconfig/config.go +++ b/internal/appconfig/config.go @@ -1270,6 +1270,27 @@ func ConfigPath() (string, error) { return configPath, nil } +// StateDir returns the XDG state directory for hexai (~/.local/state/hexai by default). +// Creates the directory if it doesn't exist. This is used for persistent state data +// like logs and history that should survive reboots. +func StateDir() (string, error) { + stateHome := os.Getenv("XDG_STATE_HOME") + if stateHome == "" { + home, err := os.UserHomeDir() + if err != nil { + return "", fmt.Errorf("cannot find user home directory: %v", err) + } + stateHome = filepath.Join(home, ".local", "state") + } + + stateDir := filepath.Join(stateHome, "hexai") + if err := os.MkdirAll(stateDir, 0o755); err != nil { + return "", fmt.Errorf("cannot create state directory: %v", err) + } + + return stateDir, nil +} + // ProjectConfigFilename is the name of the per-project config file placed at a git repo root. const ProjectConfigFilename = ".hexaiconfig.toml" |
