Skip to content

Commit 3e59ac4

Browse files
committed
fixup! 6ef1b77
1 parent 6ef1b77 commit 3e59ac4

File tree

11 files changed

+47
-47
lines changed

11 files changed

+47
-47
lines changed

src/git_draft/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import logging
44

5-
from .bots import Action, Bot, Goal, UserFeedback, WorkTree
5+
from .bots import Action, Bot, Goal, UserFeedback, Worktree
66

77

88
__all__ = [
99
"Action",
1010
"Bot",
1111
"Goal",
1212
"UserFeedback",
13-
"WorkTree",
13+
"Worktree",
1414
]
1515

1616
logging.getLogger(__name__).addHandler(logging.NullHandler())

src/git_draft/bots/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import sys
66

77
from ..common import BotConfig, reindent
8-
from .common import Action, Bot, Goal, UserFeedback, WorkTree
8+
from .common import Action, Bot, Goal, UserFeedback, Worktree
99

1010

1111
__all__ = [
1212
"Action",
1313
"Bot",
1414
"Goal",
1515
"UserFeedback",
16-
"WorkTree",
16+
"Worktree",
1717
]
1818

1919

src/git_draft/bots/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Goal:
1919
# TODO: Add timeout.
2020

2121

22-
class WorkTree(Protocol):
22+
class Worktree(Protocol):
2323
"""File operations
2424
2525
Implementations may not be thread-safe. Concurrent operations should be
@@ -111,7 +111,7 @@ def state_folder_path(cls, ensure_exists: bool = False) -> Path:
111111
return path
112112

113113
async def act(
114-
self, goal: Goal, tree: WorkTree, feedback: UserFeedback
114+
self, goal: Goal, tree: Worktree, feedback: UserFeedback
115115
) -> Action:
116116
"""Runs the bot, striving to achieve the goal"""
117117
raise NotImplementedError()

src/git_draft/bots/openai.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import openai
2222

2323
from ..common import JSONObject, UnreachableError, config_string, reindent
24-
from .common import Action, Bot, Goal, UserFeedback, WorkTree
24+
from .common import Action, Bot, Goal, UserFeedback, Worktree
2525

2626

2727
_logger = logging.getLogger(__name__)
@@ -173,7 +173,7 @@ def params(self) -> Sequence[openai.types.chat.ChatCompletionToolParam]:
173173

174174

175175
class _ToolHandler[V]:
176-
def __init__(self, tree: WorkTree) -> None:
176+
def __init__(self, tree: Worktree) -> None:
177177
self._tree = tree
178178
self.question: str | None = None
179179

@@ -235,7 +235,7 @@ def __init__(self, client: openai.OpenAI, model: str) -> None:
235235
self._model = model
236236

237237
async def act(
238-
self, goal: Goal, tree: WorkTree, _feedback: UserFeedback
238+
self, goal: Goal, tree: Worktree, _feedback: UserFeedback
239239
) -> Action:
240240
tools = _ToolsFactory(strict=False).params()
241241
tool_handler = _CompletionsToolHandler(tree)
@@ -321,7 +321,7 @@ def _load_assistant_id(self) -> str:
321321
return assistant_id
322322

323323
async def act(
324-
self, goal: Goal, tree: WorkTree, _feedback: UserFeedback
324+
self, goal: Goal, tree: Worktree, _feedback: UserFeedback
325325
) -> Action:
326326
assistant_id = self._load_assistant_id()
327327

@@ -346,7 +346,7 @@ async def act(
346346

347347
class _EventHandler(openai.AssistantEventHandler):
348348
def __init__(
349-
self, client: openai.Client, tree: WorkTree, action: Action
349+
self, client: openai.Client, tree: Worktree, action: Action
350350
) -> None:
351351
super().__init__()
352352
self._client = client
@@ -404,7 +404,7 @@ class _ToolOutput(TypedDict):
404404

405405

406406
class _ThreadToolHandler(_ToolHandler[_ToolOutput]):
407-
def __init__(self, tree: WorkTree, call_id: str) -> None:
407+
def __init__(self, tree: Worktree, call_id: str) -> None:
408408
super().__init__(tree)
409409
self._call_id = call_id
410410

src/git_draft/drafter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .prompt import TemplatedPrompt
2020
from .store import Store, sql
2121
from .user_feedbacks import BatchUserFeedback
22-
from .work_trees import GitWorkTree, WorkTreeHooks
22+
from .worktrees import GitWorktree, WorktreeHooks
2323

2424

2525
_logger = logging.getLogger(__name__)
@@ -115,7 +115,7 @@ async def generate_draft(
115115
with self._progress.spinner("Preparing prompt...") as spinner:
116116
# Handle prompt templating and editing. We do this first in case
117117
# this fails, to avoid creating unnecessary branches.
118-
tree, dirty = GitWorkTree.for_working_dir(self._repo)
118+
tree, dirty = GitWorktree.for_working_dir(self._repo)
119119
with spinner.hidden():
120120
prompt_contents = self._prepare_prompt(
121121
prompt,
@@ -333,7 +333,7 @@ def _prepare_prompt(
333333
self,
334334
prompt: str | TemplatedPrompt,
335335
prompt_transform: Callable[[str], str] | None,
336-
tree: GitWorkTree,
336+
tree: GitWorktree,
337337
) -> str:
338338
if isinstance(prompt, TemplatedPrompt):
339339
contents = prompt.render(tree)
@@ -349,7 +349,7 @@ async def _generate_change(
349349
self,
350350
bot: Bot,
351351
goal: Goal,
352-
tree: GitWorkTree,
352+
tree: GitWorktree,
353353
feedback: UserFeedback,
354354
) -> _Change:
355355
old_tree_sha = tree.sha()
@@ -433,7 +433,7 @@ class _Change:
433433
is_noop: bool
434434

435435

436-
class _OperationRecorder(WorkTreeHooks):
436+
class _OperationRecorder(WorktreeHooks):
437437
"""Visitor which keeps track of which operations have been performed
438438
439439
This is useful to store a summary of each change in our database for later

