* 删除 Workspace * * - 删除前检查是否有 RUNNING 状态的 Session,有则拒绝删除 * - 删除时先停止所有关联 Session 的进程 * - 删除时调用 WorktreeManager.remove 清理 worktree * - worktree 清理失败时仍然删除数据库记录(记录警告日志)
(id: string)
| 1710 | 'MERGED_WORKSPACE_STATE_CHANGED', |
| 1711 | 409, |
| 1712 | ); |
| 1713 | } |
| 1714 | |
| 1715 | this.runCopyFiles(workspace.task.project.repoPath, worktreePath, workspace.task.project.copyFiles); |
| 1716 | this.fireSetupScript(workspace.id, workspace.taskId, worktreePath, workspace.task.project.setupScript); |
| 1717 | |
| 1718 | const activated = await prisma.workspace.findUniqueOrThrow({ |
| 1719 | where: { id: workspace.id }, |
| 1720 | include: { sessions: visibleSessionsFilter, task: { include: { project: true } } }, |
| 1721 | }); |
| 1722 | return activated; |
| 1723 | } |
| 1724 | |
| 1725 | private async waitForWorkspaceReady(workspace: WorkspaceWithTaskProject): Promise<WorkspaceWithTaskProject> { |
| 1726 | if (workspace.branchName) { |
| 1727 | return workspace; |
| 1728 | } |
| 1729 | |
| 1730 | for (let attempt = 0; attempt < WORKSPACE_READY_RETRY_COUNT; attempt++) { |
| 1731 | await sleep(WORKSPACE_READY_RETRY_DELAY_MS); |
| 1732 | const reloaded = await prisma.workspace.findUnique({ |
| 1733 | where: { id: workspace.id }, |
| 1734 | include: { task: { include: { project: true } } }, |
| 1735 | }); |
| 1736 | if (!reloaded) { |
| 1737 | break; |
| 1738 | } |
| 1739 | if (reloaded.branchName) { |
| 1740 | return reloaded; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | throw new ServiceError( |
| 1745 | `Workspace ${workspace.id} is still initializing`, |
| 1746 | 'WORKSPACE_INITIALIZING', |
| 1747 | 409 |
| 1748 | ); |
| 1749 | } |
| 1750 | |
| 1751 | private async ensureActiveWorkspaceWorktree(workspace: WorkspaceWithTaskProject): Promise<WorkspaceWithVisibleSessions> { |
| 1752 | ensureTaskNotDeleted(workspace.task); |
| 1753 | this.assertWorktreeWorkspace(workspace); |
| 1754 | |
| 1755 | if (!workspace.branchName) { |
| 1756 | workspace = await this.waitForWorkspaceReady(workspace); |
| 1757 | } |
| 1758 | |
| 1759 | if (workspace.worktreePath) { |
no test coverage detected