feat(Chat): add blank-input prompt history navigation#78
Merged
Conversation
Summary: Add shell-like prompt history navigation to the chat input: when the input is blank, `Up` recalls older submitted prompts and `Down` moves forward toward newer prompts, ending at an empty draft. History is scoped to the current chat session, derived from that session's persisted transcript on load, then maintained in memory for the rest of the mounted session. Implementation Changes: - Extend `Chat/Input` to own prompt-history state: - Initialize history from the active session's existing user prompts. - Append newly submitted non-command user prompts after trimming and successful submit. - Track a navigation index plus an empty-draft state so `Down` can return to blank input after recall. - Reset navigation state whenever the input `history` prop changes for a different session. - Update `Chat` to derive session prompt history once from `initialMessages` for the active session and pass it into `Input` as `history`. - Include only `role === user` messages. - Exclude slash commands from history. - Do not persist or read any separate history file. - Intercept `Up`/`Down` in `Chat/Input` only when: - input is blank, or - the user is already navigating history. - Preserve existing behavior when not navigating history: - `Up`/`Down` continue to work for file suggestions and command menus. - Normal typing exits navigation mode and resumes ordinary editing from the recalled value. Public Interface Changes: - `Input` props gain `history: string[]`. Tests: - Add `Chat` coverage for deriving `history` from `initialMessages`, including excluding slash commands. - Add `Input` tests for: - recalling the most recent prompt with blank-input `Up` - stepping backward through multiple prompts with repeated `Up` - stepping forward with `Down` - returning to empty input at the end of forward navigation - not recording empty submissions - not recording slash commands - resetting navigation state when `history` changes for the new session - preserving existing file-suggestion `Up`/`Down` behavior when suggestions are visible Assumptions: - Source of truth for persisted recall is `~/.code-ollama/sessions/<sessionId>/messages.jsonl`, already loaded into `initialMessages`. - History derivation happens once per active session load; no repeated transcript scans during input editing. - Prompt history is prompt-only, not command history. - `/clear` creates a new session and therefore starts with empty history.
- Rename Input.tsx to ChatInput.tsx - Rename Input.test.tsx to ChatInput.test.tsx - Update component name from Input to ChatInput - Update all imports and references - Update mock in Chat.test.tsx
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?
Feature: add shell-like prompt history navigation to the chat input.
What is the current behavior?
Pressing
Up/Downin the chat input only controls file suggestions and command menus — there is no way to recall previously submitted prompts.What is the new behavior?
When the input is blank,
Uprecalls older submitted prompts andDownmoves forward toward newer prompts, ending at an empty draft. History is scoped to the current chat session, initialized from the session's persisted transcript on load, and maintained in memory for the rest of the mounted session.Implementation changes:
Chat/Inputto own prompt-history state, initialized from the active session's existing user prompts. Append newly submitted non-command user prompts; track a navigation index and empty-draft state soDownreturns to blank input. Reset navigation state when thehistoryprop changes (new session).Chatto derive session prompt history once frominitialMessages(roleuser, excluding slash commands) and pass it intoInputashistory.Up/DowninChat/Inputonly when input is blank or already navigating history; preserve existing behavior otherwise.Inputcomponent toChatInput.Public interface changes:
Inputprops gainhistory: string[].plan.md
Checklist: