Skip to content

Use persistent session directories for agent workspaces #1198

Closed

Description

@malibio

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

Activity

  1. malibio commented on May 29, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 131 passed, 3924 tests

  2. self-assigned this
    on May 29, 2026
  3. added a commit that references this issue on May 29, 2026
    08a29a4
  4. added a commit that references this issue on Jun 22, 2026
    d327619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions