@zaip-ai/cli 1.0.8 → 1.3.1
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/README.md +1 -1
- package/dist/services/adapters.d.ts +1 -1
- package/dist/services/adapters.js +1 -1
- package/dist/services/agent-adapters.js +3 -3
- package/dist/services/agent-adapters.js.map +1 -1
- package/dist/services/agent-adapters.test.js +7 -1
- package/dist/services/agent-adapters.test.js.map +1 -1
- package/dist/services/codex-pre-tool-hook-template.d.ts.map +1 -1
- package/dist/services/codex-pre-tool-hook-template.js +89 -7
- package/dist/services/codex-pre-tool-hook-template.js.map +1 -1
- package/dist/services/codex-rules.d.ts +1 -1
- package/dist/services/codex-rules.d.ts.map +1 -1
- package/dist/services/codex-rules.js +7 -0
- package/dist/services/codex-rules.js.map +1 -1
- package/dist/services/install-agents-template.d.ts.map +1 -1
- package/dist/services/install-agents-template.js +1 -0
- package/dist/services/install-agents-template.js.map +1 -1
- package/dist/services/logger.test.js +2 -2
- package/dist/services/runtime-template.test.js +31 -7
- package/dist/services/runtime-template.test.js.map +1 -1
- package/dist/services/template-manifest.d.ts.map +1 -1
- package/dist/services/template-manifest.js +12 -3
- package/dist/services/template-manifest.js.map +1 -1
- package/package.json +1 -1
- package/templates/.agents/architecture/software-architecture.md +131 -0
- package/templates/.agents/branding/brandbook.docx +0 -0
- package/templates/.agents/branding/brandbook.md +60 -0
- package/templates/.agents/config/agents/catalog.yaml +7 -7
- package/templates/.agents/config/clients/codex/agents/zaip-agent-backend.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-designer.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-finalizer.toml +1 -1
- package/templates/.agents/config/clients/codex/agents/zaip-agent-frontend.toml +8 -8
- package/templates/.agents/config/clients/codex/agents/zaip-agent-orchestrator.toml +1 -1
- package/templates/.agents/dashboard/.tmp-run-list.json +254 -0
- package/templates/.agents/dashboard/.zaip-managed.json +457 -173
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{CostCalculationGuidePage-Z60df2r-.js → CostCalculationGuidePage-ovxurkIk.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/DashboardHelpDialog-BgVgrfhQ.js +2310 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{PricingSettingsDialog-Coc6pA-1.js → PricingSettingsDialog-vSvvOHQp.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-BomxqCBU.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-zH758vfs.js +3 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-DLn-Mz2M.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{TraceabilityWorkspace-CaKwQP43.css → TraceabilityWorkspace-DvvavDLY.css} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-DKwP1stV.js +68 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-PoJA2PI1.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{icons-vendor-DFBuc_qp.js → icons-vendor-B_lDDHn1.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-B31GMG5O.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-CZQlsLV9.js +2 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{react-vendor-CCQOHdVI.js → react-vendor-B3TJrD4O.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{traceability-pC2_0J8x.js → traceability-7f1j5wx3.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/index.html +7 -7
- package/templates/.agents/dashboard/apps/frontend/package.json +1 -1
- package/templates/.agents/dashboard/apps/frontend/playwright.dom.config.ts +32 -0
- package/templates/.agents/dashboard/apps/frontend/src/App.tsx +199 -140
- package/templates/.agents/dashboard/apps/frontend/src/AppOverlays.tsx +0 -21
- package/templates/.agents/dashboard/apps/frontend/src/DashboardAlternateContent.tsx +20 -11
- package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.tsx +14 -7
- package/templates/.agents/dashboard/apps/frontend/src/ProjectStackEditor.tsx +4 -2
- package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.dom.e2e.ts +56 -0
- package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.test.ts +21 -2
- package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.tsx +89 -19
- package/templates/.agents/dashboard/apps/frontend/src/cost-period-refresh.test.ts +19 -4
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.test.ts +49 -3
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.ts +29 -10
- package/templates/.agents/dashboard/apps/frontend/src/operations-period-render.test.ts +4 -4
- package/templates/.agents/dashboard/apps/frontend/src/overview-status-page.test.ts +4 -2
- package/templates/.agents/dashboard/apps/frontend/src/project-settings-page.css +36 -26
- package/templates/.agents/dashboard/apps/frontend/src/project-settings.test.ts +2 -2
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-banner-semantics.test.ts +47 -6
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-coherence.test.ts +59 -9
- package/templates/.agents/dashboard/apps/frontend/src/sqlite-page-export.test.ts +32 -0
- package/templates/.agents/dashboard/apps/frontend/src/sqlite-page-export.ts +21 -0
- package/templates/.agents/dashboard/apps/frontend/src/styles.css +19 -0
- package/templates/.agents/dashboard/apps/frontend/src/traceability-task-pagination.test.ts +32 -0
- package/templates/.agents/dashboard/apps/frontend/src/traceability-task-pagination.ts +36 -0
- package/templates/.agents/dashboard/apps/frontend/src/traceability-workspace.css +6 -2
- package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.test.ts +137 -23
- package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.ts +229 -35
- package/templates/.agents/dashboard/apps/frontend/src/use-app-effects.ts +61 -7
- package/templates/.agents/dashboard/apps/frontend/src/use-app-operations-pages.ts +3 -6
- package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-documents.ts +7 -1
- package/templates/.agents/dashboard/apps/frontend/src/use-app-work-list-page.test.ts +163 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-app-work-list-page.ts +136 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-operations-detail-export.ts +76 -0
- package/templates/.agents/dashboard/apps/frontend/src/work-list-load-dedup.test.ts +23 -0
- package/templates/.agents/dashboard/apps/frontend/src/work-list-load-dedup.ts +27 -0
- package/templates/.agents/dashboard/apps/frontend/src/work-list-pagination.test.ts +39 -15
- package/templates/.agents/dashboard/apps/frontend/src/work-list-pagination.ts +3 -4
- package/templates/.agents/dashboard/apps/frontend/vite.config.ts +4 -1
- package/templates/.agents/dashboard/modules/cost-monitor/package.json +1 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CompactLifecycleCostTable.test.ts +89 -19
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CompactLifecycleCostTable.tsx +31 -16
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostCharts.test.ts +43 -14
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostCharts.tsx +5 -5
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostDeveloperAttributionPanel.tsx +60 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostDeveloperAttributionTable.tsx +191 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.loading.test.ts +14 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.run-page.test.ts +18 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.tsx +18 -3
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostModelsAuditTable.tsx +1 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorContent.tsx +75 -44
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorLoadErrors.tsx +35 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.test.ts +162 -40
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.tsx +221 -79
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTableLoading.test.ts +132 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTableLoading.tsx +70 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.test.ts +203 -155
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.tsx +164 -125
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-copy.ts +2 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-views.ts +3 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor.css +5 -2
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-page-range.ts +35 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/index.ts +2 -2
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/period-cost-groups.ts +2 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-compact-cost-page.ts +32 -9
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.test.ts +37 -2
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.ts +131 -9
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-run-page.ts +34 -17
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.test.ts +0 -24
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.test.ts +225 -424
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.ts +24 -15
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-terminal-day.test.ts +6 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/source-size-cost-server/build-cost-monitor-projection-agents.test.ts +31 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/source-size-cost-server/build-cost-summary-projection-duration.test.ts +414 -0
- package/templates/.agents/dashboard/modules/operations/package.json +1 -1
- package/templates/.agents/dashboard/modules/operations/src/contracts.ts +46 -26
- package/templates/.agents/dashboard/modules/operations/src/react/DeveloperAttributionPanel.test.ts +54 -0
- package/templates/.agents/dashboard/modules/operations/src/react/DeveloperAttributionPanel.tsx +247 -0
- package/templates/.agents/dashboard/modules/operations/src/react/EntityTables.tsx +31 -11
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsMainContent.tsx +39 -13
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.helpers.tsx +107 -2
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.macro-metrics.test.ts +55 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.test.ts +23 -29
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.tsx +211 -184
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverviewTopPanel.tsx +127 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPage.tsx +60 -51
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageNavigation.tsx +1 -4
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageOverview.tsx +3 -0
- package/templates/.agents/dashboard/modules/operations/src/react/PagedWorkList.test.tsx +43 -0
- package/templates/.agents/dashboard/modules/operations/src/react/PagedWorkList.tsx +181 -0
- package/templates/.agents/dashboard/modules/operations/src/react/PeriodSummaryTable.tsx +32 -10
- package/templates/.agents/dashboard/modules/operations/src/react/TaskDetailsDialog.tsx +9 -3
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkBoard.tsx +13 -5
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.test.ts +16 -6
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.tsx +14 -4
- package/templates/.agents/dashboard/modules/operations/src/react/conversation-rows.ts +1 -2
- package/templates/.agents/dashboard/modules/operations/src/react/developer-identities.test.ts +18 -0
- package/templates/.agents/dashboard/modules/operations/src/react/developer-identities.ts +30 -0
- package/templates/.agents/dashboard/modules/operations/src/react/execution-metrics.ts +1 -0
- package/templates/.agents/dashboard/modules/operations/src/react/export/ExcelExportAction.test.ts +393 -4
- package/templates/.agents/dashboard/modules/operations/src/react/export/ExcelExportAction.tsx +484 -61
- package/templates/.agents/dashboard/modules/operations/src/react/export/export-layout.test.ts +23 -1
- package/templates/.agents/dashboard/modules/operations/src/react/export/xlsx-runtime-e2e.test.ts +248 -0
- package/templates/.agents/dashboard/modules/operations/src/react/index.ts +1 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operation-duration.test.ts +4 -4
- package/templates/.agents/dashboard/modules/operations/src/react/operation-duration.ts +6 -4
- package/templates/.agents/dashboard/modules/operations/src/react/operations-coverage-toast.test.ts +4 -3
- package/templates/.agents/dashboard/modules/operations/src/react/operations-date-filters.css +1 -1
- package/templates/.agents/dashboard/modules/operations/src/react/operations-global-filters.test.ts +4 -1
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview-period-filter.test.ts +22 -12
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.css +4 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.status-cards.test.ts +1 -1
- package/templates/.agents/dashboard/modules/operations/src/react/operations-page-contract.ts +53 -6
- package/templates/.agents/dashboard/modules/operations/src/react/operations-view-order.test.ts +2 -4
- package/templates/.agents/dashboard/modules/operations/src/react/period-summary.test.ts +82 -6
- package/templates/.agents/dashboard/modules/operations/src/react/period-summary.ts +1 -0
- package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.test.ts +2 -1
- package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.ts +1 -1
- package/templates/.agents/dashboard/modules/operations/src/server/execution-relationship-counts.test.ts +19 -7
- package/templates/.agents/dashboard/modules/operations/src/server/execution-relationship-counts.ts +4 -1
- package/templates/.agents/dashboard/modules/operations/src/server/metric-coverage.ts +1 -0
- package/templates/.agents/dashboard/modules/operations/src/server/quick-daily-operations-projection.ts +11 -5
- package/templates/.agents/dashboard/modules/traceability/package.json +1 -1
- package/templates/.agents/dashboard/packages/branding/package.json +1 -1
- package/templates/.agents/dashboard/packages/branding/src/index.ts +1 -1
- package/templates/.agents/dashboard/packages/contracts/package.json +1 -1
- package/templates/.agents/dashboard/packages/contracts/src/index.ts +1 -0
- package/templates/.agents/dashboard/packages/data-export/package.json +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs +533 -338
- package/templates/.agents/dashboard/packages/local-runtime/dist/sqlite-read-model.cjs +506 -311
- package/templates/.agents/dashboard/packages/local-runtime/gitignore.template +2 -0
- package/templates/.agents/dashboard/packages/local-runtime/package.json +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-dashboard.mjs +15 -7
- package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-runtime.mjs +44 -13
- package/templates/.agents/dashboard/packages/local-runtime/scripts/rebuild-sqlite-read-model.mjs +8 -3
- package/templates/.agents/dashboard/packages/local-runtime/scripts/source-size-runtime-scripts/sqlite-read-model-fixture.mjs +397 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/test-sqlite-read-model.mjs +472 -145
- package/templates/.agents/dashboard/packages/local-runtime/scripts/test-unix-launchers.mjs +15 -3
- package/templates/.agents/dashboard/packages/local-runtime/scripts/validate-sqlite-read-model.mjs +141 -33
- package/templates/.agents/dashboard/packages/local-runtime/server.mjs +533 -338
- package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.test.ts +6 -2
- package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.ts +3 -3
- package/templates/.agents/dashboard/packages/local-runtime/src/server-board.test.ts +89 -16
- package/templates/.agents/dashboard/packages/local-runtime/src/server-board.ts +33 -16
- package/templates/.agents/dashboard/packages/local-runtime/src/server-classification-page.test.ts +87 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-period-macro-metric.test.ts +44 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-period-macro-metric.ts +125 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-reconciliation-refresh.test.ts +66 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-request-authority.test.ts +61 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-request-authority.ts +18 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-run-projections.test.ts +42 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-refresh.ts +97 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot.test.ts +22 -5
- package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-task-trace.ts +91 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-workspace.ts +7 -3
- package/templates/.agents/dashboard/packages/local-runtime/src/server.test-fixtures.ts +36 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server.test.ts +230 -132
- package/templates/.agents/dashboard/packages/local-runtime/src/server.ts +224 -182
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-artifact-counts.ts +28 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-agent-page.test.ts +63 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-agent-page.ts +109 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-aggregates.ts +497 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-fast-page-parity.test-support.ts +65 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-page.test.ts +176 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-page.ts +119 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-projection.ts +41 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-invocation-page.test.ts +16 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-invocation-page.ts +29 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-cache.ts +355 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-persistence.ts +121 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-timing.ts +27 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-metric-contract.ts +16 -2
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-operations-projection.ts +15 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-operations-work-list.test.ts +223 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-operations-work-list.ts +304 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-cache.test-support.ts +23 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-first-fold-types.ts +89 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-multi-provider-fixture.ts +227 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-multi-provider.test.ts +691 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-source-fingerprint.ts +81 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.test.ts +1655 -567
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.ts +2168 -1268
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-cache.ts +129 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-install.test.ts +26 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-install.ts +28 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-seed.test.ts +116 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-launch-page.mjs +146 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-launch-page.test.mjs +165 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-refresh.mjs +140 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.mjs +255 -289
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.test.mjs +94 -88
- package/templates/.agents/dashboard/packages/ui/package.json +1 -1
- package/templates/.agents/dashboard/packages/windows-launcher/Program.cs +5 -2
- package/templates/.agents/dashboard/tests/e2e/package.json +1 -1
- package/templates/.agents/dashboard/tests/e2e/playwright.config.ts +4 -1
- package/templates/.agents/dashboard/tests/e2e/specs/cost-monitor-loading.spec.ts +142 -0
- package/templates/.agents/dashboard/tests/e2e/specs/cost-monitor-pagination.spec.ts +232 -0
- package/templates/.agents/dashboard/tests/e2e/specs/dashboard-performance-matrix.spec.ts +743 -0
- package/templates/.agents/dashboard/tests/e2e/specs/dashboard.spec.ts +189 -214
- package/templates/.agents/dashboard/zaip-dashboard-windows.exe +0 -0
- package/templates/.agents/design/.zaip-managed.json +3 -3
- package/templates/.agents/design/apps/catalog/package.json +1 -1
- package/templates/.agents/design/packages/local-runtime/package.json +1 -1
- package/templates/.agents/growth/estrategia-bootstrap-90-dias.md +169 -0
- package/templates/.agents/growth/strategy.md +27 -0
- package/templates/.agents/marketing/estrategia-marketing-zaip-90-dias.md +197 -0
- package/templates/.agents/marketing/strategy.md +29 -0
- package/templates/.agents/requirements/autonomous-assurance.md +6 -6
- package/templates/.agents/requirements/comparative-audit.md +1 -1
- package/templates/.agents/requirements/context-engine.md +1 -1
- package/templates/.agents/requirements/cost-observability.md +1 -1
- package/templates/.agents/requirements/dashboard-launch.md +1 -1
- package/templates/.agents/requirements/data-export.md +1 -1
- package/templates/.agents/requirements/design-system.md +1 -1
- package/templates/.agents/requirements/execution-engine.md +3 -3
- package/templates/.agents/requirements/kanban-dashboard.md +10 -2
- package/templates/.agents/requirements/model-orchestration.md +1 -1
- package/templates/.agents/requirements/public-distribution.md +1 -1
- package/templates/.agents/requirements/software-architecture.md +1 -1
- package/templates/.agents/requirements/strategic-improvements.md +1 -1
- package/templates/.agents/requirements/work-lifecycle.md +4 -4
- package/templates/.agents/requirements/zaip-strategic-95.md +1 -1
- package/templates/.agents/rules/dashboard-ui-consistency.md +14 -0
- package/templates/.agents/rules/frontend-lite.md +4 -4
- package/templates/.agents/rules/run-lifecycle-closure.md +4 -4
- package/templates/.agents/runtime/VERSION +1 -1
- package/templates/.agents/runtime/bin/zaip.mjs +1142 -1041
- package/templates/.agents/runtime/checksums.sha256 +6 -6
- package/templates/.agents/runtime/manifest.json +1 -1
- package/templates/.agents/runtime/pnpm-lock.sha256 +1 -1
- package/templates/.agents/runtime/provenance.json +5 -5
- package/templates/.agents/runtime/sbom.cdx.json +3 -3
- package/templates/.agents/sales/playbook.md +32 -0
- package/templates/.agents/sales/roteiro-comercial-zaip.md +252 -0
- package/templates/.agents/skills/criar-pasta-obsidian/scripts/generate-obsidian-vault.test.mjs +20 -16
- package/templates/.agents/skills/zaip-aios/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-agent-catalog/SKILL.md +22 -0
- package/templates/.agents/skills/zaip-skill-agent-catalog/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-author-skills/SKILL.md +3 -2
- package/templates/.agents/skills/zaip-skill-author-skills/scripts/audit-skill-catalog.mjs +49 -0
- package/templates/.agents/skills/zaip-skill-author-skills/scripts/author-skill-scripts.test.mjs +27 -0
- package/templates/.agents/skills/zaip-skill-author-skills/scripts/run-skill-tests.mjs +37 -0
- package/templates/.agents/skills/zaip-skill-backend/SKILL.md +1 -0
- package/templates/.agents/skills/zaip-skill-brand-governance/SKILL.md +9 -2
- package/templates/.agents/skills/zaip-skill-brand-governance/references/brandbook-framework.md +39 -0
- package/templates/.agents/skills/zaip-skill-brand-governance/references/brandbook-standards.md +1 -1
- package/templates/.agents/skills/zaip-skill-change/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-change/references/observable-evidence.md +83 -0
- package/templates/.agents/skills/zaip-skill-dashboard-diagnostics/SKILL.md +22 -0
- package/templates/.agents/skills/zaip-skill-dashboard-diagnostics/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-enforce-architecture/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-execution/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-frontend/SKILL.md +4 -3
- package/templates/.agents/skills/zaip-skill-frontend/agents/openai.yaml +2 -2
- package/templates/.agents/skills/zaip-skill-github-deploy/SKILL.md +10 -10
- package/templates/.agents/skills/zaip-skill-growth-strategy-revops/SKILL.md +6 -0
- package/templates/.agents/skills/zaip-skill-lifecycle-closure/SKILL.md +27 -0
- package/templates/.agents/skills/zaip-skill-lifecycle-closure/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-marketing/SKILL.md +6 -0
- package/templates/.agents/skills/zaip-skill-prd/SKILL.md +4 -0
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-local-telemetry.mjs +111 -104
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-explicit-recovery.mjs +223 -0
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.mjs +55 -9
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.test.mjs +145 -14
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.mjs +19 -9
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.test.mjs +82 -5
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/source-size-telemetry/model-identity-reconciliation.mjs +77 -0
- package/templates/.agents/skills/zaip-skill-release-qualification/SKILL.md +20 -0
- package/templates/.agents/skills/zaip-skill-release-qualification/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-review/SKILL.md +5 -0
- package/templates/.agents/skills/zaip-skill-rules/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-sales-methodology/SKILL.md +6 -0
- package/templates/.agents/skills/zaip-skill-spec/SKILL.md +4 -0
- package/templates/.agents/skills/zaip-skill-sqlite-read-model/SKILL.md +22 -90
- package/templates/.agents/skills/zaip-skill-sqlite-read-model/scripts/ensure-node.mjs +28 -5
- package/templates/.agents/zaip-aios/INDEX.md +57 -22
- package/templates/.agents/zaip-aios/README.md +24 -13
- package/templates/.agents/zaip-aios/VERSION +1 -1
- package/templates/.agents/zaip-aios/guides/02-requirements.md +5 -0
- package/templates/.agents/zaip-aios/guides/06-execucao.md +13 -4
- package/templates/.agents/zaip-aios/guides/07-revisao-e-validacao.md +7 -0
- package/templates/.agents/zaip-aios/guides/10-seguranca.md +23 -0
- package/templates/.agents/zaip-aios/guides/11-observabilidade-e-custos.md +6 -6
- package/templates/.agents/zaip-aios/guides/13-boas-praticas.md +3 -0
- package/templates/.agents/zaip-aios/guides/16-lifecycle-e-reconciliacao.md +12 -3
- package/templates/.agents/zaip-aios/guides/17-como-o-custo-e-calculado.md +5 -5
- package/templates/.agents/zaip-aios/guides/18-catalogo-de-agentes.md +76 -0
- package/templates/.agents/zaip-aios/guides/19-assurance-e-autonomia.md +95 -0
- package/templates/.agents/zaip-aios/guides/20-instalacao-detalhada.md +366 -0
- package/templates/.agents/zaip-aios/guides/21-telemetria-monitor-custos.md +46 -0
- package/templates/.agents/zaip-aios/guides/22-fluxos-e-roteamento.md +74 -0
- package/templates/.agents/zaip-aios/guides/23-orquestracao-de-modelos.md +483 -0
- package/templates/.agents/zaip-aios/guides/24-calculo-de-custos-openai.md +85 -0
- package/templates/.agents/zaip-aios/guides/25-fontes-de-precos-openai.md +19 -0
- package/templates/.agents/zaip-aios/guides/26-qualidade-e-release.md +111 -0
- package/templates/.agents/zaip-aios/guides/27-telemetria-git-native.md +172 -0
- package/templates/.agents/zaip-aios/guides/28-lifecycle-completo.md +149 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/lifecycles-task-spec-prd.png +0 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/prd-lifecycle.png +0 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/spec-lifecycle.png +0 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/task-lifecycle.png +0 -0
- package/templates/template-manifest.json +756 -235
- package/templates/.agents/dashboard/apps/frontend/dist/assets/DashboardHelpDialog-Cs6dzDmW.js +0 -1505
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-QE1k9yZB.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-_Pf5DA_A.js +0 -3
- package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-BVlz3DLZ.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-BZ5WdaMN.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-Cf9ctPVt.js +0 -68
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-8A4DcNXM.js +0 -2
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DK_enB5Z.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/src/use-idle-cost-prefetch.ts +0 -45
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
2
|
+
|
|
3
|
+
type CostAgentProfile = {
|
|
4
|
+
persona: string | null;
|
|
5
|
+
job: string | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type CostDimensionAggregateRow = {
|
|
9
|
+
key: string;
|
|
10
|
+
label: string;
|
|
11
|
+
invocation_count: number;
|
|
12
|
+
task_count: number;
|
|
13
|
+
total_duration: number | null;
|
|
14
|
+
source_event_count: number | null;
|
|
15
|
+
total_tokens: number | null;
|
|
16
|
+
total_cost_usd: number | null;
|
|
17
|
+
total_cost_brl: number | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type CostRemoteAggregateRow = CostDimensionAggregateRow & {
|
|
21
|
+
id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
status: string | null;
|
|
24
|
+
risk: string | null;
|
|
25
|
+
persona: string | null;
|
|
26
|
+
job: string | null;
|
|
27
|
+
latest_started_at: string;
|
|
28
|
+
first_day: string;
|
|
29
|
+
last_day: string;
|
|
30
|
+
occurred_at: string;
|
|
31
|
+
llm_call_count: number | null;
|
|
32
|
+
duration_unknown: number;
|
|
33
|
+
duration_known: number;
|
|
34
|
+
total_input_tokens: number | null;
|
|
35
|
+
total_cached_input_tokens: number | null;
|
|
36
|
+
total_output_tokens: number | null;
|
|
37
|
+
total_reasoning_tokens: number | null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type CostRemoteAggregateProjection = {
|
|
41
|
+
rows: CostRemoteAggregateRow[];
|
|
42
|
+
totals: Record<string, number | null>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type CostDimensionAggregateSnapshot = Record<
|
|
46
|
+
"model" | "provider",
|
|
47
|
+
CostDimensionAggregateRow[]
|
|
48
|
+
> & {
|
|
49
|
+
remote: Record<"agent" | "execution" | "task" | "conversation", CostRemoteAggregateProjection>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function observedDimensionValue(value: unknown): string | null {
|
|
53
|
+
if (typeof value !== "string") return null;
|
|
54
|
+
const normalized = value.trim();
|
|
55
|
+
return normalized.length > 0 &&
|
|
56
|
+
!["unavailable", "unknown", "mixed"].includes(normalized.toLowerCase())
|
|
57
|
+
? normalized
|
|
58
|
+
: null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function buildCostDimensionAggregates(
|
|
62
|
+
database: DatabaseSync,
|
|
63
|
+
agentProfiles: Map<string, CostAgentProfile>,
|
|
64
|
+
): CostDimensionAggregateSnapshot {
|
|
65
|
+
const dimensions = ["model", "provider"] as const;
|
|
66
|
+
const allowedProviders = new Set(
|
|
67
|
+
(
|
|
68
|
+
database.prepare("SELECT provider FROM zaip_dim_provider").all() as Array<{
|
|
69
|
+
provider: string;
|
|
70
|
+
}>
|
|
71
|
+
).map((row) => row.provider),
|
|
72
|
+
);
|
|
73
|
+
const activities = database
|
|
74
|
+
.prepare(`SELECT activity_row_id, agent_invocation_id, task_id, duration_ms,
|
|
75
|
+
source_event_count, provider, model, total_tokens, cost_usd, cost_brl,
|
|
76
|
+
activity_source_kind, zaip_agent, zaip_agent_persona, zaip_agent_job,
|
|
77
|
+
execution_id, conversation_id, occurred_at, occurred_day_sp, llm_call_count,
|
|
78
|
+
input_tokens, cached_input_tokens, output_tokens, reasoning_tokens
|
|
79
|
+
FROM zaip_aios_activities WHERE payload_type IS NULL`)
|
|
80
|
+
.all() as Array<Record<string, unknown>>;
|
|
81
|
+
const segments = database
|
|
82
|
+
.prepare(`SELECT agent_invocation_id, provider, model, total_tokens, cost_usd, cost_brl
|
|
83
|
+
FROM invocation_usage_segments`)
|
|
84
|
+
.all() as Array<Record<string, unknown>>;
|
|
85
|
+
const activityByInvocation = new Map(
|
|
86
|
+
activities
|
|
87
|
+
.filter((row) => typeof row.agent_invocation_id === "string")
|
|
88
|
+
.map((row) => [String(row.agent_invocation_id), row] as const),
|
|
89
|
+
);
|
|
90
|
+
const rowsByDimension = new Map<"model" | "provider", Map<string, CostDimensionAggregateRow>>(
|
|
91
|
+
dimensions.map((dimension) => [dimension, new Map()]),
|
|
92
|
+
);
|
|
93
|
+
const ensure = (dimension: "model" | "provider", key: string) => {
|
|
94
|
+
const rows = rowsByDimension.get(dimension)!;
|
|
95
|
+
const current = rows.get(key);
|
|
96
|
+
if (current !== undefined) return current;
|
|
97
|
+
const created: CostDimensionAggregateRow = {
|
|
98
|
+
key,
|
|
99
|
+
label: key,
|
|
100
|
+
invocation_count: 0,
|
|
101
|
+
task_count: 0,
|
|
102
|
+
total_duration: null,
|
|
103
|
+
source_event_count: null,
|
|
104
|
+
total_tokens: null,
|
|
105
|
+
total_cost_usd: null,
|
|
106
|
+
total_cost_brl: null,
|
|
107
|
+
};
|
|
108
|
+
rows.set(key, created);
|
|
109
|
+
return created;
|
|
110
|
+
};
|
|
111
|
+
const add = (
|
|
112
|
+
target: CostDimensionAggregateRow,
|
|
113
|
+
field: "total_tokens" | "total_cost_usd" | "total_cost_brl",
|
|
114
|
+
value: unknown,
|
|
115
|
+
) => {
|
|
116
|
+
if (typeof value === "number") target[field] = (target[field] ?? 0) + value;
|
|
117
|
+
};
|
|
118
|
+
const segmentsByInvocation = new Map<string, Array<Record<string, unknown>>>();
|
|
119
|
+
for (const segment of segments) {
|
|
120
|
+
const id = String(segment.agent_invocation_id ?? "");
|
|
121
|
+
if (id.length === 0) continue;
|
|
122
|
+
const invocationSegments = segmentsByInvocation.get(id);
|
|
123
|
+
if (invocationSegments === undefined) segmentsByInvocation.set(id, [segment]);
|
|
124
|
+
else invocationSegments.push(segment);
|
|
125
|
+
}
|
|
126
|
+
for (const [id, invocationSegments] of segmentsByInvocation) {
|
|
127
|
+
const activity = activityByInvocation.get(id);
|
|
128
|
+
if (activity === undefined) continue;
|
|
129
|
+
for (const dimension of dimensions) {
|
|
130
|
+
const financialSegments = invocationSegments.filter(
|
|
131
|
+
(segment) =>
|
|
132
|
+
observedDimensionValue(segment[dimension]) !== null &&
|
|
133
|
+
observedDimensionValue(segment.provider) !== null &&
|
|
134
|
+
allowedProviders.has(observedDimensionValue(segment.provider)!) &&
|
|
135
|
+
(typeof segment.total_tokens === "number" ||
|
|
136
|
+
typeof segment.cost_usd === "number" ||
|
|
137
|
+
typeof segment.cost_brl === "number"),
|
|
138
|
+
);
|
|
139
|
+
const keys = [
|
|
140
|
+
...new Set(financialSegments.map((row) => observedDimensionValue(row[dimension])!)),
|
|
141
|
+
];
|
|
142
|
+
if (keys.length === 0) {
|
|
143
|
+
// Keep auditable, dimensionless invocation facts visible so Models
|
|
144
|
+
// and Providers reconcile to the Cost KPI instead of silently
|
|
145
|
+
// dropping them.
|
|
146
|
+
const target = ensure(dimension, "unavailable");
|
|
147
|
+
target.invocation_count += 1;
|
|
148
|
+
if (typeof activity.duration_ms === "number")
|
|
149
|
+
target.total_duration = (target.total_duration ?? 0) + activity.duration_ms;
|
|
150
|
+
if (typeof activity.source_event_count === "number")
|
|
151
|
+
target.source_event_count =
|
|
152
|
+
(target.source_event_count ?? 0) + activity.source_event_count;
|
|
153
|
+
add(target, "total_tokens", activity.total_tokens);
|
|
154
|
+
add(target, "total_cost_usd", activity.cost_usd);
|
|
155
|
+
add(target, "total_cost_brl", activity.cost_brl);
|
|
156
|
+
}
|
|
157
|
+
for (const segment of financialSegments) {
|
|
158
|
+
const target = ensure(dimension, observedDimensionValue(segment[dimension])!);
|
|
159
|
+
add(target, "total_tokens", segment.total_tokens);
|
|
160
|
+
add(target, "total_cost_usd", segment.cost_usd);
|
|
161
|
+
add(target, "total_cost_brl", segment.cost_brl);
|
|
162
|
+
}
|
|
163
|
+
// An invocation's elapsed time is attributable only when its observed
|
|
164
|
+
// financial segments agree on one dimension. Do not fabricate a
|
|
165
|
+
// mixed bucket or split wall-clock time across models/providers.
|
|
166
|
+
if (keys.length === 1) {
|
|
167
|
+
const target = ensure(dimension, keys[0]!);
|
|
168
|
+
target.invocation_count += 1;
|
|
169
|
+
if (typeof activity.duration_ms === "number")
|
|
170
|
+
target.total_duration = (target.total_duration ?? 0) + activity.duration_ms;
|
|
171
|
+
if (typeof activity.source_event_count === "number")
|
|
172
|
+
target.source_event_count =
|
|
173
|
+
(target.source_event_count ?? 0) + activity.source_event_count;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const taskKeys = new Map<"model" | "provider", Map<string, Set<string>>>(
|
|
178
|
+
dimensions.map((dimension) => [dimension, new Map()]),
|
|
179
|
+
);
|
|
180
|
+
for (const [id, invocationSegments] of segmentsByInvocation) {
|
|
181
|
+
const taskId = activityByInvocation.get(id)?.task_id;
|
|
182
|
+
if (typeof taskId !== "string") continue;
|
|
183
|
+
for (const dimension of dimensions) {
|
|
184
|
+
const byTask = taskKeys.get(dimension)!;
|
|
185
|
+
const keys = byTask.get(taskId) ?? new Set<string>();
|
|
186
|
+
for (const segment of invocationSegments) {
|
|
187
|
+
const key = observedDimensionValue(segment[dimension]);
|
|
188
|
+
const provider = observedDimensionValue(segment.provider);
|
|
189
|
+
const hasFinancialFact =
|
|
190
|
+
typeof segment.total_tokens === "number" ||
|
|
191
|
+
typeof segment.cost_usd === "number" ||
|
|
192
|
+
typeof segment.cost_brl === "number";
|
|
193
|
+
if (key !== null && provider !== null && allowedProviders.has(provider) && hasFinancialFact)
|
|
194
|
+
keys.add(key);
|
|
195
|
+
}
|
|
196
|
+
byTask.set(taskId, keys);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (const dimension of dimensions)
|
|
200
|
+
for (const keys of taskKeys.get(dimension)!.values())
|
|
201
|
+
for (const key of keys) ensure(dimension, key).task_count += 1;
|
|
202
|
+
for (const activity of activities) {
|
|
203
|
+
if (typeof activity.agent_invocation_id === "string") continue;
|
|
204
|
+
const hasFinancialFact =
|
|
205
|
+
typeof activity.total_tokens === "number" ||
|
|
206
|
+
typeof activity.cost_usd === "number" ||
|
|
207
|
+
typeof activity.cost_brl === "number";
|
|
208
|
+
if (!hasFinancialFact) continue;
|
|
209
|
+
const provider = observedDimensionValue(activity.provider);
|
|
210
|
+
if (provider === null || !allowedProviders.has(provider)) continue;
|
|
211
|
+
for (const dimension of dimensions) {
|
|
212
|
+
const key = observedDimensionValue(activity[dimension]) ?? "unavailable";
|
|
213
|
+
const target = ensure(dimension, key);
|
|
214
|
+
target.invocation_count += 1;
|
|
215
|
+
if (typeof activity.task_id === "string") target.task_count += 1;
|
|
216
|
+
if (typeof activity.duration_ms === "number")
|
|
217
|
+
target.total_duration = (target.total_duration ?? 0) + activity.duration_ms;
|
|
218
|
+
if (typeof activity.source_event_count === "number")
|
|
219
|
+
target.source_event_count = (target.source_event_count ?? 0) + activity.source_event_count;
|
|
220
|
+
add(target, "total_tokens", activity.total_tokens);
|
|
221
|
+
add(target, "total_cost_usd", activity.cost_usd);
|
|
222
|
+
add(target, "total_cost_brl", activity.cost_brl);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const base = Object.fromEntries(
|
|
226
|
+
dimensions.map((dimension) => [
|
|
227
|
+
dimension,
|
|
228
|
+
[...rowsByDimension.get(dimension)!.values()].sort(
|
|
229
|
+
(left, right) =>
|
|
230
|
+
(right.total_cost_brl ?? -1) - (left.total_cost_brl ?? -1) ||
|
|
231
|
+
left.key.localeCompare(right.key),
|
|
232
|
+
),
|
|
233
|
+
]),
|
|
234
|
+
) as Record<"model" | "provider", CostDimensionAggregateRow[]>;
|
|
235
|
+
const numericFields = [
|
|
236
|
+
"total_input_tokens",
|
|
237
|
+
"total_cached_input_tokens",
|
|
238
|
+
"total_output_tokens",
|
|
239
|
+
"total_reasoning_tokens",
|
|
240
|
+
"total_tokens",
|
|
241
|
+
"total_cost_usd",
|
|
242
|
+
"total_cost_brl",
|
|
243
|
+
] as const;
|
|
244
|
+
const createRemoteRow = (key: string): CostRemoteAggregateRow => ({
|
|
245
|
+
key,
|
|
246
|
+
id: key,
|
|
247
|
+
label: key,
|
|
248
|
+
title: key,
|
|
249
|
+
status: null,
|
|
250
|
+
risk: null,
|
|
251
|
+
persona: null,
|
|
252
|
+
job: null,
|
|
253
|
+
latest_started_at: "",
|
|
254
|
+
first_day: "",
|
|
255
|
+
last_day: "",
|
|
256
|
+
occurred_at: "",
|
|
257
|
+
invocation_count: 0,
|
|
258
|
+
task_count: 0,
|
|
259
|
+
llm_call_count: null,
|
|
260
|
+
total_duration: null,
|
|
261
|
+
duration_unknown: 0,
|
|
262
|
+
duration_known: 0,
|
|
263
|
+
source_event_count: null,
|
|
264
|
+
total_input_tokens: null,
|
|
265
|
+
total_cached_input_tokens: null,
|
|
266
|
+
total_output_tokens: null,
|
|
267
|
+
total_reasoning_tokens: null,
|
|
268
|
+
total_tokens: null,
|
|
269
|
+
total_cost_usd: null,
|
|
270
|
+
total_cost_brl: null,
|
|
271
|
+
});
|
|
272
|
+
const addRemoteNumber = (
|
|
273
|
+
row: CostRemoteAggregateRow,
|
|
274
|
+
field: (typeof numericFields)[number],
|
|
275
|
+
value: unknown,
|
|
276
|
+
) => {
|
|
277
|
+
if (typeof value === "number") row[field] = (row[field] ?? 0) + value;
|
|
278
|
+
};
|
|
279
|
+
const updateRemoteRow = (row: CostRemoteAggregateRow, activity: Record<string, unknown>) => {
|
|
280
|
+
row.invocation_count += 1;
|
|
281
|
+
if (typeof activity.llm_call_count === "number")
|
|
282
|
+
row.llm_call_count = (row.llm_call_count ?? 0) + activity.llm_call_count;
|
|
283
|
+
if (typeof activity.duration_ms === "number") {
|
|
284
|
+
row.total_duration = (row.total_duration ?? 0) + activity.duration_ms;
|
|
285
|
+
row.duration_known += activity.duration_ms;
|
|
286
|
+
} else {
|
|
287
|
+
row.duration_unknown += 1;
|
|
288
|
+
}
|
|
289
|
+
if (typeof activity.source_event_count === "number")
|
|
290
|
+
row.source_event_count = (row.source_event_count ?? 0) + activity.source_event_count;
|
|
291
|
+
for (const field of numericFields) {
|
|
292
|
+
const source =
|
|
293
|
+
field === "total_input_tokens"
|
|
294
|
+
? "input_tokens"
|
|
295
|
+
: field === "total_cached_input_tokens"
|
|
296
|
+
? "cached_input_tokens"
|
|
297
|
+
: field === "total_output_tokens"
|
|
298
|
+
? "output_tokens"
|
|
299
|
+
: field === "total_reasoning_tokens"
|
|
300
|
+
? "reasoning_tokens"
|
|
301
|
+
: field === "total_cost_usd"
|
|
302
|
+
? "cost_usd"
|
|
303
|
+
: field === "total_cost_brl"
|
|
304
|
+
? "cost_brl"
|
|
305
|
+
: field;
|
|
306
|
+
addRemoteNumber(row, field, activity[source]);
|
|
307
|
+
}
|
|
308
|
+
const occurredAt = typeof activity.occurred_at === "string" ? activity.occurred_at : "";
|
|
309
|
+
const day = typeof activity.occurred_day_sp === "string" ? activity.occurred_day_sp : "";
|
|
310
|
+
if (occurredAt > row.latest_started_at) row.latest_started_at = occurredAt;
|
|
311
|
+
if (row.first_day === "" || (day !== "" && day < row.first_day)) row.first_day = day;
|
|
312
|
+
if (day > row.last_day) row.last_day = day;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const agentRows = new Map<string, { row: CostRemoteAggregateRow; tasks: Set<string> }>();
|
|
316
|
+
const agentTasks = new Set<string>();
|
|
317
|
+
for (const activity of activities) {
|
|
318
|
+
const key = activity.zaip_agent;
|
|
319
|
+
const hasFinancialFact =
|
|
320
|
+
typeof activity.total_tokens === "number" ||
|
|
321
|
+
typeof activity.cost_usd === "number" ||
|
|
322
|
+
typeof activity.cost_brl === "number";
|
|
323
|
+
if (
|
|
324
|
+
typeof key !== "string" ||
|
|
325
|
+
key.length === 0 ||
|
|
326
|
+
(activity.activity_source_kind !== "agent_run" && !hasFinancialFact)
|
|
327
|
+
)
|
|
328
|
+
continue;
|
|
329
|
+
const entry = agentRows.get(key) ?? { row: createRemoteRow(key), tasks: new Set<string>() };
|
|
330
|
+
const persona =
|
|
331
|
+
typeof activity.zaip_agent_persona === "string"
|
|
332
|
+
? activity.zaip_agent_persona
|
|
333
|
+
: (agentProfiles.get(key)?.persona ?? null);
|
|
334
|
+
const job =
|
|
335
|
+
typeof activity.zaip_agent_job === "string"
|
|
336
|
+
? activity.zaip_agent_job
|
|
337
|
+
: (agentProfiles.get(key)?.job ?? null);
|
|
338
|
+
if (persona !== null && (entry.row.persona === null || persona > entry.row.persona))
|
|
339
|
+
entry.row.persona = persona;
|
|
340
|
+
if (job !== null && (entry.row.job === null || job > entry.row.job)) entry.row.job = job;
|
|
341
|
+
if (typeof activity.task_id === "string") {
|
|
342
|
+
entry.tasks.add(activity.task_id);
|
|
343
|
+
agentTasks.add(activity.task_id);
|
|
344
|
+
}
|
|
345
|
+
updateRemoteRow(entry.row, activity);
|
|
346
|
+
agentRows.set(key, entry);
|
|
347
|
+
}
|
|
348
|
+
const agents = [...agentRows.values()]
|
|
349
|
+
.map(({ row, tasks }) => ({ ...row, task_count: tasks.size }))
|
|
350
|
+
.sort(
|
|
351
|
+
(left, right) =>
|
|
352
|
+
(right.total_cost_brl ?? -1) - (left.total_cost_brl ?? -1) ||
|
|
353
|
+
left.key.localeCompare(right.key),
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const lifecycleMetadata = new Map<
|
|
357
|
+
string,
|
|
358
|
+
{ title: string; status: string | null; risk: string | null }
|
|
359
|
+
>();
|
|
360
|
+
for (const item of database
|
|
361
|
+
.prepare(
|
|
362
|
+
"SELECT entity_kind, id, title, status, risk FROM canonical_work_items WHERE entity_kind IN ('task', 'conversation')",
|
|
363
|
+
)
|
|
364
|
+
.all() as Array<{
|
|
365
|
+
entity_kind: string;
|
|
366
|
+
id: string;
|
|
367
|
+
title: string | null;
|
|
368
|
+
status: string | null;
|
|
369
|
+
risk: string | null;
|
|
370
|
+
}>)
|
|
371
|
+
lifecycleMetadata.set(`${item.entity_kind}:${item.id}`, {
|
|
372
|
+
title: item.title ?? item.id,
|
|
373
|
+
status: item.status,
|
|
374
|
+
risk: item.entity_kind === "task" ? item.risk : null,
|
|
375
|
+
});
|
|
376
|
+
for (const execution of database
|
|
377
|
+
.prepare("SELECT id, status FROM canonical_executions")
|
|
378
|
+
.all() as Array<{ id: string; status: string | null }>)
|
|
379
|
+
lifecycleMetadata.set(`execution:${execution.id}`, {
|
|
380
|
+
title: execution.id,
|
|
381
|
+
status: execution.status,
|
|
382
|
+
risk: null,
|
|
383
|
+
});
|
|
384
|
+
const lifecycleDefinitions = [
|
|
385
|
+
{ dimension: "execution", column: "execution_id" },
|
|
386
|
+
{ dimension: "task", column: "task_id" },
|
|
387
|
+
{ dimension: "conversation", column: "conversation_id" },
|
|
388
|
+
] as const;
|
|
389
|
+
const lifecycleRows = Object.fromEntries(
|
|
390
|
+
lifecycleDefinitions.map(({ dimension, column }) => {
|
|
391
|
+
const grouped = new Map<string, { row: CostRemoteAggregateRow; tasks: Set<string> }>();
|
|
392
|
+
for (const activity of activities) {
|
|
393
|
+
const key = activity[column];
|
|
394
|
+
if (
|
|
395
|
+
activity.activity_source_kind !== "agent_run" ||
|
|
396
|
+
typeof key !== "string" ||
|
|
397
|
+
key.length === 0
|
|
398
|
+
)
|
|
399
|
+
continue;
|
|
400
|
+
const entry = grouped.get(key) ?? { row: createRemoteRow(key), tasks: new Set<string>() };
|
|
401
|
+
const metadata = lifecycleMetadata.get(`${dimension}:${key}`);
|
|
402
|
+
entry.row.title = metadata?.title ?? key;
|
|
403
|
+
entry.row.status = metadata?.status ?? null;
|
|
404
|
+
entry.row.risk = metadata?.risk ?? null;
|
|
405
|
+
if (typeof activity.task_id === "string") entry.tasks.add(activity.task_id);
|
|
406
|
+
updateRemoteRow(entry.row, activity);
|
|
407
|
+
grouped.set(key, entry);
|
|
408
|
+
}
|
|
409
|
+
const rows = [...grouped.values()]
|
|
410
|
+
.map(({ row, tasks }) => ({
|
|
411
|
+
...row,
|
|
412
|
+
task_count: tasks.size,
|
|
413
|
+
occurred_at: row.last_day === "" ? "" : `${row.last_day}T12:00:00.000Z`,
|
|
414
|
+
}))
|
|
415
|
+
.sort(
|
|
416
|
+
(left, right) =>
|
|
417
|
+
(right.total_cost_brl ?? -1) - (left.total_cost_brl ?? -1) ||
|
|
418
|
+
left.key.localeCompare(right.key),
|
|
419
|
+
);
|
|
420
|
+
return [dimension, rows] as const;
|
|
421
|
+
}),
|
|
422
|
+
) as Record<"execution" | "task" | "conversation", CostRemoteAggregateRow[]>;
|
|
423
|
+
const lifecycleDurationTotals = Object.fromEntries(
|
|
424
|
+
lifecycleDefinitions.map(({ dimension, column }) => {
|
|
425
|
+
const result = database
|
|
426
|
+
.prepare(
|
|
427
|
+
`SELECT ROUND(SUM(duration_ms)) AS total_duration
|
|
428
|
+
FROM zaip_aios_activities
|
|
429
|
+
WHERE payload_type IS NULL AND activity_source_kind='agent_run'
|
|
430
|
+
AND ${column} IS NOT NULL`,
|
|
431
|
+
)
|
|
432
|
+
.get() as { total_duration: number | null };
|
|
433
|
+
return [dimension, result.total_duration] as const;
|
|
434
|
+
}),
|
|
435
|
+
) as Record<"execution" | "task" | "conversation", number | null>;
|
|
436
|
+
const aggregateTotals = (
|
|
437
|
+
rows: CostRemoteAggregateRow[],
|
|
438
|
+
taskCount: number,
|
|
439
|
+
): Record<string, number | null> => ({
|
|
440
|
+
entity_count: rows.length,
|
|
441
|
+
invocation_count: rows.reduce((sum, row) => sum + row.invocation_count, 0),
|
|
442
|
+
task_count: taskCount,
|
|
443
|
+
total_duration: rows.some((row) => row.total_duration !== null)
|
|
444
|
+
? rows.reduce((sum, row) => sum + (row.total_duration ?? 0), 0)
|
|
445
|
+
: null,
|
|
446
|
+
duration_unknown: rows.reduce((sum, row) => sum + row.duration_unknown, 0),
|
|
447
|
+
duration_known: rows.reduce((sum, row) => sum + row.duration_known, 0),
|
|
448
|
+
source_event_count: rows.some((row) => row.source_event_count !== null)
|
|
449
|
+
? rows.reduce((sum, row) => sum + (row.source_event_count ?? 0), 0)
|
|
450
|
+
: null,
|
|
451
|
+
total_tokens: rows.some((row) => row.total_tokens !== null)
|
|
452
|
+
? rows.reduce((sum, row) => sum + (row.total_tokens ?? 0), 0)
|
|
453
|
+
: null,
|
|
454
|
+
total_cost_usd: rows.some((row) => row.total_cost_usd !== null)
|
|
455
|
+
? rows.reduce((sum, row) => sum + (row.total_cost_usd ?? 0), 0)
|
|
456
|
+
: null,
|
|
457
|
+
total_cost_brl: rows.some((row) => row.total_cost_brl !== null)
|
|
458
|
+
? rows.reduce((sum, row) => sum + (row.total_cost_brl ?? 0), 0)
|
|
459
|
+
: null,
|
|
460
|
+
});
|
|
461
|
+
const lifecycleAggregateTotals = (
|
|
462
|
+
rows: CostRemoteAggregateRow[],
|
|
463
|
+
totalDuration: number | null,
|
|
464
|
+
): Record<string, number | null> => {
|
|
465
|
+
const totals = aggregateTotals(rows, 0);
|
|
466
|
+
return {
|
|
467
|
+
...totals,
|
|
468
|
+
total_duration: totalDuration,
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
return {
|
|
472
|
+
...base,
|
|
473
|
+
remote: {
|
|
474
|
+
agent: { rows: agents, totals: aggregateTotals(agents, agentTasks.size) },
|
|
475
|
+
execution: {
|
|
476
|
+
rows: lifecycleRows.execution,
|
|
477
|
+
totals: lifecycleAggregateTotals(
|
|
478
|
+
lifecycleRows.execution,
|
|
479
|
+
lifecycleDurationTotals.execution,
|
|
480
|
+
),
|
|
481
|
+
},
|
|
482
|
+
task: {
|
|
483
|
+
rows: lifecycleRows.task,
|
|
484
|
+
totals: lifecycleAggregateTotals(lifecycleRows.task, lifecycleDurationTotals.task),
|
|
485
|
+
},
|
|
486
|
+
conversation: {
|
|
487
|
+
rows: lifecycleRows.conversation,
|
|
488
|
+
totals: lifecycleAggregateTotals(
|
|
489
|
+
lifecycleRows.conversation,
|
|
490
|
+
lifecycleDurationTotals.conversation,
|
|
491
|
+
),
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Only canonical inputs consumed by the fact or its direct dimensions. */
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import { expect } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
type SqliteReadModelFileSystem,
|
|
5
|
+
type SqliteViewName,
|
|
6
|
+
sqliteReadModelPath,
|
|
7
|
+
} from "./sqlite-read-model.js";
|
|
8
|
+
|
|
9
|
+
const parityViews = [
|
|
10
|
+
["cost_monitor_zaip_agents", "key"],
|
|
11
|
+
["cost_monitor_executions", "id"],
|
|
12
|
+
["cost_monitor_tasks", "id"],
|
|
13
|
+
["cost_monitor_conversations", "id"],
|
|
14
|
+
] as const satisfies ReadonlyArray<readonly [SqliteViewName, string]>;
|
|
15
|
+
|
|
16
|
+
const commonTotals = [
|
|
17
|
+
"invocation_count",
|
|
18
|
+
"total_duration",
|
|
19
|
+
"total_tokens",
|
|
20
|
+
"total_cost_usd",
|
|
21
|
+
"total_cost_brl",
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
function selectedTotals(value: unknown): Record<string, unknown> {
|
|
25
|
+
const totals = (value ?? {}) as Record<string, unknown>;
|
|
26
|
+
return Object.fromEntries(commonTotals.map((key) => [key, totals[key] ?? null]));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Compares the all-time technical payload path with the bounded canonical path. */
|
|
30
|
+
export function expectFastCostPagesMatchCanonical(
|
|
31
|
+
root: string,
|
|
32
|
+
filesystem: SqliteReadModelFileSystem,
|
|
33
|
+
): void {
|
|
34
|
+
for (const [view, idField] of parityViews) {
|
|
35
|
+
const fast = filesystem.viewPage(view, { limit: 200, offset: 0 });
|
|
36
|
+
const canonical = filesystem.viewPage(view, {
|
|
37
|
+
from: "1900-01-01",
|
|
38
|
+
to: "2999-12-31",
|
|
39
|
+
limit: 200,
|
|
40
|
+
offset: 0,
|
|
41
|
+
});
|
|
42
|
+
expect(fast.total_count, `${view} total_count`).toBe(canonical.total_count);
|
|
43
|
+
expect(fast.rows.map((row) => String(row[idField])).sort(), `${view} identifiers`).toEqual(
|
|
44
|
+
canonical.rows.map((row) => String(row[idField])).sort(),
|
|
45
|
+
);
|
|
46
|
+
expect(selectedTotals(fast.totals), `${view} totals`).toEqual(selectedTotals(canonical.totals));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const database = new DatabaseSync(sqliteReadModelPath(root), { readOnly: true });
|
|
50
|
+
try {
|
|
51
|
+
const observedAgentKeys = (
|
|
52
|
+
database
|
|
53
|
+
.prepare(
|
|
54
|
+
"SELECT zaip_agent FROM zaip_vw_cost_monitor_zaip_agents WHERE zaip_agent IS NOT NULL",
|
|
55
|
+
)
|
|
56
|
+
.all() as Array<{ zaip_agent: string }>
|
|
57
|
+
).map((row) => row.zaip_agent);
|
|
58
|
+
const fastAgentKeys = filesystem
|
|
59
|
+
.viewPage("cost_monitor_zaip_agents", { limit: 200, offset: 0 })
|
|
60
|
+
.rows.map((row) => String(row.key));
|
|
61
|
+
expect(fastAgentKeys).toEqual(expect.arrayContaining(observedAgentKeys));
|
|
62
|
+
} finally {
|
|
63
|
+
database.close();
|
|
64
|
+
}
|
|
65
|
+
}
|