@@ -36,58 +36,41 @@ class Toolbox:
3636 # feedback more than once during a bot action, which leads to a better
3737 # experience when used interactively.
3838
39- # TODO: Remove all reason arguments. They are not currently used, and there
40- # is no obvious use-case at the moment.
41-
4239 def __init__ (self , visitors : Sequence [ToolVisitor ] | None = None ) -> None :
4340 self ._visitors = visitors or []
4441
4542 def _dispatch (self , effect : Callable [[ToolVisitor ], None ]) -> None :
4643 for visitor in self ._visitors :
4744 effect (visitor )
4845
49- def list_files (self , reason : str | None = None ) -> Sequence [PurePosixPath ]:
46+ def list_files (self ) -> Sequence [PurePosixPath ]:
5047 paths = self ._list ()
51- self ._dispatch (lambda v : v .on_list_files (paths , reason ))
48+ self ._dispatch (lambda v : v .on_list_files (paths ))
5249 return paths
5350
54- def read_file (
55- self ,
56- path : PurePosixPath ,
57- reason : str | None = None ,
58- ) -> str | None :
51+ def read_file (self , path : PurePosixPath ) -> str | None :
5952 try :
6053 contents = self ._read (path )
6154 except FileNotFoundError :
6255 contents = None
63- self ._dispatch (lambda v : v .on_read_file (path , contents , reason ))
56+ self ._dispatch (lambda v : v .on_read_file (path , contents ))
6457 return contents
6558
66- def write_file (
67- self ,
68- path : PurePosixPath ,
69- contents : str ,
70- reason : str | None = None ,
71- ) -> None :
72- self ._dispatch (lambda v : v .on_write_file (path , contents , reason ))
59+ def write_file (self , path : PurePosixPath , contents : str ) -> None :
60+ self ._dispatch (lambda v : v .on_write_file (path , contents ))
7361 return self ._write (path , contents )
7462
75- def delete_file (
76- self ,
77- path : PurePosixPath ,
78- reason : str | None = None ,
79- ) -> None :
80- self ._dispatch (lambda v : v .on_delete_file (path , reason ))
63+ def delete_file (self , path : PurePosixPath ) -> None :
64+ self ._dispatch (lambda v : v .on_delete_file (path ))
8165 self ._delete (path )
8266
8367 def rename_file (
8468 self ,
8569 src_path : PurePosixPath ,
8670 dst_path : PurePosixPath ,
87- reason : str | None = None ,
8871 ) -> None :
8972 """Rename a single file"""
90- self ._dispatch (lambda v : v .on_rename_file (src_path , dst_path , reason ))
73+ self ._dispatch (lambda v : v .on_rename_file (src_path , dst_path ))
9174 self ._rename (src_path , dst_path )
9275
9376 def expose_files (
@@ -134,26 +117,25 @@ class ToolVisitor(Protocol):
134117 """Tool usage hook"""
135118
136119 def on_list_files (
137- self , paths : Sequence [PurePosixPath ], reason : str | None
120+ self , paths : Sequence [PurePosixPath ]
138121 ) -> None : ... # pragma: no cover
139122
140123 def on_read_file (
141- self , path : PurePosixPath , contents : str | None , reason : str | None
124+ self , path : PurePosixPath , contents : str | None
142125 ) -> None : ... # pragma: no cover
143126
144127 def on_write_file (
145- self , path : PurePosixPath , contents : str , reason : str | None
128+ self , path : PurePosixPath , contents : str
146129 ) -> None : ... # pragma: no cover
147130
148131 def on_delete_file (
149- self , path : PurePosixPath , reason : str | None
132+ self , path : PurePosixPath
150133 ) -> None : ... # pragma: no cover
151134
152135 def on_rename_file (
153136 self ,
154137 src_path : PurePosixPath ,
155138 dst_path : PurePosixPath ,
156- reason : str | None ,
157139 ) -> None : ... # pragma: no cover
158140
159141 def on_expose_files (self ) -> None : ... # pragma: no cover
@@ -266,24 +248,6 @@ def _write(self, path: PurePosixPath, contents: str) -> None:
266248 temp .close ()
267249 self ._write_from_disk (path , Path (temp .name ))
268250
269- @override
270- @contextlib .contextmanager
271- def _expose (self ) -> Iterator [Path ]:
272- tree_sha = self .tree_sha ()
273- commit_sha = self ._repo .git (
274- "commit-tree" , "-m" , "draft! worktree" , tree_sha
275- ).stdout
276- with tempfile .TemporaryDirectory () as path_str :
277- try :
278- self ._repo .git (
279- "worktree" , "add" , "--detach" , path_str , commit_sha
280- )
281- path = Path (path_str )
282- yield path
283- self ._sync_updates (worktree_path = path )
284- finally :
285- self ._repo .git ("worktree" , "remove" , "-f" , path_str )
286-
287251 def _write_from_disk (
288252 self , path : PurePosixPath , contents_path : Path
289253 ) -> None :
@@ -300,6 +264,23 @@ def _write_from_disk(
300264 def _delete (self , path : PurePosixPath ) -> None :
301265 self ._tree_updates .append (_DeleteBlob (path ))
302266
267+ @override
268+ @contextlib .contextmanager
269+ def _expose (self ) -> Iterator [Path ]:
270+ commit_sha = self ._repo .git (
271+ "commit-tree" , "-m" , "draft! worktree" , self .tree_sha ()
272+ ).stdout
273+ with tempfile .TemporaryDirectory () as path_str :
274+ try :
275+ self ._repo .git (
276+ "worktree" , "add" , "--detach" , path_str , commit_sha
277+ )
278+ path = Path (path_str )
279+ yield path
280+ self ._sync_updates (worktree_path = path )
281+ finally :
282+ self ._repo .git ("worktree" , "remove" , "-f" , path_str )
283+
303284
304285class _TreeUpdate :
305286 """Generic tree update"""
0 commit comments