-
Notifications
You must be signed in to change notification settings - Fork 289
feat: Add persistent chat history with directory isolation #2635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
298852a
to
26bce5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the intention of this PR, we do support persistent chat history per working directory already (try it q chat --resume
!).
If the intention is to store readline history, then it should be stored directly with the conversation state as part of the serialization process (see the conversations table under the database
module) instead of being handled separately.
crates/chat-cli/src/database/mod.rs
Outdated
@@ -62,6 +62,10 @@ const IDC_REGION_KEY: &str = "auth.idc.region"; | |||
const CUSTOMIZATION_STATE_KEY: &str = "api.selectedCustomization"; | |||
const PROFILE_MIGRATION_KEY: &str = "profile.Migrated"; | |||
|
|||
// Chat history limits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make any new SQLite tables or migrations for this without a very necessary reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
The SQLite database will enable many more powerful features so being very clear here will help future contributors.
@brandonskiser thank you for the review! I disagree with you. This feature should be included regardless of --resume. Customers should be able to access the prompt history without having to resume the context because context and prompt history are not the same. By coupling prompt history and context, you make prompt history less flexible. If a customer inputs a complex prompt, exits q, then restarts q, they should have access to their previous prompts without requiring resuming the previous context. Customers may want a fresh context while still having access to previous prompts. If customers want the previous context then they can use --resume. And with this PR they also have the added benefit of having access to the previous prompts. Your suggestion forces customers to resume the context to be able to have access to their previous prompts. Customers should not be forced to use --resume to have access to their previous prompts. There is no reason to have this limitation. |
If we want previous prompt history to be related to conversation and when using --resume (or /load) the readline is preloaded with chat history from that conversation first then that can be a secondary improvement but not a blocker for this PR. |
@brandonskiser My main point is this feature should work by default. I'm totally onboard with changing the behavior if the customer uses |
@jmmoser got it, that explanation makes a lot more sense now! In which case you should create a new migration for "chat_readline_history" table that includes a timestamp field (it's the array of migrations in that same database file you're updating). Then, we can create an index on cwd and timestamp, so we'd just delete all entries after the latest 100 entries per cwd whenever we insert a new entry. Shouldn't have any references to
Don't think this is necessary. For now let's just set it to 100.
Yes - let's just filter out "y/n/t" when saving the history entry.
I would say no |
21bb7c0
to
0b15d59
Compare
Implements persistent chat history that survives CLI restarts and is isolated by working directory. Features: - Chat history persists across CLI sessions using SQLite database - History is isolated per working directory (/project/a vs /project/b) - Up arrow navigation works with persistent history - Dual cleanup limits: max 100 entries per directory, 1000 total - Silent failure: history issues don't break CLI functionality - Filters out empty/whitespace-only and confirmation inputs Implementation: - Database table: chat_readline_history(input TEXT, cwd TEXT, timestamp INTEGER) with index on cwd and timestamp - Uses existing database infrastructure and Os abstraction - Transactional insert+cleanup for data consistency - Early return for empty inputs to avoid unnecessary DB operations Files modified: - crates/chat-cli/src/database/mod.rs: Added add_chat_readline_history_entry() and get_chat_readline_history() - crates/chat-cli/src/cli/chat/input_source.rs: Load history on startup, save on input Edge cases handled: - Database failures (silent) - Empty/whitespace and confirmation inputs (filtered) - Working directory access failures (fallback to default) - Unicode/special characters (parameterized queries)
@brandonskiser Updated based on your feedback! |
Issue #, if available:
#2633
Description of changes:
Implements persistent chat history that survives CLI restarts and is isolated by working directory.
Features:
Implementation:
Files modified:
Edge cases handled:
Interaction with other features:
--resume
. It enhances it./load
.Questions:
!ls
, be ignored?By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.