@zaip-ai/cli 2.6.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/README.md +36 -13
  2. package/dist/services/adapters.d.ts +1 -1
  3. package/dist/services/adapters.d.ts.map +1 -1
  4. package/dist/services/adapters.js +5 -2
  5. package/dist/services/adapters.js.map +1 -1
  6. package/dist/services/agent-adapters.js +12 -9
  7. package/dist/services/agent-adapters.js.map +1 -1
  8. package/dist/services/codex-conversation-lifecycle-hook.d.ts.map +1 -1
  9. package/dist/services/codex-conversation-lifecycle-hook.js +32 -21
  10. package/dist/services/codex-conversation-lifecycle-hook.js.map +1 -1
  11. package/dist/services/install-agents-template.js +9 -1
  12. package/dist/services/install-agents-template.js.map +1 -1
  13. package/dist/services/runtime-template.test.js +25 -2
  14. package/dist/services/runtime-template.test.js.map +1 -1
  15. package/dist/services/transactional-files.d.ts.map +1 -1
  16. package/dist/services/transactional-files.js +59 -14
  17. package/dist/services/transactional-files.js.map +1 -1
  18. package/package.json +1 -1
  19. package/templates/.agents/README-ENG.md +75 -10
  20. package/templates/.agents/README.md +76 -10
  21. package/templates/.agents/config/agents/catalog.yaml +3 -0
  22. package/templates/.agents/config/agents/discovery.json +2 -2
  23. package/templates/.agents/config/clients/codex/agents/zaip-agent-analyst.toml +1 -1
  24. package/templates/.agents/config/clients/codex/agents/zaip-agent-auditor.toml +1 -1
  25. package/templates/.agents/config/clients/codex/agents/zaip-agent-backend.toml +1 -1
  26. package/templates/.agents/config/clients/codex/agents/zaip-agent-brand-strategist.toml +1 -1
  27. package/templates/.agents/config/clients/codex/agents/zaip-agent-builder.toml +1 -1
  28. package/templates/.agents/config/clients/codex/agents/zaip-agent-cloud-engineer.toml +1 -1
  29. package/templates/.agents/config/clients/codex/agents/zaip-agent-data-analyst.toml +1 -1
  30. package/templates/.agents/config/clients/codex/agents/zaip-agent-designer.toml +1 -1
  31. package/templates/.agents/config/clients/codex/agents/zaip-agent-finalizer.toml +2 -2
  32. package/templates/.agents/config/clients/codex/agents/zaip-agent-frontend.toml +1 -1
  33. package/templates/.agents/config/clients/codex/agents/zaip-agent-general-operations.toml +1 -1
  34. package/templates/.agents/config/clients/codex/agents/zaip-agent-governance-compliance.toml +1 -1
  35. package/templates/.agents/config/clients/codex/agents/zaip-agent-growth-strategist.toml +1 -1
  36. package/templates/.agents/config/clients/codex/agents/zaip-agent-integrator.toml +1 -1
  37. package/templates/.agents/config/clients/codex/agents/zaip-agent-marketing-analyst.toml +1 -1
  38. package/templates/.agents/config/clients/codex/agents/zaip-agent-orchestrator.toml +13 -10
  39. package/templates/.agents/config/clients/codex/agents/zaip-agent-refactoring-specialist.toml +1 -1
  40. package/templates/.agents/config/clients/codex/agents/zaip-agent-reviewer.toml +1 -1
  41. package/templates/.agents/config/clients/codex/agents/zaip-agent-sales-specialist.toml +1 -1
  42. package/templates/.agents/config/clients/codex/agents/zaip-agent-security-auditor.toml +1 -1
  43. package/templates/.agents/config/clients/codex/agents/zaip-agent-task-executor.toml +1 -1
  44. package/templates/.agents/config/clients/codex/agents/zaip-agent-website-developer.toml +1 -1
  45. package/templates/.agents/config/clients/codex/agents/zaip-agent-writer.toml +1 -1
  46. package/templates/.agents/config/project.yaml +10 -1
  47. package/templates/.agents/dashboard/.zaip-managed.json +274 -138
  48. package/templates/.agents/dashboard/README.md +16 -0
  49. package/templates/.agents/dashboard/apps/frontend/dist/assets/{CostCalculationGuidePage-CGxeQak4.js → CostCalculationGuidePage-CEDZjl4V.js} +1 -1
  50. package/templates/.agents/dashboard/apps/frontend/dist/assets/{DashboardHelpDialog-tzS7YxYB.js → DashboardHelpDialog-DIWDmvAS.js} +930 -550
  51. package/templates/.agents/dashboard/apps/frontend/dist/assets/{PricingSettingsDialog-DEbCi1gP.js → PricingSettingsDialog-BBRBKaHa.js} +1 -1
  52. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-B9GWkEyN.css +1 -0
  53. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-BAvLPAee.js +3 -0
  54. package/templates/.agents/dashboard/apps/frontend/dist/assets/{TraceabilityWorkspace-t1Om0Abw.js → TraceabilityWorkspace-C9dDhj34.js} +1 -1
  55. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-06__WZco.js +68 -0
  56. package/templates/.agents/dashboard/apps/frontend/dist/assets/dashboard-localization-CoAVMZN6.js +828 -0
  57. package/templates/.agents/dashboard/apps/frontend/dist/assets/{icons-vendor-DiGC-dsJ.js → icons-vendor-DEmo6Tn2.js} +1 -1
  58. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-BVzw_Wux.js +2 -0
  59. package/templates/.agents/dashboard/apps/frontend/dist/assets/{react-vendor-kPO6yNed.js → react-vendor-CadYsm83.js} +1 -1
  60. package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-BzKK8kK3.js +1 -0
  61. package/templates/.agents/dashboard/apps/frontend/dist/index.html +5 -5
  62. package/templates/.agents/dashboard/apps/frontend/package.json +1 -1
  63. package/templates/.agents/dashboard/apps/frontend/src/AppDashboardContent.tsx +10 -5
  64. package/templates/.agents/dashboard/apps/frontend/src/AutonomySettings.tsx +82 -0
  65. package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.dom.test.ts +38 -7
  66. package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.tsx +164 -171
  67. package/templates/.agents/dashboard/apps/frontend/src/__tests__/app-composition-support.ts +6 -1
  68. package/templates/.agents/dashboard/apps/frontend/src/cost-monitor-population.test.tsx +149 -0
  69. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api-settings.ts +2 -1
  70. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.test.ts +19 -0
  71. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.ts +22 -1
  72. package/templates/.agents/dashboard/apps/frontend/src/dashboard-cost-facts.test.ts +54 -0
  73. package/templates/.agents/dashboard/apps/frontend/src/dashboard-cost-facts.ts +20 -2
  74. package/templates/.agents/dashboard/apps/frontend/src/dashboard-localization.test.ts +37 -43
  75. package/templates/.agents/dashboard/apps/frontend/src/dashboard-localization.ts +9 -251
  76. package/templates/.agents/dashboard/apps/frontend/src/dashboard-project-overview.ts +34 -7
  77. package/templates/.agents/dashboard/apps/frontend/src/dashboard-view-actions.test.ts +51 -0
  78. package/templates/.agents/dashboard/apps/frontend/src/dashboard-view-actions.ts +3 -1
  79. package/templates/.agents/dashboard/apps/frontend/src/operations-period-render.test.ts +35 -0
  80. package/templates/.agents/dashboard/apps/frontend/src/operations-period.test.ts +19 -4
  81. package/templates/.agents/dashboard/apps/frontend/src/operations-period.ts +5 -3
  82. package/templates/.agents/dashboard/apps/frontend/src/project-installation-status.test.ts +112 -23
  83. package/templates/.agents/dashboard/apps/frontend/src/project-installation-status.ts +49 -12
  84. package/templates/.agents/dashboard/apps/frontend/src/project-settings-copy.ts +181 -0
  85. package/templates/.agents/dashboard/apps/frontend/src/project-settings-model.ts +11 -1
  86. package/templates/.agents/dashboard/apps/frontend/src/project-settings-page.css +34 -51
  87. package/templates/.agents/dashboard/apps/frontend/src/project-settings-state.css +55 -0
  88. package/templates/.agents/dashboard/apps/frontend/src/project-settings.test.ts +12 -0
  89. package/templates/.agents/dashboard/apps/frontend/src/snapshot-coherence.test.ts +1 -1
  90. package/templates/.agents/dashboard/apps/frontend/src/traceability-task-pagination.ts +1 -2
  91. package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.test.ts +6 -0
  92. package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.ts +2 -0
  93. package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-documents.ts +3 -1
  94. package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-task-pagination.ts +4 -15
  95. package/templates/.agents/dashboard/apps/frontend/src/use-dashboard-app-model.tsx +2 -2
  96. package/templates/.agents/dashboard/modules/cost-monitor/package.json +1 -1
  97. package/templates/.agents/dashboard/modules/cost-monitor/src/complete-cost-average.test.ts +73 -0
  98. package/templates/.agents/dashboard/modules/cost-monitor/src/contracts.ts +9 -0
  99. package/templates/.agents/dashboard/modules/cost-monitor/src/period-averages.ts +60 -0
  100. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorContent.tsx +8 -22
  101. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.tsx +2 -3
  102. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostPeriodAverageCards.tsx +32 -8
  103. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-summary.ts +3 -2
  104. package/templates/.agents/dashboard/modules/cost-monitor/src/react/period-cost-groups.ts +1 -42
  105. package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.ts +2 -1
  106. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.ts +3 -2
  107. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.ts +8 -2
  108. package/templates/.agents/dashboard/modules/cost-monitor/src/server/index.ts +1 -0
  109. package/templates/.agents/dashboard/modules/operations/package.json +1 -1
  110. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview-keeps-structure-classes-mutually-exclusive.test.ts +4 -3
  111. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.helpers.tsx +66 -3
  112. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.test.ts +71 -1
  113. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.tsx +36 -30
  114. package/templates/.agents/dashboard/modules/operations/src/react/OperationsPage.tsx +5 -14
  115. package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageOverview.tsx +3 -0
  116. package/templates/.agents/dashboard/modules/operations/src/react/OverviewCostKpi.tsx +46 -0
  117. package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.test.ts +28 -1
  118. package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.tsx +11 -4
  119. package/templates/.agents/dashboard/modules/operations/src/react/index.ts +1 -0
  120. package/templates/.agents/dashboard/modules/operations/src/react/operations-coverage-toast.test.ts +2 -2
  121. package/templates/.agents/dashboard/modules/operations/src/react/operations-overview-period-filter.test.ts +28 -8
  122. package/templates/.agents/dashboard/modules/operations/src/react/operations-page-contract.ts +19 -2
  123. package/templates/.agents/dashboard/modules/operations/src/react/overview-cost-card.test.tsx +89 -0
  124. package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.test.ts +3 -3
  125. package/templates/.agents/dashboard/modules/operations/src/work-board-model.ts +2 -1
  126. package/templates/.agents/dashboard/modules/traceability/package.json +1 -1
  127. package/templates/.agents/dashboard/packages/branding/package.json +1 -1
  128. package/templates/.agents/dashboard/packages/contracts/package.json +1 -1
  129. package/templates/.agents/dashboard/packages/data-export/package.json +1 -1
  130. package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs +279 -245
  131. package/templates/.agents/dashboard/packages/local-runtime/dist/sqlite-read-model.cjs +247 -215
  132. package/templates/.agents/dashboard/packages/local-runtime/package.json +2 -2
  133. package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-runtime.mjs +15 -25
  134. package/templates/.agents/dashboard/packages/local-runtime/server.mjs +279 -245
  135. package/templates/.agents/dashboard/packages/local-runtime/src/active-codex-telemetry.ts +1 -1
  136. package/templates/.agents/dashboard/packages/local-runtime/src/project-installation-summary.test.ts +142 -0
  137. package/templates/.agents/dashboard/packages/local-runtime/src/project-installation-summary.ts +190 -0
  138. package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.test.ts +65 -0
  139. package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.ts +67 -66
  140. package/templates/.agents/dashboard/packages/local-runtime/src/server-browser-lease.test.ts +91 -0
  141. package/templates/.agents/dashboard/packages/local-runtime/src/server-browser-lease.ts +24 -4
  142. package/templates/.agents/dashboard/packages/local-runtime/src/server-hono-security.test.ts +17 -0
  143. package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-routes.ts +21 -2
  144. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-refresh.test.ts +94 -2
  145. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-refresh.ts +62 -12
  146. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-synchronization.test.ts +26 -0
  147. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-synchronization.ts +4 -1
  148. package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-task-trace.test.ts +97 -0
  149. package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-task-trace.ts +10 -13
  150. package/templates/.agents/dashboard/packages/local-runtime/src/server-trace-routes.ts +2 -10
  151. package/templates/.agents/dashboard/packages/local-runtime/src/server-traceability-index.test.ts +84 -0
  152. package/templates/.agents/dashboard/packages/local-runtime/src/server.ts +15 -1
  153. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-calendar.ts +17 -0
  154. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cold-parse.test.ts +78 -0
  155. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-dimension-facts.test.ts +12 -1
  156. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-projection.test.ts +94 -0
  157. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-projection.ts +5 -5
  158. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-duration-lookup.test.ts +59 -0
  159. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-entity-label-views.test.ts +72 -0
  160. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-file-index.test.ts +69 -0
  161. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-cache.ts +3 -1
  162. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-force-canonical.test.ts +3 -1
  163. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-incremental-refresh.test.ts +2 -0
  164. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-projections.ts +9 -0
  165. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-runs.ts +4 -5
  166. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-period-averages.ts +46 -0
  167. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-provider-alias-parity.test.ts +50 -0
  168. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-entity-group.test.ts +171 -0
  169. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-entity-group.ts +36 -16
  170. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-filtered-dimension.ts +13 -2
  171. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-summary.ts +25 -7
  172. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-temporal-dimension.ts +2 -0
  173. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-canonical-parsing.ts +7 -0
  174. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-canonical.ts +5 -15
  175. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-counts-every-root-execution-day-returns.test.ts +34 -10
  176. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-filesystem.ts +17 -3
  177. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-keeps-orphan-telemetry-out-kanban-without.test.ts +1 -1
  178. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-rebuild.ts +11 -0
  179. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-schema.ts +5 -4
  180. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-source-fingerprint.test.ts +54 -1
  181. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-source-fingerprint.ts +7 -3
  182. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.test.ts +4 -1
  183. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-risk-population.test.ts +98 -0
  184. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-schema-base-views.ts +29 -16
  185. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-schema-dashboard-views.ts +2 -1
  186. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-seed.test.ts +2 -0
  187. package/templates/.agents/dashboard/packages/local-runtime/src/verify-project-settings.mjs +57 -0
  188. package/templates/.agents/dashboard/packages/ui/package.json +1 -1
  189. package/templates/.agents/dashboard/scripts/qualify-observability.mjs +130 -0
  190. package/templates/.agents/dashboard/scripts/verify-autonomy-settings.mjs +175 -0
  191. package/templates/.agents/dashboard/scripts/verify-observability.mjs +254 -0
  192. package/templates/.agents/dashboard/scripts/verify-project-setup.mjs +64 -0
  193. package/templates/.agents/dashboard/tests/e2e/lease-global-setup.ts +37 -0
  194. package/templates/.agents/dashboard/tests/e2e/package.json +1 -1
  195. package/templates/.agents/dashboard/tests/e2e/playwright.config.ts +5 -3
  196. package/templates/.agents/dashboard/tests/e2e/specs/cost-monitor-period-transition.spec.ts +22 -1
  197. package/templates/.agents/dashboard/tests/e2e/specs/dashboard-performance-matrix.spec.ts +17 -8
  198. package/templates/.agents/dashboard/tests/e2e/specs/dashboard.spec.ts +47 -6
  199. package/templates/.agents/dashboard/tests/e2e/specs/lease-lifetime.spec.ts +14 -0
  200. package/templates/.agents/dashboard/tests/observability-fixture.mjs +200 -0
  201. package/templates/.agents/design/.zaip-managed.json +84 -40
  202. package/templates/.agents/design/apps/catalog/dist/assets/index-BJV597iq.js +72 -0
  203. package/templates/.agents/design/apps/catalog/dist/assets/index-BOjCcUaU.js +72 -0
  204. package/templates/.agents/design/apps/catalog/dist/assets/index-B_WhrCZe.js +72 -0
  205. package/templates/.agents/design/apps/catalog/dist/assets/index-CqtYXZfV.js +72 -0
  206. package/templates/.agents/design/apps/catalog/dist/assets/index-D_lfqoyx.js +72 -0
  207. package/templates/.agents/design/apps/catalog/dist/assets/index-i_PO2k9R.js +9 -0
  208. package/templates/.agents/design/apps/catalog/dist/index.html +1 -1
  209. package/templates/.agents/design/apps/catalog/dist/storybook/assets/CatalogShell-Cstn1UwA.js +1 -0
  210. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{Color-6AOWCN3U-B-kAgAjB.js → Color-6AOWCN3U-Cm-yJJz_.js} +1 -1
  211. package/templates/.agents/design/apps/catalog/dist/storybook/assets/Components.stories-D1WopB2L.js +137 -0
  212. package/templates/.agents/design/apps/catalog/dist/storybook/assets/DesignSystem.stories-DQ9PJ3N3.js +1 -0
  213. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{DocsRenderer-JROSPFPF-BVN7xHtv.js → DocsRenderer-JROSPFPF-Belk4jRr.js} +4 -4
  214. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{WithTooltip-7X4HQR7L-CDHtKYkz.js → WithTooltip-7X4HQR7L-DoPvjkS1.js} +1 -1
  215. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{chunk-DRQKCCAG-D6AsDkMK.js → chunk-DRQKCCAG-B1itKXEN.js} +1 -1
  216. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{chunk-W22LQPXL-B4m5uloN.js → chunk-W22LQPXL-C-Eb5SPY.js} +1 -1
  217. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{components-CN8YyTUg.js → components-DnyKLwhj.js} +5 -5
  218. package/templates/.agents/design/apps/catalog/dist/storybook/assets/formatter-L2YTDE3Q-D0OSgxWz.js +1 -0
  219. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{iframe-9yZfIsdT.js → iframe-DcXBsFPz.js} +3 -3
  220. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{react-18-BoCSnq6H.js → react-18-CRM89QRf.js} +1 -1
  221. package/templates/.agents/design/apps/catalog/dist/storybook/assets/react-C3tkVMIp.js +1 -0
  222. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{syntaxhighlighter-YFXUGROL-Bnn_nMwJ.js → syntaxhighlighter-YFXUGROL-B03jQGTF.js} +1 -1
  223. package/templates/.agents/design/apps/catalog/dist/storybook/assets/{theming-DS_ue2sb.js → theming-4ZyufAga.js} +1 -1
  224. package/templates/.agents/design/apps/catalog/dist/storybook/iframe.html +1 -1
  225. package/templates/.agents/design/apps/catalog/dist/storybook/index.json +1 -1
  226. package/templates/.agents/design/apps/catalog/package.json +2 -2
  227. package/templates/.agents/design/apps/catalog/src/components/AutonomySpecimen.tsx +15 -0
  228. package/templates/.agents/design/apps/catalog/src/components/CostPopulationSpecimen.test.tsx +19 -0
  229. package/templates/.agents/design/apps/catalog/src/components/CostPopulationSpecimen.tsx +45 -0
  230. package/templates/.agents/design/apps/catalog/src/components/EstimatedCostSpecimen.tsx +48 -0
  231. package/templates/.agents/design/apps/catalog/src/components/ProjectStatusSpecimen.tsx +169 -0
  232. package/templates/.agents/design/apps/catalog/src/pages/ComponentsPage.tsx +55 -0
  233. package/templates/.agents/design/apps/catalog/src/stories/Components.stories.tsx +60 -0
  234. package/templates/.agents/design/packages/local-runtime/package.json +1 -1
  235. package/templates/.agents/requirements/autonomous-assurance.md +1 -1
  236. package/templates/.agents/requirements/cloud-hostinger-autonomy.md +1 -1
  237. package/templates/.agents/requirements/comparative-audit.md +1 -1
  238. package/templates/.agents/requirements/context-engine.md +1 -1
  239. package/templates/.agents/requirements/cost-observability.md +1 -1
  240. package/templates/.agents/requirements/dashboard-launch.md +1 -1
  241. package/templates/.agents/requirements/data-export.md +1 -1
  242. package/templates/.agents/requirements/design-system.md +1 -1
  243. package/templates/.agents/requirements/execution-engine.md +1 -1
  244. package/templates/.agents/requirements/kanban-dashboard.md +1 -1
  245. package/templates/.agents/requirements/model-orchestration.md +1 -1
  246. package/templates/.agents/requirements/public-distribution.md +1 -1
  247. package/templates/.agents/requirements/software-architecture.md +1 -1
  248. package/templates/.agents/requirements/strategic-improvements.md +1 -1
  249. package/templates/.agents/requirements/work-lifecycle.md +5 -5
  250. package/templates/.agents/requirements/zaip-strategic-95.md +1 -1
  251. package/templates/.agents/rules/astra-diagnostic.md +3 -1
  252. package/templates/.agents/rules/autonomy-decision.md +10 -2
  253. package/templates/.agents/rules/core.md +12 -1
  254. package/templates/.agents/rules/run-lifecycle-closure.md +8 -6
  255. package/templates/.agents/rules/workflow.md +2 -2
  256. package/templates/.agents/runtime/VERSION +1 -1
  257. package/templates/.agents/runtime/bin/zaip.mjs +383 -350
  258. package/templates/.agents/runtime/checksums.sha256 +6 -6
  259. package/templates/.agents/runtime/manifest.json +1 -1
  260. package/templates/.agents/runtime/pnpm-lock.sha256 +1 -1
  261. package/templates/.agents/runtime/provenance.json +5 -5
  262. package/templates/.agents/runtime/sbom.cdx.json +3 -3
  263. package/templates/.agents/skills/zaip-skill-dev-environment/SKILL.md +2 -0
  264. package/templates/.agents/skills/zaip-skill-execution/SKILL.md +28 -5
  265. package/templates/.agents/skills/zaip-skill-execution/references/runtime-governance.md +17 -3
  266. package/templates/.agents/skills/zaip-skill-github-deploy/SKILL.md +8 -9
  267. package/templates/.agents/skills/zaip-skill-github-deploy/references/deployment-workflow.md +10 -6
  268. package/templates/.agents/skills/zaip-skill-github-deploy/references/release-identity.md +17 -12
  269. package/templates/.agents/skills/zaip-skill-move-prd/SKILL.md +2 -0
  270. package/templates/.agents/skills/zaip-skill-prd/SKILL.md +2 -0
  271. package/templates/.agents/skills/zaip-skill-release-qualification/SKILL.md +21 -23
  272. package/templates/.agents/skills/zaip-skill-release-qualification/references/local-preparation.md +37 -13
  273. package/templates/.agents/skills/zaip-skill-setup/SKILL.md +2 -0
  274. package/templates/.agents/skills/zaip-skill-tool-setup/SKILL.md +2 -0
  275. package/templates/.agents/zaip-aios/INDEX.md +9 -1
  276. package/templates/.agents/zaip-aios/README.md +24 -2
  277. package/templates/.agents/zaip-aios/VERSION +1 -1
  278. package/templates/.agents/zaip-aios/guides/01-primeiros-passos.md +5 -1
  279. package/templates/.agents/zaip-aios/guides/03-tasks.md +15 -2
  280. package/templates/.agents/zaip-aios/guides/04-specs.md +13 -0
  281. package/templates/.agents/zaip-aios/guides/05-prds.md +13 -0
  282. package/templates/.agents/zaip-aios/guides/06-execucao.md +19 -4
  283. package/templates/.agents/zaip-aios/guides/07-revisao-e-validacao.md +14 -0
  284. package/templates/.agents/zaip-aios/guides/08-contexto-e-tokens.md +4 -3
  285. package/templates/.agents/zaip-aios/guides/09-agentes-e-squads.md +17 -9
  286. package/templates/.agents/zaip-aios/guides/10-seguranca.md +9 -0
  287. package/templates/.agents/zaip-aios/guides/11-observabilidade-e-custos.md +69 -0
  288. package/templates/.agents/zaip-aios/guides/12-instalacao-e-upgrade.md +9 -4
  289. package/templates/.agents/zaip-aios/guides/13-boas-praticas.md +7 -1
  290. package/templates/.agents/zaip-aios/guides/14-troubleshooting.md +18 -0
  291. package/templates/.agents/zaip-aios/guides/16-lifecycle-e-reconciliacao.md +54 -3
  292. package/templates/.agents/zaip-aios/guides/18-catalogo-de-agentes.md +10 -2
  293. package/templates/.agents/zaip-aios/guides/19-assurance-e-autonomia.md +186 -5
  294. package/templates/.agents/zaip-aios/guides/20-instalacao-detalhada.md +21 -15
  295. package/templates/.agents/zaip-aios/guides/21-telemetria-monitor-custos.md +18 -2
  296. package/templates/.agents/zaip-aios/guides/22-fluxos-e-roteamento.md +14 -2
  297. package/templates/.agents/zaip-aios/guides/23-orquestracao-de-modelos.md +190 -489
  298. package/templates/.agents/zaip-aios/guides/26-qualidade-e-release.md +72 -13
  299. package/templates/.agents/zaip-aios/guides/27-telemetria-git-native.md +18 -0
  300. package/templates/.agents/zaip-aios/guides/28-lifecycle-completo.md +18 -1
  301. package/templates/template-manifest.json +454 -274
  302. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-1L7Qw-Gq.js +0 -3
  303. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-EInWr641.css +0 -1
  304. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-B6aZfo5f.js +0 -68
  305. package/templates/.agents/dashboard/apps/frontend/dist/assets/dashboard-localization-CLJ0lT9v.js +0 -231
  306. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DgTmNHN5.js +0 -2
  307. package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-DQpKX9c1.js +0 -1
  308. package/templates/.agents/design/apps/catalog/dist/storybook/assets/CatalogShell-BWY-80s4.js +0 -1
  309. package/templates/.agents/design/apps/catalog/dist/storybook/assets/Components.stories-Be2mDUQj.js +0 -27
  310. package/templates/.agents/design/apps/catalog/dist/storybook/assets/DesignSystem.stories-DRx9blDs.js +0 -1
  311. package/templates/.agents/design/apps/catalog/dist/storybook/assets/formatter-L2YTDE3Q-EwuTh8Zk.js +0 -1
  312. package/templates/.agents/design/apps/catalog/dist/storybook/assets/react-DyL61NPT.js +0 -1
