From 977d3960b073080b3a2e494570c90f2646511c7a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 7 Jun 2026 06:57:43 +0100 Subject: [PATCH] refac --- cptr/utils/chat_task.py | 4 ++-- cptr/utils/tools.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cptr/utils/chat_task.py b/cptr/utils/chat_task.py index f7aeb4d..3d05cf4 100644 --- a/cptr/utils/chat_task.py +++ b/cptr/utils/chat_task.py @@ -322,8 +322,8 @@ def _load_system_prompt(workspace: str) -> str: if instructions: base += f"\n\n\n{instructions}\n" base += ( - "\n\nThe above were loaded from files in the workspace root " - "(MEMORY.md, AGENTS.md, CLAUDE.md). These files persist across sessions. " + "\n\nThe above were loaded from instruction files in the workspace root. " + "These files persist across sessions. " "You can update them with your file tools to save learnings, decisions, or " "project conventions for future sessions." ) diff --git a/cptr/utils/tools.py b/cptr/utils/tools.py index b65f578..2860fb7 100644 --- a/cptr/utils/tools.py +++ b/cptr/utils/tools.py @@ -295,22 +295,27 @@ async def _search_python(query: str, full: Path, case_insensitive: bool) -> str: async def create_file( - path: str, - content: str, + path: str = "", + content: str = "", overwrite: bool = False, artifact_type: str = "", *, workspace: str, ) -> str: - """Create a new file. Errors if file already exists unless overwrite is true. - For non-trivial tasks (multi-file changes, ambiguous requirements, architectural decisions), - create an implementation plan first with artifact_type='implementation_plan'. Write the plan - as markdown, then wait for the user to review before making changes. - :param path: Path relative to workspace root. + """Create a new file, or create an artifact for user review. + When artifact_type is set, path is optional. The artifact is saved automatically. + :param path: Path relative to workspace root (optional for artifacts). :param content: File contents to write. :param overwrite: Set to true to overwrite an existing file. :param artifact_type: Set to 'implementation_plan' to present a plan for user review before coding. """ + # Artifact-only: skip workspace file write + if artifact_type and not path: + return f"Artifact created ({len(content)} bytes)" + + if not path: + return "Error: path is required when artifact_type is not set." + full = _resolve_path(path, workspace) if full.is_file() and not overwrite: return f"Error: file already exists: {path}. Use overwrite=true or edit_file to modify."