(args: Record<string, unknown>)
| 1419 | } |
| 1420 | |
| 1421 | async function resolveProjectForTool(args: Record<string, unknown>): Promise<ProjectResolution> { |
| 1422 | const requestedProject = parseProjectSelector(args.project); |
| 1423 | const requestedProjectDirectory = parseProjectSelector(args.project_directory); |
| 1424 | |
| 1425 | if (requestedProject || requestedProjectDirectory) { |
| 1426 | return resolveExplicitProjectSelection({ |
| 1427 | project: requestedProject, |
| 1428 | projectDirectory: requestedProjectDirectory |
| 1429 | }); |
| 1430 | } |
| 1431 | |
| 1432 | const activeProject = activeProjectKey ? getTrackedRootPathByKey(activeProjectKey) : undefined; |
| 1433 | if (activeProject) { |
| 1434 | const project = getOrCreateProject(activeProject); |
| 1435 | await initProject(project.rootPath, watcherDebounceMs, { enableWatcher: true }); |
| 1436 | touchProject(project.rootPath); |
| 1437 | return { ok: true, project }; |
| 1438 | } |
| 1439 | |
| 1440 | const availableProjects = listProjectDescriptors(); |
| 1441 | if (availableProjects.length === 0) { |
| 1442 | return { |
| 1443 | ok: false, |
| 1444 | response: buildProjectSelectionError( |
| 1445 | 'selection_required', |
| 1446 | 'No active project is available yet. Retry with project or wait for MCP roots to arrive.', |
| 1447 | { |
| 1448 | reason: clientRootsEnabled |
| 1449 | ? 'workspace_waiting_for_project_selection' |
| 1450 | : 'workspace_waiting_for_roots_or_project', |
| 1451 | nextAction: 'retry_with_project' |
| 1452 | } |
| 1453 | ) |
| 1454 | }; |
| 1455 | } |
| 1456 | |
| 1457 | if (availableProjects.length === 1) { |
| 1458 | const project = getOrCreateProject(availableProjects[0].rootPath); |
| 1459 | await initProject(project.rootPath, watcherDebounceMs, { enableWatcher: true }); |
| 1460 | setActiveProject(project.rootPath); |
| 1461 | return { ok: true, project }; |
| 1462 | } |
| 1463 | |
| 1464 | return { |
| 1465 | ok: false, |
| 1466 | response: buildProjectSelectionError( |
| 1467 | 'selection_required', |
| 1468 | 'Multiple projects are available and no active project could be inferred. Retry with project.', |
| 1469 | { |
| 1470 | reason: 'multiple_projects_configured_no_active_context', |
| 1471 | nextAction: 'retry_with_project' |
| 1472 | } |
| 1473 | ) |
| 1474 | }; |
| 1475 | } |
| 1476 | |
| 1477 | async function resolveProjectForResource(): Promise<ProjectState | undefined> { |
| 1478 | const activeProject = activeProjectKey ? getTrackedRootPathByKey(activeProjectKey) : undefined; |
no test coverage detected