diff --git a/gsd-openclaw/src/gsd_openclaw/orchestrator.py b/gsd-openclaw/src/gsd_openclaw/orchestrator.py index 6313361..ce06e04 100644 --- a/gsd-openclaw/src/gsd_openclaw/orchestrator.py +++ b/gsd-openclaw/src/gsd_openclaw/orchestrator.py @@ -136,6 +136,60 @@ class Orchestrator: content=str(e)[-self.MAX_OUTPUT_LENGTH:] ) + def _handle_use_project(self, user_id: str, project_name: str) -> Dict[str, Any]: + """Handle /gsd:use command. + + Switches the user's current project context. Shows error with + "Create New Project" button if the project doesn't exist. + + Args: + user_id: ID of the user sending the command. + project_name: Name of the project to switch to. + + Returns: + Feishu Card JSON dict as response. + """ + # Validate project name + if not project_name or not project_name.strip(): + return self.formatter.format_error( + title="Project name required", + content="Please provide a project name: /gsd:use " + ) + + project_name = project_name.strip() + + try: + # Check if project session exists + session = self.tmux_manager.get_session(project_name) + + if session is not None: + # Project exists - update user context and return success + user_ctx = self._get_user_context_manager(user_id) + user_ctx.set_current_project(project_name) + + return self.formatter.format_success( + title="Project switched", + content=f"Switched to project '{project_name}'" + ) + else: + # Project doesn't exist - return error with Create button + create_button = CardButton( + text="Create New Project", + value={"action": "new-project", "name": project_name}, + button_type="primary" + ) + return self.formatter.format_error( + title="Project not found", + content=f"Project '{project_name}' does not exist", + buttons=[create_button] + ) + + except Exception as e: + return self.formatter.format_error( + title="Switch failed", + content=str(e)[-self.MAX_OUTPUT_LENGTH:] + ) + def parse_command(self, message: str) -> Optional[Tuple[str, str]]: """Parse a message for /gsd:* command pattern. @@ -192,6 +246,8 @@ class Orchestrator: # Route special commands if command == 'new-project': return self._handle_new_project(user_id, args) + if command == 'use': + return self._handle_use_project(user_id, args) # Get project name from context project_name = context.get("project", "default")