mcoda 0.1.2 → 0.1.4
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/CHANGELOG.md +2 -2
- package/README.md +9 -300
- package/dist/bin/McodaEntrypoint.d.ts +5 -0
- package/dist/bin/McodaEntrypoint.d.ts.map +1 -0
- package/dist/bin/McodaEntrypoint.js +175 -0
- package/dist/commands/agents/AgentsCommands.d.ts +4 -0
- package/dist/commands/agents/AgentsCommands.d.ts.map +1 -0
- package/dist/commands/agents/AgentsCommands.js +376 -0
- package/dist/commands/agents/GatewayAgentCommand.d.ts +4 -0
- package/dist/commands/agents/GatewayAgentCommand.d.ts.map +1 -0
- package/dist/commands/agents/GatewayAgentCommand.js +583 -0
- package/dist/commands/agents/TestAgentCommand.d.ts +4 -0
- package/dist/commands/agents/TestAgentCommand.d.ts.map +1 -0
- package/dist/commands/agents/TestAgentCommand.js +57 -0
- package/dist/commands/backlog/BacklogCommands.d.ts +17 -0
- package/dist/commands/backlog/BacklogCommands.d.ts.map +1 -0
- package/dist/commands/backlog/BacklogCommands.js +260 -0
- package/dist/commands/backlog/OrderTasksCommand.d.ts +16 -0
- package/dist/commands/backlog/OrderTasksCommand.d.ts.map +1 -0
- package/dist/commands/backlog/OrderTasksCommand.js +211 -0
- package/dist/commands/backlog/TaskShowCommands.d.ts +16 -0
- package/dist/commands/backlog/TaskShowCommands.d.ts.map +1 -0
- package/dist/commands/backlog/TaskShowCommands.js +275 -0
- package/dist/commands/docs/DocsCommands.d.ts +37 -0
- package/dist/commands/docs/DocsCommands.d.ts.map +1 -0
- package/dist/commands/docs/DocsCommands.js +381 -0
- package/dist/commands/estimate/EstimateCommands.d.ts +24 -0
- package/dist/commands/estimate/EstimateCommands.d.ts.map +1 -0
- package/dist/commands/estimate/EstimateCommands.js +259 -0
- package/dist/commands/jobs/JobsCommands.d.ts +24 -0
- package/dist/commands/jobs/JobsCommands.d.ts.map +1 -0
- package/dist/commands/jobs/JobsCommands.js +535 -0
- package/dist/commands/openapi/OpenapiCommands.d.ts +14 -0
- package/dist/commands/openapi/OpenapiCommands.d.ts.map +1 -0
- package/dist/commands/openapi/OpenapiCommands.js +157 -0
- package/dist/commands/planning/CreateTasksCommand.d.ts +17 -0
- package/dist/commands/planning/CreateTasksCommand.d.ts.map +1 -0
- package/dist/commands/planning/CreateTasksCommand.js +134 -0
- package/dist/commands/planning/MigrateTasksCommand.d.ts +15 -0
- package/dist/commands/planning/MigrateTasksCommand.d.ts.map +1 -0
- package/dist/commands/planning/MigrateTasksCommand.js +95 -0
- package/dist/commands/planning/PlanningCommands.d.ts +3 -0
- package/dist/commands/planning/PlanningCommands.d.ts.map +1 -0
- package/dist/commands/planning/PlanningCommands.js +2 -0
- package/dist/commands/planning/QaTasksCommand.d.ts +30 -0
- package/dist/commands/planning/QaTasksCommand.d.ts.map +1 -0
- package/dist/commands/planning/QaTasksCommand.js +293 -0
- package/dist/commands/planning/RefineTasksCommand.d.ts +30 -0
- package/dist/commands/planning/RefineTasksCommand.d.ts.map +1 -0
- package/dist/commands/planning/RefineTasksCommand.js +365 -0
- package/dist/commands/review/CodeReviewCommand.d.ts +21 -0
- package/dist/commands/review/CodeReviewCommand.d.ts.map +1 -0
- package/dist/commands/review/CodeReviewCommand.js +236 -0
- package/dist/commands/routing/RoutingCommands.d.ts +7 -0
- package/dist/commands/routing/RoutingCommands.d.ts.map +1 -0
- package/dist/commands/routing/RoutingCommands.js +484 -0
- package/dist/commands/telemetry/TelemetryCommands.d.ts +26 -0
- package/dist/commands/telemetry/TelemetryCommands.d.ts.map +1 -0
- package/dist/commands/telemetry/TelemetryCommands.js +313 -0
- package/dist/commands/update/UpdateCommands.d.ts +4 -0
- package/dist/commands/update/UpdateCommands.d.ts.map +1 -0
- package/dist/commands/update/UpdateCommands.js +280 -0
- package/dist/commands/work/WorkOnTasksCommand.d.ts +21 -0
- package/dist/commands/work/WorkOnTasksCommand.d.ts.map +1 -0
- package/dist/commands/work/WorkOnTasksCommand.js +238 -0
- package/dist/commands/workspace/SetWorkspaceCommand.d.ts +9 -0
- package/dist/commands/workspace/SetWorkspaceCommand.d.ts.map +1 -0
- package/dist/commands/workspace/SetWorkspaceCommand.js +128 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +31 -16
- package/.editorconfig +0 -9
- package/.eslintrc.cjs +0 -12
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -29
- package/.github/ISSUE_TEMPLATE/config.yml +0 -5
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -19
- package/.github/workflows/ci.yml +0 -37
- package/.github/workflows/nightly.yml +0 -38
- package/.github/workflows/release-dry-run.yml +0 -40
- package/.github/workflows/release-please.yml +0 -22
- package/.github/workflows/release.yml +0 -139
- package/.prettierrc +0 -5
- package/.release-please-manifest.json +0 -8
- package/CLA.md +0 -42
- package/CONTRIBUTING.md +0 -38
- package/docs/oss_publishing_plan.md +0 -41
- package/docs/pdr/.gitkeep +0 -0
- package/docs/quality_gates.md +0 -32
- package/docs/rfp/.gitkeep +0 -0
- package/docs/sds/sds.md +0 -11963
- package/docs/usage.md +0 -72
- package/openapi/gen-openapi.ts +0 -1
- package/openapi/generated/clients/.gitkeep +0 -0
- package/openapi/generated/types/.gitkeep +0 -0
- package/openapi/generated/types/index.ts +0 -118
- package/openapi/mcoda.yaml +0 -2063
- package/pack-mcoda.sh +0 -88
- package/packages/agents/CHANGELOG.md +0 -7
- package/packages/agents/LICENSE +0 -21
- package/packages/agents/README.md +0 -9
- package/packages/agents/package.json +0 -41
- package/packages/agents/src/AgentService/.gitkeep +0 -0
- package/packages/agents/src/AgentService/AgentService.d.ts +0 -21
- package/packages/agents/src/AgentService/AgentService.d.ts.map +0 -1
- package/packages/agents/src/AgentService/AgentService.js +0 -141
- package/packages/agents/src/AgentService/AgentService.ts +0 -308
- package/packages/agents/src/__tests__/AgentService.test.ts +0 -284
- package/packages/agents/src/adapters/AdapterTypes.d.ts +0 -29
- package/packages/agents/src/adapters/AdapterTypes.d.ts.map +0 -1
- package/packages/agents/src/adapters/AdapterTypes.js +0 -1
- package/packages/agents/src/adapters/AdapterTypes.ts +0 -32
- package/packages/agents/src/adapters/codex/.gitkeep +0 -0
- package/packages/agents/src/adapters/codex/CodexAdapter.d.ts +0 -11
- package/packages/agents/src/adapters/codex/CodexAdapter.d.ts.map +0 -1
- package/packages/agents/src/adapters/codex/CodexAdapter.js +0 -43
- package/packages/agents/src/adapters/codex/CodexAdapter.ts +0 -63
- package/packages/agents/src/adapters/codex/CodexCliRunner.ts +0 -154
- package/packages/agents/src/adapters/gemini/.gitkeep +0 -0
- package/packages/agents/src/adapters/gemini/GeminiAdapter.d.ts +0 -11
- package/packages/agents/src/adapters/gemini/GeminiAdapter.d.ts.map +0 -1
- package/packages/agents/src/adapters/gemini/GeminiAdapter.js +0 -42
- package/packages/agents/src/adapters/gemini/GeminiAdapter.ts +0 -58
- package/packages/agents/src/adapters/gemini/GeminiCliRunner.ts +0 -75
- package/packages/agents/src/adapters/local/.gitkeep +0 -0
- package/packages/agents/src/adapters/local/LocalAdapter.d.ts +0 -11
- package/packages/agents/src/adapters/local/LocalAdapter.d.ts.map +0 -1
- package/packages/agents/src/adapters/local/LocalAdapter.js +0 -38
- package/packages/agents/src/adapters/local/LocalAdapter.ts +0 -43
- package/packages/agents/src/adapters/ollama/OllamaCliAdapter.ts +0 -58
- package/packages/agents/src/adapters/ollama/OllamaCliRunner.ts +0 -70
- package/packages/agents/src/adapters/ollama/OllamaRemoteAdapter.ts +0 -205
- package/packages/agents/src/adapters/openai/.gitkeep +0 -0
- package/packages/agents/src/adapters/openai/OpenAiAdapter.d.ts +0 -11
- package/packages/agents/src/adapters/openai/OpenAiAdapter.d.ts.map +0 -1
- package/packages/agents/src/adapters/openai/OpenAiAdapter.js +0 -51
- package/packages/agents/src/adapters/openai/OpenAiAdapter.ts +0 -56
- package/packages/agents/src/adapters/openai/OpenAiCliAdapter.ts +0 -62
- package/packages/agents/src/adapters/qa/.gitkeep +0 -0
- package/packages/agents/src/adapters/qa/QaAdapter.d.ts +0 -11
- package/packages/agents/src/adapters/qa/QaAdapter.d.ts.map +0 -1
- package/packages/agents/src/adapters/qa/QaAdapter.js +0 -37
- package/packages/agents/src/adapters/qa/QaAdapter.ts +0 -42
- package/packages/agents/src/adapters/zhipu/ZhipuApiAdapter.ts +0 -273
- package/packages/agents/src/index.d.ts +0 -8
- package/packages/agents/src/index.d.ts.map +0 -1
- package/packages/agents/src/index.js +0 -7
- package/packages/agents/src/index.ts +0 -11
- package/packages/agents/tsconfig.json +0 -14
- package/packages/cli/CHANGELOG.md +0 -7
- package/packages/cli/LICENSE +0 -21
- package/packages/cli/README.md +0 -23
- package/packages/cli/package.json +0 -61
- package/packages/cli/src/__tests__/AgentsCommands.test.ts +0 -137
- package/packages/cli/src/__tests__/BacklogCommands.test.ts +0 -40
- package/packages/cli/src/__tests__/CodeReviewCommand.test.ts +0 -594
- package/packages/cli/src/__tests__/CreateTasksCommand.test.ts +0 -40
- package/packages/cli/src/__tests__/DocsCommands.test.ts +0 -41
- package/packages/cli/src/__tests__/EstimateCommands.test.ts +0 -54
- package/packages/cli/src/__tests__/JobsCommands.behavior.test.ts +0 -311
- package/packages/cli/src/__tests__/JobsCommands.test.ts +0 -49
- package/packages/cli/src/__tests__/MigrateTasksCommand.test.ts +0 -36
- package/packages/cli/src/__tests__/OpenapiCommands.test.ts +0 -34
- package/packages/cli/src/__tests__/OrderTasksCommand.test.ts +0 -150
- package/packages/cli/src/__tests__/PlanningCommands.test.ts +0 -9
- package/packages/cli/src/__tests__/QaTasksCommand.test.ts +0 -58
- package/packages/cli/src/__tests__/RefineTasksCommand.test.ts +0 -63
- package/packages/cli/src/__tests__/RoutingCommands.test.ts +0 -302
- package/packages/cli/src/__tests__/SetWorkspaceCommand.test.ts +0 -18
- package/packages/cli/src/__tests__/TaskShowCommands.test.ts +0 -130
- package/packages/cli/src/__tests__/TelemetryCommands.test.ts +0 -35
- package/packages/cli/src/__tests__/TestAgentCommand.test.ts +0 -41
- package/packages/cli/src/__tests__/UpdateCommands.test.ts +0 -292
- package/packages/cli/src/__tests__/WorkOnTasksCommand.test.ts +0 -42
- package/packages/cli/src/bin/.gitkeep +0 -0
- package/packages/cli/src/bin/McodaEntrypoint.ts +0 -180
- package/packages/cli/src/commands/agents/.gitkeep +0 -0
- package/packages/cli/src/commands/agents/AgentsCommands.ts +0 -374
- package/packages/cli/src/commands/agents/GatewayAgentCommand.ts +0 -621
- package/packages/cli/src/commands/agents/TestAgentCommand.ts +0 -63
- package/packages/cli/src/commands/backlog/.gitkeep +0 -0
- package/packages/cli/src/commands/backlog/BacklogCommands.ts +0 -286
- package/packages/cli/src/commands/backlog/OrderTasksCommand.ts +0 -237
- package/packages/cli/src/commands/backlog/TaskShowCommands.ts +0 -289
- package/packages/cli/src/commands/docs/.gitkeep +0 -0
- package/packages/cli/src/commands/docs/DocsCommands.ts +0 -413
- package/packages/cli/src/commands/estimate/EstimateCommands.ts +0 -290
- package/packages/cli/src/commands/jobs/.gitkeep +0 -0
- package/packages/cli/src/commands/jobs/JobsCommands.ts +0 -595
- package/packages/cli/src/commands/openapi/OpenapiCommands.ts +0 -167
- package/packages/cli/src/commands/planning/.gitkeep +0 -0
- package/packages/cli/src/commands/planning/CreateTasksCommand.ts +0 -149
- package/packages/cli/src/commands/planning/MigrateTasksCommand.ts +0 -105
- package/packages/cli/src/commands/planning/PlanningCommands.ts +0 -1
- package/packages/cli/src/commands/planning/QaTasksCommand.ts +0 -320
- package/packages/cli/src/commands/planning/RefineTasksCommand.ts +0 -408
- package/packages/cli/src/commands/review/CodeReviewCommand.ts +0 -262
- package/packages/cli/src/commands/routing/.gitkeep +0 -0
- package/packages/cli/src/commands/routing/RoutingCommands.ts +0 -554
- package/packages/cli/src/commands/telemetry/.gitkeep +0 -0
- package/packages/cli/src/commands/telemetry/TelemetryCommands.ts +0 -348
- package/packages/cli/src/commands/update/.gitkeep +0 -0
- package/packages/cli/src/commands/update/UpdateCommands.ts +0 -301
- package/packages/cli/src/commands/work/WorkOnTasksCommand.ts +0 -264
- package/packages/cli/src/commands/workspace/SetWorkspaceCommand.ts +0 -132
- package/packages/cli/test/packaging_guardrails.test.js +0 -75
- package/packages/cli/tsconfig.json +0 -20
- package/packages/core/CHANGELOG.md +0 -7
- package/packages/core/LICENSE +0 -21
- package/packages/core/README.md +0 -9
- package/packages/core/package.json +0 -45
- package/packages/core/src/__tests__/SmokeClasses.test.ts +0 -32
- package/packages/core/src/api/AgentsApi.ts +0 -219
- package/packages/core/src/api/QaTasksApi.ts +0 -38
- package/packages/core/src/api/TasksApi.ts +0 -35
- package/packages/core/src/api/__tests__/AgentsApi.test.ts +0 -203
- package/packages/core/src/api/__tests__/QaTasksApi.test.ts +0 -51
- package/packages/core/src/api/__tests__/TasksApi.test.ts +0 -56
- package/packages/core/src/config/.gitkeep +0 -0
- package/packages/core/src/config/ConfigService.ts +0 -1
- package/packages/core/src/domain/dependencies/.gitkeep +0 -0
- package/packages/core/src/domain/dependencies/Dependency.ts +0 -1
- package/packages/core/src/domain/epics/.gitkeep +0 -0
- package/packages/core/src/domain/epics/Epic.ts +0 -1
- package/packages/core/src/domain/projects/.gitkeep +0 -0
- package/packages/core/src/domain/projects/Project.ts +0 -1
- package/packages/core/src/domain/tasks/.gitkeep +0 -0
- package/packages/core/src/domain/tasks/Task.ts +0 -1
- package/packages/core/src/domain/userStories/.gitkeep +0 -0
- package/packages/core/src/domain/userStories/UserStory.ts +0 -1
- package/packages/core/src/index.ts +0 -27
- package/packages/core/src/prompts/.gitkeep +0 -0
- package/packages/core/src/prompts/PdrPrompts.ts +0 -23
- package/packages/core/src/prompts/PromptLoader.ts +0 -1
- package/packages/core/src/prompts/SdsPrompts.ts +0 -47
- package/packages/core/src/services/agents/.gitkeep +0 -0
- package/packages/core/src/services/agents/AgentManagementService.ts +0 -1
- package/packages/core/src/services/agents/GatewayAgentService.ts +0 -956
- package/packages/core/src/services/agents/RoutingService.ts +0 -461
- package/packages/core/src/services/agents/__tests__/GatewayAgentService.test.ts +0 -72
- package/packages/core/src/services/agents/__tests__/RoutingService.test.ts +0 -267
- package/packages/core/src/services/agents/generated/RoutingApiClient.ts +0 -89
- package/packages/core/src/services/backlog/.gitkeep +0 -0
- package/packages/core/src/services/backlog/BacklogService.ts +0 -580
- package/packages/core/src/services/backlog/TaskOrderingService.ts +0 -868
- package/packages/core/src/services/backlog/__tests__/BacklogService.test.ts +0 -219
- package/packages/core/src/services/backlog/__tests__/TaskOrderingService.test.ts +0 -268
- package/packages/core/src/services/docs/.gitkeep +0 -0
- package/packages/core/src/services/docs/DocsService.ts +0 -1913
- package/packages/core/src/services/docs/__tests__/DocsService.test.ts +0 -350
- package/packages/core/src/services/estimate/EstimateService.ts +0 -111
- package/packages/core/src/services/estimate/VelocityService.ts +0 -272
- package/packages/core/src/services/estimate/__tests__/VelocityAndEstimate.test.ts +0 -209
- package/packages/core/src/services/estimate/types.ts +0 -41
- package/packages/core/src/services/execution/.gitkeep +0 -0
- package/packages/core/src/services/execution/ExecutionService.ts +0 -1
- package/packages/core/src/services/execution/QaFollowupService.ts +0 -289
- package/packages/core/src/services/execution/QaProfileService.ts +0 -160
- package/packages/core/src/services/execution/QaTasksService.ts +0 -1303
- package/packages/core/src/services/execution/TaskSelectionService.ts +0 -362
- package/packages/core/src/services/execution/TaskStateService.ts +0 -64
- package/packages/core/src/services/execution/WorkOnTasksService.ts +0 -2023
- package/packages/core/src/services/execution/__tests__/QaFollowupService.test.ts +0 -58
- package/packages/core/src/services/execution/__tests__/QaProfileService.test.ts +0 -49
- package/packages/core/src/services/execution/__tests__/QaTasksService.test.ts +0 -157
- package/packages/core/src/services/execution/__tests__/TaskSelectionService.test.ts +0 -179
- package/packages/core/src/services/execution/__tests__/TaskStateService.test.ts +0 -51
- package/packages/core/src/services/execution/__tests__/WorkOnTasksService.test.ts +0 -285
- package/packages/core/src/services/jobs/.gitkeep +0 -0
- package/packages/core/src/services/jobs/JobInsightsService.ts +0 -355
- package/packages/core/src/services/jobs/JobResumeService.ts +0 -119
- package/packages/core/src/services/jobs/JobService.ts +0 -648
- package/packages/core/src/services/jobs/JobsApiClient.ts +0 -113
- package/packages/core/src/services/jobs/__tests__/JobInsightsService.test.ts +0 -17
- package/packages/core/src/services/jobs/__tests__/JobResumeService.test.ts +0 -45
- package/packages/core/src/services/jobs/__tests__/JobService.test.ts +0 -44
- package/packages/core/src/services/openapi/OpenApiService.ts +0 -558
- package/packages/core/src/services/openapi/__tests__/OpenApiService.test.ts +0 -57
- package/packages/core/src/services/planning/.gitkeep +0 -0
- package/packages/core/src/services/planning/CreateTasksService.ts +0 -1280
- package/packages/core/src/services/planning/KeyHelpers.ts +0 -80
- package/packages/core/src/services/planning/PlanningService.ts +0 -1
- package/packages/core/src/services/planning/RefineTasksService.ts +0 -1552
- package/packages/core/src/services/planning/__tests__/CreateTasksService.test.ts +0 -288
- package/packages/core/src/services/planning/__tests__/KeyHelpers.test.ts +0 -16
- package/packages/core/src/services/planning/__tests__/RefineTasksService.test.ts +0 -172
- package/packages/core/src/services/review/CodeReviewService.ts +0 -1386
- package/packages/core/src/services/review/__tests__/CodeReviewService.test.ts +0 -89
- package/packages/core/src/services/system/SystemUpdateService.ts +0 -177
- package/packages/core/src/services/system/__tests__/SystemUpdateService.test.ts +0 -40
- package/packages/core/src/services/tasks/TaskApiResolver.ts +0 -37
- package/packages/core/src/services/tasks/TaskDetailService.ts +0 -494
- package/packages/core/src/services/tasks/__tests__/TaskApiResolver.test.ts +0 -41
- package/packages/core/src/services/tasks/__tests__/TaskDetailService.test.ts +0 -178
- package/packages/core/src/services/telemetry/.gitkeep +0 -0
- package/packages/core/src/services/telemetry/TelemetryService.ts +0 -515
- package/packages/core/src/services/telemetry/__tests__/TelemetryService.test.ts +0 -160
- package/packages/core/src/workspace/.gitkeep +0 -0
- package/packages/core/src/workspace/WorkspaceManager.ts +0 -234
- package/packages/core/tsconfig.json +0 -20
- package/packages/db/CHANGELOG.md +0 -7
- package/packages/db/LICENSE +0 -21
- package/packages/db/README.md +0 -9
- package/packages/db/package.json +0 -42
- package/packages/db/src/__tests__/GlobalRepository.test.ts +0 -109
- package/packages/db/src/__tests__/SchemaAlignment.test.ts +0 -80
- package/packages/db/src/__tests__/WorkspaceRepository.test.ts +0 -19
- package/packages/db/src/index.d.ts +0 -6
- package/packages/db/src/index.d.ts.map +0 -1
- package/packages/db/src/index.js +0 -5
- package/packages/db/src/index.ts +0 -6
- package/packages/db/src/migrations/global/.gitkeep +0 -0
- package/packages/db/src/migrations/global/GlobalMigrations.d.ts +0 -9
- package/packages/db/src/migrations/global/GlobalMigrations.d.ts.map +0 -1
- package/packages/db/src/migrations/global/GlobalMigrations.js +0 -68
- package/packages/db/src/migrations/global/GlobalMigrations.ts +0 -336
- package/packages/db/src/migrations/workspace/.gitkeep +0 -0
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.d.ts +0 -9
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.d.ts.map +0 -1
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.js +0 -251
- package/packages/db/src/migrations/workspace/WorkspaceMigrations.ts +0 -248
- package/packages/db/src/repositories/global/.gitkeep +0 -0
- package/packages/db/src/repositories/global/GlobalRepository.d.ts +0 -30
- package/packages/db/src/repositories/global/GlobalRepository.d.ts.map +0 -1
- package/packages/db/src/repositories/global/GlobalRepository.js +0 -209
- package/packages/db/src/repositories/global/GlobalRepository.ts +0 -492
- package/packages/db/src/repositories/workspace/.gitkeep +0 -0
- package/packages/db/src/repositories/workspace/WorkspaceRepository.d.ts +0 -282
- package/packages/db/src/repositories/workspace/WorkspaceRepository.d.ts.map +0 -1
- package/packages/db/src/repositories/workspace/WorkspaceRepository.js +0 -773
- package/packages/db/src/repositories/workspace/WorkspaceRepository.ts +0 -1511
- package/packages/db/src/sqlite/connection.d.ts +0 -11
- package/packages/db/src/sqlite/connection.d.ts.map +0 -1
- package/packages/db/src/sqlite/connection.js +0 -31
- package/packages/db/src/sqlite/connection.ts +0 -35
- package/packages/db/src/sqlite/pragmas.d.ts +0 -5
- package/packages/db/src/sqlite/pragmas.d.ts.map +0 -1
- package/packages/db/src/sqlite/pragmas.js +0 -6
- package/packages/db/src/sqlite/pragmas.ts +0 -10
- package/packages/db/tsconfig.json +0 -13
- package/packages/generators/package.json +0 -21
- package/packages/generators/src/__tests__/Generators.test.ts +0 -19
- package/packages/generators/src/index.ts +0 -1
- package/packages/generators/src/openapi/generateTypes.ts +0 -1
- package/packages/generators/src/openapi/validateSchema.ts +0 -1
- package/packages/generators/src/scaffolding/docs/.gitkeep +0 -0
- package/packages/generators/src/scaffolding/docs/DocsScaffolder.ts +0 -1
- package/packages/generators/src/scaffolding/global/.gitkeep +0 -0
- package/packages/generators/src/scaffolding/global/GlobalScaffolder.ts +0 -1
- package/packages/generators/src/scaffolding/workspace/.gitkeep +0 -0
- package/packages/generators/src/scaffolding/workspace/WorkspaceScaffolder.ts +0 -1
- package/packages/generators/tsconfig.json +0 -10
- package/packages/integrations/CHANGELOG.md +0 -7
- package/packages/integrations/LICENSE +0 -21
- package/packages/integrations/README.md +0 -9
- package/packages/integrations/package.json +0 -47
- package/packages/integrations/src/docdex/.gitkeep +0 -0
- package/packages/integrations/src/docdex/DocdexClient.d.ts +0 -50
- package/packages/integrations/src/docdex/DocdexClient.d.ts.map +0 -1
- package/packages/integrations/src/docdex/DocdexClient.js +0 -216
- package/packages/integrations/src/docdex/DocdexClient.ts +0 -261
- package/packages/integrations/src/docdex/__tests__/DocdexClient.test.ts +0 -29
- package/packages/integrations/src/index.d.ts +0 -2
- package/packages/integrations/src/index.d.ts.map +0 -1
- package/packages/integrations/src/index.js +0 -4
- package/packages/integrations/src/index.ts +0 -5
- package/packages/integrations/src/issues/.gitkeep +0 -0
- package/packages/integrations/src/issues/IssuesClient.ts +0 -1
- package/packages/integrations/src/issues/__tests__/IssuesClient.test.ts +0 -10
- package/packages/integrations/src/qa/.gitkeep +0 -0
- package/packages/integrations/src/qa/ChromiumQaAdapter.ts +0 -89
- package/packages/integrations/src/qa/CliQaAdapter.ts +0 -95
- package/packages/integrations/src/qa/MaestroQaAdapter.ts +0 -91
- package/packages/integrations/src/qa/QaAdapter.ts +0 -7
- package/packages/integrations/src/qa/QaClient.ts +0 -1
- package/packages/integrations/src/qa/QaTypes.ts +0 -26
- package/packages/integrations/src/qa/__tests__/ChromiumQaAdapter.test.ts +0 -30
- package/packages/integrations/src/qa/__tests__/CliQaAdapter.test.ts +0 -33
- package/packages/integrations/src/qa/__tests__/MaestroQaAdapter.test.ts +0 -30
- package/packages/integrations/src/qa/index.ts +0 -5
- package/packages/integrations/src/system/SystemClient.ts +0 -50
- package/packages/integrations/src/system/__tests__/SystemClient.test.ts +0 -40
- package/packages/integrations/src/telemetry/TelemetryClient.ts +0 -139
- package/packages/integrations/src/telemetry/__tests__/TelemetryClient.test.ts +0 -41
- package/packages/integrations/src/vcs/.gitkeep +0 -0
- package/packages/integrations/src/vcs/VcsClient.ts +0 -211
- package/packages/integrations/src/vcs/__tests__/VcsClient.test.ts +0 -26
- package/packages/integrations/tsconfig.json +0 -14
- package/packages/shared/CHANGELOG.md +0 -7
- package/packages/shared/LICENSE +0 -21
- package/packages/shared/README.md +0 -9
- package/packages/shared/package.json +0 -40
- package/packages/shared/src/__tests__/CommandMetadata.test.ts +0 -15
- package/packages/shared/src/__tests__/ServiceShells.test.ts +0 -16
- package/packages/shared/src/crypto/.gitkeep +0 -0
- package/packages/shared/src/crypto/CryptoHelper.d.ts +0 -15
- package/packages/shared/src/crypto/CryptoHelper.d.ts.map +0 -1
- package/packages/shared/src/crypto/CryptoHelper.js +0 -54
- package/packages/shared/src/crypto/CryptoHelper.ts +0 -57
- package/packages/shared/src/errors/.gitkeep +0 -0
- package/packages/shared/src/errors/ErrorFactory.ts +0 -1
- package/packages/shared/src/index.d.ts +0 -6
- package/packages/shared/src/index.d.ts.map +0 -1
- package/packages/shared/src/index.js +0 -4
- package/packages/shared/src/index.ts +0 -35
- package/packages/shared/src/logging/.gitkeep +0 -0
- package/packages/shared/src/logging/Logger.ts +0 -1
- package/packages/shared/src/metadata/CommandMetadata.ts +0 -165
- package/packages/shared/src/openapi/.gitkeep +0 -0
- package/packages/shared/src/openapi/OpenApiTypes.d.ts +0 -216
- package/packages/shared/src/openapi/OpenApiTypes.d.ts.map +0 -1
- package/packages/shared/src/openapi/OpenApiTypes.js +0 -1
- package/packages/shared/src/openapi/OpenApiTypes.ts +0 -312
- package/packages/shared/src/paths/.gitkeep +0 -0
- package/packages/shared/src/paths/PathHelper.d.ts +0 -12
- package/packages/shared/src/paths/PathHelper.d.ts.map +0 -1
- package/packages/shared/src/paths/PathHelper.js +0 -24
- package/packages/shared/src/paths/PathHelper.ts +0 -29
- package/packages/shared/src/qa/QaProfile.ts +0 -14
- package/packages/shared/src/utils/.gitkeep +0 -0
- package/packages/shared/src/utils/UtilityService.ts +0 -1
- package/packages/shared/tsconfig.json +0 -10
- package/packages/testing/package.json +0 -26
- package/packages/testing/src/__tests__/TestingFakes.test.ts +0 -15
- package/packages/testing/src/cli/e2e/.gitkeep +0 -0
- package/packages/testing/src/cli/e2e/E2eSuite.ts +0 -1
- package/packages/testing/src/fakes/agents/.gitkeep +0 -0
- package/packages/testing/src/fakes/agents/FakeAgents.ts +0 -1
- package/packages/testing/src/fakes/docdex/.gitkeep +0 -0
- package/packages/testing/src/fakes/docdex/FakeDocdexClient.ts +0 -1
- package/packages/testing/src/fakes/qa/.gitkeep +0 -0
- package/packages/testing/src/fakes/qa/FakeQaClient.ts +0 -1
- package/packages/testing/src/fakes/vcs/.gitkeep +0 -0
- package/packages/testing/src/fakes/vcs/FakeVcsClient.ts +0 -1
- package/packages/testing/src/fixtures/db/.gitkeep +0 -0
- package/packages/testing/src/fixtures/db/DbFixtures.ts +0 -1
- package/packages/testing/src/fixtures/workspaces/.gitkeep +0 -0
- package/packages/testing/src/fixtures/workspaces/WorkspaceFixtures.ts +0 -1
- package/packages/testing/src/index.ts +0 -1
- package/packages/testing/tsconfig.json +0 -10
- package/pnpm-workspace.yaml +0 -2
- package/prompts/README.md +0 -5
- package/prompts/code-reviewer.md +0 -23
- package/prompts/code-writer.md +0 -35
- package/prompts/gateway-agent.md +0 -27
- package/prompts/qa-agent.md +0 -21
- package/release-please-config.json +0 -39
- package/scripts/build-all.ts +0 -1
- package/scripts/dev.ts +0 -1
- package/scripts/install-local-cli.sh +0 -28
- package/scripts/pack-npm-tarballs.js +0 -63
- package/scripts/release.ts +0 -1
- package/scripts/run-node-tests.js +0 -37
- package/tests/all.js +0 -127
- package/tests/api/openapi_spec.test.js +0 -21
- package/tests/artifacts.md +0 -31
- package/tests/component/cli_version.test.js +0 -38
- package/tests/integration/workspace_resolver.test.js +0 -44
- package/tests/unit/crypto_helper.test.js +0 -36
- package/tests/unit/path_helper.test.js +0 -20
- package/tsconfig.base.json +0 -32
- /package/{packages/cli/src/index.ts → dist/index.js} +0 -0
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { Connection, GlobalRepository, type Database } from "@mcoda/db";
|
|
4
|
-
import { PathHelper } from "@mcoda/shared";
|
|
5
|
-
import { TelemetryClient, TokenUsageRow, TokenUsageSummaryRow, type TelemetryConfig as ApiTelemetryConfig } from "@mcoda/integrations";
|
|
6
|
-
import { WorkspaceResolution } from "../../workspace/WorkspaceManager.js";
|
|
7
|
-
|
|
8
|
-
export type { TokenUsageRow, TokenUsageSummaryRow } from "@mcoda/integrations";
|
|
9
|
-
|
|
10
|
-
type GroupByDimension = "project" | "agent" | "command" | "day" | "model" | "job" | "action";
|
|
11
|
-
|
|
12
|
-
export interface TelemetryConfigState extends ApiTelemetryConfig {
|
|
13
|
-
configPath: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface TelemetrySummaryOptions {
|
|
17
|
-
projectKey?: string;
|
|
18
|
-
agent?: string;
|
|
19
|
-
command?: string;
|
|
20
|
-
jobId?: string;
|
|
21
|
-
since?: string;
|
|
22
|
-
until?: string;
|
|
23
|
-
groupBy?: GroupByDimension[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface TokenUsageQueryOptions {
|
|
27
|
-
projectKey?: string;
|
|
28
|
-
agent?: string;
|
|
29
|
-
command?: string;
|
|
30
|
-
jobId?: string;
|
|
31
|
-
since?: string;
|
|
32
|
-
until?: string;
|
|
33
|
-
page?: number;
|
|
34
|
-
pageSize?: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface DbTokenUsageRow {
|
|
38
|
-
workspace_id: string;
|
|
39
|
-
agent_id: string | null;
|
|
40
|
-
model_name: string | null;
|
|
41
|
-
job_id: string | null;
|
|
42
|
-
command_run_id: string | null;
|
|
43
|
-
task_run_id: string | null;
|
|
44
|
-
task_id: string | null;
|
|
45
|
-
project_id: string | null;
|
|
46
|
-
epic_id: string | null;
|
|
47
|
-
user_story_id: string | null;
|
|
48
|
-
tokens_prompt: number | null;
|
|
49
|
-
tokens_completion: number | null;
|
|
50
|
-
tokens_total: number | null;
|
|
51
|
-
cost_estimate: number | null;
|
|
52
|
-
duration_seconds: number | null;
|
|
53
|
-
timestamp: string;
|
|
54
|
-
metadata_json?: string | null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const hasTables = async (db: Database, required: string[]): Promise<boolean> => {
|
|
58
|
-
const rows = await db.all<{ name: string }[]>(`SELECT name FROM sqlite_master WHERE type='table'`);
|
|
59
|
-
const names = new Set(rows.map((r) => r.name));
|
|
60
|
-
return required.every((name) => names.has(name));
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const parseMetadata = (raw?: string | null): Record<string, unknown> => {
|
|
64
|
-
if (!raw) return {};
|
|
65
|
-
try {
|
|
66
|
-
return JSON.parse(raw) as Record<string, unknown>;
|
|
67
|
-
} catch {
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const addCost = (current: number | null, value: number | null | undefined): number | null => {
|
|
73
|
-
if (value === null || value === undefined) return current;
|
|
74
|
-
return (current ?? 0) + value;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const parseDurationMs = (input: string): number | undefined => {
|
|
78
|
-
const match = input.trim().match(/^(\d+)([smhdw])$/i);
|
|
79
|
-
if (!match) return undefined;
|
|
80
|
-
const amount = Number(match[1]);
|
|
81
|
-
const unit = match[2].toLowerCase();
|
|
82
|
-
const multipliers: Record<string, number> = {
|
|
83
|
-
s: 1000,
|
|
84
|
-
m: 60 * 1000,
|
|
85
|
-
h: 60 * 60 * 1000,
|
|
86
|
-
d: 24 * 60 * 60 * 1000,
|
|
87
|
-
w: 7 * 24 * 60 * 60 * 1000,
|
|
88
|
-
};
|
|
89
|
-
return multipliers[unit] ? amount * multipliers[unit] : undefined;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const parseTimeInput = (input?: string): string | undefined => {
|
|
93
|
-
if (!input) return undefined;
|
|
94
|
-
const duration = parseDurationMs(input);
|
|
95
|
-
if (duration !== undefined) {
|
|
96
|
-
return new Date(Date.now() - duration).toISOString();
|
|
97
|
-
}
|
|
98
|
-
const parsed = Date.parse(input);
|
|
99
|
-
if (!Number.isNaN(parsed)) {
|
|
100
|
-
return new Date(parsed).toISOString();
|
|
101
|
-
}
|
|
102
|
-
return undefined;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const normalizeGroupBy = (groupBy?: GroupByDimension[]): GroupByDimension[] => {
|
|
106
|
-
if (!groupBy || groupBy.length === 0) {
|
|
107
|
-
return ["project", "command", "agent"];
|
|
108
|
-
}
|
|
109
|
-
const seen = new Set<GroupByDimension>();
|
|
110
|
-
for (const dim of groupBy) {
|
|
111
|
-
if (["project", "agent", "command", "day", "model", "job", "action"].includes(dim)) {
|
|
112
|
-
seen.add(dim);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return Array.from(seen);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const dayFromTimestamp = (timestamp: string | undefined): string | null => {
|
|
119
|
-
if (!timestamp) return null;
|
|
120
|
-
const parsed = Date.parse(timestamp);
|
|
121
|
-
if (Number.isNaN(parsed)) return null;
|
|
122
|
-
return new Date(parsed).toISOString().slice(0, 10);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export class TelemetryService {
|
|
126
|
-
private globalRepo?: GlobalRepository;
|
|
127
|
-
private client?: TelemetryClient;
|
|
128
|
-
private db?: Database;
|
|
129
|
-
private connection?: Connection;
|
|
130
|
-
|
|
131
|
-
private constructor(private workspace: WorkspaceResolution, deps: { db?: Database; connection?: Connection; client?: TelemetryClient }) {
|
|
132
|
-
this.db = deps.db;
|
|
133
|
-
this.connection = deps.connection;
|
|
134
|
-
this.client = deps.client;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
static async create(
|
|
138
|
-
workspace: WorkspaceResolution,
|
|
139
|
-
options: { allowMissingTelemetry?: boolean; requireApi?: boolean } = {},
|
|
140
|
-
): Promise<TelemetryService> {
|
|
141
|
-
const baseUrl = workspace.config?.telemetry?.endpoint ?? process.env.MCODA_TELEMETRY_API;
|
|
142
|
-
const authToken = workspace.config?.telemetry?.authToken ?? process.env.MCODA_TELEMETRY_TOKEN;
|
|
143
|
-
if (baseUrl) {
|
|
144
|
-
return new TelemetryService(workspace, { client: new TelemetryClient({ baseUrl, authToken }) });
|
|
145
|
-
}
|
|
146
|
-
if (options.requireApi) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
"Telemetry API is not configured (set MCODA_TELEMETRY_API/MCODA_TELEMETRY_TOKEN or telemetry.endpoint in workspace config).",
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const dbPath = PathHelper.getWorkspaceDbPath(workspace.workspaceRoot);
|
|
153
|
-
try {
|
|
154
|
-
await fs.access(dbPath);
|
|
155
|
-
} catch {
|
|
156
|
-
if (!options.allowMissingTelemetry) {
|
|
157
|
-
throw new Error(`No workspace DB found at ${dbPath}. Run mcoda init or create-tasks first.`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const connection = await Connection.open(dbPath);
|
|
161
|
-
const ok = await hasTables(connection.db, ["token_usage"]);
|
|
162
|
-
if (!ok && !options.allowMissingTelemetry) {
|
|
163
|
-
await connection.close();
|
|
164
|
-
throw new Error("Workspace DB is missing telemetry tables (token_usage). Run create-tasks to initialize it.");
|
|
165
|
-
}
|
|
166
|
-
return new TelemetryService(workspace, { db: connection.db, connection });
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async close(): Promise<void> {
|
|
170
|
-
if (this.connection) {
|
|
171
|
-
await this.connection.close();
|
|
172
|
-
}
|
|
173
|
-
if (this.globalRepo) {
|
|
174
|
-
await this.globalRepo.close();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private get configPath(): string {
|
|
179
|
-
return path.join(this.workspace.mcodaDir, "config.json");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private async readConfigFile(): Promise<Record<string, any>> {
|
|
183
|
-
try {
|
|
184
|
-
const raw = await fs.readFile(this.configPath, "utf8");
|
|
185
|
-
return JSON.parse(raw) as Record<string, any>;
|
|
186
|
-
} catch {
|
|
187
|
-
return {};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private async writeConfigFile(config: Record<string, any>): Promise<void> {
|
|
192
|
-
await fs.mkdir(this.workspace.mcodaDir, { recursive: true });
|
|
193
|
-
await fs.writeFile(this.configPath, JSON.stringify(config, null, 2), "utf8");
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private async resolveProjectId(projectKey?: string): Promise<string | undefined> {
|
|
197
|
-
if (!projectKey || !this.db) return undefined;
|
|
198
|
-
const row = await this.db.get<{ id: string } | undefined>(`SELECT id FROM projects WHERE key = ?`, projectKey);
|
|
199
|
-
return row?.id;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
private async getGlobalRepo(): Promise<GlobalRepository> {
|
|
203
|
-
if (!this.globalRepo) {
|
|
204
|
-
this.globalRepo = await GlobalRepository.create();
|
|
205
|
-
}
|
|
206
|
-
return this.globalRepo;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private async resolveAgentId(agent?: string): Promise<string | undefined> {
|
|
210
|
-
if (!agent) return undefined;
|
|
211
|
-
try {
|
|
212
|
-
const repo = await this.getGlobalRepo();
|
|
213
|
-
const asId = await repo.getAgentById(agent);
|
|
214
|
-
if (asId) return asId.id;
|
|
215
|
-
const bySlug = await repo.getAgentBySlug(agent);
|
|
216
|
-
if (bySlug) return bySlug.id;
|
|
217
|
-
} catch {
|
|
218
|
-
// ignore lookup failures; fall through to raw value
|
|
219
|
-
}
|
|
220
|
-
return agent;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private filterRows(
|
|
224
|
-
rows: DbTokenUsageRow[],
|
|
225
|
-
options: { command?: string },
|
|
226
|
-
): { row: DbTokenUsageRow; metadata: Record<string, unknown> }[] {
|
|
227
|
-
const filtered: { row: DbTokenUsageRow; metadata: Record<string, unknown> }[] = [];
|
|
228
|
-
for (const row of rows) {
|
|
229
|
-
const metadata = parseMetadata(row.metadata_json);
|
|
230
|
-
const commandName =
|
|
231
|
-
(metadata.commandName as string | undefined) ??
|
|
232
|
-
(metadata.command_name as string | undefined) ??
|
|
233
|
-
(metadata.command as string | undefined);
|
|
234
|
-
if (options.command && commandName && options.command !== commandName) {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
filtered.push({ row, metadata });
|
|
238
|
-
}
|
|
239
|
-
return filtered;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private mapConfig(apiConfig: ApiTelemetryConfig): TelemetryConfigState {
|
|
243
|
-
return {
|
|
244
|
-
...apiConfig,
|
|
245
|
-
localRecording: apiConfig.localRecording ?? true,
|
|
246
|
-
remoteExport: apiConfig.remoteExport ?? true,
|
|
247
|
-
optOut: apiConfig.optOut ?? false,
|
|
248
|
-
strict: apiConfig.strict ?? false,
|
|
249
|
-
configPath: this.configPath,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
async getSummary(options: TelemetrySummaryOptions = {}): Promise<TokenUsageSummaryRow[]> {
|
|
254
|
-
const groupBy = normalizeGroupBy(options.groupBy);
|
|
255
|
-
const since = parseTimeInput(options.since ?? "7d") ?? undefined;
|
|
256
|
-
const until = parseTimeInput(options.until);
|
|
257
|
-
const projectId = options.projectKey ? await this.resolveProjectId(options.projectKey) : undefined;
|
|
258
|
-
if (options.projectKey && !projectId && !this.client) {
|
|
259
|
-
throw new Error(`Unknown project key: ${options.projectKey}`);
|
|
260
|
-
}
|
|
261
|
-
const agentId = await this.resolveAgentId(options.agent);
|
|
262
|
-
|
|
263
|
-
if (this.client) {
|
|
264
|
-
return this.client.getSummary({
|
|
265
|
-
workspaceId: this.workspace.workspaceId,
|
|
266
|
-
projectId: projectId ?? options.projectKey,
|
|
267
|
-
agentId: agentId ?? options.agent,
|
|
268
|
-
commandName: options.command,
|
|
269
|
-
jobId: options.jobId,
|
|
270
|
-
from: since,
|
|
271
|
-
to: until,
|
|
272
|
-
groupBy,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (!this.db) {
|
|
277
|
-
throw new Error("Telemetry DB not available and no telemetry client configured.");
|
|
278
|
-
}
|
|
279
|
-
const clauses = ["workspace_id = ?"];
|
|
280
|
-
const params: any[] = [this.workspace.workspaceId];
|
|
281
|
-
if (projectId) {
|
|
282
|
-
clauses.push("project_id = ?");
|
|
283
|
-
params.push(projectId);
|
|
284
|
-
}
|
|
285
|
-
if (agentId) {
|
|
286
|
-
clauses.push("agent_id = ?");
|
|
287
|
-
params.push(agentId);
|
|
288
|
-
}
|
|
289
|
-
if (options.jobId) {
|
|
290
|
-
clauses.push("job_id = ?");
|
|
291
|
-
params.push(options.jobId);
|
|
292
|
-
}
|
|
293
|
-
if (since) {
|
|
294
|
-
clauses.push("timestamp >= ?");
|
|
295
|
-
params.push(since);
|
|
296
|
-
}
|
|
297
|
-
if (until) {
|
|
298
|
-
clauses.push("timestamp <= ?");
|
|
299
|
-
params.push(until);
|
|
300
|
-
}
|
|
301
|
-
const query = `SELECT * FROM token_usage ${clauses.length ? `WHERE ${clauses.join(" AND ")}` : ""}`;
|
|
302
|
-
const rows = await this.db.all<DbTokenUsageRow[]>(query, ...params);
|
|
303
|
-
const filtered = this.filterRows(rows, { command: options.command });
|
|
304
|
-
|
|
305
|
-
const summary = new Map<string, TokenUsageSummaryRow>();
|
|
306
|
-
for (const { row, metadata } of filtered) {
|
|
307
|
-
const commandName =
|
|
308
|
-
(metadata.commandName as string | undefined) ??
|
|
309
|
-
(metadata.command_name as string | undefined) ??
|
|
310
|
-
(metadata.command as string | undefined) ??
|
|
311
|
-
null;
|
|
312
|
-
const action = (metadata.action as string | undefined) ?? (metadata.phase as string | undefined) ?? null;
|
|
313
|
-
const keyParts = groupBy.map((dim) => {
|
|
314
|
-
switch (dim) {
|
|
315
|
-
case "project":
|
|
316
|
-
return row.project_id ?? "";
|
|
317
|
-
case "agent":
|
|
318
|
-
return row.agent_id ?? "";
|
|
319
|
-
case "model":
|
|
320
|
-
return row.model_name ?? "";
|
|
321
|
-
case "command":
|
|
322
|
-
return commandName ?? "";
|
|
323
|
-
case "day":
|
|
324
|
-
return dayFromTimestamp(row.timestamp) ?? "";
|
|
325
|
-
case "job":
|
|
326
|
-
return row.job_id ?? "";
|
|
327
|
-
case "action":
|
|
328
|
-
return action ?? "";
|
|
329
|
-
default:
|
|
330
|
-
return "";
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
const key = keyParts.join("|");
|
|
334
|
-
let record = summary.get(key);
|
|
335
|
-
if (!record) {
|
|
336
|
-
record = {
|
|
337
|
-
workspace_id: this.workspace.workspaceId,
|
|
338
|
-
project_id: groupBy.includes("project") ? row.project_id ?? null : undefined,
|
|
339
|
-
agent_id: groupBy.includes("agent") ? row.agent_id ?? null : undefined,
|
|
340
|
-
model_name: groupBy.includes("model") ? row.model_name ?? null : undefined,
|
|
341
|
-
command_name: groupBy.includes("command") ? commandName : undefined,
|
|
342
|
-
action: groupBy.includes("action") ? action : undefined,
|
|
343
|
-
job_id: groupBy.includes("job") ? row.job_id ?? null : undefined,
|
|
344
|
-
day: groupBy.includes("day") ? dayFromTimestamp(row.timestamp) : undefined,
|
|
345
|
-
calls: 0,
|
|
346
|
-
tokens_prompt: 0,
|
|
347
|
-
tokens_completion: 0,
|
|
348
|
-
tokens_total: 0,
|
|
349
|
-
cost_estimate: null,
|
|
350
|
-
};
|
|
351
|
-
summary.set(key, record);
|
|
352
|
-
}
|
|
353
|
-
record.calls += 1;
|
|
354
|
-
record.tokens_prompt += row.tokens_prompt ?? 0;
|
|
355
|
-
record.tokens_completion += row.tokens_completion ?? 0;
|
|
356
|
-
record.tokens_total += row.tokens_total ?? 0;
|
|
357
|
-
record.cost_estimate = addCost(record.cost_estimate, row.cost_estimate);
|
|
358
|
-
}
|
|
359
|
-
return Array.from(summary.values());
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
async getTokenUsage(options: TokenUsageQueryOptions = {}): Promise<TokenUsageRow[]> {
|
|
363
|
-
const since = parseTimeInput(options.since);
|
|
364
|
-
const until = parseTimeInput(options.until);
|
|
365
|
-
const projectId = options.projectKey ? await this.resolveProjectId(options.projectKey) : undefined;
|
|
366
|
-
if (options.projectKey && !projectId && !this.client) {
|
|
367
|
-
throw new Error(`Unknown project key: ${options.projectKey}`);
|
|
368
|
-
}
|
|
369
|
-
const agentId = await this.resolveAgentId(options.agent);
|
|
370
|
-
|
|
371
|
-
if (this.client) {
|
|
372
|
-
const rows = await this.client.getTokenUsage({
|
|
373
|
-
workspaceId: this.workspace.workspaceId,
|
|
374
|
-
projectId: projectId ?? options.projectKey,
|
|
375
|
-
agentId: agentId ?? options.agent,
|
|
376
|
-
commandName: options.command,
|
|
377
|
-
jobId: options.jobId,
|
|
378
|
-
from: since,
|
|
379
|
-
to: until,
|
|
380
|
-
page: options.page,
|
|
381
|
-
pageSize: options.pageSize,
|
|
382
|
-
sort: "timestamp:asc",
|
|
383
|
-
});
|
|
384
|
-
return rows.sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp));
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (!this.db) {
|
|
388
|
-
throw new Error("Telemetry DB not available and no telemetry client configured.");
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const clauses = ["workspace_id = ?"];
|
|
392
|
-
const params: any[] = [this.workspace.workspaceId];
|
|
393
|
-
if (projectId) {
|
|
394
|
-
clauses.push("project_id = ?");
|
|
395
|
-
params.push(projectId);
|
|
396
|
-
}
|
|
397
|
-
if (agentId) {
|
|
398
|
-
clauses.push("agent_id = ?");
|
|
399
|
-
params.push(agentId);
|
|
400
|
-
}
|
|
401
|
-
if (options.jobId) {
|
|
402
|
-
clauses.push("job_id = ?");
|
|
403
|
-
params.push(options.jobId);
|
|
404
|
-
}
|
|
405
|
-
if (since) {
|
|
406
|
-
clauses.push("timestamp >= ?");
|
|
407
|
-
params.push(since);
|
|
408
|
-
}
|
|
409
|
-
if (until) {
|
|
410
|
-
clauses.push("timestamp <= ?");
|
|
411
|
-
params.push(until);
|
|
412
|
-
}
|
|
413
|
-
const query = `SELECT * FROM token_usage ${clauses.length ? `WHERE ${clauses.join(" AND ")}` : ""}`;
|
|
414
|
-
const rows = await this.db.all<DbTokenUsageRow[]>(query, ...params);
|
|
415
|
-
const filtered = this.filterRows(rows, { command: options.command });
|
|
416
|
-
const mapped: TokenUsageRow[] = filtered
|
|
417
|
-
.map(({ row, metadata }) => {
|
|
418
|
-
const commandName =
|
|
419
|
-
(metadata.commandName as string | undefined) ??
|
|
420
|
-
(metadata.command_name as string | undefined) ??
|
|
421
|
-
(metadata.command as string | undefined) ??
|
|
422
|
-
null;
|
|
423
|
-
const action = (metadata.action as string | undefined) ?? (metadata.phase as string | undefined) ?? null;
|
|
424
|
-
const errorKind =
|
|
425
|
-
(metadata.error_kind as string | undefined) ??
|
|
426
|
-
(metadata.errorKind as string | undefined) ??
|
|
427
|
-
(metadata.error as string | undefined) ??
|
|
428
|
-
null;
|
|
429
|
-
return {
|
|
430
|
-
workspace_id: row.workspace_id,
|
|
431
|
-
agent_id: row.agent_id,
|
|
432
|
-
model_name: row.model_name,
|
|
433
|
-
job_id: row.job_id,
|
|
434
|
-
command_run_id: row.command_run_id,
|
|
435
|
-
task_run_id: row.task_run_id,
|
|
436
|
-
task_id: row.task_id,
|
|
437
|
-
project_id: row.project_id,
|
|
438
|
-
epic_id: row.epic_id,
|
|
439
|
-
user_story_id: row.user_story_id,
|
|
440
|
-
tokens_prompt: row.tokens_prompt,
|
|
441
|
-
tokens_completion: row.tokens_completion,
|
|
442
|
-
tokens_total: row.tokens_total,
|
|
443
|
-
cost_estimate: row.cost_estimate,
|
|
444
|
-
duration_seconds: row.duration_seconds,
|
|
445
|
-
timestamp: row.timestamp,
|
|
446
|
-
command_name: commandName,
|
|
447
|
-
action,
|
|
448
|
-
error_kind: errorKind,
|
|
449
|
-
metadata,
|
|
450
|
-
};
|
|
451
|
-
})
|
|
452
|
-
.sort((a, b) => {
|
|
453
|
-
const aTs = Date.parse(a.timestamp);
|
|
454
|
-
const bTs = Date.parse(b.timestamp);
|
|
455
|
-
if (Number.isNaN(aTs) || Number.isNaN(bTs)) return 0;
|
|
456
|
-
return aTs - bTs;
|
|
457
|
-
});
|
|
458
|
-
if (options.page && options.pageSize) {
|
|
459
|
-
const start = (options.page - 1) * options.pageSize;
|
|
460
|
-
return mapped.slice(start, start + options.pageSize);
|
|
461
|
-
}
|
|
462
|
-
return mapped;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
async getConfig(): Promise<TelemetryConfigState> {
|
|
466
|
-
if (this.client) {
|
|
467
|
-
const config = await this.client.getConfig(this.workspace.workspaceId);
|
|
468
|
-
return this.mapConfig(config);
|
|
469
|
-
}
|
|
470
|
-
const config = await this.readConfigFile();
|
|
471
|
-
const telemetry = config.telemetry ?? {};
|
|
472
|
-
const envOptOut = (process.env.MCODA_TELEMETRY ?? "").toLowerCase() === "off";
|
|
473
|
-
const optOut = telemetry.optOut === true || telemetry.optedOut === true || false;
|
|
474
|
-
const strict = telemetry.strict === true || false;
|
|
475
|
-
const remoteExport = !optOut && !envOptOut;
|
|
476
|
-
const localRecording = !strict;
|
|
477
|
-
return {
|
|
478
|
-
localRecording,
|
|
479
|
-
remoteExport,
|
|
480
|
-
optOut,
|
|
481
|
-
strict,
|
|
482
|
-
configPath: this.configPath,
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
async optOut(strict = false): Promise<TelemetryConfigState> {
|
|
487
|
-
if (this.client) {
|
|
488
|
-
const config = await this.client.optOut(this.workspace.workspaceId, strict);
|
|
489
|
-
return this.mapConfig(config);
|
|
490
|
-
}
|
|
491
|
-
const config = await this.readConfigFile();
|
|
492
|
-
config.telemetry = {
|
|
493
|
-
...(config.telemetry ?? {}),
|
|
494
|
-
optOut: true,
|
|
495
|
-
strict: strict || (config.telemetry?.strict ?? false),
|
|
496
|
-
};
|
|
497
|
-
await this.writeConfigFile(config);
|
|
498
|
-
return this.getConfig();
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
async optIn(): Promise<TelemetryConfigState> {
|
|
502
|
-
if (this.client) {
|
|
503
|
-
const config = await this.client.optIn(this.workspace.workspaceId);
|
|
504
|
-
return this.mapConfig(config);
|
|
505
|
-
}
|
|
506
|
-
const config = await this.readConfigFile();
|
|
507
|
-
config.telemetry = {
|
|
508
|
-
...(config.telemetry ?? {}),
|
|
509
|
-
optOut: false,
|
|
510
|
-
strict: false,
|
|
511
|
-
};
|
|
512
|
-
await this.writeConfigFile(config);
|
|
513
|
-
return this.getConfig();
|
|
514
|
-
}
|
|
515
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import fs from "node:fs/promises";
|
|
6
|
-
import { Connection, WorkspaceMigrations, WorkspaceRepository } from "@mcoda/db";
|
|
7
|
-
import { PathHelper } from "@mcoda/shared";
|
|
8
|
-
import { TelemetryService } from "../TelemetryService.js";
|
|
9
|
-
import { WorkspaceResolution } from "../../../workspace/WorkspaceManager.js";
|
|
10
|
-
|
|
11
|
-
const workspaceFromRoot = (workspaceRoot: string): WorkspaceResolution => ({
|
|
12
|
-
workspaceRoot,
|
|
13
|
-
workspaceId: workspaceRoot,
|
|
14
|
-
mcodaDir: path.join(workspaceRoot, ".mcoda"),
|
|
15
|
-
id: workspaceRoot,
|
|
16
|
-
legacyWorkspaceIds: [],
|
|
17
|
-
workspaceDbPath: PathHelper.getWorkspaceDbPath(workspaceRoot),
|
|
18
|
-
globalDbPath: PathHelper.getGlobalDbPath(),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("TelemetryService", () => {
|
|
22
|
-
let workspaceRoot: string;
|
|
23
|
-
let connection: Connection;
|
|
24
|
-
let repo: WorkspaceRepository;
|
|
25
|
-
let workspace: WorkspaceResolution;
|
|
26
|
-
let projectId: string;
|
|
27
|
-
let job1: string;
|
|
28
|
-
let job2: string;
|
|
29
|
-
|
|
30
|
-
beforeEach(async () => {
|
|
31
|
-
workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), "mcoda-telemetry-"));
|
|
32
|
-
await fs.mkdir(path.join(workspaceRoot, ".mcoda"), { recursive: true });
|
|
33
|
-
const dbPath = PathHelper.getWorkspaceDbPath(workspaceRoot);
|
|
34
|
-
connection = await Connection.open(dbPath);
|
|
35
|
-
await WorkspaceMigrations.run(connection.db);
|
|
36
|
-
repo = new WorkspaceRepository(connection.db, connection);
|
|
37
|
-
const project = await repo.createProjectIfMissing({ key: "PROJ", name: "Project" });
|
|
38
|
-
projectId = project.id;
|
|
39
|
-
workspace = workspaceFromRoot(workspaceRoot);
|
|
40
|
-
const jobRow1 = await repo.createJob({ workspaceId: workspace.workspaceId, type: "work-on-tasks", state: "running", commandName: "work-on-tasks" });
|
|
41
|
-
const jobRow2 = await repo.createJob({ workspaceId: workspace.workspaceId, type: "docs", state: "running", commandName: "docs-pdr-generate" });
|
|
42
|
-
job1 = jobRow1.id;
|
|
43
|
-
job2 = jobRow2.id;
|
|
44
|
-
|
|
45
|
-
const now = new Date().toISOString();
|
|
46
|
-
const recent = new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString();
|
|
47
|
-
const old = new Date(Date.now() - 10 * 24 * 60 * 60 * 1000).toISOString();
|
|
48
|
-
|
|
49
|
-
await repo.recordTokenUsage({
|
|
50
|
-
workspaceId: workspace.workspaceId,
|
|
51
|
-
projectId,
|
|
52
|
-
agentId: "agent-1",
|
|
53
|
-
modelName: "gpt-4",
|
|
54
|
-
jobId: job1,
|
|
55
|
-
tokensPrompt: 10,
|
|
56
|
-
tokensCompletion: 5,
|
|
57
|
-
tokensTotal: 15,
|
|
58
|
-
costEstimate: 0.5,
|
|
59
|
-
durationSeconds: 2,
|
|
60
|
-
timestamp: now,
|
|
61
|
-
metadata: { commandName: "work-on-tasks", action: "plan" },
|
|
62
|
-
});
|
|
63
|
-
await repo.recordTokenUsage({
|
|
64
|
-
workspaceId: workspace.workspaceId,
|
|
65
|
-
projectId,
|
|
66
|
-
agentId: "agent-1",
|
|
67
|
-
modelName: "gpt-4",
|
|
68
|
-
jobId: job1,
|
|
69
|
-
tokensPrompt: 6,
|
|
70
|
-
tokensCompletion: 4,
|
|
71
|
-
tokensTotal: 10,
|
|
72
|
-
costEstimate: 0.25,
|
|
73
|
-
durationSeconds: 1,
|
|
74
|
-
timestamp: recent,
|
|
75
|
-
metadata: { commandName: "work-on-tasks", action: "draft" },
|
|
76
|
-
});
|
|
77
|
-
await repo.recordTokenUsage({
|
|
78
|
-
workspaceId: workspace.workspaceId,
|
|
79
|
-
projectId,
|
|
80
|
-
agentId: "agent-2",
|
|
81
|
-
modelName: "gpt-3",
|
|
82
|
-
jobId: job2,
|
|
83
|
-
tokensPrompt: 3,
|
|
84
|
-
tokensCompletion: 2,
|
|
85
|
-
tokensTotal: 5,
|
|
86
|
-
costEstimate: null,
|
|
87
|
-
durationSeconds: 0.5,
|
|
88
|
-
timestamp: old,
|
|
89
|
-
metadata: { commandName: "docs-pdr-generate", action: "context" },
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
afterEach(async () => {
|
|
94
|
-
await repo.close();
|
|
95
|
-
await fs.rm(workspaceRoot, { recursive: true, force: true });
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("aggregates token usage with default grouping and window", async () => {
|
|
99
|
-
const service = await TelemetryService.create(workspace);
|
|
100
|
-
try {
|
|
101
|
-
const summary = await service.getSummary();
|
|
102
|
-
assert.equal(summary.length, 1);
|
|
103
|
-
const row = summary[0];
|
|
104
|
-
assert.equal(row.calls, 2);
|
|
105
|
-
assert.equal(row.tokens_total, 25);
|
|
106
|
-
assert.equal(row.tokens_prompt, 16);
|
|
107
|
-
assert.equal(row.tokens_completion, 9);
|
|
108
|
-
assert.equal(row.cost_estimate, 0.75);
|
|
109
|
-
assert.equal(row.command_name, "work-on-tasks");
|
|
110
|
-
assert.equal(row.agent_id, "agent-1");
|
|
111
|
-
assert.equal(row.project_id, projectId);
|
|
112
|
-
} finally {
|
|
113
|
-
await service.close();
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("supports grouping by day", async () => {
|
|
118
|
-
const service = await TelemetryService.create(workspace);
|
|
119
|
-
try {
|
|
120
|
-
const summary = await service.getSummary({ groupBy: ["day"] });
|
|
121
|
-
assert.equal(summary.length, 1);
|
|
122
|
-
assert.ok(summary[0].day);
|
|
123
|
-
assert.equal(summary[0].calls, 2);
|
|
124
|
-
} finally {
|
|
125
|
-
await service.close();
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("filters raw token usage by job id and since", async () => {
|
|
130
|
-
const service = await TelemetryService.create(workspace);
|
|
131
|
-
try {
|
|
132
|
-
const rows = await service.getTokenUsage({ jobId: job1 });
|
|
133
|
-
assert.equal(rows.length, 2);
|
|
134
|
-
assert.equal(rows[0].job_id, job1);
|
|
135
|
-
const oldRows = await service.getTokenUsage({ jobId: job2, since: "7d" });
|
|
136
|
-
assert.equal(oldRows.length, 0);
|
|
137
|
-
} finally {
|
|
138
|
-
await service.close();
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("manages telemetry config opt-out and opt-in", async () => {
|
|
143
|
-
const service = await TelemetryService.create(workspace, { allowMissingTelemetry: true });
|
|
144
|
-
try {
|
|
145
|
-
const initial = await service.getConfig();
|
|
146
|
-
assert.equal(initial.optOut, false);
|
|
147
|
-
assert.equal(initial.strict, false);
|
|
148
|
-
const optedOut = await service.optOut(true);
|
|
149
|
-
assert.equal(optedOut.optOut, true);
|
|
150
|
-
assert.equal(optedOut.strict, true);
|
|
151
|
-
assert.equal(optedOut.localRecording, false);
|
|
152
|
-
const optedIn = await service.optIn();
|
|
153
|
-
assert.equal(optedIn.optOut, false);
|
|
154
|
-
assert.equal(optedIn.strict, false);
|
|
155
|
-
assert.equal(optedIn.localRecording, true);
|
|
156
|
-
} finally {
|
|
157
|
-
await service.close();
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
});
|
|
File without changes
|