-
Notifications
You must be signed in to change notification settings - Fork 44.6k
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
Add workspace abstraction #2982
Add workspace abstraction #2982
Conversation
@@ -226,3 +232,14 @@ def start_interaction_loop(self): | |||
logger.typewriter_log( | |||
"SYSTEM: ", Fore.YELLOW, "Unable to execute command" | |||
) | |||
|
|||
def _resolve_pathlike_command_args(self, command_args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want some kind of introspection mechanism for pathlike command args at some point.
@@ -164,6 +174,27 @@ def main( | |||
system_prompt = ai_config.construct_full_prompt() | |||
if cfg.debug_mode: | |||
logger.typewriter_log("Prompt:", Fore.GREEN, system_prompt) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main purpose of the addition here is to pull the creation of the workspace and file logger file from import time and remove them from the global namespace.
@@ -43,12 +40,7 @@ def log_operation(operation: str, filename: str) -> None: | |||
filename (str): The name of the file the operation was performed on | |||
""" | |||
log_entry = f"{operation}: {filename}\n" | |||
|
|||
# Create the log file if it doesn't exist | |||
if not os.path.exists(LOG_FILE_PATH): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now done at app start
@@ -222,16 +210,13 @@ def search_files(directory: str) -> list[str]: | |||
""" | |||
found_files = [] | |||
|
|||
if directory in {"", "/"}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now done in agent path resolution
@@ -28,19 +25,12 @@ | |||
|
|||
|
|||
@requires_api_key("OPENAI_API_KEY") | |||
def test_write_file() -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The introduction of a pytest fixture that does its own cleanup removes a ton of boilerplate setup/teardown from tests
@@ -24,24 +23,24 @@ class TestFileOperations(unittest.TestCase): | |||
""" | |||
|
|||
def setUp(self): | |||
self.test_file = "test_file.txt" | |||
self.config = Config() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone knows how to make unittest classes use pytest fixtures, let me know. Otherwise I think we should add a backlog item to refactor things so we're using pytest only.
…o feature/workspace-abstraction
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2982 +/- ##
==========================================
- Coverage 45.81% 37.44% -8.38%
==========================================
Files 60 61 +1
Lines 2918 2938 +20
Branches 480 490 +10
==========================================
- Hits 1337 1100 -237
- Misses 1472 1778 +306
+ Partials 109 60 -49
... and 14 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to run locally before merge. Don’t have laptop handy but code LGTM
Background
This is the first change on the path to building a self-contained "AICore" in line with our project plan, and focuses on wrangling the Agent workspace into a coherent abstraction. It gathers workspace path resolution into a class that the Agent instantiates and uses.
Due to the prior global nature of the existingworkspace, this change necessarily touches a large number of files, but should radically reduce the scope of certain kinds of future PRs. Importantly, despite the breadth of this PR, this code change is structured to require no behavior on the user side, however (except, of course, for those users hacking deeply into the codebase).
Changes
All changes here are in service of creating a workspace abstraction and removing the workspace from the global namespace.
workspace_directory
argument to theAgent
used to construct the Agent's workspace abstraction.Agent
helper function.path_in_workspace
have been removed.WORKSPACE_PATH
no longer exists, so commands (and other code) now access it from the config (for now)workspace_path
andfile_logger_path
to the config.workspace
package and module and aWorkspace
class to do the path resolution work.Could be separate, but I uncovered these issues in testing
functools.wraps
decorators to thecommand
decorator and the `to allow pytest fixtures to work correctly.Documentation
All public functions have complete typing and docstrings and any complex logic is accompanied by comments.
Test Plan
~40 tests submitted to accompany code changes and all current unit and integration tests pass.
PR Quality Checklist