feat(04-02): implement _handle_use_project with context tracking

- Add _handle_use_project method
- Update user context when switching projects
- Return error card with Create button for non-existent projects
- Route use command in handle_message

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 18:49:53 +08:00
parent c61296a24e
commit 3047605d14
@@ -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 <name>"
)
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")