Skip to content

Add in-session cancelled command and agent prompt history managers#313

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/add-history-managers-for-agent-mode
Draft

Add in-session cancelled command and agent prompt history managers#313
Copilot wants to merge 3 commits intomasterfrom
copilot/add-history-managers-for-agent-mode

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

Users had no way to recall commands they Ctrl+C'd or prompts previously sent to agent mode within a session.

New behavior

  • Ctrl+C on non-empty buffer — saves buffer to cancelled_command_history before exiting (existing exit behavior preserved)
  • Ctrl+C on empty buffer — opens a fuzzy picker for cancelled commands (same UX as Ctrl+R) if cancelled history exists
  • Shift+Enter on empty buffer (AI configured, agent history exists) — opens a fuzzy picker for agent prompts instead of immediately launching AI mode
  • start_ai_mode() — pushes current buffer to agent_prompt_history before spawning the AI subprocess

Implementation

src/history.rs

Added HistoryManager::empty() constructor to create lightweight in-session-only managers (no file I/O; entries are lost on session exit). Also added push() and is_empty() methods to HistoryManager.

src/app/mod.rs

  • Added FuzzyHistorySource enum (BashHistory, CancelledCommands, AgentPrompts) with a label() helper
  • Extended ContentMode::FuzzyHistorySearch to carry a FuzzyHistorySource, replacing the need for separate mode variants — a single content mode handles all three history managers
  • Added cancelled_command_history and agent_prompt_history fields on App (typed as HistoryManager, initialized with HistoryManager::empty())
  • Added ContentMode::fuzzy_source() and App::history_manager_for(source) helpers to eliminate repeated dispatch matches across key handlers, mouse handlers, and the accept method
  • Full key handling (Up/Down/PageUp/PageDown/Enter/Shift+Enter/Tab/Esc) and mouse hover/click via the unified mode
  • Extracted the fuzzy history rendering block into a render_fuzzy_history_results() free function shared by all three history sources; moved ts_to_timeago_string_5chars() to module level accordingly
Original prompt

This section details on the original issue you should resolve

<issue_title>ctrl+c, agent mode history buffers</issue_title>
<issue_description>I often want to go back to the previous prompt I used for agent mode and previous command I ctrl+c'ed.
We could store them for the current session.
Then when you press ctrl+c on an emtpy line or shift enter on an empty, it will act like ctrl+r but for the other history buffers.

You will need to create two other history managers: cancelled _command_history_manager and agent_prompt_history_manager.
Store them in the settings struct.

The app will push new entries to them.
</issue_description>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

- Add SessionHistoryManager struct to history.rs for in-session, transient
  history (no file I/O). Supports push(), is_empty(), and the full
  fuzzy-search API (shared FuzzyHistorySearch internals).

- Add FuzzyCancelledCommandSearch and FuzzyAgentPromptSearch ContentMode variants.

- Add cancelled_command_history and agent_prompt_history fields to App.

- Ctrl+C on non-empty buffer now saves the buffer to cancelled_command_history
  before exiting. Ctrl+C on an empty buffer (with saved history) opens the
  FuzzyCancelledCommandSearch fuzzy picker instead of exiting.

- Shift+Enter on an empty buffer (when AI is configured and agent history
  exists) opens FuzzyAgentPromptSearch instead of starting AI mode immediately.

- start_ai_mode() records the prompt in agent_prompt_history before launching.

- Full keyboard navigation (Up/Down/PageUp/PageDown/Enter/Shift+Enter/Tab/Esc)
  and mouse hover/click support for both new modes.

- Extract fuzzy history rendering into a shared render_fuzzy_history_results()
  free function; move ts_to_timeago_string_5chars() to module level.

- Add 3 new unit tests for SessionHistoryManager.

Co-authored-by: HalFrgrd <4559349+HalFrgrd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/HalFrgrd/flyline/sessions/7117513e-e128-4df3-8422-63d00f4d2ae9
Copilot AI changed the title [WIP] Add history managers for agent mode buffers Add in-session cancelled command and agent prompt history managers Mar 20, 2026
Copilot AI requested a review from HalFrgrd March 20, 2026 18:31
Copy link
Copy Markdown
Owner

@HalFrgrd HalFrgrd left a comment

Choose a reason for hiding this comment

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

I only want one content mode to handle all three different history managers. Figure out the best way to make this happen. This will make the code change small

Don't create a new history session manager class. Reuse the current history manager. Give it a constructor called empty to generate empty ones.

…uctor

Per reviewer feedback:
- Remove SessionHistoryManager; add HistoryManager::empty(), push(), is_empty()
  so the same struct handles both file-backed and in-session-only history
- Collapse FuzzyHistorySearch / FuzzyCancelledCommandSearch / FuzzyAgentPromptSearch
  into a single ContentMode::FuzzyHistorySearch(FuzzyHistorySource) variant
- Add FuzzyHistorySource enum (BashHistory / CancelledCommands / AgentPrompts)
  with a label() helper
- Add ContentMode::fuzzy_source() and App::history_manager_for() helpers to
  eliminate repeated dispatch matches across key handlers, mouse handlers, and
  the accept method

Co-authored-by: HalFrgrd <4559349+HalFrgrd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/HalFrgrd/flyline/sessions/2e957992-e36d-4fae-bf62-c94fe26462ef
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 24, 2026

I only want one content mode to handle all three different history managers. Figure out the best way to make this happen. This will make the code change small

Don't create a new history session mana...

Done in fd83cbc.

  • SessionHistoryManager is gone — HistoryManager::empty() creates a lightweight in-session manager using the same struct (plus new push() and is_empty() methods).
  • The three content mode variants are now one: ContentMode::FuzzyHistorySearch(FuzzyHistorySource) where FuzzyHistorySource is a Copy enum (BashHistory, CancelledCommands, AgentPrompts) with a label() helper.
  • Added ContentMode::fuzzy_source() and App::history_manager_for(source) helpers to remove the repeated dispatch patterns from key handlers, mouse handlers, and the accept method.

Copilot AI requested a review from HalFrgrd March 24, 2026 21:52
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.

ctrl+c, agent mode history buffers

2 participants