Commit 42d4d0a
committed
feat(Chat): add blank-input prompt history navigation
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.1 parent 22fde11 commit 42d4d0a
4 files changed
Lines changed: 289 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
| 108 | + | |
| 109 | + | |
105 | 110 | | |
106 | 111 | | |
107 | 112 | | |
| |||
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
219 | 246 | | |
220 | 247 | | |
221 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | 49 | | |
43 | 50 | | |
| |||
586 | 593 | | |
587 | 594 | | |
588 | 595 | | |
| 596 | + | |
589 | 597 | | |
590 | 598 | | |
591 | 599 | | |
| |||
0 commit comments