Skip to content

persist terminal directories on restart#101

Merged
forketyfork merged 2 commits intomainfrom
fix/persist-terminals
Jan 13, 2026
Merged

persist terminal directories on restart#101
forketyfork merged 2 commits intomainfrom
fix/persist-terminals

Conversation

@forketyfork
Copy link
Owner

Summary

  • persist running terminals' working directories under [terminals] in persistence.toml using terminal__ keys, pruning out-of-grid entries and restoring valid cells at startup
  • duplicate parser-owned data to avoid UAF, seed cwd when spawning/restarting, save dirs on exit, and align with Zig 0.15 ArrayList/Writer APIs plus manual z-string handling
  • document the new persistence behavior in README and add pitfall notes to CLAUDE; builds tested with "just build" and "zig build test"

Prompt: When exiting the app, save the state of the terminals (spawned, in which directory) in the persistence.toml file (e.g., terminal_1_2: "/Users/local/dev"); on running the app, spawn the terminals that were running the previous time in the respective directories. If the new grid layout doesn't have terminals at such positions (e.g., the user has decreased the number of cells), ignore those values and remove them from persistence.toml.
Solution: Added terminal state persistence with grid pruning and restore on startup; duplicated TOML data to avoid ownership bugs and aligned with Zig 0.15 ArrayList/io APIs. Seed cwd on spawn, persisted dirs on exit, and documented behavior and pitfalls; README/CLAUDE updated and builds/tests pass.
@forketyfork forketyfork requested a review from Copilot January 13, 2026 09:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds persistence for terminal working directories, ensuring running terminals restore to their previous directories when the application restarts.

Changes:

  • Added terminal directory persistence using terminal_<row>_<col> keys in persistence.toml
  • Implemented pruning logic to remove out-of-bounds terminal entries when grid dimensions change
  • Added seedCwd and replaceCwdPath methods to properly track and manage terminal working directories

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/session/state.zig Added cwd tracking methods and basename handling for terminal directories
src/main.zig Integrated terminal restoration from persistence at startup and saving on exit
src/config.zig Implemented Persistence terminal storage with pruning, collection, and serialization logic
README.md Documented the new terminal state persistence feature with example
CLAUDE.md Added implementation notes about Zig 0.15 API changes and TOML parser pitfalls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b27939aae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@forketyfork
Copy link
Owner Author

  • Switched temporary lists to ArrayList.empty with allocator-aware append/deinit (Zig 0.15 has no init()).\n- [x] Same change for collected terminal entries and fallback list.\n- [ ] Keeping two-phase removal: removing while iterating StringHashMap invalidates the iterator; grid is tiny so extra allocation is negligible.\n- [x] Added allocZ helper and reuse for restored dirs.\n- [x] Cwd persistence now macOS-only; other platforms skip saving/restoring terminals to avoid stale paths until cross-platform tracking exists. README/CLAUDE note added.

@forketyfork forketyfork merged commit 480be5e into main Jan 13, 2026
5 checks passed
@forketyfork forketyfork deleted the fix/persist-terminals branch January 13, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants