Skip to content

feat: add /clear and /compact slash commands#132

Draft
yamaceay wants to merge 3 commits into
stippi:mainfrom
yamaceay:feat/clear-compact-commands
Draft

feat: add /clear and /compact slash commands#132
yamaceay wants to merge 3 commits into
stippi:mainfrom
yamaceay:feat/clear-compact-commands

Conversation

@yamaceay

@yamaceay yamaceay commented Jun 10, 2026

Copy link
Copy Markdown

Context

PR 2 of 5 — slash-command autocomplete series.

Dependency / merge order:

#136 → #131 (SlashCommand registry) → #132 → #133 → #134 → #135

Why

Users need a way to reset a long-running conversation without quitting the
process. /clear is the minimal version; /compact reserves the name for a
future summarisation implementation.

What

Two new slash commands, wired end-to-end through all four layers:

User types /clear
  → CommandResult::ClearContext          (commands.rs — new match arm + CommandResult variant)
  → KeyEventResult::ClearContext         (input.rs   — new KeyEventResult variant + mapping)
  → BackendEvent::ClearContext           (app.rs     — new match arm, sends to backend)
  → clear ChatSession fields             (backend.rs — handler)
  → UiEvent::ClearMessages              (backend.rs → terminal renderer)

/clear — wipes the active session's message history:

  • Clears message_nodes, active_path, next_node_id, messages, and plan
    on the ChatSession struct.
  • Emits UiEvent::ClearMessages so the TUI transcript is immediately cleared.
  • The session identity (ID, name, sandbox policy, current model) is preserved —
    the user can keep chatting in the same session immediately.

/compact — currently a stub:

  • Emits UiEvent::DisplayError with "not yet implemented — use /clear to reset"
    until a proper summarisation implementation is added.

Files changed

File Change
commands.rs ClearContext + CompactContext in CommandResult; new match arms; new entries in all_commands()
input.rs ClearContext + CompactContext in KeyEventResult; mapping from CommandResult
backend.rs ClearContext + CompactContext in BackendEvent; two new handler arms
app.rs Two new arms in the event loop forwarding to backend

Test plan

  • Type /clear → transcript clears; new messages work normally in the same session.
  • Type /compact → info/error message appears; session is unaffected.
  • /help output includes both new commands with descriptions.
  • Pre-existing commands (/model, /plan, etc.) are unaffected.
  • cargo build --no-default-features passes.

yamaceay added 3 commits June 11, 2026 10:40
The GPUI desktop UI depends on Metal shader compilation, which requires
Xcode developer tools to be installed (xcrun must find the `metal` binary).
On machines without Xcode this hard-blocked every `cargo build`, even when
only the terminal TUI was needed.

Introduce a `gpui-ui` Cargo feature that gates all GPUI-related code:

- `Cargo.toml`: `gpui`, `gpui_platform`, and `gpui-component` are now
  optional dependencies, activated only by `--features gpui-ui`.
  The gpui entry in `[dev-dependencies]` is removed (it was unused in
  the unit-test suite).

- `src/app/mod.rs`, `src/ui/mod.rs`: `pub mod gpui` gated behind
  `#[cfg(feature = "gpui-ui")]`.

- `src/ui/backend.rs`: The `GpuiTerminalCommandExecutor` import and its
  single usage site are gated; the TUI-only path falls back to
  `DefaultCommandExecutor` (which `GpuiTerminalCommandExecutor` itself
  delegates to internally).

- `src/main.rs`: The `--ui` code paths (logging setup, model resolution,
  `app::gpui::run()`) are gated.  Passing `--ui` without the feature
  produces a clear error message rather than a linker crash.

- `src/cli.rs`: The `UiSettings::load()` call that reads the GPUI-
  persisted default model is gated; TUI-only builds fall through to the
  alphabetical-first-model fallback.

Build commands:
  # TUI only (no Xcode required):
  cargo build --no-default-features

  # With GPUI desktop UI (requires Xcode / Metal):
  cargo build --features gpui-ui
Introduce a `SlashCommand` struct (name, aliases, description) and an
`all_commands()` function that returns a static slice of all registered
commands.  This gives the rest of the codebase — in particular the
upcoming autocomplete popup — a single, authoritative place to discover
what slash commands exist, without needing to duplicate the match arms
in `process_command`.

The help text is now derived from the registry instead of being a hard-
coded string, so adding a new command in one place is sufficient.

No behavior change: all existing commands keep the same names, aliases,
and runtime behaviour.
Adds two new slash commands to the terminal TUI:

- `/clear`   — wipes the conversation message history (message nodes,
               active path, plan) for the current session, then clears
               the UI transcript.  The session itself stays alive so the
               user can continue without re-starting.
- `/compact` — placeholder that shows an informational error until a
               proper summarisation implementation lands.

The data path is:
  CommandProcessor (commands.rs)
    → KeyEventResult::{ClearContext,CompactContext}  (input.rs)
    → BackendEvent::{ClearContext,CompactContext}     (app.rs)
    → handler in handle_backend_events               (backend.rs)
    → UiEvent::ClearMessages / UiEvent::DisplayError (terminal UI)
@yamaceay yamaceay force-pushed the feat/clear-compact-commands branch from b3ac43b to 73deb60 Compare June 11, 2026 09:20
@yamaceay yamaceay marked this pull request as draft June 11, 2026 09:48
};
if let Some(session_id) = current_session_id {
let _ = backend_event_tx
.send(BackendEvent::ClearContext { session_id })

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would make /clear start a new session instead. Not actually clear the current one.

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