@@ -34,6 +34,18 @@ const config: ProjectConfigSettings = {
34
34
  };
35
35
 
36
36
  describe("project settings form mapping", () => {
37
+ it.each([
38
+ "essential",
39
+ "balanced",
40
+ "persistent",
41
+ ] as const)("preserves autonomy %s without rewriting execution or assurance", (preset) => {
42
+ const source = { ...config, autonomy: { version: 1 as const, preset } };
43
+ const draft = projectSettingsDraft(source);
44
+ const payload = buildProjectSettingsPayload(source, draft.components, draft.otherOverrides);
45
+ expect(payload.autonomy).toEqual(source.autonomy);
46
+ expect(payload.execution).toEqual(source.execution);
47
+ expect(payload.assurance).toEqual(source.assurance);
48
+ });
37
49
  it("renders a canonical framework SemVer as a short major.minor label", () => {
38
50
  expect(shortFrameworkVersion("2.5.0")).toBe("v2.5");
39
51
  expect(shortFrameworkVersion("v2.5.0")).toBe("v2.5");
@@ -277,7 +277,7 @@ describe("atomic Cost snapshot loading", () => {
277
277
  periodChange.lastIndexOf("setOperationsPeriod(nextPeriod);"),
278
278
  );
279
279
  expect(periodChange).toContain(
280
- "isAllTimeDisplayRangeChange(operationsPeriodRef.current, nextPeriod)",
280
+ "isSameOperationsRequestPeriod(operationsPeriodRef.current, nextPeriod)",
281
281
  );
282
282
  expect(periodChange).toContain("setOperationsLoading(true);");
283
283
  expect(periodChange).toContain('setLoadingArea("operations");');
@@ -1,5 +1,4 @@
1
1
  import type { OperationsProjection } from "@zaip-ai/dashboard-operations/contracts";
2
- import type { OperationsBoardPage } from "./dashboard-api.js";
3
2
 
4
3
  /** The selector is a navigation aid, not a full task export. */
5
4
  export const traceabilityTaskPageSize = 10;
@@ -12,7 +11,7 @@ export function appendTraceabilityTaskPage({
12
11
  tasks,
13
12
  }: {
14
13
  cursor: TraceabilityTaskCursor;
15
- page: OperationsBoardPage;
14
+ page: { tasks: OperationsProjection["tasks"]; total: number };
16
15
  tasks: OperationsProjection["tasks"];
17
16
  }): { cursor: TraceabilityTaskCursor; tasks: OperationsProjection["tasks"] } {
18
17
  const tasksById = new Map(tasks.map((task) => [task.id, task]));
@@ -10,12 +10,15 @@ import {
10
10
  describe("daily Cost Monitor continuous pagination", () => {
11
11
  it("uses cost_monitor_daily as a 30-day direct pager across months and keeps full-filter totals", async () => {
12
12
  const calls: Array<{ view: string; range: unknown; page: Record<string, unknown> }> = [];
13
+ const average = { tasks: 5, specs: 2, prds: 1, durationMs: 1000, tokens: 50, cost: 10 };
14
+ const periodAverages = { BRL: average, USD: { ...average, cost: 2 } };
13
15
  const api = {
14
16
  sqliteViewPage: async (view: string, range: unknown, page: Record<string, unknown>) => {
15
17
  calls.push({ view, range, page });
16
18
  if (page.offset === 0) {
17
19
  return {
18
20
  offset: 0,
21
+ period_averages: periodAverages,
19
22
  limit: 30,
20
23
  total_count: 35,
21
24
  has_more: true,
@@ -34,6 +37,7 @@ describe("daily Cost Monitor continuous pagination", () => {
34
37
  }
35
38
  return {
36
39
  offset: 30,
40
+ period_averages: periodAverages,
37
41
  limit: 30,
38
42
  total_count: 35,
39
43
  has_more: false,
@@ -83,6 +87,8 @@ describe("daily Cost Monitor continuous pagination", () => {
83
87
  filters,
84
88
  });
85
89
 
90
+ expect(firstPage.period_averages).toEqual(periodAverages);
91
+ expect(secondPage.period_averages).toEqual(periodAverages);
86
92
  expect(calls).toEqual([
87
93
  {
88
94
  view: "cost_monitor_daily",
@@ -90,6 +90,7 @@ export async function loadSqliteCostGroupPage(
90
90
  total_count: page.total_count,
91
91
  has_more: page.has_more,
92
92
  rows: page.rows.map(adaptSqliteCostGroup),
93
+ ...(page.period_averages === undefined ? {} : { period_averages: page.period_averages }),
93
94
  ...(page.totals === undefined ? {} : { totals: adaptSqliteCostGroup(page.totals) }),
94
95
  };
95
96
  }
@@ -114,6 +115,7 @@ export async function loadSqliteCostGroupPage(
114
115
  total_count: page.total_count,
115
116
  has_more: page.has_more,
116
117
  rows: page.rows.map(adaptSqliteCostGroup),
118
+ ...(page.period_averages === undefined ? {} : { period_averages: page.period_averages }),
117
119
  ...(page.totals === undefined ? {} : { totals: adaptSqliteCostGroup(page.totals) }),
118
120
  };
119
121
  }
@@ -65,7 +65,9 @@ export function useAppTraceDocuments({
65
65
  task_title: cardTask?.title || loadedTrace.task_title || taskId,
66
66
  task_risk: cardTask?.risk || loadedTrace.task_risk || null,
67
67
  task_created_at: cardTask?.created_at || loadedTrace.task_created_at || null,
68
- task_progress: cardTask?.progress ?? loadedTrace.task_progress ?? 0,
68
+ // The detail response is authoritative; an earlier quick card may still
69
+ // carry a partial/default progress value during hydration.
70
+ task_progress: loadedTrace.task_progress ?? cardTask?.progress ?? 0,
69
71
  });
70
72
  return true;
71
73
  } catch (cause) {
@@ -7,7 +7,6 @@ import {
7
7
  useRef,
8
8
  useState,
9
9
  } from "react";
10
- import { traceTaskSearchStages } from "./AppWorkBoard.js";
11
10
  import type { DashboardApiClient } from "./dashboard-api.js";
12
11
  import {
13
12
  appendTraceabilityTaskPage,
@@ -35,24 +34,14 @@ export function useAppTraceTaskPagination(
35
34
  setTraceTasks([]);
36
35
  setTraceTasksHasMore(true);
37
36
  }
38
- if (traceTaskCursorRef.current.stageIndex >= traceTaskSearchStages.length)
39
- return traceTasksRef.current;
37
+ if (traceTaskCursorRef.current.stageIndex >= 1) return traceTasksRef.current;
40
38
 
41
39
  traceTasksLoadingRef.current = true;
42
40
  setTraceTasksLoading(true);
43
41
  try {
44
42
  do {
45
43
  const cursor = traceTaskCursorRef.current;
46
- const stage = traceTaskSearchStages[cursor.stageIndex];
47
- if (stage === undefined) break;
48
- const page = await api.operationsBoard(
49
- { from: null, to: null },
50
- stage,
51
- cursor.offset,
52
- { kind: "all-tasks" },
53
- undefined,
54
- traceabilityTaskPageSize,
55
- );
44
+ const page = await api.traceabilityTasks(cursor.offset, traceabilityTaskPageSize);
56
45
  const updated = appendTraceabilityTaskPage({
57
46
  cursor,
58
47
  page,
@@ -62,8 +51,8 @@ export function useAppTraceTaskPagination(
62
51
  setTraceTasks(traceTasksRef.current);
63
52
  traceTaskCursorRef.current = updated.cursor;
64
53
  if (page.tasks.length > 0 && !loadAll) break;
65
- } while (traceTaskCursorRef.current.stageIndex < traceTaskSearchStages.length);
66
- setTraceTasksHasMore(traceTaskCursorRef.current.stageIndex < traceTaskSearchStages.length);
54
+ } while (traceTaskCursorRef.current.stageIndex < 1);
55
+ setTraceTasksHasMore(traceTaskCursorRef.current.stageIndex < 1);
67
56
  return traceTasksRef.current;
68
57
  } finally {
69
58
  traceTasksLoadingRef.current = false;
@@ -620,7 +620,7 @@ export function useDashboardAppModel() {
620
620
  setTraceLoadingTaskId,
621
621
  });
622
622
  const currentCostByRun = buildCurrentCostByRun(costs, displayedCosts, currency);
623
- const { total: factualCostTotal, periods: factualCostPeriods } = factualCostFacts(
623
+ const { fact: factualCostFact, periods: factualCostPeriods } = factualCostFacts(
624
624
  costs,
625
625
  displayedCosts,
626
626
  currency,
@@ -724,7 +724,7 @@ export function useDashboardAppModel() {
724
724
  entityPage,
725
725
  dashboardIdentity,
726
726
  operationsLoading,
727
- factualCostTotal,
727
+ factualCostFact,
728
728
  factualCostPeriods,
729
729
  setOperationsSurfaceLoading,
730
730
  currentCostByRun,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaip-ai/dashboard-cost-monitor",
3
- "version": "2.6.0",
3
+ "version": "3.1.0",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,73 @@
1
+ import type { OperationsProjection } from "@zaip-ai/dashboard-operations/contracts";
2
+ import { describe, expect, it } from "vitest";
3
+ import { averageCompleteCost } from "./contracts.js";
4
+ import { buildCostSummaryProjection } from "./server/build-cost-summary-projection.js";
5
+
6
+ describe("population cost averages", () => {
7
+ it.each([
8
+ { unknown: 1, total: 10, expected: null },
9
+ { unknown: 1, total: 0, expected: null },
10
+ { unknown: 0, total: 0, expected: 0 },
11
+ { unknown: 0, total: 10, expected: 5 },
12
+ ])("summary retains subtotal but not diluted mean: $unknown/$total", ({
13
+ unknown,
14
+ total,
15
+ expected,
16
+ }) => {
17
+ const operations = {
18
+ schema_version: 2,
19
+ layout_version: 3,
20
+ readonly: true,
21
+ source: ".agents/records",
22
+ filters: { from: null, to: null },
23
+ summary: { task_count: 1, overview_metrics: {}, usage: {} },
24
+ prds: [],
25
+ specs: [],
26
+ runs: [],
27
+ } as unknown as OperationsProjection;
28
+ const cost = {
29
+ known_sum: total,
30
+ unknown,
31
+ complete: unknown === 0,
32
+ coverage_ratio: (2 - unknown) / 2,
33
+ currency: "BRL",
34
+ };
35
+ const projection = buildCostSummaryProjection(
36
+ {
37
+ periods: {
38
+ daily: {
39
+ "2026-08-19": {
40
+ prds: 0,
41
+ specs: 0,
42
+ tasks: 1,
43
+ validations: 0,
44
+ evidences: 0,
45
+ runs: 2,
46
+ usage: {
47
+ total_tokens: { known_sum: 100, unknown: 0, complete: true, coverage_ratio: 1 },
48
+ cost,
49
+ },
50
+ },
51
+ },
52
+ },
53
+ cost_monitor_daily_duration: {},
54
+ daily_rows: [{ key: "2026-08-19", total_cost_usd: total, total_cost_brl: total }],
55
+ },
56
+ operations,
57
+ "BRL",
58
+ null,
59
+ );
60
+ expect(projection.overview.estimated_brl).toBe(total);
61
+ expect(projection.overview.average_run_cost_brl).toBe(expected);
62
+ });
63
+ it.each([
64
+ { values: [], expected: null },
65
+ { values: [null], expected: null },
66
+ { values: [10, null], expected: null },
67
+ { values: [0, null], expected: null },
68
+ { values: [0, 0], expected: 0 },
69
+ { values: [10, 20], expected: 15 },
70
+ ])("preserves completeness: $values", ({ values, expected }) => {
71
+ expect(averageCompleteCost(values)).toBe(expected);
72
+ });
73
+ });
@@ -1,4 +1,7 @@
1
1
  import type { ReadonlyV2Projection } from "@zaip-ai/dashboard-contracts";
2
+
3
+ export type { CostPeriodAverages } from "./period-averages.js";
4
+
2
5
  import type {
3
6
  MacroProjection,
4
7
  ProjectionTimeFilter,
@@ -22,6 +25,12 @@ export interface DurationCoverage {
22
25
  export type DurationAggregationScope = "root_execution" | "all_execution" | "all_invocations";
23
26
 
24
27
  /** Returns the sum of reported values; missing telemetry does not erase known usage. */
28
+ /** A population average must not treat missing Run costs as observed zero. */
29
+ export function averageCompleteCost(values: readonly (number | null)[]): number | null {
30
+ if (values.length === 0 || values.some((value) => value === null)) return null;
31
+ return values.reduce<number>((total, value) => total + (value ?? 0), 0) / values.length;
32
+ }
33
+
25
34
  export function sumKnown(values: readonly (number | null)[]): number | null {
26
35
  const known = values.filter((value): value is number => value !== null);
27
36
  return known.length === 0 ? null : known.reduce((sum, value) => sum + value, 0);
@@ -0,0 +1,60 @@
1
+ import type { CostGroupRow } from "./contracts.js";
2
+
3
+ export interface CostPeriodAverages {
4
+ tasks: number | null;
5
+ specs: number | null;
6
+ prds: number | null;
7
+ durationMs: number | null;
8
+ tokens: number | null;
9
+ cost: number | null;
10
+ }
11
+
12
+ export function summarizeCostPeriodAverages(
13
+ rows: readonly Pick<
14
+ CostGroupRow,
15
+ | "task_count"
16
+ | "spec_count"
17
+ | "prd_count"
18
+ | "duration_ms"
19
+ | "total_tokens"
20
+ | "estimated_usd"
21
+ | "estimated_brl"
22
+ >[],
23
+ currency: "BRL" | "USD",
24
+ ): CostPeriodAverages {
25
+ const divisor = rows.length;
26
+ return {
27
+ tasks: averagePerPeriod(
28
+ rows.map((row) => row.task_count),
29
+ divisor,
30
+ ),
31
+ specs: averagePerPeriod(
32
+ rows.map((row) => row.spec_count),
33
+ divisor,
34
+ ),
35
+ prds: averagePerPeriod(
36
+ rows.map((row) => row.prd_count),
37
+ divisor,
38
+ ),
39
+ durationMs: averagePerPeriod(
40
+ rows.map((row) => row.duration_ms),
41
+ divisor,
42
+ ),
43
+ tokens: averageObserved(rows.map((row) => row.total_tokens)),
44
+ cost: averageObserved(
45
+ rows.map((row) => (currency === "BRL" ? row.estimated_brl : row.estimated_usd)),
46
+ ),
47
+ };
48
+ }
49
+
50
+ function averageObserved(values: readonly (number | null)[]): number | null {
51
+ const present = values.filter((value): value is number => value !== null);
52
+ return present.length === 0
53
+ ? null
54
+ : present.reduce((sum, value) => sum + value, 0) / present.length;
55
+ }
56
+
57
+ function averagePerPeriod(values: readonly (number | null)[], periodCount: number): number | null {
58
+ if (periodCount === 0 || values.every((value) => value === null)) return null;
59
+ return values.reduce<number>((sum, value) => sum + (value ?? 0), 0) / periodCount;
60
+ }
@@ -11,9 +11,9 @@ import type { CostCurrency, CostLocale } from "./cost-monitor-copy.js";
11
11
  import type { CostView } from "./cost-monitor-views.js";
12
12
  import { MacroCostTable } from "./MacroCostTable.js";
13
13
  import {
14
+ type CostGroupPage,
14
15
  type CostGroupTotals,
15
16
  costGroupPageLabel,
16
- reconcileCostGroupTotalsWithCards,
17
17
  } from "./use-cost-group-page.js";
18
18
 
19
19
  type CostRunRows = ComponentProps<typeof CostRunsTable>["rows"];
@@ -90,13 +90,7 @@ export function CostMonitorContent({
90
90
  providers: CostGroupRows;
91
91
  tasks: CostGroupRows;
92
92
  };
93
- groupPage: {
94
- offset: number;
95
- limit: number;
96
- total_count: number;
97
- has_more: boolean;
98
- totals?: CostGroupTotals;
99
- } | null;
93
+ groupPage: Omit<CostGroupPage, "rows"> | null;
100
94
  groupPageLoading: boolean;
101
95
  groupPageOffset: number;
102
96
  locale: CostLocale;
@@ -290,15 +284,7 @@ export function CostMonitorContent({
290
284
  locale={locale}
291
285
  loading={groupPageLoading}
292
286
  rows={groups[key]}
293
- {...(key === "models"
294
- ? groupPage?.totals === undefined
295
- ? {}
296
- : { totals: groupPage.totals }
297
- : key === "providers"
298
- ? { totals: summaryTotals }
299
- : groupPage?.totals === undefined
300
- ? {}
301
- : { totals: groupPage.totals })}
287
+ {...(groupPage?.totals === undefined ? {} : { totals: groupPage.totals })}
302
288
  {...(key === "agents"
303
289
  ? { showDateTime: false, showAgentIdentity: true }
304
290
  : key === "models"
@@ -316,6 +302,10 @@ export function CostMonitorContent({
316
302
  <CostPeriodAverageCards
317
303
  currency={currency}
318
304
  locale={locale}
305
+ loading={groupPageLoading}
306
+ {...(groupPage === null
307
+ ? {}
308
+ : { average: groupPage.period_averages?.[currency] ?? null })}
319
309
  period={view}
320
310
  rows={groups[view]}
321
311
  />
@@ -326,11 +316,7 @@ export function CostMonitorContent({
326
316
  period={view}
327
317
  rows={groups[view]}
328
318
  showDateTime={false}
329
- totals={
330
- groupPage?.totals === undefined
331
- ? summaryTotals
332
- : reconcileCostGroupTotalsWithCards(groupPage.totals, summaryTotals)
333
- }
319
+ totals={groupPage?.totals ?? summaryTotals}
334
320
  />
335
321
  {groupPager}
336
322
  </>
@@ -491,9 +491,8 @@ export function CostMonitorPage({
491
491
  (total, row) => total + row.duration.known_sum,
492
492
  0,
493
493
  );
494
- // Model/provider rows intentionally omit untrusted dimensions. Their footer
495
- // remains the canonical card population for the same filters, never the
496
- // visible subset or its paginated SQLite total.
494
+ // Card totals are a fallback for local, non-paged data only. Remote tables
495
+ // retain the full filtered totals returned alongside their paginated rows.
497
496
  const cardMetrics = operations?.summary.overview_metrics;
498
497
  const cardDurationTotal = cardMetrics ? cardMetrics.duration_ms : canonicalDurationTotal;
499
498
  const summaryTotals = {
@@ -5,49 +5,73 @@ import {
5
5
  formatNumber,
6
6
  PeriodAverageCards,
7
7
  } from "@zaip-ai/dashboard-ui";
8
- import type { CostGroupRow } from "../contracts.js";
8
+ import type { CostGroupRow, CostPeriodAverages } from "../contracts.js";
9
9
  import type { CostCurrency, CostLocale } from "./cost-monitor-copy.js";
10
10
  import { type CostPeriodGranularity, summarizeCostPeriodAverages } from "./period-cost-groups.js";
11
11
 
12
12
  export function CostPeriodAverageCards({
13
13
  currency,
14
14
  locale,
15
+ loading = false,
16
+ average: suppliedAverage,
15
17
  period,
16
18
  rows,
17
19
  }: {
18
20
  currency: CostCurrency;
19
21
  locale: CostLocale;
22
+ loading?: boolean;
23
+ average?: CostPeriodAverages | null;
20
24
  period: CostPeriodGranularity;
21
25
  rows: readonly CostGroupRow[];
22
26
  }) {
23
- const average = summarizeCostPeriodAverages(rows, currency);
27
+ if (loading) {
28
+ return <p role="status">{locale === "pt-BR" ? "Carregando médias…" : "Loading averages…"}</p>;
29
+ }
30
+ // A server page without full-population averages is unavailable, never a page-only average.
31
+ const average =
32
+ suppliedAverage === undefined
33
+ ? summarizeCostPeriodAverages(rows, currency)
34
+ : (suppliedAverage ?? {
35
+ tasks: null,
36
+ specs: null,
37
+ prds: null,
38
+ durationMs: null,
39
+ tokens: null,
40
+ cost: null,
41
+ });
42
+ const unavailable = locale === "pt-BR" ? "Indisponível" : "Unavailable";
24
43
  return (
25
44
  <PeriodAverageCards
26
45
  ariaLabel={periodAverageAriaLabel(period, locale)}
27
46
  metrics={[
28
47
  {
29
48
  label: periodAverageMetricLabel(locale === "pt-BR" ? "Tarefas" : "Tasks", period, locale),
30
- value: formatNumber(average.tasks, locale, 1),
49
+ value: average.tasks === null ? unavailable : formatNumber(average.tasks, locale, 1),
31
50
  },
32
51
  {
33
52
  label: periodAverageMetricLabel("SPECs", period, locale),
34
- value: formatNumber(average.specs, locale, 1),
53
+ value: average.specs === null ? unavailable : formatNumber(average.specs, locale, 1),
35
54
  },
36
55
  {
37
56
  label: periodAverageMetricLabel("PRDs", period, locale),
38
- value: formatNumber(average.prds, locale, 1),
57
+ value: average.prds === null ? unavailable : formatNumber(average.prds, locale, 1),
39
58
  },
40
59
  {
41
60
  label: periodAverageMetricLabel(locale === "pt-BR" ? "Tempo" : "Time", period, locale),
42
- value: formatAverageDurationMs(average.durationMs, locale),
61
+ value:
62
+ average.durationMs === null
63
+ ? unavailable
64
+ : formatAverageDurationMs(average.durationMs, locale),
43
65
  },
44
66
  {
45
67
  label: periodAverageMetricLabel("Tokens", period, locale),
46
- value: formatCompactNumber(average.tokens, locale),
68
+ value:
69
+ average.tokens === null ? unavailable : formatCompactNumber(average.tokens, locale),
47
70
  },
48
71
  {
49
72
  label: periodAverageMetricLabel(locale === "pt-BR" ? "Custo" : "Cost", period, locale),
50
- value: formatCurrency(average.cost, currency, locale),
73
+ value:
74
+ average.cost === null ? unavailable : formatCurrency(average.cost, currency, locale),
51
75
  },
52
76
  ]}
53
77
  />
@@ -5,6 +5,7 @@ import {
5
5
  } from "@zaip-ai/dashboard-operations/contracts";
6
6
  import {
7
7
  aggregateDurationCoverage,
8
+ averageCompleteCost,
8
9
  type CostGroupRow,
9
10
  type CostMonitorProjection,
10
11
  type CostRunRow,
@@ -120,8 +121,8 @@ export function summarizeCostRows(
120
121
  estimated_brl: sumKnown(rows.map((row) => row.estimated_brl)),
121
122
  recorded_usd: sumKnown(rows.map((row) => row.recorded_usd)),
122
123
  recorded_brl: sumKnown(rows.map((row) => row.recorded_brl)),
123
- average_run_cost_usd: average(rows.map((row) => row.estimated_usd)),
124
- average_run_cost_brl: average(rows.map((row) => row.estimated_brl)),
124
+ average_run_cost_usd: averageCompleteCost(rows.map((row) => row.estimated_usd)),
125
+ average_run_cost_brl: averageCompleteCost(rows.map((row) => row.estimated_brl)),
125
126
  average_run_duration_ms: average(durationContributors(rows).map((row) => row.duration_ms)),
126
127
  known_tokens_per_cycle: knownCycles === 0 ? null : knownTokens / knownCycles,
127
128
  top_10_token_share: knownTokens === 0 ? null : top10Tokens / knownTokens,
@@ -3,14 +3,7 @@ import type { CostGroupRow } from "../contracts.js";
3
3
 
4
4
  export type CostPeriodGranularity = "daily" | "monthly" | "annual";
5
5
 
6
- export interface CostPeriodAverages {
7
- tasks: number | null;
8
- specs: number | null;
9
- prds: number | null;
10
- durationMs: number | null;
11
- tokens: number | null;
12
- cost: number | null;
13
- }
6
+ export { type CostPeriodAverages, summarizeCostPeriodAverages } from "../period-averages.js";
14
7
 
15
8
  interface PeriodEntities {
16
9
  prds: readonly { created_at: string | null }[];
@@ -122,40 +115,6 @@ export function enrichPeriodCostGroups(
122
115
  return [...rows.values()].sort((left, right) => right.key.localeCompare(left.key));
123
116
  }
124
117
 
125
- export function summarizeCostPeriodAverages(
126
- rows: readonly CostGroupRow[],
127
- currency: "BRL" | "USD",
128
- ): CostPeriodAverages {
129
- const divisor = rows.length;
130
- return {
131
- tasks:
132
- divisor === 0 ? null : rows.reduce((sum, row) => sum + (row.task_count ?? 0), 0) / divisor,
133
- specs:
134
- divisor === 0 ? null : rows.reduce((sum, row) => sum + (row.spec_count ?? 0), 0) / divisor,
135
- prds: divisor === 0 ? null : rows.reduce((sum, row) => sum + (row.prd_count ?? 0), 0) / divisor,
136
- durationMs: averagePerPeriod(
137
- rows.map((row) => row.duration_ms),
138
- divisor,
139
- ),
140
- tokens: averageObserved(rows.map((row) => row.total_tokens)),
141
- cost: averageObserved(
142
- rows.map((row) => (currency === "BRL" ? row.estimated_brl : row.estimated_usd)),
143
- ),
144
- };
145
- }
146
-
147
- function averageObserved(values: readonly (number | null)[]): number | null {
148
- const present = values.filter((value): value is number => value !== null);
149
- return present.length === 0
150
- ? null
151
- : present.reduce((sum, value) => sum + value, 0) / present.length;
152
- }
153
-
154
- function averagePerPeriod(values: readonly (number | null)[], periodCount: number): number | null {
155
- if (periodCount === 0) return null;
156
- return values.reduce<number>((sum, value) => sum + (value ?? 0), 0) / periodCount;
157
- }
158
-
159
118
  function periodKey(value: string | null, granularity: CostPeriodGranularity): string | null {
160
119
  return saoPauloPeriodKey(
161
120
  value,
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
- import type { CostGroupRow } from "../contracts.js";
2
+ import type { CostGroupRow, CostPeriodAverages } from "../contracts.js";
3
3
  import type { CostFilterState } from "./CostFilters.js";
4
4
  import type { CostLocale } from "./cost-monitor-copy.js";
5
5
 
@@ -26,6 +26,7 @@ export type CostGroupPage = {
26
26
  has_more: boolean;
27
27
  rows: readonly CostGroupRow[];
28
28
  totals?: CostGroupTotals;
29
+ period_averages?: Record<"BRL" | "USD", CostPeriodAverages>;
29
30
  };
30
31
  export type CostGroupFilters = CostFilterState;
31
32
  export type LoadCostGroupPage = (request: {
@@ -15,6 +15,7 @@ import type {
15
15
  import { LEGACY_EFFORT_SNAPSHOT, saoPauloPeriodKey } from "@zaip-ai/dashboard-operations/contracts";
16
16
  import { includeConfiguredAgentGroups } from "../agent-groups.js";
17
17
  import {
18
+ averageCompleteCost,
18
19
  type CostMonitorProjection,
19
20
  type CostRunRow,
20
21
  durationAggregationRows,
@@ -215,8 +216,8 @@ export function buildCostMonitorProjection(
215
216
  recorded_brl: availableCurrencySum(
216
217
  tableRuns.map((run) => recordedRunsById.get(run.id)?.usage.total.cost.brl ?? null),
217
218
  ),
218
- average_run_cost_usd: averageAvailable(rows.map((row) => row.estimated_usd)),
219
- average_run_cost_brl: averageAvailable(rows.map((row) => row.estimated_brl)),
219
+ average_run_cost_usd: averageCompleteCost(rows.map((row) => row.estimated_usd)),
220
+ average_run_cost_brl: averageCompleteCost(rows.map((row) => row.estimated_brl)),
220
221
  average_run_duration_ms: averageAvailable(
221
222
  durationAggregationRows(rows).map((row) => row.duration_ms),
222
223
  ),
@@ -183,8 +183,14 @@ export function buildCostSummaryProjection(
183
183
  estimated_brl: brlTotal,
184
184
  recorded_usd: null,
185
185
  recorded_brl: null,
186
- average_run_cost_usd: runCount === 0 || usdTotal === null ? null : usdTotal / runCount,
187
- average_run_cost_brl: runCount === 0 || brlTotal === null ? null : brlTotal / runCount,
186
+ average_run_cost_usd:
187
+ runCount === 0 || usdTotal === null || coverage.usd !== runCount
188
+ ? null
189
+ : usdTotal / runCount,
190
+ average_run_cost_brl:
191
+ runCount === 0 || brlTotal === null || coverage.brl !== runCount
192
+ ? null
193
+ : brlTotal / runCount,
188
194
  // Legacy effort has no individual Run cardinality, so it is not a
189
195
  // legitimate contributor to an average per Run.
190
196
  average_run_duration_ms: observedDurationAverage,
@@ -1,3 +1,4 @@
1
+ export { summarizeCostPeriodAverages } from "../period-averages.js";
1
2
  export * from "./build-cost-monitor-projection.js";
2
3
  export * from "./build-cost-summary-projection.js";
3
4
  export * from "./run-telemetry.js";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaip-ai/dashboard-operations",
3
- "version": "2.6.0",
3
+ "version": "3.1.0",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {