Skip to content

Commit 452f9ea

Browse files
authored
feat: add initial OpenAI backend (#11)
1 parent ba30752 commit 452f9ea

File tree

15 files changed

+491
-252
lines changed

15 files changed

+491
-252
lines changed

.github/actions/setup/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ runs:
1919
- name: Lint
2020
shell: bash
2121
run: poetry run poe lint
22+
- name: Set up git config
23+
shell: bash
24+
run: |
25+
git config --global user.email [email protected]
26+
git config --global user.name tester

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# `git-draft(1)`
22

3-
WIP
3+
> [!NOTE]
4+
> WIP: Not quite functional yet.
5+
6+
## Highlights
7+
8+
* Concurrent editing. Continue editing while the assistant runs, without any
9+
risks of interference.

docs/git-draft.adoc

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ v{manversion}
1212

1313
git-draft - git-friendly code assistant
1414

15+
IMPORTANT: _git-draft_ is WIP.
16+
Options documented below may not be implemented yet.
17+
1518

1619
== Synopsis
1720

18-
*git-draft* _-C_
21+
*git-draft* _[--generate]_ _[--prompt PROMPT]_ _[--reset]_ _[TEMPLATE [...]]_
1922

20-
*git-draft* _-E_
23+
*git-draft* _--finalize_ _[--delete]_
2124

22-
*git-draft* _-A_
25+
*git-draft* _--discard_ _[--delete]_
2326

2427

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

2932
=== How it works
3033

31-
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.
32-
Additionally, any uncommitted changes are automatically committed (`draft! sync`).
3334

34-
Once the draft is created, we can use AI to edit our code using `git draft -E`.
35-
It expects the prompt as standard input, for example `echo "Add a test for compute_offset in chart.py" | git draft -E`.
36-
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.
37-
Once the response has been received and changes, applied a commit is created (`draft! prompt: a short summary of the change`).
35+
The workhorse command is `git draft --generate` which leverages AI to edit our code.
36+
A prompt can be specified as standard input, for example `echo "Add a test for compute_offset in chart.py" | git draft --generate`.
37+
If no prompt is specified and stdin is a TTY, `$EDITOR` will be opened to enter the prompt.
38+
39+
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.
40+
By default any unstaged changes are then automatically added and committed (`draft! sync`).
41+
This behavior can be disabled by passing in `--stash`, which will instead add them to the stash.
42+
Staged changes are always committed.
43+
44+
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.
45+
Once the response has been received and changes applied, a commit is created (`draft! prompt: a short summary of the change`).
3846

39-
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.
47+
The `--generate` step can be repeated as many times as needed.
48+
Once you are satisfied with the changes, run `git draft --finalize` to apply them.
4049
This will check out the branch used when creating the draft, adding the final state of the draft to the worktree.
4150
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.
4251

poetry.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ packages = [{include = 'git_draft', from = 'src'}]
1515
git-draft = 'git_draft.__main__:main'
1616

1717
[tool.poetry.dependencies]
18+
gitpython = '^3.1.44'
19+
openai = '^1.64.0'
1820
python = '>=3.12,<4'
1921

2022
[tool.poetry.group.dev.dependencies]
2123
black = '^25.1.0'
2224
flake8 = '^7.0.0'
2325
flake8-pyproject = '^1.2.3'
24-
gitpython = '^3.1.44'
2526
mypy = '^1.2.0'
26-
openai = '^1.64.0'
2727
poethepoet = '^0.25.0'
2828
pytest = '^7.1.2'
2929

src/git_draft/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from .actions import apply_draft, create_draft, extend_draft
1+
from .assistant import Assistant, OpenAIAssistant
2+
from .common import open_editor
3+
from .manager import Manager, enclosing_repo
24

35
__all__ = [
4-
"apply_draft",
5-
"create_draft",
6-
"extend_draft",
6+
"Assistant",
7+
"OpenAIAssistant",
8+
"Manager",
9+
"enclosing_repo",
10+
"open_editor",
711
]

0 commit comments

Comments
 (0)