src/git_draft/prompt.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import docopt
1515
import jinja2
1616

17-
from .bots import WorkTree
17+
from .bots import Worktree
1818
from .common import Config, Table, package_root
19-
from .work_trees import EmptyWorkTree
19+
from .worktrees import EmptyWorktree
2020

2121

2222
_extension = "jinja"
@@ -37,8 +37,8 @@ def public(cls, name: PromptName, args: Sequence[str]) -> Self:
3737
_check_public_template_name(name)
3838
return cls(name, tuple(args))
3939

40-
def render(self, work_tree: WorkTree) -> str:
41-
prompt = _load_prompt(_jinja_environment(), self.name, work_tree)
40+
def render(self, worktree: Worktree) -> str:
41+
prompt = _load_prompt(_jinja_environment(), self.name, worktree)
4242
return prompt.render(self.args)
4343

4444

@@ -86,7 +86,7 @@ def _load_layouts() -> Mapping[str, str]:
8686
class _Context(TypedDict):
8787
prompt: Mapping[str, str]
8888
program: PromptName
89-
work_tree: WorkTree
89+
worktree: Worktree
9090

9191

9292
@dataclasses.dataclass(frozen=True)
@@ -182,13 +182,13 @@ def _template_path(template: jinja2.Template) -> Path:
182182

183183

184184
def _load_prompt(
185-
env: jinja2.Environment, name: PromptName, work_tree: WorkTree
185+
env: jinja2.Environment, name: PromptName, worktree: Worktree
186186
) -> _Prompt:
187187
rel_path = Path(f"{name}.{_extension}")
188188
assert env.loader, "No loader in environment"
189189
template = env.loader.load(env, str(rel_path))
190190
context: _Context = dict(
191-
program=name, prompt=_load_layouts(), work_tree=work_tree
191+
program=name, prompt=_load_layouts(), worktree=worktree
192192
)
193193
try:
194194
module = template.make_module(vars=cast(dict, context))
@@ -204,22 +204,22 @@ def _load_prompt(
204204

205205
def find_prompt_metadata(name: PromptName) -> PromptMetadata | None:
206206
try:
207-
prompt = _load_prompt(_jinja_environment(), name, EmptyWorkTree())
207+
prompt = _load_prompt(_jinja_environment(), name, EmptyWorktree())
208208
except jinja2.TemplateNotFound:
209209
return None
210210
return prompt.metadata
211211

212212

213213
def templates_table(*, include_local: bool = True) -> Table:
214214
env = _jinja_environment(include_local=include_local)
215-
work_tree = EmptyWorkTree()
215+
worktree = EmptyWorktree()
216216
table = Table.empty()
217217
table.data.field_names = ["name", "local", "description"]
218218
for rel_path in env.list_templates(extensions=[_extension]):
219219
if any(p.startswith(".") for p in rel_path.split(os.sep)):
220220
continue
221221
name, _ext = os.path.splitext(rel_path)
222-
prompt = _load_prompt(env, name, work_tree)
222+
prompt = _load_prompt(env, name, worktree)
223223
metadata = prompt.metadata
224224
local = "y" if metadata.is_local() else "n"
225225
table.data.add_row([name, local, metadata.description or ""])

src/git_draft/prompts/.MACROS.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% macro file_list() %}
2-
{% set paths = work_tree.list_files() %}
2+
{% set paths = worktree.list_files() %}
33
{% if paths %}
44
For reference, here is the list of all currently available files in the
55
repository:
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Work tree implementations"""
1+
"""Worktree implementations"""
22

33
from __future__ import annotations
44

@@ -11,15 +11,15 @@
1111
import tempfile
1212
from typing import Protocol, Self, override
1313

14-
from .bots import WorkTree
14+
from .bots import Worktree
1515
from .common import UnreachableError
1616
from .git import SHA, GitError, Repo, null_delimited
1717

1818

1919
_logger = logging.getLogger(__name__)
2020

2121

22-
class EmptyWorkTree(WorkTree):
22+
class EmptyWorktree(Worktree):
2323
"""No-op read-only work tree
2424
2525
This tree is used when gathering template metadata.
@@ -52,7 +52,7 @@ def edit_files(self) -> contextlib.AbstractContextManager[Path]:
5252
raise RuntimeError()
5353

