mcoda 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintrc.cjs +12 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
- package/.github/workflows/ci.yml +37 -0
- package/.github/workflows/nightly.yml +38 -0
- package/.github/workflows/release-dry-run.yml +40 -0
- package/.github/workflows/release-please.yml +22 -0
- package/.github/workflows/release.yml +149 -0
- package/.prettierrc +5 -0
- package/.release-please-manifest.json +8 -0
- package/CHANGELOG.md +7 -0
- package/CLA.md +42 -0
- package/CONTRIBUTING.md +38 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/docs/oss_publishing_plan.md +41 -0
- package/docs/pdr/.gitkeep +0 -0
- package/docs/quality_gates.md +32 -0
- package/docs/rfp/.gitkeep +0 -0
- package/docs/sds/sds.md +11963 -0
- package/docs/usage.md +72 -0
- package/openapi/gen-openapi.ts +1 -0
- package/openapi/generated/clients/.gitkeep +0 -0
- package/openapi/generated/types/.gitkeep +0 -0
- package/openapi/generated/types/index.ts +118 -0
- package/openapi/mcoda.yaml +2063 -0
- package/pack-mcoda.sh +88 -0
- package/package.json +46 -0
- package/packages/agents/CHANGELOG.md +7 -0
- package/packages/agents/LICENSE +21 -0
- package/packages/agents/README.md +9 -0
- package/packages/agents/package.json +41 -0
- package/packages/agents/src/AgentService/.gitkeep +0 -0
- package/packages/agents/src/AgentService/AgentService.d.ts +21 -0
- package/packages/agents/src/AgentService/AgentService.d.ts.map +1 -0
- package/packages/agents/src/AgentService/AgentService.js +141 -0
- package/packages/agents/src/AgentService/AgentService.ts +308 -0
- package/packages/agents/src/__tests__/AgentService.test.ts +284 -0
- package/packages/agents/src/adapters/AdapterTypes.d.ts +29 -0
- package/packages/agents/src/adapters/AdapterTypes.d.ts.map +1 -0
- package/packages/agents/src/adapters/AdapterTypes.js +1 -0
- package/packages/agents/src/adapters/AdapterTypes.ts +32 -0
- package/packages/agents/src/adapters/codex/.gitkeep +0 -0
- package/packages/agents/src/adapters/codex/CodexAdapter.d.ts +11 -0
- package/packages/agents/src/adapters/codex/CodexAdapter.d.ts.map +1 -0
- package/packages/agents/src/adapters/codex/CodexAdapter.js +43 -0
- package/packages/agents/src/adapters/codex/CodexAdapter.ts +63 -0
- package/packages/agents/src/adapters/codex/CodexCliRunner.ts +154 -0
- package/packages/agents/src/adapters/gemini/.gitkeep +0 -0
- package/packages/agents/src/adapters/gemini/GeminiAdapter.d.ts +11 -0
- package/packages/agents/src/adapters/gemini/GeminiAdapter.d.ts.map +1 -0
- package/packages/agents/src/adapters/gemini/GeminiAdapter.js +42 -0
- package/packages/agents/src/adapters/gemini/GeminiAdapter.ts +58 -0
- package/packages/agents/src/adapters/gemini/GeminiCliRunner.ts +75 -0
- package/packages/agents/src/adapters/local/.gitkeep +0 -0
- package/packages/agents/src/adapters/local/LocalAdapter.d.ts +11 -0
- package/packages/agents/src/adapters/local/LocalAdapter.d.ts.map +1 -0
- package/packages/agents/src/adapters/local/LocalAdapter.js +38 -0
- package/packages/agents/src/adapters/local/LocalAdapter.ts +43 -0
- package/packages/agents/src/adapters/ollama/OllamaCliAdapter.ts +58 -0
- package/packages/agents/src/adapters/ollama/OllamaCliRunner.ts +70 -0
- package/packages/agents/src/adapters/ollama/OllamaRemoteAdapter.ts +205 -0
- package/packages/agents/src/adapters/openai/.gitkeep +0 -0
- package/packages/agents/src/adapters/openai/OpenAiAdapter.d.ts +11 -0
- package/packages/agents/src/adapters/openai/OpenAiAdapter.d.ts.map +1 -0
- package/packages/agents/src/adapters/openai/OpenAiAdapter.js +51 -0
- package/packages/agents/src/adapters/openai/OpenAiAdapter.ts +56 -0
- package/packages/agents/src/adapters/openai/OpenAiCliAdapter.ts +62 -0
- package/packages/agents/src/adapters/qa/.gitkeep +0 -0
- package/packages/agents/src/adapters/qa/QaAdapter.d.ts +11 -0
- package/packages/agents/src/adapters/qa/QaAdapter.d.ts.map +1 -0
- package/packages/agents/src/adapters/qa/QaAdapter.js +37 -0
- package/packages/agents/src/adapters/qa/QaAdapter.ts +42 -0
- package/packages/agents/src/adapters/zhipu/ZhipuApiAdapter.ts +273 -0
- package/packages/agents/src/index.d.ts +8 -0
- package/packages/agents/src/index.d.ts.map +1 -0
- package/packages/agents/src/index.js +7 -0
- package/packages/agents/src/index.ts +11 -0
- package/packages/agents/tsconfig.json +14 -0
- package/packages/cli/CHANGELOG.md +7 -0
- package/packages/cli/LICENSE +21 -0
- package/packages/cli/README.md +23 -0
- package/packages/cli/package.json +61 -0
- package/packages/cli/src/__tests__/AgentsCommands.test.ts +137 -0
- package/packages/cli/src/__tests__/BacklogCommands.test.ts +40 -0
- package/packages/cli/src/__tests__/CodeReviewCommand.test.ts +594 -0
- package/packages/cli/src/__tests__/CreateTasksCommand.test.ts +40 -0
- package/packages/cli/src/__tests__/DocsCommands.test.ts +41 -0
- package/packages/cli/src/__tests__/EstimateCommands.test.ts +54 -0
- package/packages/cli/src/__tests__/JobsCommands.behavior.test.ts +311 -0
- package/packages/cli/src/__tests__/JobsCommands.test.ts +49 -0
- package/packages/cli/src/__tests__/MigrateTasksCommand.test.ts +36 -0
- package/packages/cli/src/__tests__/OpenapiCommands.test.ts +34 -0
- package/packages/cli/src/__tests__/OrderTasksCommand.test.ts +150 -0
- package/packages/cli/src/__tests__/PlanningCommands.test.ts +9 -0
- package/packages/cli/src/__tests__/QaTasksCommand.test.ts +58 -0
- package/packages/cli/src/__tests__/RefineTasksCommand.test.ts +63 -0
- package/packages/cli/src/__tests__/RoutingCommands.test.ts +302 -0
- package/packages/cli/src/__tests__/SetWorkspaceCommand.test.ts +18 -0
- package/packages/cli/src/__tests__/TaskShowCommands.test.ts +130 -0
- package/packages/cli/src/__tests__/TelemetryCommands.test.ts +35 -0
- package/packages/cli/src/__tests__/TestAgentCommand.test.ts +41 -0
- package/packages/cli/src/__tests__/UpdateCommands.test.ts +292 -0
- package/packages/cli/src/__tests__/WorkOnTasksCommand.test.ts +42 -0
- package/packages/cli/src/bin/.gitkeep +0 -0
- package/packages/cli/src/bin/McodaEntrypoint.ts +180 -0
- package/packages/cli/src/commands/agents/.gitkeep +0 -0
- package/packages/cli/src/commands/agents/AgentsCommands.ts +374 -0
- package/packages/cli/src/commands/agents/GatewayAgentCommand.ts +621 -0
- package/packages/cli/src/commands/agents/TestAgentCommand.ts +63 -0
- package/packages/cli/src/commands/backlog/.gitkeep +0 -0
- package/packages/cli/src/commands/backlog/BacklogCommands.ts +286 -0
- package/packages/cli/src/commands/backlog/OrderTasksCommand.ts +237 -0
- package/packages/cli/src/commands/backlog/TaskShowCommands.ts +289 -0
- package/packages/cli/src/commands/docs/.gitkeep +0 -0
- package/packages/cli/src/commands/docs/DocsCommands.ts +413 -0
- package/packages/cli/src/commands/estimate/EstimateCommands.ts +290 -0
- package/packages/cli/src/commands/jobs/.gitkeep +0 -0
- package/packages/cli/src/commands/jobs/JobsCommands.ts +595 -0
- package/packages/cli/src/commands/openapi/OpenapiCommands.ts +167 -0
- package/packages/cli/src/commands/planning/.gitkeep +0 -0
- package/packages/cli/src/commands/planning/CreateTasksCommand.ts +149 -0
- package/packages/cli/src/commands/planning/MigrateTasksCommand.ts +105 -0
- package/packages/cli/src/commands/planning/PlanningCommands.ts +1 -0
- package/packages/cli/src/commands/planning/QaTasksCommand.ts +320 -0
- package/packages/cli/src/commands/planning/RefineTasksCommand.ts +408 -0
- package/packages/cli/src/commands/review/CodeReviewCommand.ts +262 -0
- package/packages/cli/src/commands/routing/.gitkeep +0 -0
- package/packages/cli/src/commands/routing/RoutingCommands.ts +554 -0
- package/packages/cli/src/commands/telemetry/.gitkeep +0 -0
- package/packages/cli/src/commands/telemetry/TelemetryCommands.ts +348 -0
- package/packages/cli/src/commands/update/.gitkeep +0 -0
- package/packages/cli/src/commands/update/UpdateCommands.ts +301 -0
- package/packages/cli/src/commands/work/WorkOnTasksCommand.ts +264 -0
- package/packages/cli/src/commands/workspace/SetWorkspaceCommand.ts +132 -0
- package/packages/cli/src/index.ts +18 -0
- package/packages/cli/test/packaging_guardrails.test.js +75 -0
- package/packages/cli/tsconfig.json +20 -0
- package/packages/core/CHANGELOG.md +7 -0
- package/packages/core/LICENSE +21 -0
- package/packages/core/README.md +9 -0
- package/packages/core/package.json +45 -0
- package/packages/core/src/__tests__/SmokeClasses.test.ts +32 -0
- package/packages/core/src/api/AgentsApi.ts +219 -0
- package/packages/core/src/api/QaTasksApi.ts +38 -0
- package/packages/core/src/api/TasksApi.ts +35 -0
- package/packages/core/src/api/__tests__/AgentsApi.test.ts +203 -0
- package/packages/core/src/api/__tests__/QaTasksApi.test.ts +51 -0
- package/packages/core/src/api/__tests__/TasksApi.test.ts +56 -0
- package/packages/core/src/config/.gitkeep +0 -0
- package/packages/core/src/config/ConfigService.ts +1 -0
- package/packages/core/src/domain/dependencies/.gitkeep +0 -0
- package/packages/core/src/domain/dependencies/Dependency.ts +1 -0
- package/packages/core/src/domain/epics/.gitkeep +0 -0
- package/packages/core/src/domain/epics/Epic.ts +1 -0
- package/packages/core/src/domain/projects/.gitkeep +0 -0
- package/packages/core/src/domain/projects/Project.ts +1 -0
- package/packages/core/src/domain/tasks/.gitkeep +0 -0
- package/packages/core/src/domain/tasks/Task.ts +1 -0
- package/packages/core/src/domain/userStories/.gitkeep +0 -0
- package/packages/core/src/domain/userStories/UserStory.ts +1 -0
- package/packages/core/src/index.ts +27 -0
- package/packages/core/src/prompts/.gitkeep +0 -0
- package/packages/core/src/prompts/PdrPrompts.ts +23 -0
- package/packages/core/src/prompts/PromptLoader.ts +1 -0
- package/packages/core/src/prompts/SdsPrompts.ts +47 -0
- package/packages/core/src/services/agents/.gitkeep +0 -0
- package/packages/core/src/services/agents/AgentManagementService.ts +1 -0
- package/packages/core/src/services/agents/GatewayAgentService.ts +956 -0
- package/packages/core/src/services/agents/RoutingService.ts +461 -0
- package/packages/core/src/services/agents/__tests__/GatewayAgentService.test.ts +72 -0
- package/packages/core/src/services/agents/__tests__/RoutingService.test.ts +267 -0
- package/packages/core/src/services/agents/generated/RoutingApiClient.ts +89 -0
- package/packages/core/src/services/backlog/.gitkeep +0 -0
- package/packages/core/src/services/backlog/BacklogService.ts +580 -0
- package/packages/core/src/services/backlog/TaskOrderingService.ts +868 -0
- package/packages/core/src/services/backlog/__tests__/BacklogService.test.ts +219 -0
- package/packages/core/src/services/backlog/__tests__/TaskOrderingService.test.ts +268 -0
- package/packages/core/src/services/docs/.gitkeep +0 -0
- package/packages/core/src/services/docs/DocsService.ts +1913 -0
- package/packages/core/src/services/docs/__tests__/DocsService.test.ts +350 -0
- package/packages/core/src/services/estimate/EstimateService.ts +111 -0
- package/packages/core/src/services/estimate/VelocityService.ts +272 -0
- package/packages/core/src/services/estimate/__tests__/VelocityAndEstimate.test.ts +209 -0
- package/packages/core/src/services/estimate/types.ts +41 -0
- package/packages/core/src/services/execution/.gitkeep +0 -0
- package/packages/core/src/services/execution/ExecutionService.ts +1 -0
- package/packages/core/src/services/execution/QaFollowupService.ts +289 -0
- package/packages/core/src/services/execution/QaProfileService.ts +160 -0
- package/packages/core/src/services/execution/QaTasksService.ts +1303 -0
- package/packages/core/src/services/execution/TaskSelectionService.ts +362 -0
- package/packages/core/src/services/execution/TaskStateService.ts +64 -0
- package/packages/core/src/services/execution/WorkOnTasksService.ts +2023 -0
- package/packages/core/src/services/execution/__tests__/QaFollowupService.test.ts +58 -0
- package/packages/core/src/services/execution/__tests__/QaProfileService.test.ts +49 -0
- package/packages/core/src/services/execution/__tests__/QaTasksService.test.ts +157 -0
- package/packages/core/src/services/execution/__tests__/TaskSelectionService.test.ts +179 -0
- package/packages/core/src/services/execution/__tests__/TaskStateService.test.ts +51 -0
- package/packages/core/src/services/execution/__tests__/WorkOnTasksService.test.ts +285 -0
- package/packages/core/src/services/jobs/.gitkeep +0 -0
- package/packages/core/src/services/jobs/JobInsightsService.ts +355 -0
- package/packages/core/src/services/jobs/JobResumeService.ts +119 -0
- package/packages/core/src/services/jobs/JobService.ts +648 -0
- package/packages/core/src/services/jobs/JobsApiClient.ts +113 -0
- package/packages/core/src/services/jobs/__tests__/JobInsightsService.test.ts +17 -0
- package/packages/core/src/services/jobs/__tests__/JobResumeService.test.ts +45 -0
- package/packages/core/src/services/jobs/__tests__/JobService.test.ts +44 -0
- package/packages/core/src/services/openapi/OpenApiService.ts +558 -0
- package/packages/core/src/services/openapi/__tests__/OpenApiService.test.ts +57 -0
- package/packages/core/src/services/planning/.gitkeep +0 -0
- package/packages/core/src/services/planning/CreateTasksService.ts +1280 -0
- package/packages/core/src/services/planning/KeyHelpers.ts +80 -0
- package/packages/core/src/services/planning/PlanningService.ts +1 -0
- package/packages/core/src/services/planning/RefineTasksService.ts +1552 -0
- package/packages/core/src/services/planning/__tests__/CreateTasksService.test.ts +288 -0
- package/packages/core/src/services/planning/__tests__/KeyHelpers.test.ts +16 -0
- package/packages/core/src/services/planning/__tests__/RefineTasksService.test.ts +172 -0
- package/packages/core/src/services/review/CodeReviewService.ts +1386 -0
- package/packages/core/src/services/review/__tests__/CodeReviewService.test.ts +89 -0
- package/packages/core/src/services/system/SystemUpdateService.ts +177 -0
- package/packages/core/src/services/system/__tests__/SystemUpdateService.test.ts +40 -0
- package/packages/core/src/services/tasks/TaskApiResolver.ts +37 -0
- package/packages/core/src/services/tasks/TaskDetailService.ts +494 -0
- package/packages/core/src/services/tasks/__tests__/TaskApiResolver.test.ts +41 -0
- package/packages/core/src/services/tasks/__tests__/TaskDetailService.test.ts +178 -0
- package/packages/core/src/services/telemetry/.gitkeep +0 -0
- package/packages/core/src/services/telemetry/TelemetryService.ts +515 -0
- package/packages/core/src/services/telemetry/__tests__/TelemetryService.test.ts +160 -0
- package/packages/core/src/workspace/.gitkeep +0 -0
- package/packages/core/src/workspace/WorkspaceManager.ts +234 -0
- package/packages/core/tsconfig.json +20 -0
- package/packages/db/CHANGELOG.md +7 -0
- package/packages/db/LICENSE +21 -0
- package/packages/db/README.md +9 -0
- package/packages/db/package.json +42 -0
- package/packages/db/src/__tests__/GlobalRepository.test.ts +109 -0
- package/packages/db/src/__tests__/SchemaAlignment.test.ts +80 -0
- package/packages/db/src/__tests__/WorkspaceRepository.test.ts +19 -0
- package/packages/db/src/index.d.ts +6 -0
- package/packages/db/src/index.d.ts.map +1 -0
- package/packages/db/src/index.js +5 -0
- package/packages/db/src/index.ts +6 -0
- package/packages/db/src/migrations/global/.gitkeep +0 -0
- package/packages/db/src/migrations/global/GlobalMigrations.d.ts +9 -0
- package/packages/db/src/migrations/global/GlobalMigrations.d.ts.map +1 -0
- package/packages/db/src/migrations/global/GlobalMigrations.js +68 -0
- package/packages/db/src/migrations/global/GlobalMigrations.ts +336 -0
- package/packages/db/src/migrations/workspace/.gitkeep +0 -0
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.d.ts +9 -0
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.d.ts.map +1 -0
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.js +251 -0
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.ts +248 -0
- package/packages/db/src/repositories/global/.gitkeep +0 -0
- package/packages/db/src/repositories/global/GlobalRepository.d.ts +30 -0
- package/packages/db/src/repositories/global/GlobalRepository.d.ts.map +1 -0
- package/packages/db/src/repositories/global/GlobalRepository.js +209 -0
- package/packages/db/src/repositories/global/GlobalRepository.ts +492 -0
- package/packages/db/src/repositories/workspace/.gitkeep +0 -0
- package/packages/db/src/repositories/workspace/WorkspaceRepository.d.ts +282 -0
- package/packages/db/src/repositories/workspace/WorkspaceRepository.d.ts.map +1 -0
- package/packages/db/src/repositories/workspace/WorkspaceRepository.js +773 -0
- package/packages/db/src/repositories/workspace/WorkspaceRepository.ts +1511 -0
- package/packages/db/src/sqlite/connection.d.ts +11 -0
- package/packages/db/src/sqlite/connection.d.ts.map +1 -0
- package/packages/db/src/sqlite/connection.js +31 -0
- package/packages/db/src/sqlite/connection.ts +35 -0
- package/packages/db/src/sqlite/pragmas.d.ts +5 -0
- package/packages/db/src/sqlite/pragmas.d.ts.map +1 -0
- package/packages/db/src/sqlite/pragmas.js +6 -0
- package/packages/db/src/sqlite/pragmas.ts +10 -0
- package/packages/db/tsconfig.json +13 -0
- package/packages/generators/package.json +21 -0
- package/packages/generators/src/__tests__/Generators.test.ts +19 -0
- package/packages/generators/src/index.ts +1 -0
- package/packages/generators/src/openapi/generateTypes.ts +1 -0
- package/packages/generators/src/openapi/validateSchema.ts +1 -0
- package/packages/generators/src/scaffolding/docs/.gitkeep +0 -0
- package/packages/generators/src/scaffolding/docs/DocsScaffolder.ts +1 -0
- package/packages/generators/src/scaffolding/global/.gitkeep +0 -0
- package/packages/generators/src/scaffolding/global/GlobalScaffolder.ts +1 -0
- package/packages/generators/src/scaffolding/workspace/.gitkeep +0 -0
- package/packages/generators/src/scaffolding/workspace/WorkspaceScaffolder.ts +1 -0
- package/packages/generators/tsconfig.json +10 -0
- package/packages/integrations/CHANGELOG.md +7 -0
- package/packages/integrations/LICENSE +21 -0
- package/packages/integrations/README.md +9 -0
- package/packages/integrations/package.json +47 -0
- package/packages/integrations/src/docdex/.gitkeep +0 -0
- package/packages/integrations/src/docdex/DocdexClient.d.ts +50 -0
- package/packages/integrations/src/docdex/DocdexClient.d.ts.map +1 -0
- package/packages/integrations/src/docdex/DocdexClient.js +216 -0
- package/packages/integrations/src/docdex/DocdexClient.ts +261 -0
- package/packages/integrations/src/docdex/__tests__/DocdexClient.test.ts +29 -0
- package/packages/integrations/src/index.d.ts +2 -0
- package/packages/integrations/src/index.d.ts.map +1 -0
- package/packages/integrations/src/index.js +4 -0
- package/packages/integrations/src/index.ts +5 -0
- package/packages/integrations/src/issues/.gitkeep +0 -0
- package/packages/integrations/src/issues/IssuesClient.ts +1 -0
- package/packages/integrations/src/issues/__tests__/IssuesClient.test.ts +10 -0
- package/packages/integrations/src/qa/.gitkeep +0 -0
- package/packages/integrations/src/qa/ChromiumQaAdapter.ts +89 -0
- package/packages/integrations/src/qa/CliQaAdapter.ts +95 -0
- package/packages/integrations/src/qa/MaestroQaAdapter.ts +91 -0
- package/packages/integrations/src/qa/QaAdapter.ts +7 -0
- package/packages/integrations/src/qa/QaClient.ts +1 -0
- package/packages/integrations/src/qa/QaTypes.ts +26 -0
- package/packages/integrations/src/qa/__tests__/ChromiumQaAdapter.test.ts +30 -0
- package/packages/integrations/src/qa/__tests__/CliQaAdapter.test.ts +33 -0
- package/packages/integrations/src/qa/__tests__/MaestroQaAdapter.test.ts +30 -0
- package/packages/integrations/src/qa/index.ts +5 -0
- package/packages/integrations/src/system/SystemClient.ts +50 -0
- package/packages/integrations/src/system/__tests__/SystemClient.test.ts +40 -0
- package/packages/integrations/src/telemetry/TelemetryClient.ts +139 -0
- package/packages/integrations/src/telemetry/__tests__/TelemetryClient.test.ts +41 -0
- package/packages/integrations/src/vcs/.gitkeep +0 -0
- package/packages/integrations/src/vcs/VcsClient.ts +211 -0
- package/packages/integrations/src/vcs/__tests__/VcsClient.test.ts +26 -0
- package/packages/integrations/tsconfig.json +14 -0
- package/packages/shared/CHANGELOG.md +7 -0
- package/packages/shared/LICENSE +21 -0
- package/packages/shared/README.md +9 -0
- package/packages/shared/package.json +40 -0
- package/packages/shared/src/__tests__/CommandMetadata.test.ts +15 -0
- package/packages/shared/src/__tests__/ServiceShells.test.ts +16 -0
- package/packages/shared/src/crypto/.gitkeep +0 -0
- package/packages/shared/src/crypto/CryptoHelper.d.ts +15 -0
- package/packages/shared/src/crypto/CryptoHelper.d.ts.map +1 -0
- package/packages/shared/src/crypto/CryptoHelper.js +54 -0
- package/packages/shared/src/crypto/CryptoHelper.ts +57 -0
- package/packages/shared/src/errors/.gitkeep +0 -0
- package/packages/shared/src/errors/ErrorFactory.ts +1 -0
- package/packages/shared/src/index.d.ts +6 -0
- package/packages/shared/src/index.d.ts.map +1 -0
- package/packages/shared/src/index.js +4 -0
- package/packages/shared/src/index.ts +35 -0
- package/packages/shared/src/logging/.gitkeep +0 -0
- package/packages/shared/src/logging/Logger.ts +1 -0
- package/packages/shared/src/metadata/CommandMetadata.ts +165 -0
- package/packages/shared/src/openapi/.gitkeep +0 -0
- package/packages/shared/src/openapi/OpenApiTypes.d.ts +216 -0
- package/packages/shared/src/openapi/OpenApiTypes.d.ts.map +1 -0
- package/packages/shared/src/openapi/OpenApiTypes.js +1 -0
- package/packages/shared/src/openapi/OpenApiTypes.ts +312 -0
- package/packages/shared/src/paths/.gitkeep +0 -0
- package/packages/shared/src/paths/PathHelper.d.ts +12 -0
- package/packages/shared/src/paths/PathHelper.d.ts.map +1 -0
- package/packages/shared/src/paths/PathHelper.js +24 -0
- package/packages/shared/src/paths/PathHelper.ts +29 -0
- package/packages/shared/src/qa/QaProfile.ts +14 -0
- package/packages/shared/src/utils/.gitkeep +0 -0
- package/packages/shared/src/utils/UtilityService.ts +1 -0
- package/packages/shared/tsconfig.json +10 -0
- package/packages/testing/package.json +26 -0
- package/packages/testing/src/__tests__/TestingFakes.test.ts +15 -0
- package/packages/testing/src/cli/e2e/.gitkeep +0 -0
- package/packages/testing/src/cli/e2e/E2eSuite.ts +1 -0
- package/packages/testing/src/fakes/agents/.gitkeep +0 -0
- package/packages/testing/src/fakes/agents/FakeAgents.ts +1 -0
- package/packages/testing/src/fakes/docdex/.gitkeep +0 -0
- package/packages/testing/src/fakes/docdex/FakeDocdexClient.ts +1 -0
- package/packages/testing/src/fakes/qa/.gitkeep +0 -0
- package/packages/testing/src/fakes/qa/FakeQaClient.ts +1 -0
- package/packages/testing/src/fakes/vcs/.gitkeep +0 -0
- package/packages/testing/src/fakes/vcs/FakeVcsClient.ts +1 -0
- package/packages/testing/src/fixtures/db/.gitkeep +0 -0
- package/packages/testing/src/fixtures/db/DbFixtures.ts +1 -0
- package/packages/testing/src/fixtures/workspaces/.gitkeep +0 -0
- package/packages/testing/src/fixtures/workspaces/WorkspaceFixtures.ts +1 -0
- package/packages/testing/src/index.ts +1 -0
- package/packages/testing/tsconfig.json +10 -0
- package/pnpm-workspace.yaml +2 -0
- package/prompts/README.md +5 -0
- package/prompts/code-reviewer.md +23 -0
- package/prompts/code-writer.md +35 -0
- package/prompts/gateway-agent.md +27 -0
- package/prompts/qa-agent.md +21 -0
- package/release-please-config.json +39 -0
- package/scripts/build-all.ts +1 -0
- package/scripts/dev.ts +1 -0
- package/scripts/install-local-cli.sh +28 -0
- package/scripts/pack-npm-tarballs.js +63 -0
- package/scripts/release.ts +1 -0
- package/scripts/run-node-tests.js +37 -0
- package/tests/all.js +127 -0
- package/tests/api/openapi_spec.test.js +21 -0
- package/tests/artifacts.md +31 -0
- package/tests/component/cli_version.test.js +38 -0
- package/tests/integration/workspace_resolver.test.js +44 -0
- package/tests/unit/crypto_helper.test.js +36 -0
- package/tests/unit/path_helper.test.js +20 -0
- package/tsconfig.base.json +32 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
AgentHealth,
|
|
4
|
+
RoutingDefaults,
|
|
5
|
+
RoutingDefaultsUpdate,
|
|
6
|
+
RoutingPreview,
|
|
7
|
+
RoutingProvenance,
|
|
8
|
+
canonicalizeCommandName,
|
|
9
|
+
getKnownDocdexScopes,
|
|
10
|
+
getKnownQaProfiles,
|
|
11
|
+
getCommandRequiredCapabilities,
|
|
12
|
+
} from "@mcoda/shared";
|
|
13
|
+
import { AgentService } from "@mcoda/agents";
|
|
14
|
+
import { GlobalRepository } from "@mcoda/db";
|
|
15
|
+
import { WorkspaceResolution } from "../../workspace/WorkspaceManager.js";
|
|
16
|
+
import { RoutingApiClient, RoutingPreviewRequest } from "./generated/RoutingApiClient.js";
|
|
17
|
+
|
|
18
|
+
export interface ResolveAgentParams {
|
|
19
|
+
workspace: WorkspaceResolution;
|
|
20
|
+
commandName: string;
|
|
21
|
+
taskType?: string;
|
|
22
|
+
overrideAgentSlug?: string;
|
|
23
|
+
projectKey?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ResolvedAgent {
|
|
27
|
+
agent: Agent;
|
|
28
|
+
agentId: string;
|
|
29
|
+
agentSlug: string;
|
|
30
|
+
model?: string;
|
|
31
|
+
capabilities: string[];
|
|
32
|
+
healthStatus: AgentHealth["status"] | "unknown";
|
|
33
|
+
source: RoutingProvenance;
|
|
34
|
+
routingPreview: RoutingPreview;
|
|
35
|
+
qaProfile?: string;
|
|
36
|
+
docdexScope?: string;
|
|
37
|
+
requiredCapabilities: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class RoutingService {
|
|
41
|
+
constructor(
|
|
42
|
+
private deps: {
|
|
43
|
+
routingApi?: RoutingApiClient;
|
|
44
|
+
agentService?: { resolveAgent(idOrSlug: string): Promise<Agent>; getCapabilities?(agentId: string): Promise<string[]>; close?(): Promise<void> };
|
|
45
|
+
globalRepo?: GlobalRepository;
|
|
46
|
+
},
|
|
47
|
+
) {}
|
|
48
|
+
|
|
49
|
+
static async create(): Promise<RoutingService> {
|
|
50
|
+
let routingApi: RoutingApiClient | undefined;
|
|
51
|
+
try {
|
|
52
|
+
routingApi = RoutingApiClient.create();
|
|
53
|
+
} catch {
|
|
54
|
+
routingApi = undefined;
|
|
55
|
+
}
|
|
56
|
+
const globalRepo = await GlobalRepository.create();
|
|
57
|
+
const agentService = new AgentService(globalRepo);
|
|
58
|
+
return new RoutingService({ routingApi, globalRepo, agentService });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async close(): Promise<void> {
|
|
62
|
+
if ((this.deps.agentService as any)?.close) {
|
|
63
|
+
await (this.deps.agentService as any).close();
|
|
64
|
+
}
|
|
65
|
+
if (!(this.deps.agentService as any)?.close && (this.deps.globalRepo as any)?.close) {
|
|
66
|
+
await (this.deps.globalRepo as any).close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private requiredCapabilities(commandName: string, taskType?: string): string[] {
|
|
71
|
+
const normalized = this.normalizeCommand(commandName);
|
|
72
|
+
const required = [...getCommandRequiredCapabilities(normalized)];
|
|
73
|
+
if (taskType) {
|
|
74
|
+
const lower = taskType.toLowerCase();
|
|
75
|
+
if (lower.includes("qa")) {
|
|
76
|
+
required.push("qa_interpretation");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Array.from(new Set(required));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
normalizeCommand(commandName: string): string {
|
|
83
|
+
return canonicalizeCommandName(commandName);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private async fetchAgent(idOrSlug: string): Promise<Agent> {
|
|
87
|
+
const apiAgent =
|
|
88
|
+
(await this.deps.routingApi?.getAgent(idOrSlug)) ??
|
|
89
|
+
(await this.deps.routingApi?.listAgents())?.find((a) => a.id === idOrSlug || a.slug === idOrSlug);
|
|
90
|
+
if (apiAgent) return apiAgent;
|
|
91
|
+
if (this.deps.agentService) {
|
|
92
|
+
return this.deps.agentService.resolveAgent(idOrSlug);
|
|
93
|
+
}
|
|
94
|
+
if (this.deps.globalRepo) {
|
|
95
|
+
const byId = await this.deps.globalRepo.getAgentById(idOrSlug);
|
|
96
|
+
if (byId) return byId;
|
|
97
|
+
const bySlug = await this.deps.globalRepo.getAgentBySlug(idOrSlug);
|
|
98
|
+
if (bySlug) return bySlug;
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`Agent ${idOrSlug} not found via routing API`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private async fetchCapabilities(agent: Agent): Promise<string[]> {
|
|
104
|
+
const caps = agent.capabilities ?? [];
|
|
105
|
+
if (caps.length) return caps;
|
|
106
|
+
if (this.deps.agentService?.getCapabilities) {
|
|
107
|
+
return this.deps.agentService.getCapabilities(agent.id);
|
|
108
|
+
}
|
|
109
|
+
if (this.deps.globalRepo) {
|
|
110
|
+
return this.deps.globalRepo.getAgentCapabilities(agent.id);
|
|
111
|
+
}
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private normalizeProfile(value?: string): string | undefined {
|
|
116
|
+
return value ? value.trim().toLowerCase().replace(/[_\s]+/g, "-") : undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getWorkspaceDefaults(workspace: WorkspaceResolution | string): Promise<RoutingDefaults> {
|
|
120
|
+
const workspaceId = typeof workspace === "string" ? workspace : workspace.workspaceId;
|
|
121
|
+
if (typeof workspace !== "string") {
|
|
122
|
+
await this.migrateLegacyDefaults(workspace);
|
|
123
|
+
}
|
|
124
|
+
if (this.deps.routingApi) {
|
|
125
|
+
return (await this.deps.routingApi.getWorkspaceDefaults(workspaceId)) ?? [];
|
|
126
|
+
}
|
|
127
|
+
if (this.deps.globalRepo) {
|
|
128
|
+
return this.deps.globalRepo.getWorkspaceDefaults(workspaceId);
|
|
129
|
+
}
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private async migrateLegacyDefaults(workspace: WorkspaceResolution): Promise<void> {
|
|
134
|
+
if (!this.deps.routingApi) return;
|
|
135
|
+
const legacyIds = workspace.legacyWorkspaceIds ?? [];
|
|
136
|
+
if (!legacyIds.length) return;
|
|
137
|
+
const current = (await this.deps.routingApi.getWorkspaceDefaults(workspace.workspaceId)) ?? [];
|
|
138
|
+
if (current.length > 0) return;
|
|
139
|
+
for (const legacyId of legacyIds) {
|
|
140
|
+
const legacy = await this.deps.routingApi.getWorkspaceDefaults(legacyId);
|
|
141
|
+
if (legacy && legacy.length) {
|
|
142
|
+
const set: Record<string, string> = {};
|
|
143
|
+
for (const entry of legacy) {
|
|
144
|
+
const agent = await this.fetchAgent(entry.agentId);
|
|
145
|
+
set[this.normalizeCommand(entry.commandName)] = agent.slug ?? agent.id;
|
|
146
|
+
}
|
|
147
|
+
await this.updateWorkspaceDefaults(workspace.workspaceId, { set });
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async getAgentSummary(agentId: string): Promise<Agent | undefined> {
|
|
154
|
+
try {
|
|
155
|
+
return await this.fetchAgent(agentId);
|
|
156
|
+
} catch {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async updateWorkspaceDefaults(workspaceId: string, update: RoutingDefaultsUpdate): Promise<RoutingDefaults> {
|
|
162
|
+
const qaProfiles = getKnownQaProfiles().map((p) => this.normalizeProfile(p)).filter(Boolean);
|
|
163
|
+
const docdexScopes = getKnownDocdexScopes().map((p) => this.normalizeProfile(p)).filter(Boolean);
|
|
164
|
+
const normalizedQa = this.normalizeProfile(update.qaProfile);
|
|
165
|
+
const normalizedDocdex = this.normalizeProfile(update.docdexScope);
|
|
166
|
+
if (normalizedQa && qaProfiles.length && !qaProfiles.includes(normalizedQa)) {
|
|
167
|
+
throw new Error(`Unknown QA profile ${update.qaProfile}; allowed values: ${qaProfiles.join(", ")}`);
|
|
168
|
+
}
|
|
169
|
+
if (normalizedDocdex && docdexScopes.length && !docdexScopes.includes(normalizedDocdex)) {
|
|
170
|
+
throw new Error(`Unknown docdex scope ${update.docdexScope}; allowed values: ${docdexScopes.join(", ")}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const normalizedSet: Record<string, string> = {};
|
|
174
|
+
const setEntries = Object.entries(update.set ?? {});
|
|
175
|
+
for (const [commandName, agentSlug] of setEntries) {
|
|
176
|
+
const normalizedCommand = this.normalizeCommand(commandName);
|
|
177
|
+
const agent = await this.fetchAgent(agentSlug);
|
|
178
|
+
const capabilities = await this.fetchCapabilities(agent);
|
|
179
|
+
const required = this.requiredCapabilities(normalizedCommand);
|
|
180
|
+
const missing = required.filter((cap) => !capabilities.includes(cap));
|
|
181
|
+
if (missing.length) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Agent ${agentSlug} is missing required capabilities for ${normalizedCommand}: ${missing.join(", ")}`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
normalizedSet[normalizedCommand] = agent.slug ?? agent.id;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const normalizedReset = (update.reset ?? []).map((command) => this.normalizeCommand(command));
|
|
190
|
+
if (this.deps.routingApi) {
|
|
191
|
+
const updated = await this.deps.routingApi.updateWorkspaceDefaults(workspaceId, {
|
|
192
|
+
...update,
|
|
193
|
+
qaProfile: normalizedQa ?? update.qaProfile,
|
|
194
|
+
docdexScope: normalizedDocdex ?? update.docdexScope,
|
|
195
|
+
set: Object.keys(normalizedSet).length ? normalizedSet : undefined,
|
|
196
|
+
reset: normalizedReset.length ? normalizedReset : undefined,
|
|
197
|
+
});
|
|
198
|
+
return updated ?? [];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!this.deps.globalRepo) {
|
|
202
|
+
throw new Error("Routing defaults are unavailable without a routing API or global repository");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
for (const [commandName, agentSlug] of Object.entries(normalizedSet)) {
|
|
206
|
+
const agent = await this.fetchAgent(agentSlug);
|
|
207
|
+
await this.deps.globalRepo.setWorkspaceDefault(workspaceId, commandName, agent.id, {
|
|
208
|
+
qaProfile: normalizedQa ?? update.qaProfile,
|
|
209
|
+
docdexScope: normalizedDocdex ?? update.docdexScope,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
for (const commandName of normalizedReset) {
|
|
213
|
+
await this.deps.globalRepo.removeWorkspaceDefault(workspaceId, commandName);
|
|
214
|
+
}
|
|
215
|
+
return this.deps.globalRepo.getWorkspaceDefaults(workspaceId);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private buildPreviewRequest(params: ResolveAgentParams): RoutingPreviewRequest {
|
|
219
|
+
const commandName = this.normalizeCommand(params.commandName);
|
|
220
|
+
return {
|
|
221
|
+
workspaceId: params.workspace.workspaceId,
|
|
222
|
+
commandName,
|
|
223
|
+
agentOverride: params.overrideAgentSlug,
|
|
224
|
+
taskType: params.taskType,
|
|
225
|
+
projectKey: params.projectKey,
|
|
226
|
+
requiredCapabilities: this.requiredCapabilities(commandName, params.taskType),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async resolveAgentForCommand(params: ResolveAgentParams): Promise<ResolvedAgent> {
|
|
231
|
+
await this.migrateLegacyDefaults(params.workspace);
|
|
232
|
+
const normalizedCommand = this.normalizeCommand(params.commandName);
|
|
233
|
+
const requiredCaps = this.requiredCapabilities(normalizedCommand, params.taskType);
|
|
234
|
+
|
|
235
|
+
const fillHealth = async (agentId: string, current?: AgentHealth): Promise<AgentHealth | undefined> => {
|
|
236
|
+
if (current && current.status) return current;
|
|
237
|
+
const apiAgent = await this.deps.routingApi?.getAgent(agentId);
|
|
238
|
+
if (apiAgent?.health) return apiAgent.health as AgentHealth;
|
|
239
|
+
if (this.deps.globalRepo) {
|
|
240
|
+
return this.deps.globalRepo.getAgentHealth(agentId);
|
|
241
|
+
}
|
|
242
|
+
return current;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const fallbackFromDefaults = async (): Promise<ResolvedAgent | null> => {
|
|
246
|
+
const workspaceDefaults = (await this.deps.routingApi?.getWorkspaceDefaults(params.workspace.workspaceId)) ?? [];
|
|
247
|
+
const globalDefaults = (await this.deps.routingApi?.getWorkspaceDefaults("__GLOBAL__")) ?? [];
|
|
248
|
+
const findDefault = (defaults: RoutingDefaults, command: string) =>
|
|
249
|
+
defaults.find((d) => this.normalizeCommand(d.commandName) === command);
|
|
250
|
+
const candidates = [
|
|
251
|
+
findDefault(workspaceDefaults, normalizedCommand),
|
|
252
|
+
findDefault(globalDefaults, normalizedCommand),
|
|
253
|
+
findDefault(workspaceDefaults, "default"),
|
|
254
|
+
findDefault(globalDefaults, "default"),
|
|
255
|
+
].filter(Boolean) as RoutingDefaults;
|
|
256
|
+
|
|
257
|
+
let chosen:
|
|
258
|
+
| { agentId: string; source: RoutingProvenance; qaProfile?: string; docdexScope?: string }
|
|
259
|
+
| undefined;
|
|
260
|
+
let capabilities: string[] = [];
|
|
261
|
+
let agent: Agent | undefined;
|
|
262
|
+
for (const candidate of candidates) {
|
|
263
|
+
const source =
|
|
264
|
+
candidate.workspaceId === "__GLOBAL__"
|
|
265
|
+
? ("global_default" as RoutingProvenance)
|
|
266
|
+
: ("workspace_default" as RoutingProvenance);
|
|
267
|
+
const resolvedAgent = await this.fetchAgent(candidate.agentId);
|
|
268
|
+
const caps = await this.fetchCapabilities(resolvedAgent);
|
|
269
|
+
const missingFallback = requiredCaps.filter((cap) => !caps.includes(cap));
|
|
270
|
+
if (missingFallback.length === 0) {
|
|
271
|
+
chosen = { agentId: resolvedAgent.id, source, qaProfile: candidate.qaProfile, docdexScope: candidate.docdexScope };
|
|
272
|
+
capabilities = caps;
|
|
273
|
+
agent = resolvedAgent;
|
|
274
|
+
const health = await fillHealth(resolvedAgent.id);
|
|
275
|
+
if (health?.status === "unreachable") {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (!chosen || !agent) return null;
|
|
282
|
+
const health = await fillHealth(agent.id);
|
|
283
|
+
const preview: RoutingPreview = {
|
|
284
|
+
workspaceId: params.workspace.workspaceId,
|
|
285
|
+
commandName: normalizedCommand,
|
|
286
|
+
resolvedAgent: { ...agent, capabilities, health },
|
|
287
|
+
provenance: chosen.source,
|
|
288
|
+
requiredCapabilities: requiredCaps,
|
|
289
|
+
candidates: [
|
|
290
|
+
{
|
|
291
|
+
agent: { ...agent, capabilities, health },
|
|
292
|
+
agentId: agent.id,
|
|
293
|
+
agentSlug: agent.slug,
|
|
294
|
+
source: chosen.source,
|
|
295
|
+
capabilities,
|
|
296
|
+
health,
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
agent,
|
|
302
|
+
agentId: agent.id,
|
|
303
|
+
agentSlug: agent.slug,
|
|
304
|
+
model: agent.defaultModel,
|
|
305
|
+
capabilities,
|
|
306
|
+
healthStatus: health?.status ?? "unknown",
|
|
307
|
+
source: chosen.source,
|
|
308
|
+
routingPreview: preview,
|
|
309
|
+
requiredCapabilities: requiredCaps,
|
|
310
|
+
qaProfile: chosen.qaProfile,
|
|
311
|
+
docdexScope: chosen.docdexScope,
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
if (this.deps.routingApi) {
|
|
316
|
+
const preview = await this.deps.routingApi.preview(this.buildPreviewRequest(params));
|
|
317
|
+
if (!preview || !preview.resolvedAgent) {
|
|
318
|
+
throw new Error(`Routing preview did not return a resolved agent for ${normalizedCommand}`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const resolvedAgent = preview.resolvedAgent;
|
|
322
|
+
const previewCandidate =
|
|
323
|
+
preview.candidates?.find((c) => c.agentId === resolvedAgent.id || c.agentSlug === resolvedAgent.slug) ??
|
|
324
|
+
undefined;
|
|
325
|
+
let capabilities =
|
|
326
|
+
previewCandidate?.capabilities ?? preview.resolvedAgent.capabilities ?? preview.requiredCapabilities ?? [];
|
|
327
|
+
if (!capabilities.length) {
|
|
328
|
+
capabilities = await this.fetchCapabilities(resolvedAgent);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const missing = requiredCaps.filter((cap) => !capabilities.includes(cap));
|
|
332
|
+
if (missing.length > 0) {
|
|
333
|
+
if (params.overrideAgentSlug) {
|
|
334
|
+
// try fetching full capabilities when override was provided as slug
|
|
335
|
+
const overrideAgent = await this.fetchAgent(params.overrideAgentSlug);
|
|
336
|
+
const overrideCaps = await this.fetchCapabilities(overrideAgent);
|
|
337
|
+
const overrideMissing = requiredCaps.filter((cap) => !overrideCaps.includes(cap));
|
|
338
|
+
if (overrideMissing.length === 0) {
|
|
339
|
+
const health = await fillHealth(overrideAgent.id, previewCandidate?.health as AgentHealth | undefined);
|
|
340
|
+
return {
|
|
341
|
+
agent: overrideAgent,
|
|
342
|
+
agentId: overrideAgent.id,
|
|
343
|
+
agentSlug: overrideAgent.slug,
|
|
344
|
+
model: overrideAgent.defaultModel,
|
|
345
|
+
capabilities: overrideCaps,
|
|
346
|
+
healthStatus: health?.status ?? "unknown",
|
|
347
|
+
source: "override",
|
|
348
|
+
routingPreview: preview,
|
|
349
|
+
requiredCapabilities: requiredCaps,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const fallback = await fallbackFromDefaults();
|
|
354
|
+
if (fallback) {
|
|
355
|
+
return fallback;
|
|
356
|
+
}
|
|
357
|
+
throw new Error(
|
|
358
|
+
`Resolved agent ${resolvedAgent.slug} is missing required capabilities for ${normalizedCommand}: ${missing.join(", ")}`,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const health = (previewCandidate?.health as AgentHealth | undefined) ?? preview.resolvedAgent.health;
|
|
363
|
+
const finalHealth = await fillHealth(resolvedAgent.id, health);
|
|
364
|
+
const healthStatus = finalHealth?.status ?? health?.status ?? "unknown";
|
|
365
|
+
|
|
366
|
+
if (healthStatus === "unreachable") {
|
|
367
|
+
const fallback = await fallbackFromDefaults();
|
|
368
|
+
if (fallback) return fallback;
|
|
369
|
+
throw new Error(`Resolved agent ${resolvedAgent.slug} is unreachable`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
agent: resolvedAgent,
|
|
374
|
+
agentId: resolvedAgent.id,
|
|
375
|
+
agentSlug: resolvedAgent.slug,
|
|
376
|
+
model: resolvedAgent.defaultModel,
|
|
377
|
+
capabilities,
|
|
378
|
+
healthStatus,
|
|
379
|
+
source: preview.provenance ?? (params.overrideAgentSlug ? "override" : "workspace_default"),
|
|
380
|
+
routingPreview: preview,
|
|
381
|
+
qaProfile: preview.qaProfile,
|
|
382
|
+
docdexScope: preview.docdexScope,
|
|
383
|
+
requiredCapabilities: requiredCaps,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (!this.deps.globalRepo) {
|
|
388
|
+
throw new Error("Routing is unavailable without a routing API or global repository");
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const workspaceDefaults = await this.deps.globalRepo.getWorkspaceDefaults(params.workspace.workspaceId);
|
|
392
|
+
const globalDefaults = await this.deps.globalRepo.getWorkspaceDefaults("__GLOBAL__");
|
|
393
|
+
|
|
394
|
+
const findDefault = (defaults: RoutingDefaults, command: string) =>
|
|
395
|
+
defaults.find((d) => this.normalizeCommand(d.commandName) === command);
|
|
396
|
+
const commandDefault = findDefault(workspaceDefaults, normalizedCommand) ?? findDefault(globalDefaults, normalizedCommand);
|
|
397
|
+
const genericDefault = findDefault(workspaceDefaults, "default") ?? findDefault(globalDefaults, "default");
|
|
398
|
+
|
|
399
|
+
const selected: { agentId: string; source: RoutingProvenance; qaProfile?: string; docdexScope?: string } | undefined =
|
|
400
|
+
params.overrideAgentSlug != null
|
|
401
|
+
? { agentId: params.overrideAgentSlug, source: "override" as RoutingProvenance }
|
|
402
|
+
: commandDefault
|
|
403
|
+
? { agentId: commandDefault.agentId, source: commandDefault.workspaceId === "__GLOBAL__" ? "global_default" : "workspace_default", qaProfile: commandDefault.qaProfile, docdexScope: commandDefault.docdexScope }
|
|
404
|
+
: genericDefault
|
|
405
|
+
? {
|
|
406
|
+
agentId: genericDefault.agentId,
|
|
407
|
+
source: genericDefault.workspaceId === "__GLOBAL__" ? "global_default" : "workspace_default",
|
|
408
|
+
qaProfile: genericDefault.qaProfile,
|
|
409
|
+
docdexScope: genericDefault.docdexScope,
|
|
410
|
+
}
|
|
411
|
+
: undefined;
|
|
412
|
+
|
|
413
|
+
if (!selected) {
|
|
414
|
+
throw new Error(`No routing defaults found for command ${normalizedCommand}`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const agent = await this.fetchAgent(selected.agentId);
|
|
418
|
+
const capabilities = await this.fetchCapabilities(agent);
|
|
419
|
+
const missing = requiredCaps.filter((cap) => !capabilities.includes(cap));
|
|
420
|
+
if (missing.length) {
|
|
421
|
+
throw new Error(
|
|
422
|
+
`Resolved agent ${agent.slug} is missing required capabilities for ${normalizedCommand}: ${missing.join(", ")}`,
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const health = await this.deps.globalRepo.getAgentHealth(agent.id);
|
|
427
|
+
const preview: RoutingPreview = {
|
|
428
|
+
workspaceId: params.workspace.workspaceId,
|
|
429
|
+
commandName: normalizedCommand,
|
|
430
|
+
resolvedAgent: { ...agent, capabilities, health },
|
|
431
|
+
provenance: selected.source,
|
|
432
|
+
requiredCapabilities: requiredCaps,
|
|
433
|
+
qaProfile: selected.qaProfile,
|
|
434
|
+
docdexScope: selected.docdexScope,
|
|
435
|
+
candidates: [
|
|
436
|
+
{
|
|
437
|
+
agent: { ...agent, capabilities, health },
|
|
438
|
+
agentId: agent.id,
|
|
439
|
+
agentSlug: agent.slug,
|
|
440
|
+
source: selected.source,
|
|
441
|
+
capabilities,
|
|
442
|
+
health,
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
return {
|
|
448
|
+
agent,
|
|
449
|
+
agentId: agent.id,
|
|
450
|
+
agentSlug: agent.slug,
|
|
451
|
+
model: agent.defaultModel,
|
|
452
|
+
capabilities,
|
|
453
|
+
healthStatus: health?.status ?? "unknown",
|
|
454
|
+
source: selected.source,
|
|
455
|
+
routingPreview: preview,
|
|
456
|
+
qaProfile: selected.qaProfile,
|
|
457
|
+
docdexScope: selected.docdexScope,
|
|
458
|
+
requiredCapabilities: requiredCaps,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { WorkspaceResolver } from "../../../workspace/WorkspaceManager.js";
|
|
7
|
+
import { GatewayAgentService } from "../GatewayAgentService.js";
|
|
8
|
+
|
|
9
|
+
test("GatewayAgentService returns analysis and agent decision", async () => {
|
|
10
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "mcoda-gateway-"));
|
|
11
|
+
const workspace = await WorkspaceResolver.resolveWorkspace({ cwd: dir, explicitWorkspace: dir });
|
|
12
|
+
|
|
13
|
+
const agent = { id: "agent-1", slug: "agent-1", adapter: "local", defaultModel: "stub", rating: 6, reasoningRating: 6 };
|
|
14
|
+
const service = new (GatewayAgentService as any)(workspace, {
|
|
15
|
+
agentService: {
|
|
16
|
+
getPrompts: async () => ({
|
|
17
|
+
jobPrompt: "Job",
|
|
18
|
+
characterPrompt: "Char",
|
|
19
|
+
commandPrompts: { "gateway-agent": "Prompt" },
|
|
20
|
+
}),
|
|
21
|
+
invoke: async () => ({
|
|
22
|
+
output: JSON.stringify({
|
|
23
|
+
summary: "Update docs",
|
|
24
|
+
reasoningSummary: "Docs work",
|
|
25
|
+
currentState: "Unknown",
|
|
26
|
+
todo: "Update README",
|
|
27
|
+
understanding: "Docs updated",
|
|
28
|
+
plan: ["Review", "Edit", "Verify"],
|
|
29
|
+
complexity: 3,
|
|
30
|
+
discipline: "docs",
|
|
31
|
+
filesLikelyTouched: ["README.md"],
|
|
32
|
+
filesToCreate: [],
|
|
33
|
+
assumptions: [],
|
|
34
|
+
risks: [],
|
|
35
|
+
docdexNotes: ["No matching docs"],
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
docdex: { search: async () => [] },
|
|
40
|
+
globalRepo: {
|
|
41
|
+
listAgents: async () => [agent],
|
|
42
|
+
listAgentHealthSummary: async () => [{ agentId: agent.id, status: "healthy" }],
|
|
43
|
+
getAgentCapabilities: async () => ["plan", "docdex_query", "code_write"],
|
|
44
|
+
},
|
|
45
|
+
jobService: {
|
|
46
|
+
startCommandRun: async () => ({ id: "run-1" }),
|
|
47
|
+
recordTokenUsage: async () => {},
|
|
48
|
+
finishCommandRun: async () => {},
|
|
49
|
+
},
|
|
50
|
+
workspaceRepo: {},
|
|
51
|
+
routingService: {
|
|
52
|
+
resolveAgentForCommand: async () => ({ agent }),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const result = await service.run({
|
|
58
|
+
workspace,
|
|
59
|
+
job: "work-on-tasks",
|
|
60
|
+
inputText: "Update README",
|
|
61
|
+
agentStream: false,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
assert.equal(result.job, "work-on-tasks");
|
|
65
|
+
assert.equal(result.gatewayAgent.id, agent.id);
|
|
66
|
+
assert.equal(result.analysis.discipline, "docs");
|
|
67
|
+
assert.equal(result.chosenAgent.agentId, agent.id);
|
|
68
|
+
} finally {
|
|
69
|
+
await service.close();
|
|
70
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
71
|
+
}
|
|
72
|
+
});
|