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: started working on auto-commit #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions gptme/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from .util import console, path_with_tilde, print_bell
from .util.ask_execute import ask_execute
from .util.context import run_precommit_checks, use_fresh_context
from .util.context import autocommit, run_precommit_checks, use_fresh_context
from .util.cost import log_costs
from .util.interrupt import clear_interruptible, set_interruptible
from .util.prompt import add_history, get_input
Expand Down Expand Up @@ -243,9 +243,13 @@ def step(
)
):
# Only check for modifications if the last assistant message has no runnable tools
if check_for_modifications(log) and (failed_check_message := check_changes()):
yield Message("system", failed_check_message, quiet=False)
return
if check_for_modifications(log):
if failed_check_message := check_changes():
yield Message("system", failed_check_message, quiet=False)
return
if get_config().get_env("GPTME_AUTOCOMMIT") in ["true", "1"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

The GPTME_AUTOCOMMIT check is case-sensitive. Consider normalizing (e.g., lowercasing) the env value to avoid misconfiguration.

Suggested change
if get_config().get_env("GPTME_AUTOCOMMIT") in ["true", "1"]:
if get_config().get_env("GPTME_AUTOCOMMIT").lower() in ["true", "1"]:

yield autocommit()
return

# If last message was a response, ask for input.
# If last message was from the user (such as from crash/edited log),
Expand Down
12 changes: 12 additions & 0 deletions gptme/util/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def use_checks() -> bool:
def file_to_display_path(f: Path, workspace: Path | None = None) -> Path:
"""
Determine how to display the path:

- If file and pwd is in workspace, show path relative to pwd
- Otherwise, show absolute path
"""
Expand Down Expand Up @@ -334,6 +335,17 @@ def run_precommit_checks() -> str | None:
)


def autocommit() -> Message:
"""
Auto-commit staged changes.
"""
# TODO: auto-stage files modified by gptme
# TODO: add a review step?
# TODO: generate commit message from diff + conversation history
# TODO: enable with GPTME_AUTOCOMMIT=true
return Message("system", "Auto-commit not implemented yet")


def enrich_messages_with_context(
msgs: list[Message], workspace: Path | None = None
) -> list[Message]:
Expand Down