feat(command): add /clear slash command#20
Merged
Merged
Conversation
Implemented `/clear` as a slash command that resets the current chat session and clears the terminal so the TUI redraws like a fresh launch. The behavior is wired in `src/components/App.tsx`: `/clear` now calls `screen.clear()`, closes any picker state, and increments a `sessionId`. `src/components/Chat/Chat.tsx` listens for that `sessionId` change and resets messages, loading, pending tool approval, and pending plan approval back to a fresh session.
The duplicate cursor came from the `/clear` path resetting the terminal directly with `\x1Bc`, which bypassed Ink’s own cursor/render management. Changed `src/utils/screen.ts` to support a registered clear handler, and `src/tui.tsx` now wires that handler to Ink’s `render(...).clear()` API. That means `/clear` still wipes the visible session, but it does it through Ink instead of hard-resetting the terminal underneath it.
Fixed the duplicate cursor that came from `/clear` path resetting the
terminal directly with `\x1Bc`, which bypassed Ink’s own cursor/render
management.
`src/tui.tsx` now uses Ink’s `render(...).clear()` API, which means
`/clear` wipes the visible session through Ink instead of hard-resetting
the terminal underneath it.
On startup, it does a one-time `process.stdout.write('\x1Bc')` in
`src/cli.ts` before Ink renders in an alternate screen. This allows
the app to open onto a truly fresh terminal and restore the original
terminal content when the app exits.
Enabled `incrementalRendering` in `src/tui.tsx` to try to stop the occasional flickering because it changes how Ink redraws lines.
Bug: the explicit clear operation is what’s fighting incremental rendering. Fix: removed the in-app `screen.clear()` call from `/clear` in `src/components/App.tsx`. `/clear` now just resets the session state, which lets Ink reconcile the frame normally under `incrementalRendering` instead of wiping the output and leaving unchanged chrome like the header behind.
The committed transcript no longer stores the hidden system message, the active assistant response now lives in separate `streamingMessage` state until it’s committed, and Ollama requests cache and prepend the system prompt at call time. That removes the sentinel first message and avoids rewriting the full transcript array for every streamed chunk. Updated `src/components/Messages.tsx` so committed rows are memoized and the live streaming row is rendered separately. That means unchanged history doesn’t rerender on every token. `src/components/Messages.test.tsx` was expanded for the streaming row path.
The flicker was coming from the renderer path, not from chat state churn. `Input.tsx` keeps typing local to `@inkjs/ui`’s `TextInput`, so the whole chat transcript is not re-rendering on every keypress. The actual hot path is `tui.tsx`, where Ink renders the terminal UI and throttles frame updates. TextInput redraws the line on each keystroke, including the inverse-video cursor; when you type faster than the default render cadence, some terminals show that as flicker/skipped repaint. Raising `maxFps` does not change app behavior, just lets the TUI flush input updates more smoothly.
/clear command
/clear command/clear slash command
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the motivation for this pull request?
Add a
/clearcommand that fully resets the current chat session in the TUI without restarting the CLI, then fix the rendering regressions uncovered while wiring that flow.What is the current behavior?
There is no in-app command to clear the active chat session. Resetting the UI can leave behind stale agent system state, duplicate cursor artifacts, missing header/footer content, lost terminal scrollback, and visible flicker while typing.
What is the new behavior?
The CLI now supports
/clearto reset the chat session and TUI state in place. Clearing also restores the agent system message correctly, keeps the header and footer rendered, preserves terminal scrollback, removes the duplicate cursor issue, and smooths TUI updates by enabling incremental rendering and raising Ink's max FPS.Checklist: