@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.
Files changed (360) hide show
  1. package/README.md +1 -1
  2. package/dist/services/adapters.d.ts +1 -1
  3. package/dist/services/adapters.js +1 -1
  4. package/dist/services/agent-adapters.js +3 -3
  5. package/dist/services/agent-adapters.js.map +1 -1
  6. package/dist/services/agent-adapters.test.js +7 -1
  7. package/dist/services/agent-adapters.test.js.map +1 -1
  8. package/dist/services/codex-pre-tool-hook-template.d.ts.map +1 -1
  9. package/dist/services/codex-pre-tool-hook-template.js +89 -7
  10. package/dist/services/codex-pre-tool-hook-template.js.map +1 -1
  11. package/dist/services/codex-rules.d.ts +1 -1
  12. package/dist/services/codex-rules.d.ts.map +1 -1
  13. package/dist/services/codex-rules.js +7 -0
  14. package/dist/services/codex-rules.js.map +1 -1
  15. package/dist/services/install-agents-template.d.ts.map +1 -1
  16. package/dist/services/install-agents-template.js +1 -0
  17. package/dist/services/install-agents-template.js.map +1 -1
  18. package/dist/services/logger.test.js +2 -2
  19. package/dist/services/runtime-template.test.js +31 -7
  20. package/dist/services/runtime-template.test.js.map +1 -1
  21. package/dist/services/template-manifest.d.ts.map +1 -1
  22. package/dist/services/template-manifest.js +12 -3
  23. package/dist/services/template-manifest.js.map +1 -1
  24. package/package.json +1 -1
  25. package/templates/.agents/architecture/software-architecture.md +131 -0
  26. package/templates/.agents/branding/brandbook.docx +0 -0
  27. package/templates/.agents/branding/brandbook.md +60 -0
  28. package/templates/.agents/config/agents/catalog.yaml +7 -7
  29. package/templates/.agents/config/clients/codex/agents/zaip-agent-backend.toml +2 -2
  30. package/templates/.agents/config/clients/codex/agents/zaip-agent-designer.toml +2 -2
  31. package/templates/.agents/config/clients/codex/agents/zaip-agent-finalizer.toml +1 -1
  32. package/templates/.agents/config/clients/codex/agents/zaip-agent-frontend.toml +8 -8
  33. package/templates/.agents/config/clients/codex/agents/zaip-agent-orchestrator.toml +1 -1
  34. package/templates/.agents/dashboard/.tmp-run-list.json +254 -0
  35. package/templates/.agents/dashboard/.zaip-managed.json +457 -173
  36. package/templates/.agents/dashboard/apps/frontend/dist/assets/{CostCalculationGuidePage-Z60df2r-.js → CostCalculationGuidePage-ovxurkIk.js} +1 -1
  37. package/templates/.agents/dashboard/apps/frontend/dist/assets/DashboardHelpDialog-BgVgrfhQ.js +2310 -0
  38. package/templates/.agents/dashboard/apps/frontend/dist/assets/{PricingSettingsDialog-Coc6pA-1.js → PricingSettingsDialog-vSvvOHQp.js} +1 -1
  39. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-BomxqCBU.css +1 -0
  40. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-zH758vfs.js +3 -0
  41. package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-DLn-Mz2M.js +1 -0
  42. package/templates/.agents/dashboard/apps/frontend/dist/assets/{TraceabilityWorkspace-CaKwQP43.css → TraceabilityWorkspace-DvvavDLY.css} +1 -1
  43. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-DKwP1stV.js +68 -0
  44. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-PoJA2PI1.css +1 -0
  45. package/templates/.agents/dashboard/apps/frontend/dist/assets/{icons-vendor-DFBuc_qp.js → icons-vendor-B_lDDHn1.js} +1 -1
  46. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-B31GMG5O.css +1 -0
  47. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-CZQlsLV9.js +2 -0
  48. package/templates/.agents/dashboard/apps/frontend/dist/assets/{react-vendor-CCQOHdVI.js → react-vendor-B3TJrD4O.js} +1 -1
  49. package/templates/.agents/dashboard/apps/frontend/dist/assets/{traceability-pC2_0J8x.js → traceability-7f1j5wx3.js} +1 -1
  50. package/templates/.agents/dashboard/apps/frontend/dist/index.html +7 -7
  51. package/templates/.agents/dashboard/apps/frontend/package.json +1 -1
  52. package/templates/.agents/dashboard/apps/frontend/playwright.dom.config.ts +32 -0
  53. package/templates/.agents/dashboard/apps/frontend/src/App.tsx +199 -140
  54. package/templates/.agents/dashboard/apps/frontend/src/AppOverlays.tsx +0 -21
  55. package/templates/.agents/dashboard/apps/frontend/src/DashboardAlternateContent.tsx +20 -11
  56. package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.tsx +14 -7
  57. package/templates/.agents/dashboard/apps/frontend/src/ProjectStackEditor.tsx +4 -2
  58. package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.dom.e2e.ts +56 -0
  59. package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.test.ts +21 -2
  60. package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.tsx +89 -19
  61. package/templates/.agents/dashboard/apps/frontend/src/cost-period-refresh.test.ts +19 -4
  62. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.test.ts +49 -3
  63. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.ts +29 -10
  64. package/templates/.agents/dashboard/apps/frontend/src/operations-period-render.test.ts +4 -4
  65. package/templates/.agents/dashboard/apps/frontend/src/overview-status-page.test.ts +4 -2
  66. package/templates/.agents/dashboard/apps/frontend/src/project-settings-page.css +36 -26
  67. package/templates/.agents/dashboard/apps/frontend/src/project-settings.test.ts +2 -2
  68. package/templates/.agents/dashboard/apps/frontend/src/snapshot-banner-semantics.test.ts +47 -6
  69. package/templates/.agents/dashboard/apps/frontend/src/snapshot-coherence.test.ts +59 -9
  70. package/templates/.agents/dashboard/apps/frontend/src/sqlite-page-export.test.ts +32 -0
  71. package/templates/.agents/dashboard/apps/frontend/src/sqlite-page-export.ts +21 -0
  72. package/templates/.agents/dashboard/apps/frontend/src/styles.css +19 -0
  73. package/templates/.agents/dashboard/apps/frontend/src/traceability-task-pagination.test.ts +32 -0
  74. package/templates/.agents/dashboard/apps/frontend/src/traceability-task-pagination.ts +36 -0
  75. package/templates/.agents/dashboard/apps/frontend/src/traceability-workspace.css +6 -2
  76. package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.test.ts +137 -23
  77. package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.ts +229 -35
  78. package/templates/.agents/dashboard/apps/frontend/src/use-app-effects.ts +61 -7
  79. package/templates/.agents/dashboard/apps/frontend/src/use-app-operations-pages.ts +3 -6
  80. package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-documents.ts +7 -1
  81. package/templates/.agents/dashboard/apps/frontend/src/use-app-work-list-page.test.ts +163 -0
  82. package/templates/.agents/dashboard/apps/frontend/src/use-app-work-list-page.ts +136 -0
  83. package/templates/.agents/dashboard/apps/frontend/src/use-operations-detail-export.ts +76 -0
  84. package/templates/.agents/dashboard/apps/frontend/src/work-list-load-dedup.test.ts +23 -0
  85. package/templates/.agents/dashboard/apps/frontend/src/work-list-load-dedup.ts +27 -0
  86. package/templates/.agents/dashboard/apps/frontend/src/work-list-pagination.test.ts +39 -15
  87. package/templates/.agents/dashboard/apps/frontend/src/work-list-pagination.ts +3 -4
  88. package/templates/.agents/dashboard/apps/frontend/vite.config.ts +4 -1
  89. package/templates/.agents/dashboard/modules/cost-monitor/package.json +1 -1
  90. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CompactLifecycleCostTable.test.ts +89 -19
  91. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CompactLifecycleCostTable.tsx +31 -16
  92. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostCharts.test.ts +43 -14
  93. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostCharts.tsx +5 -5
  94. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostDeveloperAttributionPanel.tsx +60 -0
  95. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostDeveloperAttributionTable.tsx +191 -0
  96. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.loading.test.ts +14 -0
  97. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.run-page.test.ts +18 -0
  98. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.tsx +18 -3
  99. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostModelsAuditTable.tsx +1 -1
  100. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorContent.tsx +75 -44
  101. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorLoadErrors.tsx +35 -0
  102. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.test.ts +162 -40
  103. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.tsx +221 -79
  104. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTableLoading.test.ts +132 -0
  105. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTableLoading.tsx +70 -0
  106. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.test.ts +203 -155
  107. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.tsx +164 -125
  108. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-copy.ts +2 -0
  109. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-views.ts +3 -1
  110. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor.css +5 -2
  111. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-page-range.ts +35 -0
  112. package/templates/.agents/dashboard/modules/cost-monitor/src/react/index.ts +2 -2
  113. package/templates/.agents/dashboard/modules/cost-monitor/src/react/period-cost-groups.ts +2 -1
  114. package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-compact-cost-page.ts +32 -9
  115. package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.test.ts +37 -2
  116. package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.ts +131 -9
  117. package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-run-page.ts +34 -17
  118. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.test.ts +0 -24
  119. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.test.ts +225 -424
  120. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.ts +24 -15
  121. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-terminal-day.test.ts +6 -1
  122. package/templates/.agents/dashboard/modules/cost-monitor/src/server/source-size-cost-server/build-cost-monitor-projection-agents.test.ts +31 -0
  123. package/templates/.agents/dashboard/modules/cost-monitor/src/server/source-size-cost-server/build-cost-summary-projection-duration.test.ts +414 -0
  124. package/templates/.agents/dashboard/modules/operations/package.json +1 -1
  125. package/templates/.agents/dashboard/modules/operations/src/contracts.ts +46 -26
  126. package/templates/.agents/dashboard/modules/operations/src/react/DeveloperAttributionPanel.test.ts +54 -0
  127. package/templates/.agents/dashboard/modules/operations/src/react/DeveloperAttributionPanel.tsx +247 -0
  128. package/templates/.agents/dashboard/modules/operations/src/react/EntityTables.tsx +31 -11
  129. package/templates/.agents/dashboard/modules/operations/src/react/OperationsMainContent.tsx +39 -13
  130. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.helpers.tsx +107 -2
  131. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.macro-metrics.test.ts +55 -0
  132. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.test.ts +23 -29
  133. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.tsx +211 -184
  134. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverviewTopPanel.tsx +127 -0
  135. package/templates/.agents/dashboard/modules/operations/src/react/OperationsPage.tsx +60 -51
  136. package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageNavigation.tsx +1 -4
  137. package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageOverview.tsx +3 -0
  138. package/templates/.agents/dashboard/modules/operations/src/react/PagedWorkList.test.tsx +43 -0
  139. package/templates/.agents/dashboard/modules/operations/src/react/PagedWorkList.tsx +181 -0
  140. package/templates/.agents/dashboard/modules/operations/src/react/PeriodSummaryTable.tsx +32 -10
  141. package/templates/.agents/dashboard/modules/operations/src/react/TaskDetailsDialog.tsx +9 -3
  142. package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkBoard.tsx +13 -5
  143. package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.test.ts +16 -6
  144. package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.tsx +14 -4
  145. package/templates/.agents/dashboard/modules/operations/src/react/conversation-rows.ts +1 -2
  146. package/templates/.agents/dashboard/modules/operations/src/react/developer-identities.test.ts +18 -0
  147. package/templates/.agents/dashboard/modules/operations/src/react/developer-identities.ts +30 -0
  148. package/templates/.agents/dashboard/modules/operations/src/react/execution-metrics.ts +1 -0
  149. package/templates/.agents/dashboard/modules/operations/src/react/export/ExcelExportAction.test.ts +393 -4
  150. package/templates/.agents/dashboard/modules/operations/src/react/export/ExcelExportAction.tsx +484 -61
  151. package/templates/.agents/dashboard/modules/operations/src/react/export/export-layout.test.ts +23 -1
  152. package/templates/.agents/dashboard/modules/operations/src/react/export/xlsx-runtime-e2e.test.ts +248 -0
  153. package/templates/.agents/dashboard/modules/operations/src/react/index.ts +1 -0
  154. package/templates/.agents/dashboard/modules/operations/src/react/operation-duration.test.ts +4 -4
  155. package/templates/.agents/dashboard/modules/operations/src/react/operation-duration.ts +6 -4
  156. package/templates/.agents/dashboard/modules/operations/src/react/operations-coverage-toast.test.ts +4 -3
  157. package/templates/.agents/dashboard/modules/operations/src/react/operations-date-filters.css +1 -1
  158. package/templates/.agents/dashboard/modules/operations/src/react/operations-global-filters.test.ts +4 -1
  159. package/templates/.agents/dashboard/modules/operations/src/react/operations-overview-period-filter.test.ts +22 -12
  160. package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.css +4 -0
  161. package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.status-cards.test.ts +1 -1
  162. package/templates/.agents/dashboard/modules/operations/src/react/operations-page-contract.ts +53 -6
  163. package/templates/.agents/dashboard/modules/operations/src/react/operations-view-order.test.ts +2 -4
  164. package/templates/.agents/dashboard/modules/operations/src/react/period-summary.test.ts +82 -6
  165. package/templates/.agents/dashboard/modules/operations/src/react/period-summary.ts +1 -0
  166. package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.test.ts +2 -1
  167. package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.ts +1 -1
  168. package/templates/.agents/dashboard/modules/operations/src/server/execution-relationship-counts.test.ts +19 -7
  169. package/templates/.agents/dashboard/modules/operations/src/server/execution-relationship-counts.ts +4 -1
  170. package/templates/.agents/dashboard/modules/operations/src/server/metric-coverage.ts +1 -0
  171. package/templates/.agents/dashboard/modules/operations/src/server/quick-daily-operations-projection.ts +11 -5
  172. package/templates/.agents/dashboard/modules/traceability/package.json +1 -1
  173. package/templates/.agents/dashboard/packages/branding/package.json +1 -1
  174. package/templates/.agents/dashboard/packages/branding/src/index.ts +1 -1
  175. package/templates/.agents/dashboard/packages/contracts/package.json +1 -1
  176. package/templates/.agents/dashboard/packages/contracts/src/index.ts +1 -0
  177. package/templates/.agents/dashboard/packages/data-export/package.json +1 -1
  178. package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs +533 -338
  179. package/templates/.agents/dashboard/packages/local-runtime/dist/sqlite-read-model.cjs +506 -311
  180. package/templates/.agents/dashboard/packages/local-runtime/gitignore.template +2 -0
  181. package/templates/.agents/dashboard/packages/local-runtime/package.json +1 -1
  182. package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-dashboard.mjs +15 -7
  183. package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-runtime.mjs +44 -13
  184. package/templates/.agents/dashboard/packages/local-runtime/scripts/rebuild-sqlite-read-model.mjs +8 -3
  185. package/templates/.agents/dashboard/packages/local-runtime/scripts/source-size-runtime-scripts/sqlite-read-model-fixture.mjs +397 -0
  186. package/templates/.agents/dashboard/packages/local-runtime/scripts/test-sqlite-read-model.mjs +472 -145
  187. package/templates/.agents/dashboard/packages/local-runtime/scripts/test-unix-launchers.mjs +15 -3
  188. package/templates/.agents/dashboard/packages/local-runtime/scripts/validate-sqlite-read-model.mjs +141 -33
  189. package/templates/.agents/dashboard/packages/local-runtime/server.mjs +533 -338
  190. package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.test.ts +6 -2
  191. package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.ts +3 -3
  192. package/templates/.agents/dashboard/packages/local-runtime/src/server-board.test.ts +89 -16
  193. package/templates/.agents/dashboard/packages/local-runtime/src/server-board.ts +33 -16
  194. package/templates/.agents/dashboard/packages/local-runtime/src/server-classification-page.test.ts +87 -0
  195. package/templates/.agents/dashboard/packages/local-runtime/src/server-period-macro-metric.test.ts +44 -0
  196. package/templates/.agents/dashboard/packages/local-runtime/src/server-period-macro-metric.ts +125 -0
  197. package/templates/.agents/dashboard/packages/local-runtime/src/server-reconciliation-refresh.test.ts +66 -0
  198. package/templates/.agents/dashboard/packages/local-runtime/src/server-request-authority.test.ts +61 -0
  199. package/templates/.agents/dashboard/packages/local-runtime/src/server-request-authority.ts +18 -0
  200. package/templates/.agents/dashboard/packages/local-runtime/src/server-run-projections.test.ts +42 -0
  201. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-refresh.ts +97 -0
  202. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot.test.ts +22 -5
  203. package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-task-trace.ts +91 -0
  204. package/templates/.agents/dashboard/packages/local-runtime/src/server-workspace.ts +7 -3
  205. package/templates/.agents/dashboard/packages/local-runtime/src/server.test-fixtures.ts +36 -0
  206. package/templates/.agents/dashboard/packages/local-runtime/src/server.test.ts +230 -132
  207. package/templates/.agents/dashboard/packages/local-runtime/src/server.ts +224 -182
  208. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-artifact-counts.ts +28 -0
  209. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-agent-page.test.ts +63 -0
  210. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-agent-page.ts +109 -0
  211. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-aggregates.ts +497 -0
  212. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-fast-page-parity.test-support.ts +65 -0
  213. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-page.test.ts +176 -0
  214. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-page.ts +119 -0
  215. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-group-projection.ts +41 -0
  216. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-invocation-page.test.ts +16 -0
  217. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-cost-invocation-page.ts +29 -0
  218. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-cache.ts +355 -0
  219. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-persistence.ts +121 -0
  220. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-first-fold-timing.ts +27 -0
  221. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-metric-contract.ts +16 -2
  222. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-operations-projection.ts +15 -0
  223. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-operations-work-list.test.ts +223 -0
  224. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-operations-work-list.ts +304 -0
  225. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-cache.test-support.ts +23 -0
  226. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-first-fold-types.ts +89 -0
  227. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-multi-provider-fixture.ts +227 -0
  228. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-multi-provider.test.ts +691 -0
  229. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-source-fingerprint.ts +81 -0
  230. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.test.ts +1655 -567
  231. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.ts +2168 -1268
  232. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-cache.ts +129 -0
  233. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-install.test.ts +26 -0
  234. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-install.ts +28 -0
  235. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-snapshot-seed.test.ts +116 -0
  236. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-launch-page.mjs +146 -0
  237. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-launch-page.test.mjs +165 -0
  238. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-refresh.mjs +140 -0
  239. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.mjs +255 -289
  240. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.test.mjs +94 -88
  241. package/templates/.agents/dashboard/packages/ui/package.json +1 -1
  242. package/templates/.agents/dashboard/packages/windows-launcher/Program.cs +5 -2
  243. package/templates/.agents/dashboard/tests/e2e/package.json +1 -1
  244. package/templates/.agents/dashboard/tests/e2e/playwright.config.ts +4 -1
  245. package/templates/.agents/dashboard/tests/e2e/specs/cost-monitor-loading.spec.ts +142 -0
  246. package/templates/.agents/dashboard/tests/e2e/specs/cost-monitor-pagination.spec.ts +232 -0
  247. package/templates/.agents/dashboard/tests/e2e/specs/dashboard-performance-matrix.spec.ts +743 -0
  248. package/templates/.agents/dashboard/tests/e2e/specs/dashboard.spec.ts +189 -214
  249. package/templates/.agents/dashboard/zaip-dashboard-windows.exe +0 -0
  250. package/templates/.agents/design/.zaip-managed.json +3 -3
  251. package/templates/.agents/design/apps/catalog/package.json +1 -1
  252. package/templates/.agents/design/packages/local-runtime/package.json +1 -1
  253. package/templates/.agents/growth/estrategia-bootstrap-90-dias.md +169 -0
  254. package/templates/.agents/growth/strategy.md +27 -0
  255. package/templates/.agents/marketing/estrategia-marketing-zaip-90-dias.md +197 -0
  256. package/templates/.agents/marketing/strategy.md +29 -0
  257. package/templates/.agents/requirements/autonomous-assurance.md +6 -6
  258. package/templates/.agents/requirements/comparative-audit.md +1 -1
  259. package/templates/.agents/requirements/context-engine.md +1 -1
  260. package/templates/.agents/requirements/cost-observability.md +1 -1
  261. package/templates/.agents/requirements/dashboard-launch.md +1 -1
  262. package/templates/.agents/requirements/data-export.md +1 -1
  263. package/templates/.agents/requirements/design-system.md +1 -1
  264. package/templates/.agents/requirements/execution-engine.md +3 -3
  265. package/templates/.agents/requirements/kanban-dashboard.md +10 -2
  266. package/templates/.agents/requirements/model-orchestration.md +1 -1
  267. package/templates/.agents/requirements/public-distribution.md +1 -1
  268. package/templates/.agents/requirements/software-architecture.md +1 -1
  269. package/templates/.agents/requirements/strategic-improvements.md +1 -1
  270. package/templates/.agents/requirements/work-lifecycle.md +4 -4
  271. package/templates/.agents/requirements/zaip-strategic-95.md +1 -1
  272. package/templates/.agents/rules/dashboard-ui-consistency.md +14 -0
  273. package/templates/.agents/rules/frontend-lite.md +4 -4
  274. package/templates/.agents/rules/run-lifecycle-closure.md +4 -4
  275. package/templates/.agents/runtime/VERSION +1 -1
  276. package/templates/.agents/runtime/bin/zaip.mjs +1142 -1041
  277. package/templates/.agents/runtime/checksums.sha256 +6 -6
  278. package/templates/.agents/runtime/manifest.json +1 -1
  279. package/templates/.agents/runtime/pnpm-lock.sha256 +1 -1
  280. package/templates/.agents/runtime/provenance.json +5 -5
  281. package/templates/.agents/runtime/sbom.cdx.json +3 -3
  282. package/templates/.agents/sales/playbook.md +32 -0
  283. package/templates/.agents/sales/roteiro-comercial-zaip.md +252 -0
  284. package/templates/.agents/skills/criar-pasta-obsidian/scripts/generate-obsidian-vault.test.mjs +20 -16
  285. package/templates/.agents/skills/zaip-aios/SKILL.md +1 -1
  286. package/templates/.agents/skills/zaip-skill-agent-catalog/SKILL.md +22 -0
  287. package/templates/.agents/skills/zaip-skill-agent-catalog/agents/openai.yaml +4 -0
  288. package/templates/.agents/skills/zaip-skill-author-skills/SKILL.md +3 -2
  289. package/templates/.agents/skills/zaip-skill-author-skills/scripts/audit-skill-catalog.mjs +49 -0
  290. package/templates/.agents/skills/zaip-skill-author-skills/scripts/author-skill-scripts.test.mjs +27 -0
  291. package/templates/.agents/skills/zaip-skill-author-skills/scripts/run-skill-tests.mjs +37 -0
  292. package/templates/.agents/skills/zaip-skill-backend/SKILL.md +1 -0
  293. package/templates/.agents/skills/zaip-skill-brand-governance/SKILL.md +9 -2
  294. package/templates/.agents/skills/zaip-skill-brand-governance/references/brandbook-framework.md +39 -0
  295. package/templates/.agents/skills/zaip-skill-brand-governance/references/brandbook-standards.md +1 -1
  296. package/templates/.agents/skills/zaip-skill-change/SKILL.md +1 -1
  297. package/templates/.agents/skills/zaip-skill-change/references/observable-evidence.md +83 -0
  298. package/templates/.agents/skills/zaip-skill-dashboard-diagnostics/SKILL.md +22 -0
  299. package/templates/.agents/skills/zaip-skill-dashboard-diagnostics/agents/openai.yaml +4 -0
  300. package/templates/.agents/skills/zaip-skill-enforce-architecture/SKILL.md +2 -0
  301. package/templates/.agents/skills/zaip-skill-execution/SKILL.md +1 -1
  302. package/templates/.agents/skills/zaip-skill-frontend/SKILL.md +4 -3
  303. package/templates/.agents/skills/zaip-skill-frontend/agents/openai.yaml +2 -2
  304. package/templates/.agents/skills/zaip-skill-github-deploy/SKILL.md +10 -10
  305. package/templates/.agents/skills/zaip-skill-growth-strategy-revops/SKILL.md +6 -0
  306. package/templates/.agents/skills/zaip-skill-lifecycle-closure/SKILL.md +27 -0
  307. package/templates/.agents/skills/zaip-skill-lifecycle-closure/agents/openai.yaml +4 -0
  308. package/templates/.agents/skills/zaip-skill-marketing/SKILL.md +6 -0
  309. package/templates/.agents/skills/zaip-skill-prd/SKILL.md +4 -0
  310. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-local-telemetry.mjs +111 -104
  311. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-explicit-recovery.mjs +223 -0
  312. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.mjs +55 -9
  313. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.test.mjs +145 -14
  314. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.mjs +19 -9
  315. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.test.mjs +82 -5
  316. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/source-size-telemetry/model-identity-reconciliation.mjs +77 -0
  317. package/templates/.agents/skills/zaip-skill-release-qualification/SKILL.md +20 -0
  318. package/templates/.agents/skills/zaip-skill-release-qualification/agents/openai.yaml +4 -0
  319. package/templates/.agents/skills/zaip-skill-review/SKILL.md +5 -0
  320. package/templates/.agents/skills/zaip-skill-rules/SKILL.md +1 -1
  321. package/templates/.agents/skills/zaip-skill-sales-methodology/SKILL.md +6 -0
  322. package/templates/.agents/skills/zaip-skill-spec/SKILL.md +4 -0
  323. package/templates/.agents/skills/zaip-skill-sqlite-read-model/SKILL.md +22 -90
  324. package/templates/.agents/skills/zaip-skill-sqlite-read-model/scripts/ensure-node.mjs +28 -5
  325. package/templates/.agents/zaip-aios/INDEX.md +57 -22
  326. package/templates/.agents/zaip-aios/README.md +24 -13
  327. package/templates/.agents/zaip-aios/VERSION +1 -1
  328. package/templates/.agents/zaip-aios/guides/02-requirements.md +5 -0
  329. package/templates/.agents/zaip-aios/guides/06-execucao.md +13 -4
  330. package/templates/.agents/zaip-aios/guides/07-revisao-e-validacao.md +7 -0
  331. package/templates/.agents/zaip-aios/guides/10-seguranca.md +23 -0
  332. package/templates/.agents/zaip-aios/guides/11-observabilidade-e-custos.md +6 -6
  333. package/templates/.agents/zaip-aios/guides/13-boas-praticas.md +3 -0
  334. package/templates/.agents/zaip-aios/guides/16-lifecycle-e-reconciliacao.md +12 -3
  335. package/templates/.agents/zaip-aios/guides/17-como-o-custo-e-calculado.md +5 -5
  336. package/templates/.agents/zaip-aios/guides/18-catalogo-de-agentes.md +76 -0
  337. package/templates/.agents/zaip-aios/guides/19-assurance-e-autonomia.md +95 -0
  338. package/templates/.agents/zaip-aios/guides/20-instalacao-detalhada.md +366 -0
  339. package/templates/.agents/zaip-aios/guides/21-telemetria-monitor-custos.md +46 -0
  340. package/templates/.agents/zaip-aios/guides/22-fluxos-e-roteamento.md +74 -0
  341. package/templates/.agents/zaip-aios/guides/23-orquestracao-de-modelos.md +483 -0
  342. package/templates/.agents/zaip-aios/guides/24-calculo-de-custos-openai.md +85 -0
  343. package/templates/.agents/zaip-aios/guides/25-fontes-de-precos-openai.md +19 -0
  344. package/templates/.agents/zaip-aios/guides/26-qualidade-e-release.md +111 -0
  345. package/templates/.agents/zaip-aios/guides/27-telemetria-git-native.md +172 -0
  346. package/templates/.agents/zaip-aios/guides/28-lifecycle-completo.md +149 -0
  347. package/templates/.agents/zaip-aios/guides/assets/diagrams/lifecycles-task-spec-prd.png +0 -0
  348. package/templates/.agents/zaip-aios/guides/assets/diagrams/prd-lifecycle.png +0 -0
  349. package/templates/.agents/zaip-aios/guides/assets/diagrams/spec-lifecycle.png +0 -0
  350. package/templates/.agents/zaip-aios/guides/assets/diagrams/task-lifecycle.png +0 -0
  351. package/templates/template-manifest.json +756 -235
  352. package/templates/.agents/dashboard/apps/frontend/dist/assets/DashboardHelpDialog-Cs6dzDmW.js +0 -1505
  353. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-QE1k9yZB.css +0 -1
  354. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-_Pf5DA_A.js +0 -3
  355. package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-BVlz3DLZ.js +0 -1
  356. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-BZ5WdaMN.css +0 -1
  357. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-Cf9ctPVt.js +0 -68
  358. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-8A4DcNXM.js +0 -2
  359. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DK_enB5Z.css +0 -1
  360. package/templates/.agents/dashboard/apps/frontend/src/use-idle-cost-prefetch.ts +0 -45
@@ -16,6 +16,7 @@ import type { EntityMetric } from "./OperationsOverview.helpers.js";
16
16
  import {
17
17
  aggregateMacroMetrics,
18
18
  aggregateTaskMetrics,
19
+ canonicalMacroMetric,
19
20
  countExecutionDays,
20
21
  findLatestCreatedAt,
21
22
  formatExecutionAverageHint,
@@ -24,12 +25,26 @@ import {
24
25
  overviewCopy,
25
26
  overviewMetricAverages,
26
27
  overviewText,
28
+ partialOverviewMetrics,
29
+ resolveOverviewCostTotal,
27
30
  riskColors,
31
+ runsForOverviewView,
32
+ scopedOverviewMetric,
33
+ selectedMacroMetricTotals,
34
+ selectedOverviewCount,
28
35
  selectTopEntities,
29
36
  statusColors,
37
+ sumKnownOverviewMetric,
30
38
  summarizeTopEntityMetrics,
31
39
  } from "./OperationsOverview.helpers.js";
40
+ import { OperationsOverviewTopPanel } from "./OperationsOverviewTopPanel.js";
32
41
  import type { OperationDatePreset, OperationDateRange } from "./operation-date-range.js";
42
+ import type {
43
+ OverviewClassification,
44
+ OverviewClassificationPage,
45
+ OverviewStatusKind,
46
+ OverviewStatusPage,
47
+ } from "./operations-page-contract.js";
33
48
  import { type OperationsLocale, riskLabel } from "./status-labels.js";
34
49
  import {
35
50
  macroWorkStage,
@@ -38,17 +53,12 @@ import {
38
53
  workStageLabel,
39
54
  workStages,
40
55
  } from "./work-board-model.js";
41
- import type {
42
- OverviewClassification,
43
- OverviewClassificationPage,
44
- OverviewStatusKind,
45
- OverviewStatusPage,
46
- } from "./operations-page-contract.js";
47
56
  import "./operations-overview.css";
48
57
 
49
58
  export {
50
59
  aggregateMacroMetrics,
51
60
  aggregateTaskMetrics,
61
+ canonicalMacroMetric,
52
62
  countExecutionDays,
53
63
  findLatestCreatedAt,
54
64
  findLatestTaskCreatedAt,
@@ -57,10 +67,17 @@ export {
57
67
  macroClassificationStats,
58
68
  overviewMetricAverages,
59
69
  overviewText,
70
+ partialOverviewMetrics,
71
+ resolveOverviewCostTotal,
72
+ runsForOverviewView,
73
+ scopedOverviewMetric,
74
+ selectedMacroMetricTotals,
75
+ selectedOverviewCount,
60
76
  selectTopEntities,
61
77
  statusColors,
62
78
  summarizeTopEntityMetrics,
63
79
  summarizeTopTaskMetrics,
80
+ taskMetricAverages,
64
81
  } from "./OperationsOverview.helpers.js";
65
82
 
66
83
  type OverviewView = "tasks" | "specs" | "prds";
@@ -81,82 +98,6 @@ function formatEntityDuration(value: number | null, locale: OperationsLocale): s
81
98
  if (value !== null) return formatDurationMs(value, locale);
82
99
  return locale === "pt-BR" ? "Indisponível" : "Unavailable";
83
100
  }
84
-
85
- export function taskMetricAverages(
86
- totals: { durationMs: number | null; tokens: number | null; costBrl: number | null },
87
- taskCount: number | null,
88
- ) {
89
- return overviewMetricAverages(totals, taskCount);
90
- }
91
-
92
- export function selectedOverviewCount(
93
- view: OverviewView,
94
- overviewMetrics: OperationsProjection["summary"]["overview_metrics"] | undefined,
95
- fallback: number,
96
- ): number | null {
97
- if (view === "specs") return overviewMetrics?.selected_counts?.specs ?? fallback;
98
- if (view === "prds") return overviewMetrics?.selected_counts?.prds ?? fallback;
99
- return overviewMetrics?.task_count ?? fallback;
100
- }
101
-
102
- /**
103
- * Selects a currency-specific total without ever treating Operations' BRL
104
- * aggregate as USD. Compact Cost Monitor summaries are authoritative even
105
- * when their intentionally bounded Run collection is empty.
106
- */
107
- export function resolveOverviewCostTotal({
108
- currency,
109
- factualSnapshotTotal,
110
- macroCostTotal,
111
- overviewView,
112
- resolvedRunTotal,
113
- operationsBrlTotal,
114
- }: {
115
- currency: "BRL" | "USD";
116
- factualSnapshotTotal: number | null | undefined;
117
- /** Macro aggregates are scoped to the selected SPEC/PRD, unlike the Task snapshot. */
118
- macroCostTotal?: number | null | undefined;
119
- overviewView?: OverviewView;
120
- resolvedRunTotal: number | null;
121
- operationsBrlTotal: number | null;
122
- }): number | null {
123
- if (overviewView !== undefined && overviewView !== "tasks") return macroCostTotal ?? null;
124
- if (factualSnapshotTotal !== null && factualSnapshotTotal !== undefined)
125
- return factualSnapshotTotal;
126
- if (resolvedRunTotal !== null) return resolvedRunTotal;
127
- return currency === "BRL" ? operationsBrlTotal : null;
128
- }
129
-
130
- /**
131
- * KPI cards are sourced exclusively from the server-selected global aggregate.
132
- * Entity, board, and Cost Monitor pages are bounded/detail views, so their
133
- * collections must never replace the period-filtered big-number population.
134
- */
135
- export function partialOverviewMetrics(data: OperationsProjection) {
136
- return data.summary.overview_metrics;
137
- }
138
-
139
- export function runsForOverviewView(
140
- view: OverviewView,
141
- tasks: OperationsProjection["tasks"],
142
- macros: OperationsProjection["specs"] | OperationsProjection["prds"],
143
- runs: OperationsProjection["runs"],
144
- ): OperationsProjection["runs"] {
145
- if (view === "tasks") {
146
- const taskIds = new Set(tasks.map((task) => task.id));
147
- return runs.filter((run) => run.task_id !== null && taskIds.has(run.task_id));
148
- }
149
- const macroIds = new Set(macros.map((macro) => macro.id));
150
- const declaredRunIds = new Set(macros.flatMap((macro) => macro.run_ids));
151
- return runs.filter(
152
- (run) =>
153
- declaredRunIds.has(run.id) ||
154
- (view === "specs"
155
- ? run.spec_id !== null && macroIds.has(run.spec_id)
156
- : run.prd_id !== null && macroIds.has(run.prd_id)),
157
- );
158
- }
159
-
160
101
  export function OperationsOverview({
161
102
  currency,
162
103
  data,
@@ -170,13 +111,14 @@ export function OperationsOverview({
170
111
  onLoadStatusPage,
171
112
  classificationPage,
172
113
  onLoadClassificationPage,
114
+ onLoadMacroMetrics,
173
115
  prds = data.prds,
174
116
  runs = data.runs,
175
117
  specs = data.specs,
176
118
  tasks = data.tasks,
177
119
  factualCostTotal,
178
120
  resolveRunCost,
179
- includeLegacyEffort = false,
121
+ includeLegacyEffort: _includeLegacyEffort = false,
180
122
  }: {
181
123
  currency: "BRL" | "USD";
182
124
  data: OperationsProjection;
@@ -188,10 +130,22 @@ export function OperationsOverview({
188
130
  onOpenTask: (taskId: string) => Promise<boolean>;
189
131
  onOpenDocument: (kind: "prd" | "spec", id: string) => void;
190
132
  onLoadStatus?: ((stage: WorkStage, kind: OverviewStatusKind, offset: number) => void) | undefined;
191
- statusPage?: ((stage: WorkStage, kind: OverviewStatusKind) => OverviewStatusPage | undefined) | undefined;
192
- onLoadStatusPage?: ((stage: WorkStage, kind: OverviewStatusKind, offset: number) => void) | undefined;
193
- classificationPage?: ((kind: OverviewStatusKind, classification: OverviewClassification) => OverviewClassificationPage | undefined) | undefined;
194
- onLoadClassificationPage?: ((kind: OverviewStatusKind, classification: OverviewClassification, offset: number) => void) | undefined;
133
+ statusPage?:
134
+ | ((stage: WorkStage, kind: OverviewStatusKind) => OverviewStatusPage | undefined)
135
+ | undefined;
136
+ onLoadStatusPage?:
137
+ | ((stage: WorkStage, kind: OverviewStatusKind, offset: number) => void)
138
+ | undefined;
139
+ classificationPage?:
140
+ | ((
141
+ kind: OverviewStatusKind,
142
+ classification: OverviewClassification,
143
+ ) => OverviewClassificationPage | undefined)
144
+ | undefined;
145
+ onLoadClassificationPage?:
146
+ | ((kind: OverviewStatusKind, classification: OverviewClassification, offset: number) => void)
147
+ | undefined;
148
+ onLoadMacroMetrics?: (() => void) | undefined;
195
149
  prds?: OperationsProjection["prds"];
196
150
  runs?: OperationsProjection["runs"];
197
151
  specs?: OperationsProjection["specs"];
@@ -203,7 +157,8 @@ export function OperationsOverview({
203
157
  }) {
204
158
  const [overviewView, setOverviewView] = useState<OverviewView>("tasks");
205
159
  const [selectedStatus, setSelectedStatus] = useState<WorkStage | null>(null);
206
- const [selectedClassification, setSelectedClassification] = useState<OverviewClassification | null>(null);
160
+ const [selectedClassification, setSelectedClassification] =
161
+ useState<OverviewClassification | null>(null);
207
162
  const completed = tasks.filter((task) => task.status === "completed").length;
208
163
  const completedSpecs = specs.filter((spec) => spec.work_status === "completed").length;
209
164
  const completedPrds = prds.filter((prd) => prd.work_status === "completed").length;
@@ -308,10 +263,47 @@ export function OperationsOverview({
308
263
  const specCompletion = specCount === null || specCount === 0 ? 0 : completedSpecCount / specCount;
309
264
  const prdCompletion = prdCount === null || prdCount === 0 ? 0 : completedPrdCount / prdCount;
310
265
  const executionRuns = executionMetrics.runs;
311
- const totalDurationMetric = overviewMetrics?.duration_ms ?? executionMetrics.durationMs;
266
+ const selectedMacroFallbackTotals = selectedMacroMetricTotals(entityMetrics);
267
+ const metricUnit =
268
+ overviewView === "tasks" ? (locale === "pt-BR" ? "tarefa" : "task") : copy.shortPlural;
269
+ const selectedMacroTotals =
270
+ overviewView === "tasks"
271
+ ? null
272
+ : {
273
+ durationMs: canonicalMacroMetric(
274
+ selectedMacroAggregate !== undefined,
275
+ selectedMacroAggregate?.total_duration_ms,
276
+ selectedMacroFallbackTotals.durationMs,
277
+ ),
278
+ tokens: canonicalMacroMetric(
279
+ selectedMacroAggregate !== undefined,
280
+ selectedMacroAggregate?.total_tokens,
281
+ selectedMacroFallbackTotals.tokens,
282
+ ),
283
+ costBrl: canonicalMacroMetric(
284
+ selectedMacroAggregate !== undefined,
285
+ selectedMacroAggregate?.total_cost_brl,
286
+ selectedMacroFallbackTotals.costBrl,
287
+ ),
288
+ };
289
+ // The selectable SPEC/PRD cards define the metric population for every KPI.
290
+ // A global Task aggregate beside a selected macro produces contradictory
291
+ // values such as "duration unavailable" and "83 h" on the same screen.
292
+ const totalDurationMetric = scopedOverviewMetric(
293
+ overviewView,
294
+ selectedMacroTotals?.durationMs,
295
+ overviewMetrics?.duration_ms ?? executionMetrics.durationMs,
296
+ );
312
297
  const totalExecutionDays =
313
- overviewMetrics?.execution_day_count ?? countExecutionDays(executionRuns);
314
- const totalTokensMetric = overviewMetrics?.tokens ?? allPhaseMetrics.tokens;
298
+ overviewView === "tasks"
299
+ ? (overviewMetrics?.execution_day_count ?? countExecutionDays(executionRuns))
300
+ : 0;
301
+ const totalTokensMetric = scopedOverviewMetric(
302
+ overviewView,
303
+ selectedMacroTotals?.tokens,
304
+ overviewMetrics?.tokens ?? allPhaseMetrics.tokens,
305
+ );
306
+ const metricPopulationCount = overviewView === "tasks" ? taskCount : selectedCount;
315
307
  const selectedCurrencyCost =
316
308
  resolveRunCost === undefined
317
309
  ? null
@@ -325,12 +317,20 @@ export function OperationsOverview({
325
317
  : currency === "USD"
326
318
  ? selectedMacroAggregate?.total_cost_usd
327
319
  : selectedMacroAggregate?.total_cost_brl;
320
+ const selectedMacroFallbackCost =
321
+ overviewView === "tasks" || currency === "USD"
322
+ ? null
323
+ : sumKnownOverviewMetric(entityMetrics.map((entity) => entity.costBrl));
328
324
  // Operations aggregates are BRL-only. USD is valid only when it is resolved
329
325
  // from Cost Monitor's factual per-Run estimates; never relabel BRL as USD.
330
326
  const totalCostMetric = resolveOverviewCostTotal({
331
327
  currency,
332
328
  factualSnapshotTotal: factualCostTotal,
333
- macroCostTotal: selectedMacroCost,
329
+ macroCostTotal: canonicalMacroMetric(
330
+ selectedMacroAggregate !== undefined,
331
+ selectedMacroCost,
332
+ selectedMacroFallbackCost,
333
+ ),
334
334
  overviewView,
335
335
  resolvedRunTotal: selectedCurrencyCost,
336
336
  operationsBrlTotal: overviewMetrics?.cost_brl ?? allPhaseMetrics.costBrl,
@@ -340,29 +340,57 @@ export function OperationsOverview({
340
340
  ? null
341
341
  : (totalCostMetric * 3_600_000) / totalDurationMetric;
342
342
  const costPerTask =
343
- totalCostMetric === null || taskCount === null || taskCount === 0
343
+ totalCostMetric === null || metricPopulationCount === null || metricPopulationCount === 0
344
344
  ? null
345
- : totalCostMetric / taskCount;
345
+ : totalCostMetric / metricPopulationCount;
346
346
  const tokensPerTask =
347
- totalTokensMetric === null || taskCount === null || taskCount === 0
347
+ totalTokensMetric === null || metricPopulationCount === null || metricPopulationCount === 0
348
348
  ? null
349
- : totalTokensMetric / taskCount;
349
+ : totalTokensMetric / metricPopulationCount;
350
350
  const tokensPerHour =
351
351
  totalDurationMetric === null || totalDurationMetric <= 0 || totalTokensMetric === null
352
352
  ? null
353
353
  : (totalTokensMetric * 3_600_000) / totalDurationMetric;
354
- const aggregateAverages = overviewMetricAverages(
355
- { durationMs: totalDurationMetric, tokens: totalTokensMetric, costBrl: totalCostMetric },
356
- selectedCount,
354
+ const averageMetricTotals =
355
+ overviewView === "tasks"
356
+ ? { durationMs: totalDurationMetric, tokens: totalTokensMetric, costBrl: totalCostMetric }
357
+ : {
358
+ durationMs: canonicalMacroMetric(
359
+ selectedMacroAggregate !== undefined,
360
+ selectedMacroAggregate?.total_duration_ms,
361
+ selectedMacroFallbackTotals.durationMs,
362
+ ),
363
+ tokens: canonicalMacroMetric(
364
+ selectedMacroAggregate !== undefined,
365
+ selectedMacroAggregate?.total_tokens,
366
+ selectedMacroFallbackTotals.tokens,
367
+ ),
368
+ costBrl: canonicalMacroMetric(
369
+ selectedMacroAggregate !== undefined,
370
+ selectedMacroCost,
371
+ currency === "BRL" ? selectedMacroFallbackCost : selectedMacroFallbackTotals.costBrl,
372
+ ),
373
+ };
374
+ const aggregateAverages = overviewMetricAverages(averageMetricTotals, selectedCount);
375
+ const averageDuration = canonicalMacroMetric(
376
+ selectedMacroAggregate !== undefined,
377
+ selectedMacroAggregate?.average_duration_ms,
378
+ aggregateAverages.durationMs,
379
+ );
380
+ const averageTokens = canonicalMacroMetric(
381
+ selectedMacroAggregate !== undefined,
382
+ selectedMacroAggregate?.average_tokens,
383
+ aggregateAverages.tokens,
357
384
  );
358
- const averageDuration =
359
- selectedMacroAggregate?.average_duration_ms ?? aggregateAverages.durationMs;
360
- const averageTokens = selectedMacroAggregate?.average_tokens ?? aggregateAverages.tokens;
361
385
  const averageCost =
362
386
  overviewView !== "tasks"
363
- ? (currency === "USD"
364
- ? selectedMacroAggregate?.average_cost_usd
365
- : selectedMacroAggregate?.average_cost_brl) ?? null
387
+ ? canonicalMacroMetric(
388
+ selectedMacroAggregate !== undefined,
389
+ currency === "USD"
390
+ ? selectedMacroAggregate?.average_cost_usd
391
+ : selectedMacroAggregate?.average_cost_brl,
392
+ aggregateAverages.costBrl,
393
+ )
366
394
  : aggregateAverages.costBrl;
367
395
  const latestCreatedAt =
368
396
  overviewView === "tasks"
@@ -393,7 +421,7 @@ export function OperationsOverview({
393
421
  tokens: metric.total_tokens,
394
422
  // EntityMetric predates the global locale selector. It is a selected
395
423
  // display-currency bucket here, never a BRL value relabelled as USD.
396
- costBrl: currency === "USD" ? metric.total_cost_usd ?? null : metric.cost_brl,
424
+ costBrl: currency === "USD" ? (metric.total_cost_usd ?? null) : metric.cost_brl,
397
425
  runCount: metric.run_count,
398
426
  }));
399
427
  const aggregateTopMacros: EntityMetric[] = (selectedMacroAggregate?.top_entities ?? []).map(
@@ -403,17 +431,22 @@ export function OperationsOverview({
403
431
  durationMs: metric.duration_ms,
404
432
  durationProvenance: metric.duration_ms === null ? "unavailable" : "observed",
405
433
  tokens: metric.total_tokens,
406
- costBrl: currency === "USD" ? metric.total_cost_usd ?? null : metric.cost_brl,
434
+ costBrl: currency === "USD" ? (metric.total_cost_usd ?? null) : metric.cost_brl,
407
435
  runCount: metric.run_count,
408
436
  }),
409
437
  );
410
438
  const topEntities =
411
439
  overviewView === "tasks" && runs.length === 0 && aggregateTopTasks.length > 0
412
440
  ? aggregateTopTasks
413
- : overviewView !== "tasks" && runs.length === 0 && aggregateTopMacros.length > 0
441
+ : overviewView !== "tasks" && aggregateTopMacros.length > 0
414
442
  ? aggregateTopMacros
415
443
  : selectTopEntities(entityMetrics);
416
- const maxDuration = Math.max(1, ...topEntities.map((entity) => entity.durationMs ?? 0));
444
+ const maxDuration = Math.max(
445
+ 1,
446
+ ...topEntities
447
+ .filter((entity) => entity.durationMs !== null)
448
+ .map((entity) => entity.durationMs ?? 0),
449
+ );
417
450
  const topEntitiesSummary =
418
451
  overviewView === "tasks" && runs.length === 0 && aggregateTopTasks.length > 0
419
452
  ? {
@@ -424,7 +457,7 @@ export function OperationsOverview({
424
457
  : topEntities.reduce((sum, entity) => sum + (entity.durationMs ?? 0), 0) /
425
458
  totalDurationMetric,
426
459
  }
427
- : overviewView !== "tasks" && runs.length === 0 && aggregateTopMacros.length > 0
460
+ : overviewView !== "tasks" && aggregateTopMacros.length > 0
428
461
  ? {
429
462
  ...summarizeTopEntityMetrics(topEntities, topEntities),
430
463
  durationShare:
@@ -441,9 +474,11 @@ export function OperationsOverview({
441
474
  // factual per-Run Cost Monitor resolver.
442
475
  const usesAggregateTopEntities =
443
476
  (overviewView === "tasks" && runs.length === 0 && aggregateTopTasks.length > 0) ||
444
- (overviewView !== "tasks" && runs.length === 0 && aggregateTopMacros.length > 0);
477
+ (overviewView !== "tasks" && aggregateTopMacros.length > 0);
445
478
  const topEntitiesCost =
446
- currency === "USD" && !usesAggregateTopEntities && (runs.length === 0 || resolveRunCost === undefined)
479
+ currency === "USD" &&
480
+ !usesAggregateTopEntities &&
481
+ (runs.length === 0 || resolveRunCost === undefined)
447
482
  ? null
448
483
  : topEntitiesSummary.costBrl;
449
484
  const topHint =
@@ -457,6 +492,7 @@ export function OperationsOverview({
457
492
  setOverviewView(view);
458
493
  setSelectedStatus(null);
459
494
  setSelectedClassification(null);
495
+ if (view !== "tasks") onLoadMacroMetrics?.();
460
496
  };
461
497
 
462
498
  return (
@@ -533,11 +569,17 @@ export function OperationsOverview({
533
569
  <Kpi
534
570
  hint={formatExecutionAverageHint(
535
571
  totalDurationMetric ?? 0,
536
- taskCount ?? 0,
572
+ metricPopulationCount ?? 0,
537
573
  totalExecutionDays,
538
574
  locale,
539
575
  )}
540
- label={text.totalExecutionTime}
576
+ label={
577
+ overviewView === "tasks"
578
+ ? text.totalExecutionTime
579
+ : locale === "pt-BR"
580
+ ? `${text.totalExecutionTime} de ${copy.shortPlural}`
581
+ : `${copy.shortPlural} ${text.totalExecutionTime.toLowerCase()}`
582
+ }
541
583
  value={formatEntityDuration(totalDurationMetric, locale)}
542
584
  />
543
585
  <Kpi
@@ -547,10 +589,18 @@ export function OperationsOverview({
547
589
  ? "Tokens por tarefa e por hora indisponíveis"
548
590
  : "Tokens per task and hour unavailable"
549
591
  : locale === "pt-BR"
550
- ? `${formatCompactNumber(tokensPerTask, locale)} / tarefa (${formatCompactNumber(tokensPerHour, locale, 0)} / hora)`
551
- : `${formatCompactNumber(tokensPerTask, locale)} / task (${formatCompactNumber(tokensPerHour, locale, 0)} / hour)`
592
+ ? `${formatCompactNumber(tokensPerTask, locale)} / ${metricUnit} (${formatCompactNumber(tokensPerHour, locale, 0)} / hora)`
593
+ : `${formatCompactNumber(tokensPerTask, locale)} / ${metricUnit} (${formatCompactNumber(tokensPerHour, locale, 0)} / hour)`
594
+ }
595
+ label={
596
+ overviewView === "tasks"
597
+ ? locale === "pt-BR"
598
+ ? "Tokens gastos"
599
+ : "Spent tokens"
600
+ : locale === "pt-BR"
601
+ ? `Tokens gastos por ${copy.shortPlural}`
602
+ : `${copy.shortPlural} tokens spent`
552
603
  }
553
- label={locale === "pt-BR" ? "Tokens gastos" : "Spent tokens"}
554
604
  value={
555
605
  totalTokensMetric === null
556
606
  ? formatEntityDuration(null, locale)
@@ -564,10 +614,18 @@ export function OperationsOverview({
564
614
  ? "Custo por tarefa e por hora indispon\u00edvel"
565
615
  : "Cost per task and hour unavailable"
566
616
  : locale === "pt-BR"
567
- ? `${formatRoundedCurrency(costPerTask, currency, locale)} / tarefa (${formatRoundedCurrency(hourlyCost, currency, locale)} / hora)`
568
- : `${formatRoundedCurrency(costPerTask, currency, locale)} / task (${formatRoundedCurrency(hourlyCost, currency, locale)} / hour)`
617
+ ? `${formatRoundedCurrency(costPerTask, currency, locale)} / ${metricUnit} (${formatRoundedCurrency(hourlyCost, currency, locale)} / hora)`
618
+ : `${formatRoundedCurrency(costPerTask, currency, locale)} / ${metricUnit} (${formatRoundedCurrency(hourlyCost, currency, locale)} / hour)`
619
+ }
620
+ label={
621
+ overviewView === "tasks"
622
+ ? locale === "pt-BR"
623
+ ? "Custo Estimado"
624
+ : "Estimated cost"
625
+ : locale === "pt-BR"
626
+ ? `Custo de ${copy.shortPlural}`
627
+ : `${copy.shortPlural} cost`
569
628
  }
570
- label={locale === "pt-BR" ? "Custo Estimado" : "Estimated cost"}
571
629
  value={
572
630
  totalCostMetric === null
573
631
  ? formatEntityDuration(null, locale)
@@ -713,65 +771,18 @@ export function OperationsOverview({
713
771
  </footer>
714
772
  </article>
715
773
 
716
- <article className="operations-panel">
717
- <PanelHeader hint={topHint} title={copy.topTitle} />
718
- {topEntities.length > 0 ? (
719
- <>
720
- <div className="operations-run-bars">
721
- {topEntities.map((entity, index) => (
722
- <button
723
- aria-label={
724
- locale === "pt-BR"
725
- ? `Abrir detalhes da tarefa ${entity.title}`
726
- : `Open details for task ${entity.title}`
727
- }
728
- className="operations-run-bar"
729
- disabled={overviewView !== "tasks"}
730
- key={entity.id}
731
- onClick={() => void onOpenTask(entity.id)}
732
- title={`${entity.title}: ${formatEntityDuration(entity.durationMs, locale)}`}
733
- type="button"
734
- >
735
- <strong>{formatEntityDuration(entity.durationMs, locale)}</strong>
736
- <i
737
- style={{
738
- height: `${Math.max(8, ((entity.durationMs ?? 0) / maxDuration) * 100)}%`,
739
- }}
740
- />
741
- <span>{`#${index + 1} ${entity.id.slice(-4)}`}</span>
742
- </button>
743
- ))}
744
- </div>
745
- <div className="operations-top-task-metrics">
746
- <div>
747
- <span>{text.accumulatedTime}</span>
748
- <strong>{formatEntityDuration(topEntitiesSummary.durationMs, locale)}</strong>
749
- <small>{`${topEntitiesSummary.runCount} ${text.associatedRuns}`}</small>
750
- </div>
751
- <div>
752
- <span>{text.concentration}</span>
753
- <strong>{formatPercent(topEntitiesSummary.durationShare, locale)}</strong>
754
- <small>{text.totalMeasuredTime}</small>
755
- </div>
756
- <div>
757
- <span>{text.topFiveCost}</span>
758
- <strong>
759
- {topEntitiesCost === null
760
- ? formatEntityDuration(null, locale)
761
- : formatCurrency(topEntitiesCost, currency, locale)}
762
- </strong>
763
- <small>
764
- {topEntitiesSummary.tokens === null
765
- ? text.tokensUnavailable
766
- : `${formatCompactNumber(topEntitiesSummary.tokens, locale)} tokens`}
767
- </small>
768
- </div>
769
- </div>
770
- </>
771
- ) : (
772
- <p className="operations-empty">{copy.emptyTop}</p>
773
- )}
774
- </article>
774
+ <OperationsOverviewTopPanel
775
+ copy={{ empty: copy.emptyTop, hint: topHint, title: copy.topTitle }}
776
+ currency={currency}
777
+ locale={locale}
778
+ maxDuration={maxDuration}
779
+ onOpenTask={onOpenTask}
780
+ summary={topEntitiesSummary}
781
+ text={text}
782
+ topCost={topEntitiesCost}
783
+ topEntities={topEntities}
784
+ view={overviewView}
785
+ />
775
786
  </div>
776
787
  {selectedStatus === null ? null : (
777
788
  <FilteredStatusDialog
@@ -795,7 +806,12 @@ export function OperationsOverview({
795
806
  setSelectedStatus(null);
796
807
  onOpenDocument(kind, id);
797
808
  }}
798
- items={statusPage?.(selectedStatus, overviewView === "tasks" ? "task" : overviewView === "specs" ? "spec" : "prd")?.items ?? []}
809
+ items={
810
+ statusPage?.(
811
+ selectedStatus,
812
+ overviewView === "tasks" ? "task" : overviewView === "specs" ? "spec" : "prd",
813
+ )?.items ?? []
814
+ }
799
815
  kind={overviewView === "tasks" ? "task" : overviewView === "specs" ? "spec" : "prd"}
800
816
  onLoadMore={(offset) =>
801
817
  onLoadStatusPage?.(
@@ -804,7 +820,10 @@ export function OperationsOverview({
804
820
  offset,
805
821
  )
806
822
  }
807
- page={statusPage?.(selectedStatus, overviewView === "tasks" ? "task" : overviewView === "specs" ? "spec" : "prd")}
823
+ page={statusPage?.(
824
+ selectedStatus,
825
+ overviewView === "tasks" ? "task" : overviewView === "specs" ? "spec" : "prd",
826
+ )}
808
827
  />
809
828
  )}
810
829
  {selectedClassification === null ? null : (
@@ -812,8 +831,12 @@ export function OperationsOverview({
812
831
  eyebrow={locale === "pt-BR" ? copy.classificationTitle : "Classification"}
813
832
  label={
814
833
  overviewView === "tasks"
815
- ? riskLabel(selectedClassification as OperationsProjection["tasks"][number]["risk"], locale)
816
- : classificationStats.find((item) => item.key === selectedClassification)?.label ?? selectedClassification
834
+ ? riskLabel(
835
+ selectedClassification as OperationsProjection["tasks"][number]["risk"],
836
+ locale,
837
+ )
838
+ : (classificationStats.find((item) => item.key === selectedClassification)?.label ??
839
+ selectedClassification)
817
840
  }
818
841
  locale={locale}
819
842
  onClose={() => setSelectedClassification(null)}
@@ -967,7 +990,11 @@ function FilteredStatusDialog({
967
990
  );
968
991
  }
969
992
 
970
- function statusTypeLabel(kind: OverviewStatusKind, count: number, locale: OperationsLocale): string {
993
+ function statusTypeLabel(
994
+ kind: OverviewStatusKind,
995
+ count: number,
996
+ locale: OperationsLocale,
997
+ ): string {
971
998
  if (kind === "prd") return count === 1 ? "PRD" : "PRDs";
972
999
  if (kind === "spec") return count === 1 ? "SPEC" : "SPECs";
973
1000
  return locale === "pt-BR" ? (count === 1 ? "tarefa" : "tarefas") : count === 1 ? "task" : "tasks";