Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ErikBjare
Copy link
Owner

@ErikBjare ErikBjare commented Nov 23, 2024

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.

  • New CLI Commands:
    • Adds prompts git command in gptme/util/cli.py for generating git repository summaries with options like --branch, --since, --max-files, and --show-diff.
    • Adds prompts workspace command in gptme/util/cli_context.py to display directory structure as a tree, respecting .gitignore.
    • Adds prompts journal command in gptme/util/cli_context.py to generate prompts from journal entries.
  • Functionality:
    • context_git() in cli_context.py gathers git status, diffs, and recent commits.
    • context_workspace() in cli_context.py shows directory structure and file statistics.
    • context_journal() in cli_context.py retrieves journal entries from specified directories.
  • Integration:
    • Updates get_workspace_prompt() in gptme/prompts.py to include references to prompts_git and prompts_workspace.

This description was created by Ellipsis for 21b3982. It will automatically update as commits are pushed.

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
86 1 85 0
View the top 1 failed tests by shortest run time
::tests.test_util_cli
Stack Traces | 0s run time
No failure message available

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

@ErikBjare ErikBjare force-pushed the dev/gptme-util-prompts branch from b47f874 to dd2a128 Compare November 24, 2024 14:52
@ErikBjare ErikBjare marked this pull request as ready for review November 24, 2024 14:52
@ErikBjare ErikBjare changed the title feat(util): added a gptme-util prompts git helper command feat(util): added gptme-util prompts workspace/git/journal helper commands Nov 24, 2024
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a 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 in 2 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 potential NameError.
  • 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, use stdout=subprocess.PIPE, stderr=subprocess.PIPE instead.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The run_git function in gptme/util/cli.py uses capture_output=True which is only available in Python 3.7 and later. If the project supports older versions, this should be changed to stdout=subprocess.PIPE, stderr=subprocess.PIPE.
3. gptme/util/cli.py:197
  • Draft comment:
    Consider using click.echo instead of print for better consistency with Click's output handling.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The prompts_git function in gptme/util/cli.py uses print for output, which might not be ideal for a CLI tool. Using click.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.

Comment on lines 308 to 315
# 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"),
]
Copy link
Owner Author

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

for file in files:
with open(file) as f:
content = f.read()
entries.append(f"\n# {date}\n{content}")
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
entries.append(f"\n# {date}\n{content}")
entries.append(f"```{file}\n{content}\n```")

Comment on lines 171 to 174
@main.group()
def prompts():
"""Commands for generating prompts/contexts."""
pass
Copy link
Owner Author

Choose a reason for hiding this comment

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

Reuse the context group

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a 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 in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/util/cli_context.py:175
  • Draft comment:
    The codeblock function is used here but is not defined in this context. This will result in a NameError. Ensure that codeblock 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:
    The codeblock function is used here but is not defined in this context. This will result in a NameError. Ensure that codeblock 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.

Comment on lines +61 to +185

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))
Copy link
Owner Author

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

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