feat: persist to disk by default with an ephemeral opt-out #5

Merged
sam merged 2 commits from feat/persist-by-default into main 2026-09-22 19:16:52 +00:00
Collaborator

Summary

Make disk persistence the default, with an explicit -ephemeral opt-out, and generalize the state-directory name (sessions are not the only state brainless will store).

Changes

  • internal/harness/config.go: Config.SessionDir → StateDir. ResolveStateDir() now takes no argument and returns only the default dir — os.UserConfigDir()/brainless (linux $XDG_CONFIG_HOME/$HOME/.config, macOS ~/Library/Application Support, windows %AppData%). It never echoes its input back.
  • cmd/brainless/main.go: STATE_DIR env / -state-dir flag; new -ephemeral flag. main is the single place that decides ephemeral vs explicit dir vs default, and errors if -ephemeral and -state-dir are both set. Persists by default.
  • internal/harness/harness.go: Config carries only the resolved StateDir (empty = in-memory); the in-memory store is allocated only when StateDir is empty.
  • Tests: ResolveStateDir default path.
  • README: document default persistence, STATE_DIR, and -ephemeral; reconcile the Paseo how-to (--state-dir). Rebased onto main (incl. the PR #4 docs merge).

Notes

  • Cross-compiles clean for linux/arm64, darwin/arm64, and windows/amd64 (CGO_ENABLED=0).
  • Uses os.UserConfigDir() rather than a hand-rolled GOOS switch, so any platform that function supports works out of the box.

Verified: go build ./..., go test ./..., golangci-lint run (0 issues), and the three cross-builds.

## Summary Make disk persistence the default, with an explicit `-ephemeral` opt-out, and generalize the state-directory name (sessions are not the only state `brainless` will store). ## Changes - **`internal/harness/config.go`**: `Config.SessionDir` → `StateDir`. `ResolveStateDir()` now takes no argument and returns only the default dir — `os.UserConfigDir()/brainless` (linux `$XDG_CONFIG_HOME`/`$HOME/.config`, macOS `~/Library/Application Support`, windows `%AppData%`). It never echoes its input back. - **`cmd/brainless/main.go`**: `STATE_DIR` env / `-state-dir` flag; new `-ephemeral` flag. `main` is the single place that decides ephemeral vs explicit dir vs default, and errors if `-ephemeral` and `-state-dir` are both set. Persists by default. - **`internal/harness/harness.go`**: `Config` carries only the resolved `StateDir` (empty = in-memory); the in-memory store is allocated only when `StateDir` is empty. - **Tests**: `ResolveStateDir` default path. - **README**: document default persistence, `STATE_DIR`, and `-ephemeral`; reconcile the Paseo how-to (`--state-dir`). Rebased onto `main` (incl. the PR #4 docs merge). ## Notes - Cross-compiles clean for `linux/arm64`, `darwin/arm64`, and `windows/amd64` (`CGO_ENABLED=0`). - Uses `os.UserConfigDir()` rather than a hand-rolled GOOS switch, so any platform that function supports works out of the box. Verified: `go build ./...`, `go test ./...`, `golangci-lint run` (0 issues), and the three cross-builds.
Make persistence the default and generalize the state directory name, since
sessions are not the only state brainless will store.

- Config: replace SessionDir with StateDir + Ephemeral. ResolveStateDir now
  defaults to os.UserConfigDir()/brainless (linux/macOS/windows), falling
  back to in-memory only when Ephemeral is set; boot fails if the platform
  has no config-dir convention (set STATE_DIR or -ephemeral to proceed).
- main: STATE_DIR env / -state-dir flag, and a new -ephemeral flag; resolves
  the state dir at boot.
- harness.New persists by default; only uses the in-memory store when
  ephemeral.
- README: document default persistence, STATE_DIR, and -ephemeral.
- Tests: ResolveStateDir for explicit and default paths.
- Config drops the Ephemeral field; StateDir now carries the final value
  (empty = in-memory). main is the single place that decides ephemeral vs
  explicit dir vs default.
- ResolveStateDir() takes no argument and only returns the default dir
  (never echoes its input back).
- main errors if both -ephemeral and -state-dir are set; only resolves the
  default dir when neither was given.
- harness.New no longer resolves the dir (already done by main) and only
  allocates the in-memory store when StateDir is empty.
Author
Collaborator

Resolved all 5 review comments (pushed as 2b6a13f):

  1. Inefficient always-in-memory store — harness.New now only allocates session.InMemoryService() when StateDir is empty; otherwise it goes straight to the SQLite store (if/else, no throwaway allocation).
  2. Should error when both stateDir and ephemeral set — main now exits with -ephemeral and -state-dir are mutually exclusive.
  3. Why emptying stateDir — fixed: main no longer force-empties; it only calls ResolveStateDir() when stateDir == "" && !ephemeral.
  4. Resolver echoing its arg — ResolveStateDir() now takes no argument and only returns the default dir; it never echoes input back.
  5. Logic duplicated in main — the ephemeral-vs-explicit-vs-default decision now lives solely in main; Config carries only the final StateDir (empty = in-memory) and harness.New just consumes it.

Verified: go build, go test ./..., golangci-lint run (0 issues), CGO_ENABLED=0 build, and darwin/windows cross-builds.

Resolved all 5 review comments (pushed as 2b6a13f): 1. **Inefficient always-in-memory store** — `harness.New` now only allocates `session.InMemoryService()` when `StateDir` is empty; otherwise it goes straight to the SQLite store (if/else, no throwaway allocation). 2. **Should error when both stateDir and ephemeral set** — `main` now exits with `-ephemeral and -state-dir are mutually exclusive`. 3. **Why emptying stateDir** — fixed: `main` no longer force-empties; it only calls `ResolveStateDir()` when `stateDir == "" && !ephemeral`. 4. **Resolver echoing its arg** — `ResolveStateDir()` now takes no argument and only returns the default dir; it never echoes input back. 5. **Logic duplicated in main** — the ephemeral-vs-explicit-vs-default decision now lives solely in `main`; `Config` carries only the final `StateDir` (empty = in-memory) and `harness.New` just consumes it. Verified: `go build`, `go test ./...`, `golangci-lint run` (0 issues), `CGO_ENABLED=0` build, and darwin/windows cross-builds.
pi-agent force-pushed feat/persist-by-default from 2b6a13f0bc to fb4855101d 2026-09-22 19:15:59 +00:00 Compare
sam merged commit 0d2d461272 into main 2026-09-22 19:16:52 +00:00
sam deleted branch feat/persist-by-default 2026-09-22 19:16:52 +00:00
Sign in to join this conversation.
No reviewers
No labels
code-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sam/brainless!5
No description provided.