Repository navigation
Description
Overview
Agent sessions currently launch in a `tempfile::tempdir()` that is deleted when the process exits, losing all artifacts the agent created. Sessions should use a persistent directory at `~/.nodespace/agent-sessions//` so artifacts, context files, and agent output survive across restarts.
Problem Statement
`packages/agent/src/pty/session.rs` line 135 creates a temp directory:
```rust
let session_dir = tempfile::tempdir()?;
```
This directory is automatically cleaned up when `session_dir` is dropped on session end. Any files the agent created — notes, code, outputs — are lost. There is no way to review what an agent did after the session closes.
Proposed Solution
Replace `tempfile::tempdir()` with a named directory under `~/.nodespace/agent-sessions//`:
```rust
let sessions_base = dirs::home_dir()
.context("HOME not set")?
.join(".nodespace")
.join("agent-sessions");
let session_dir = sessions_base.join(session_id.to_string());
std::fs::create_dir_all(&session_dir)?;
```
The session UUID already exists as the gRPC session ID — use that as the directory name so the filesystem path is directly tied to the session record.
Acceptance Criteria
- Each agent session launches with cwd set to `~/.nodespace/agent-sessions//`
- Directory is created on session launch, not deleted on session end
- Context file (`CLAUDE.md` / `AGENTS.md`) is written into the session directory as before
- Old temp directory approach removed
- `~/.nodespace/agent-sessions/` is created on first session launch if it doesn't exist
- `cargo build --workspace` succeeds
- `bun run test:all` passes
Technical Specifications
Files to Modify
- `packages/agent/src/pty/session.rs` — replace `tempfile::tempdir()` with named directory; session UUID must be threaded through to `launch()`
- `packages/daemon/src/services/agent_session_service.rs` — pass session UUID into `PtySession::launch()` at creation time
Session UUID availability
The session UUID is generated in `agent_session_service.rs` when `LaunchSession` is called. It needs to be passed into `PtySession::launch()` as a parameter so the session directory can be named accordingly.
Remove tempfile dependency
Once the temp directory is replaced, check if `tempfile` is still needed in `packages/agent/Cargo.toml`. Remove it if not used elsewhere (keep in dev-dependencies if needed for tests).
Related Issues
- Implement AgentSessionService gRPC handler in nodespaced #1119 (AgentSessionService implementation)
Activity
malibio commentedon May 29, 2026
Frontend baseline: 131 passed, 3924 tests
Use persistent session dirs for agent workspaces (closes #1198) (#1235)
Use persistent session dirs for agent workspaces (closes #1198) (#1235)