8000 feat: add history by shlomomdahan · Pull Request #17 · dtnewman/zev · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add history #17

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

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

shlomomdahan
Copy link
@shlomomdahan shlomomdahan commented Apr 25, 2025

Command History

  • Add History class to handle saving and retrieving command history.
  • App now supports -p and --past commands to display history
  • Defaults to showing the last 5 commands with a "show more" option.

Argument Handling

  • Added support for -h and --help flags to display help documentation.
  • Implemented argument validation for no_prompt() to also check for args.

- Add ability to recall and reuse previous command options
- Implement get_last_options and save_last_options functions
- Add 'last' keyword support in show_options
@dtnewman
Copy link
Owner

hey there. I have been thinking about how to implement something like this. Unfortunately, this doesn't feel like the right implementation to me (I freely admit that it's a personal preference). My goal is to maintain simplicity and ease of use, and add as few commands as possible (i think that --setup is unavoidable).

I have to think about this a bit more. What i really want are two things:

  1. go back to last commands
  2. add the ability to increment on a prior command. In other words, tell the model that something isn't right and keep searching.

I'll have to think about this more. Not saying your implementation isn't good, just that it adds an additional keyword for people to remember. I have to ponder it over some more :)

src/zev/utils.py Outdated
def save_last_options(commands: list[Command]):
app_data_dir = platformdirs.user_data_dir("zev")
os.makedirs(app_data_dir, exist_ok=True)
last_options_file = os.path.join(app_data_dir, "last_options.json")
Copy link
Owner

Choose a reason for hiding this comment

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

see my overarching comment on PR before doing anything here, but i think that if we do go this route, a jsonl file would be more appropriate

Copy link
Owner

Choose a reason for hiding this comment

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

to clarify, jsonl, because i think it's better to keep last few searches (maybe default 100) around

src/zev/main.py Outdated
import sys

from zev.config.setup import run_setup
from zev.constants import OPENAI_BASE_URL, OPENAI_DEFAULT_MODEL, CONFIG_FILE_NAME
from zev.constants import OPENAI_BASE_URL, OPENAI_DEFAULT_MODEL, CONFIG_FILE_NAME, EDIT_PROMPT
Copy link
Owner
8000

Choose a reason for hiding this comment

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

i don't see any changes to zev.constants (where is EDIT_PROMPT coming from?)

Copy link
Author

Choose a reason for hiding this comment

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

sorry - accidentally left this when deleting the edit prompt feat.

@shlomomdahan
Copy link
Author

Hey @dtnewman, thanks for reviewing the PR.

I think it would be best to split the below features into separate PRs, so I'll keep this one for commands history.

  1. go back to last commands
  2. add the ability to increment on a prior command. In other words, tell the model that something isn't right and keep searching.

I see how introducing a last argument goes against the simplicity of the tool. I was considering including history by default in run_no_prompt() but that would introduce an extra step when prompting, which doesn't seem right either.

Happy to hear your thoughts if you think there's a cleaner way to approach it.

@dtnewman
Copy link
Owner

i've given this some thought. My general take is that i want the vast majority of users to be able to use this by just typing zev. It should be stupid simple.

My concern here is that users won't even know that zev last is an option.

I think the solution is to do what Ollama does here:

image

The add a little filler message with (/? for help). I think zev should have the same thing. When you run /? it can give you a list of commands. Right now, the only options would be version, setup and last.

Another thought: when i run zev last it doesn't just take me to the last command. It gives me a list of the last 10 or so commands and i can move up and down the list with arrows.

Thoughts?

p.s. re: splitting into two PRs, 1 for last commands, 1 for incrementing, i think that's reasonable

…avigating history, move version to constants
@shlomomdahan
Copy link
Author

I completely agree about keeping it extremely simple.

Regarding the /? command - this is not ideal as its a windows convention which would break cross functionality as it would need to be escaped in unix. I think it would be better to stick to -h and --help.

below is a demo of the changes so far.

demo.mp4

@dtnewman
Copy link
Owner

+1000 for including a video

I'll take a look in a bit (possibly tomorrow)

class History:
def __init__(self, max_entries: int = 100):
self.history_dir = Path.home() / ".zev"
self.history_file = self.history_dir / "zev_history.jsonl"
Copy link
Owner

Choose a reason for hiding this comment

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

i think i would just call the file .zevhistory (it can still _contain JSONL, just not be called zev_history.jsonl) rather than creating a new directory for zev

dangerous_explanation=cmd_dict.get("dangerous_explanation")
)

def get_history(self) -> Optional[dict[str, OptionsResponse]]:
Copy link
Owner

Choose a reason for hiding this comment

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

this is so complicated. Why not just read the file in its entirety and return a list?

src/zev/main.py Outdated

history_items = list(response_history.keys())

while True:
Copy link
Owner

Choose a reason for hiding this comment

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

i don't like a while true. Doesn't feel right.

src/zev/main.py Outdated

selected = cli.display_command_options(response_history[selected_query].commands, f"Commands for '{selected_query}'", history=True)

if selected == "_back":
Copy link
Owner

Choose a reason for hiding this comment

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

no need for a back option. Keep it as simple as possible for now. Worst case, user will just rerun the history command.

src/zev/main.py Outdated
print(f"zev version: {VERSION}")
return True

if command in ("--last", "-l"):
Copy link
Owner

Choose a reason for hiding this comment

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

i prefer --history and -h, but help is already taken. What about --past 67E6 and -p?

@@ -0,0 +1,121 @@
import questionary
Copy link
Owner

Choose a reason for hiding this comment

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

too much reorganization. For a first-time PR, keep the file structure intact. Don't worry about main.py getting too long. We can tackle that down the road.

@shlomomdahan F438 shlomomdahan force-pushed the feat/last-command-history branch from 347f641 to 91e47c4 Compare April 30, 2025 15:38
src/zev/main.py Outdated
@@ -9,7 +9,8 @@
from zev.config.setup import run_setup
from zev.constants import CONFIG_FILE_NAME
from zev.llms.llm import get_inference_provider
from zev.utils import get_env_context, get_input_string
from zev.utils import get_env_context, show_help, get_input_string
from zev.history.history import history
Copy link
Owner

Choose a reason for hiding this comment

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

oof... this is a bit much. i think that this kind of tells me that history.py should just be a file at the root level.

@shlomomdahan shlomomdahan changed the title feat: add last command history functionality feat: add history May 1, 2025
src/zev/main.py Outdated
f"[red]Could not copy to clipboard: {e} (the clipboard may not work at all if you are running over SSH)[/red]"
)
rprint("[cyan]Here is your command:[/cyan]")
print(selected.command)
Copy link
Owner

Choose a reason for hiding this comment

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

why not put all of this history related stuff inside of the History class?

Copy link
Author

Choose a reason for hiding this comment

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

This ma BC74 kes sense. Do you think its worth considering a UI class in the future to handle all the console logic like displaying the options, handling user input, copying, etc.?
It feels like bad practice for this History class to have to worry about the questionary logic.

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.

2 participants
0