(workspaceId: string)
| 17 | * - Any other workspace-* directory that exists |
| 18 | */ |
| 19 | export function resolveWorkspace(workspaceId: string): string | null { |
| 20 | if (!workspaceId) return null; |
| 21 | |
| 22 | // Direct workspace match |
| 23 | if (workspaceId === 'workspace') { |
| 24 | const p = path.join(OPENCLAW_DIR, 'workspace'); |
| 25 | return fs.existsSync(p) ? p : null; |
| 26 | } |
| 27 | |
| 28 | // workspace-* match (e.g., workspace-codev, workspace-linkedin) |
| 29 | if (workspaceId.startsWith('workspace-')) { |
| 30 | const p = path.join(OPENCLAW_DIR, workspaceId); |
| 31 | return fs.existsSync(p) ? p : null; |
| 32 | } |
| 33 | |
| 34 | // Check if it's a subdirectory of the main workspace (e.g., mission-control, mission-control-v2) |
| 35 | const subdir = path.join(OPENCLAW_DIR, 'workspace', workspaceId); |
| 36 | if (fs.existsSync(subdir)) { |
| 37 | return subdir; |
| 38 | } |
| 39 | |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Validate that a resolved file path is within its workspace base. |
no outgoing calls
no test coverage detected