-
-
Notifications
You must be signed in to change notification settings - Fork 207
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
feat(util): added gptme-util prompts workspace/git/journal
helper commands
#271
base: master
Are you sure you want to change the base?
Conversation
❌ 1 Tests Failed:
View the top 1 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
b47f874
to
dd2a128
Compare
gptme-util prompts git
helper commandgptme-util prompts workspace/git/journal
helper commands
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.
👍 Looks good to me! Reviewed everything up to dd2a128 in 1 minute and 24 seconds
More details
- Looked at
451
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
3
drafted comments based on config settings.
1. gptme/util/cli.py:38
- Draft comment:
logger
is used here but is defined later in the file. Move the logger definition above this line to avoid potentialNameError
. - Reason this comment was not posted:
Comment looked like it was already resolved.
2. gptme/util/cli.py:41
- Draft comment:
capture_output=True
is only available in Python 3.7+. If supporting older versions, usestdout=subprocess.PIPE, stderr=subprocess.PIPE
instead. - Reason this comment was not posted:
Confidence changes required:50%
Therun_git
function ingptme/util/cli.py
usescapture_output=True
which is only available in Python 3.7 and later. If the project supports older versions, this should be changed tostdout=subprocess.PIPE, stderr=subprocess.PIPE
.
3. gptme/util/cli.py:197
- Draft comment:
Consider usingclick.echo
instead ofprint
for better consistency with Click's output handling. - Reason this comment was not posted:
Confidence changes required:50%
Theprompts_git
function ingptme/util/cli.py
usesprint
for output, which might not be ideal for a CLI tool. Usingclick.echo
would be more consistent with the rest of the Click-based CLI.
Workflow ID: wflow_DzH7rxyXWXe2nEkm
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
gptme/util/cli.py
Outdated
# Common journal locations to try | ||
locations = [ | ||
path, # User-specified path first | ||
os.path.expanduser("~/journal"), | ||
os.path.expanduser("~/Documents/journal"), | ||
os.path.expanduser("~/notes"), | ||
os.path.expanduser("~/Documents/notes"), | ||
] |
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.
Should check <git root>/journal
gptme/util/cli.py
Outdated
for file in files: | ||
with open(file) as f: | ||
content = f.read() | ||
entries.append(f"\n# {date}\n{content}") |
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.
entries.append(f"\n# {date}\n{content}") | |
entries.append(f"```{file}\n{content}\n```") |
gptme/util/cli.py
Outdated
@main.group() | ||
def prompts(): | ||
"""Commands for generating prompts/contexts.""" | ||
pass |
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.
Reuse the context
group
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.
👍 Looks good to me! Incremental review on 21b3982 in 21 seconds
More details
- Looked at
897
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. gptme/util/cli_context.py:175
- Draft comment:
Thecodeblock
function is used here but is not defined in this context. This will result in a NameError. Ensure thatcodeblock
is defined or imported before use. - Reason this comment was not posted:
Comment did not seem useful.
2. gptme/util/cli_context.py:182
- Draft comment:
Thecodeblock
function is used here but is not defined in this context. This will result in a NameError. Ensure thatcodeblock
is defined or imported before use. - Reason this comment was not posted:
Marked as duplicate.
Workflow ID: wflow_rpn38I60OcMkv1Ms
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
|
||
result = [f"\n### {title}"] | ||
|
||
for item in items: | ||
item_prefix = "- " | ||
result.append(f"{item_prefix}{item}") | ||
return result | ||
|
||
# Check if we're in a git repo | ||
logger.debug("Checking if in git repo...") | ||
output, success = _git(["rev-parse", "--git-dir"]) | ||
logger.debug(f"Git repo check result: {success=}, {output=}") | ||
if not success: | ||
logger.error("Not a git repository") | ||
return | ||
|
||
sections = [] | ||
|
||
# Basic repo info | ||
remote_url, success = _git(["config", "--get", "remote.origin.url"]) | ||
if success and remote_url: | ||
sections.extend([f"Repository: {remote_url}"]) | ||
|
||
# Get current branch | ||
branch_name, success = _git(["rev-parse", "--abbrev-ref", "HEAD"]) | ||
if success: | ||
if branch_name == "HEAD": | ||
# We're in detached HEAD state | ||
commit_hash, _ = _git(["rev-parse", "--short", "HEAD"]) | ||
sections.append(f"HEAD is detached at {commit_hash}") | ||
branch_name = "" | ||
else: | ||
sections.append(f"Current branch: {branch_name}") | ||
|
||
# Recent commits | ||
log_format = "--pretty=format:%h (%ad) %s" | ||
commits_output, success = _git( | ||
[ | ||
"log", | ||
log_format, | ||
"--date=format:%Y-%m-%d %H:%M", | ||
"-n", | ||
"5", | ||
branch or branch_name or "HEAD", | ||
] | ||
) | ||
if success and commits_output: | ||
commit_items = commits_output.split("\n") | ||
sections.extend(format_section("Recent commits", commit_items)) | ||
|
||
# Staged files | ||
staged_files, success = _git(["diff", "--name-only", "--cached"]) | ||
if success and staged_files: | ||
files = staged_files.split("\n") | ||
if files and files[0]: | ||
shown_files = files[:max_files] | ||
sections.extend(format_section("Staged files", shown_files)) | ||
if len(files) > max_files: | ||
sections.append(f"... and {len(files) - max_files} more staged files") | ||
|
||
# Changed files | ||
changed_files, success = _git(["diff", "--name-only"]) | ||
|
||
if success and changed_files: | ||
files = changed_files.split("\n") | ||
if files and files[0]: | ||
shown_files = files[:max_files] | ||
sections.extend(format_section("Changed files (unstaged)", shown_files)) | ||
if len(files) > max_files: | ||
sections.append(f"... and {len(files) - max_files} more changed files") | ||
|
||
# Untracked files | ||
untracked_files, success = _git(["ls-files", "--others", "--exclude-standard"]) | ||
if success and untracked_files: | ||
files = untracked_files.split("\n") | ||
if files and files[0]: | ||
shown_files = files[:max_files] | ||
sections.extend(format_section("Untracked files", shown_files)) | ||
if len(files) > max_files: | ||
sections.append( | ||
f"... and {len(files) - max_files} more untracked files" | ||
) | ||
|
||
# Add diffs if requested | ||
if show_diff: | ||
# Add staged changes | ||
staged_diff, success = _git(["diff", "--cached"]) | ||
if success and staged_diff: | ||
sections.extend( | ||
["\n### Staged changes", f"\n{codeblock("diff", staged_diff)}"] | ||
) | ||
|
||
# Add unstaged changes | ||
unstaged_diff, success = _git(["diff"]) | ||
if success and unstaged_diff: | ||
sections.extend( | ||
["\n### Unstaged changes", f"\n{codeblock("diff", unstaged_diff)}"] | ||
) | ||
|
||
print("\n".join(sections)) |
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.
This should just be git status -vv
The idea is to move the helper scripts for prompt generation in gptme-bob into gptme.
Important
Adds new CLI commands to
gptme
for generating git, workspace, and journal prompts, enhancing context generation capabilities.prompts git
command ingptme/util/cli.py
for generating git repository summaries with options like--branch
,--since
,--max-files
, and--show-diff
.prompts workspace
command ingptme/util/cli_context.py
to display directory structure as a tree, respecting.gitignore
.prompts journal
command ingptme/util/cli_context.py
to generate prompts from journal entries.context_git()
incli_context.py
gathers git status, diffs, and recent commits.context_workspace()
incli_context.py
shows directory structure and file statistics.context_journal()
incli_context.py
retrieves journal entries from specified directories.get_workspace_prompt()
ingptme/prompts.py
to include references toprompts_git
andprompts_workspace
.This description was created by for 21b3982. It will automatically update as commits are pushed.