Skip to content

feat(tui): add /delete command to remove current session - #182701

Open
thetingster wants to merge 1 commit into
openclaw:mainfrom
thetingster:feat/tui-delete-command
Open

thetingster wants to merge 1 commit into
openclaw:mainfrom
thetingster:feat/tui-delete-command

Conversation

@thetingster

@thetingster thetingster commented Oct 24, 2026 •

Copy link
Copy Markdown

What Problem This Solves

The OpenClaw TUI provides /new (spawn a new session) and /reset (reset current session history), but there is no way for a user to remove a session entirely. Users who want to clean up old sessions must exit the TUI and use external tools or the Gateway API directly.

This PR exposes the existing sessions.delete RPC (already fully implemented server-side) through the TUI, giving users a first-class way to delete sessions without leaving the terminal interface.

Evidence

  • End-to-end RPC test: Created throwaway session via sessions.create, called sessions.delete with exact TUI params, confirmed:
    • deleted: true returned
    • Session no longer appears in sessions.list
    • Original transcript removed from disk
    • Archived copy present at .deleted.<timestamp>.<hash>.zst
  • Syntax verification: All 5 modified files pass node --check
  • Backward compatibility: Purely additive — no existing commands or APIs changed
  • Both modes: Works in gateway-connected and local/embedded TUI modes

Summary

Adds a /delete slash command (with /rm alias) to the OpenClaw TUI that permanently deletes the current session and its transcript, then falls back to a fresh session.

Behavior

  • /delete opens a confirmation overlay showing the target session key and warning that the session and transcript will be permanently removed.
  • Choosing Delete session calls sessions.delete with:
    • deleteTranscript: true — archives the transcript to <session>.jsonl.deleted.<ts>.<hash>.zst
    • expectedSessionId — optimistic-concurrency guard to prevent deleting a session that was recreated
  • After deletion, the TUI falls back to:
    • The agent's home session, if one exists and is different from the deleted session
    • A newly created tui-<uuid> session otherwise
  • Guards inherited from existing session-action machinery:
    • Blocked while a run is active (abort the current run before /delete)
    • Blocked during another session transition
    • Blocked while disconnected from the gateway

Implementation

Files changed

File Change
src/tui/commands.ts Add /delete and /rm to command definitions
src/tui/tui-command-handlers.ts Add deleteCurrentSession, confirmDeleteSession, createFallbackSession, clearRememberedSessionPointer; wire into dispatch map; extend session transition types
src/tui/gateway-chat.ts Add client.deleteSession() → sessions.delete RPC wrapper
src/tui/embedded-backend.ts Add deleteSession() for local/embedded mode; add resolveLocalGatewayContext() helper
src/gateway/local-request-context.ts Export createLocalGatewayRequestContext (needed by embedded backend)

Key design decisions

  1. Confirmation overlay: Deletion is destructive, so a two-step confirmation (/delete → overlay → select) prevents accidental data loss.
  2. Transcript archival, not hard-deletion: The server-side sessions.delete already archives transcripts before removing them. The TUI inherits this behavior without additional work.
  3. Fallback session creation: After deletion, the user must land somewhere. The TUI first tries the agent's home session, then creates a fresh one. This mirrors how /new behaves.
  4. Scope compatibility: sessions.delete requires operator.admin. The TUI already requests this scope at connection time, so no auth changes are needed.

Compatibility

  • Backward compatible: purely additive — no existing commands or APIs changed
  • Alias: /rm provided as shorthand (matches common CLI conventions)
  • Local/embedded mode: works in both gateway-connected and --local TUI modes

Example

User: /delete
TUI:  [overlay] Delete the current session?
      Session: agent:main:tui-abc123
      This permanently removes the session and its transcript.
      > Cancel
      > Delete session

User: [selects Delete session]
TUI:  session agent:main:tui-abc123 deleted
      now in session agent:main:tui-def456

Checklist

  • Feature implemented
  • Confirmation overlay added
  • Both connected and local/embedded modes handled
  • Transcript archival preserved (server-side behavior)
  • Session transition guards respected
  • Syntax check passes on all modified files
  • End-to-end RPC test completed

Source-level patch: For maintainers who want the exact src/ changes rather than reading the diff, all changes are in the 5 files listed above. The logic maps directly from the compiled dist/ patches that were tested against [email protected].

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 24, 2026
@thetingster
thetingster force-pushed the feat/tui-delete-command branch 2 times, most recently from b30c7e1 to 51ed561 Compare October 24, 2026 16:14
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 24, 2026
@thetingster
thetingster force-pushed the feat/tui-delete-command branch from 51ed561 to 11d3224 Compare October 24, 2026 16:28
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 11d3224b5bbc32bd7c0a6792f71693de0846b18d, but the PR head is now ac41a5d9caafc2a551da7beb76745cc57818ce99. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-10-24T16:47:54.427Z sha 11d3224b5bbc32bd7c0a6792f71693de0846b18d :: needs real behavior proof before merge. :: [P1] Bind confirmation to the incarnation shown when the prompt opened | [P1] Preserve restore pointers belonging to other Gateway connections | [P2] Keep deletion behind the active session-transition guard | [P2] Include deletion in the submit-admission result type | [P2] Make the fallback resolver contract consistently required | [P2] Fit the deletion implementation within the enforced module budgets

@thetingster
thetingster force-pushed the feat/tui-delete-command branch 3 times, most recently from 5dd588f to 39058fa Compare October 24, 2026 18:03
Adds a /delete slash command (with /rm alias) to the OpenClaw TUI that
permanently deletes the current session and its transcript, then falls back
to a fresh session.

- Confirmation overlay prevents accidental deletion
- Archives transcript to .deleted.<ts>.<hash>.zst before removal
- Falls back to agent home session or creates new tui-<uuid>
- Works in both gateway-connected and local/embedded modes
- Leverages existing sessions.delete RPC (already server-side)
@thetingster
thetingster force-pushed the feat/tui-delete-command branch from 39058fa to ac41a5d Compare October 24, 2026 18:23
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant