Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ runs:
- name: Lint
shell: bash
run: poetry run poe lint
- name: Set up git config
shell: bash
run: |
git config --global user.email [email protected]
git config --global user.name tester
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# `git-draft(1)`

WIP
> [!NOTE]
> WIP: Not quite functional yet.

## Highlights

* Concurrent editing. Continue editing while the assistant runs, without any
risks of interference.
29 changes: 19 additions & 10 deletions docs/git-draft.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ v{manversion}

git-draft - git-friendly code assistant

IMPORTANT: _git-draft_ is WIP.
Options documented below may not be implemented yet.


== Synopsis

*git-draft* _-C_
*git-draft* _[--generate]_ _[--prompt PROMPT]_ _[--reset]_ _[TEMPLATE [...]]_

*git-draft* _-E_
*git-draft* _--finalize_ _[--delete]_

*git-draft* _-A_
*git-draft* _--discard_ _[--delete]_


== Description
Expand All @@ -28,15 +31,21 @@ _git-draft_ is a git-centric way to edit code using AI.

=== How it works

When you create a new draft with `git draft -C $name`, a new branch called `$branch/drafts/$name-$hash` is created (`$hash` is a random suffix used to guarantee uniqueness of branch names) and checked out.
Additionally, any uncommitted changes are automatically committed (`draft! sync`).

Once the draft is created, we can use AI to edit our code using `git draft -E`.
It expects the prompt as standard input, for example `echo "Add a test for compute_offset in chart.py" | git draft -E`.
The prompt will automatically get augmented with information about the files in the repository, and give the AI access to tools for reading and writing files.
Once the response has been received and changes, applied a commit is created (`draft! prompt: a short summary of the change`).
The workhorse command is `git draft --generate` which leverages AI to edit our code.
A prompt can be specified as standard input, for example `echo "Add a test for compute_offset in chart.py" | git draft --generate`.
If no prompt is specified and stdin is a TTY, `$EDITOR` will be opened to enter the prompt.

If not on a draft branch, a new draft branch called `drafts/$parent/$hash` will be created (`$hash` is a random suffix used to guarantee uniqueness of branch names) and checked out.
By default any unstaged changes are then automatically added and committed (`draft! sync`).
This behavior can be disabled by passing in `--stash`, which will instead add them to the stash.
Staged changes are always committed.

The prompt automatically gets augmented with information about the files in the repository, and give the AI access to tools for reading and writing files.
Once the response has been received and changes applied, a commit is created (`draft! prompt: a short summary of the change`).

The prompt step can be repeated as many times as needed. Once you are satisfied with the changes, run `git draft -A` to apply them.
The `--generate` step can be repeated as many times as needed.
Once you are satisfied with the changes, run `git draft --finalize` to apply them.
This will check out the branch used when creating the draft, adding the final state of the draft to the worktree.
Note that you can come back to an existing draft anytime (by checking its branch out), but you will not be able to apply it if its origin branch has moved since the draft was created.

Expand Down
42 changes: 21 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ packages = [{include = 'git_draft', from = 'src'}]
git-draft = 'git_draft.__main__:main'

[tool.poetry.dependencies]
gitpython = '^3.1.44'
openai = '^1.64.0'
python = '>=3.12,<4'

[tool.poetry.group.dev.dependencies]
black = '^25.1.0'
flake8 = '^7.0.0'
flake8-pyproject = '^1.2.3'
gitpython = '^3.1.44'
mypy = '^1.2.0'
openai = '^1.64.0'
poethepoet = '^0.25.0'
pytest = '^7.1.2'

Expand Down
12 changes: 8 additions & 4 deletions src/git_draft/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from .actions import apply_draft, create_draft, extend_draft
from .assistant import Assistant, OpenAIAssistant
from .common import open_editor
from .manager import Manager, enclosing_repo

__all__ = [
"apply_draft",
"create_draft",
"extend_draft",
"Assistant",
"OpenAIAssistant",
"Manager",
"enclosing_repo",
"open_editor",
]
Loading