5454

55-
class GitWorkTree(WorkTree):
55+
class GitWorktree(Worktree):
5656
"""Git-backed worktree implementation
5757
5858
All files are directly read from and written to a standalone tree. This
@@ -73,7 +73,7 @@ def __init__(
7373
self,
7474
repo: Repo,
7575
start_rev: SHA,
76-
hooks: WorkTreeHooks | None = None,
76+
hooks: WorktreeHooks | None = None,
7777
) -> None:
7878
call = repo.git("rev-parse", "--verify", f"{start_rev}^{{tree}}")
7979
self._sha = call.stdout
@@ -109,7 +109,7 @@ def ls_files(*args: str) -> Iterator[str]:
109109
worktree_path / path_str if worktree_path else Path(path_str),
110110
)
111111

112-
def with_hooks(self, hooks: WorkTreeHooks) -> Self:
112+
def with_hooks(self, hooks: WorktreeHooks) -> Self:
113113
return self.__class__(self._repo, self.sha(), hooks)
114114

115115
def sha(self) -> SHA:
@@ -118,7 +118,7 @@ def sha(self) -> SHA:
118118
updates.clear()
119119
return self._sha
120120

121-
def _dispatch(self, effect: Callable[[WorkTreeHooks], None]) -> None:
121+
def _dispatch(self, effect: Callable[[WorktreeHooks], None]) -> None:
122122
if hook := self._hooks:
123123
effect(hook)
124124

@@ -225,7 +225,7 @@ def _edit(self) -> Iterator[Path]:
225225
self._repo.git("worktree", "remove", "-f", path_str)
226226

227227

228-
class WorkTreeHooks(Protocol):
228+
class WorktreeHooks(Protocol):
229229
"""Tool usage hook"""
230230

231231
def on_list_files(

tests/git_draft/drafter_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from git_draft.bots import Action, Bot, Goal, UserFeedback, WorkTree
7+
from git_draft.bots import Action, Bot, Goal, UserFeedback, Worktree
88
from git_draft.common import Progress
99
import git_draft.drafter as sut
1010
from git_draft.git import SHA, GitError, Repo
@@ -30,7 +30,7 @@ def prompt(cls) -> Self:
3030
return cls({"PROMPT": lambda goal: goal.prompt})
3131

3232
async def act(
33-
self, goal: Goal, tree: WorkTree, _feedback: UserFeedback
33+
self, goal: Goal, tree: Worktree, _feedback: UserFeedback
3434
) -> Action:
3535
for key, value in self._contents.items():
3636
path = PurePosixPath(key)

tests/git_draft/prompt_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
import git_draft.prompt as sut
4-
from git_draft.work_trees import GitWorkTree
4+
from git_draft.worktrees import GitWorktree
55

66

77
class TestCheckPublicTemplateName:
@@ -18,7 +18,7 @@ def test_raises(self, name: str) -> None:
1818
class TestTemplatedPrompt:
1919
@pytest.fixture(autouse=True)
2020
def setup(self, repo) -> None:
21-
self._tree = GitWorkTree(repo, "HEAD")
21+
self._tree = GitWorktree(repo, "HEAD")
2222

2323
def test_ok(self) -> None:
2424
prompt = sut.TemplatedPrompt("add-test", ("--symbol=foo",))

0 commit comments

Comments
 (0)