Skip to content

Implement opt-in session capture: create ai-chat node at PTY session end #1125

Closed

Description

@malibio

Overview

Implement opt-in session capture for PTY agent sessions. When enabled, nodespaced creates an ai-chat node at session end containing configurable levels of session content: metadata only, a summary, or the full transcript. Capture is off by default, controlled by user settings, and the session ID is never synced externally.

Problem Statement

PTY sessions produce valuable context — decisions made, code written, problems solved. Without capture, this context is lost when the terminal closes. Users who want to preserve session context in their knowledge graph need an opt-in mechanism that respects privacy (off by default, configurable content level) and stays within NodeSpace's data model (ai-chat node type).

Proposed Solution

PtySession accumulates output chunks in a circular buffer (capped to avoid unbounded memory). On session end (natural exit or terminate), if capture is enabled in settings, nodespaced assembles the content per the configured level and creates an ai-chat node via the NodeService ops layer. The agent_session_id (UUID) is stored as a local-only node property, never synced.

Acceptance Criteria

Settings

  • Three capture settings stored in NodeSpace user config:
    • capture.enabled (bool, default: false)
    • capture.sync (bool, default: false — session nodes excluded from sync)
    • capture.content (enum: metadata_only | summary | full, default: metadata_only)
  • Settings readable and writable via a GetSettings / UpdateSettings gRPC call (or existing settings mechanism)
  • Settings UI in the desktop app (toggle + content level selector)

Session capture

  • When capture.enabled = false: no node is created at session end (default behavior)
  • When capture.enabled = true, content = metadata_only: ai-chat node created with: agent type, start time, end time, exit code, session ID
  • When capture.enabled = true, content = summary: as above plus a brief summary (first 500 chars of output or agent's final response if detectable)
  • When capture.enabled = true, content = full: as above plus full transcript (all output chunks concatenated)
  • ai-chat node created using the existing ai-chat schema via NodeService.CreateNode
  • agent_session_id stored as a node property; not included in sync payload
  • Session capture happens after the PTY process exits; it does not block session termination
  • Failed capture (e.g., ops error) is logged but does not surface as an error to the user
  • capture.sync = false (default): sync service excludes nodes with agent_session_id property

UI

  • AgentLaunchPanel.svelte shows capture settings (enabled toggle, content level selector) before launch
  • After a captured session, a link to the created ai-chat node is shown in the sessions panel

Testing

  • Unit test: metadata_only capture creates a node with correct fields and no transcript
  • Unit test: full capture creates a node with the full output buffer
  • Unit test: capture disabled → no node created
  • All frontend tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Files to create/modify

  • packages/agent/src/pty/capture.rs (NEW) — SessionCapture struct: output ring buffer, finalize() method that assembles the ai-chat node payload
  • packages/agent/src/pty/session.rs — integrate SessionCapture: accumulate output chunks; call capture.finalize() on exit
  • packages/daemon/src/capture_service.rs (NEW) — after session exit, calls NodeService ops to create the ai-chat node
  • packages/desktop-app/src/lib/components/agent/AgentLaunchPanel.svelte — add capture settings controls
  • packages/desktop-app/src/lib/components/agent/SessionsPanel.svelte — show link to captured node after session end

ai-chat node schema

The ai-chat node type already exists in the schema. The capture creates a node with:

node_type: "ai-chat"
content: "<agent_type> session — <start_time>"
properties:
  agent_type:        "claude_code" | "codex" | "gemini" | "pi" | "opencode"
  started_at:        ISO 8601 timestamp
  ended_at:          ISO 8601 timestamp
  exit_code:         integer
  agent_session_id:  UUID string (local-only, excluded from sync)
  transcript:        string (only present when content = "full")
  summary:           string (only present when content = "summary" or "full")

Output ring buffer

pub struct SessionCapture {
    buffer: VecDeque<OutputChunk>,
    max_bytes: usize,
    current_bytes: usize,
}

impl SessionCapture {
    pub fn push(&mut self, chunk: OutputChunk) { ... }  // evicts oldest on overflow
    pub fn transcript(&self) -> String { ... }          // all chunks concatenated
    pub fn summary(&self) -> String { ... }             // first 500 chars
}

Max buffer size: 1 MB (configurable constant). Older chunks are evicted when the buffer is full.

Sync exclusion

The sync service checks for the agent_session_id property and excludes matching nodes from sync payloads when capture.sync = false. This is implemented as a filter in the sync service, not by using a separate node type.

Reference files

Dependencies

Non-Goals

  • Automatic summarization via LLM (summary is a text truncation, not an AI-generated summary)
  • Streaming capture to the node during the session (capture happens only at end)
  • Exporting transcripts to formats other than the ai-chat node (future)
  • Capture of stdin (only stdout/stderr is captured)

Activity

  1. self-assigned this
    on May 18, 2026
  2. malibio commented on May 18, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 128 test files, 3916 tests passed

  3. added 2 commits that reference this issue on May 18, 2026
    1d6460d
    19a5745
  4. added a commit that references this issue on Jun 22, 2026
    fd1fc3a
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