@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
@@ -1,7 +1,4 @@
1
- import {
2
- globalLegacyEffortDurationMs,
3
- type OperationsProjection,
4
- } from "@zaip-ai/dashboard-operations/contracts";
1
+ import type { OperationsProjection } from "@zaip-ai/dashboard-operations/contracts";
5
2
  import { describe, expect, it } from "vitest";
6
3
  import {
7
4
  buildCostSummaryProjection,
@@ -11,25 +8,49 @@ import {
11
8
  describe("buildCostSummaryProjection", () => {
12
9
  it("retains factual USD from a compact SQLite summary with no Run rows", () => {
13
10
  const operations = {
14
- schema_version: 2, layout_version: 2, readonly: true, source: ".agents/records",
15
- filters: { from: null, to: null }, summary: { task_count: 1, overview_metrics: {}, usage: {} },
16
- prds: [], specs: [], runs: [],
11
+ schema_version: 2,
12
+ layout_version: 2,
13
+ readonly: true,
14
+ source: ".agents/records",
15
+ filters: { from: null, to: null },
16
+ summary: { task_count: 1, overview_metrics: {}, usage: {} },
17
+ prds: [],
18
+ specs: [],
19
+ runs: [],
17
20
  } as unknown as OperationsProjection;
18
- const projection = buildCostSummaryProjection({
19
- periods: { daily: {
20
- "2026-08-19": {
21
- prds: 0, specs: 0, tasks: 1, validations: 0, evidences: 0, runs: 1,
22
- usage: {
23
- total_tokens: { known_sum: 100, unknown: 0, complete: true, coverage_ratio: 1 },
24
- cost: { known_sum: 47.5, unknown: 0, complete: true, coverage_ratio: 1, currency: "BRL" },
21
+ const projection = buildCostSummaryProjection(
22
+ {
23
+ periods: {
24
+ daily: {
25
+ "2026-08-19": {
26
+ prds: 0,
27
+ specs: 0,
28
+ tasks: 1,
29
+ validations: 0,
30
+ evidences: 0,
31
+ runs: 1,
32
+ usage: {
33
+ total_tokens: { known_sum: 100, unknown: 0, complete: true, coverage_ratio: 1 },
34
+ cost: {
35
+ known_sum: 47.5,
36
+ unknown: 0,
37
+ complete: true,
38
+ coverage_ratio: 1,
39
+ currency: "BRL",
40
+ },
41
+ },
42
+ },
25
43
  },
26
44
  },
27
- } },
28
- daily_rows: [{ key: "2026-08-19", total_cost_usd: 8.7, total_cost_brl: 47.5 }],
29
- cost_monitor_daily_duration: {
30
- "2026-08-19": { known_sum: 60_000, eligible_runs: 1, known_runs: 1 },
45
+ daily_rows: [{ key: "2026-08-19", total_cost_usd: 8.7, total_cost_brl: 47.5 }],
46
+ cost_monitor_daily_duration: {
47
+ "2026-08-19": { known_sum: 60_000, eligible_runs: 1, known_runs: 1 },
48
+ },
31
49
  },
32
- }, operations, "USD", null);
50
+ operations,
51
+ "USD",
52
+ null,
53
+ );
33
54
 
34
55
  expect(projection).toMatchObject({
35
56
  aggregate_only: true,
@@ -43,41 +64,101 @@ describe("buildCostSummaryProjection", () => {
43
64
  const metric = (total: number) => ({
44
65
  events: 1,
45
66
  duration_ms: total,
46
- tokens: { input: total, cached_input: total / 2, output: total / 4, reasoning: total / 8, total: total + total / 4 },
67
+ tokens: {
68
+ input: total,
69
+ cached_input: total / 2,
70
+ output: total / 4,
71
+ reasoning: total / 8,
72
+ total: total + total / 4,
73
+ },
47
74
  cost: { usd: total / 100, brl: total / 20 },
48
75
  coverage: { events: 1, tokens: 1, usd: 1, brl: 1 },
49
76
  });
50
77
  const aggregate = {
51
- conversation: metric(10), planning: metric(20), execution: metric(30),
52
- total: metric(60), new_work: metric(60), rework: metric(0),
78
+ conversation: metric(10),
79
+ planning: metric(20),
80
+ execution: metric(30),
81
+ total: metric(60),
82
+ new_work: metric(60),
83
+ rework: metric(0),
53
84
  };
54
85
  const operations = {
55
- schema_version: 2, layout_version: 2, readonly: true, source: ".agents/records",
56
- filters: { from: null, to: null }, summary: { task_count: 0, overview_metrics: {}, usage: {} },
57
- prds: [], specs: [], runs: [],
86
+ schema_version: 2,
87
+ layout_version: 2,
88
+ readonly: true,
89
+ source: ".agents/records",
90
+ filters: { from: null, to: null },
91
+ summary: { task_count: 0, overview_metrics: {}, usage: {} },
92
+ prds: [],
93
+ specs: [],
94
+ runs: [],
58
95
  } as unknown as OperationsProjection;
59
- const projection = buildCostSummaryProjection({
60
- periods: { daily: {} },
61
- aggregate_usage: aggregate,
62
- // Contradictory legacy input proves the aggregate transport wins.
63
- run_metrics: [{
64
- id: "LEGACY", started_at: "2026-08-10T12:00:00.000Z", finished_at: null,
65
- task_id: null, phase: "execution", parent_run_id: null, status: null,
66
- duration_ms: 999, total_tokens: 999, cost: 999, currency: "BRL", events: 999,
67
- }],
68
- }, operations, "BRL", null);
96
+ const projection = buildCostSummaryProjection(
97
+ {
98
+ periods: { daily: {} },
99
+ aggregate_usage: aggregate,
100
+ // Contradictory legacy input proves the aggregate transport wins.
101
+ run_metrics: [
102
+ {
103
+ id: "LEGACY",
104
+ started_at: "2026-08-10T12:00:00.000Z",
105
+ finished_at: null,
106
+ task_id: null,
107
+ phase: "execution",
108
+ parent_run_id: null,
109
+ status: null,
110
+ duration_ms: 999,
111
+ total_tokens: 999,
112
+ cost: 999,
113
+ currency: "BRL",
114
+ events: 999,
115
+ },
116
+ ],
117
+ },
118
+ operations,
119
+ "BRL",
120
+ null,
121
+ );
69
122
 
70
123
  expect(projection.usage).toBe(aggregate);
71
124
  expect(projection.runs).toEqual([]);
72
- expect(projection.usage.total.tokens).toMatchObject({ input: 60, cached_input: 30, output: 15, reasoning: 7.5, total: 75 });
125
+ expect(projection.usage.total.tokens).toMatchObject({
126
+ input: 60,
127
+ cached_input: 30,
128
+ output: 15,
129
+ reasoning: 7.5,
130
+ total: 75,
131
+ });
73
132
  });
74
133
 
75
134
  it("derives phase-aware inclusive usage from compact Run facts when the aggregate transport is empty", () => {
76
- const run = (id: string, phase: "conversation" | "planning" | "execution", input: number, cached: number, output: number, reasoning: number, cost: number, duration: number) => ({
77
- id, started_at: "2026-08-10T12:00:00.000Z", finished_at: null, task_id: null,
78
- phase, parent_run_id: null, status: null, duration_ms: duration, source_duration_ms: duration,
79
- input_tokens: input, cached_input_tokens: cached, output_tokens: output,
80
- reasoning_tokens: reasoning, total_tokens: input + output, cost, currency: "BRL", events: 1,
135
+ const run = (
136
+ id: string,
137
+ phase: "conversation" | "planning" | "execution",
138
+ input: number,
139
+ cached: number,
140
+ output: number,
141
+ reasoning: number,
142
+ cost: number,
143
+ duration: number,
144
+ ) => ({
145
+ id,
146
+ started_at: "2026-08-10T12:00:00.000Z",
147
+ finished_at: null,
148
+ task_id: null,
149
+ phase,
150
+ parent_run_id: null,
151
+ status: null,
152
+ duration_ms: duration,
153
+ source_duration_ms: duration,
154
+ input_tokens: input,
155
+ cached_input_tokens: cached,
156
+ output_tokens: output,
157
+ reasoning_tokens: reasoning,
158
+ total_tokens: input + output,
159
+ cost,
160
+ currency: "BRL",
161
+ events: 1,
81
162
  });
82
163
  const summary = {
83
164
  periods: { daily: {} },
@@ -88,61 +169,138 @@ describe("buildCostSummaryProjection", () => {
88
169
  ],
89
170
  } as CostSummarySource;
90
171
  const operations = {
91
- schema_version: 1, layout_version: 2, readonly: true, source: ".agents/records",
92
- filters: { from: null, to: null }, summary: { task_count: 0, usage: {} },
93
- prds: [], specs: [], runs: [],
172
+ schema_version: 1,
173
+ layout_version: 2,
174
+ readonly: true,
175
+ source: ".agents/records",
176
+ filters: { from: null, to: null },
177
+ summary: { task_count: 0, usage: {} },
178
+ prds: [],
179
+ specs: [],
180
+ runs: [],
94
181
  } as unknown as OperationsProjection;
95
182
 
96
183
  const projection = buildCostSummaryProjection(summary, operations, "BRL", null);
97
184
 
98
185
  expect(projection.aggregate_only).toBe(true);
99
186
  expect(projection.runs).toEqual([]);
100
- expect(projection.usage.conversation.tokens).toMatchObject({ input: 10, cached_input: 4, output: 5, reasoning: 2, total: 15 });
101
- expect(projection.usage.planning.tokens).toMatchObject({ input: 20, cached_input: 8, output: 7, reasoning: 3, total: 27 });
102
- expect(projection.usage.execution.tokens).toMatchObject({ input: 30, cached_input: 12, output: 9, reasoning: 4, total: 39 });
103
- expect(projection.usage.total.tokens).toMatchObject({ input: 60, cached_input: 24, output: 21, reasoning: 9, total: 81 });
187
+ expect(projection.usage.conversation.tokens).toMatchObject({
188
+ input: 10,
189
+ cached_input: 4,
190
+ output: 5,
191
+ reasoning: 2,
192
+ total: 15,
193
+ });
194
+ expect(projection.usage.planning.tokens).toMatchObject({
195
+ input: 20,
196
+ cached_input: 8,
197
+ output: 7,
198
+ reasoning: 3,
199
+ total: 27,
200
+ });
201
+ expect(projection.usage.execution.tokens).toMatchObject({
202
+ input: 30,
203
+ cached_input: 12,
204
+ output: 9,
205
+ reasoning: 4,
206
+ total: 39,
207
+ });
208
+ expect(projection.usage.total.tokens).toMatchObject({
209
+ input: 60,
210
+ cached_input: 24,
211
+ output: 21,
212
+ reasoning: 9,
213
+ total: 81,
214
+ });
104
215
  expect(projection.usage.total.cost.brl).toBe(6);
105
216
  expect(projection.usage.total.duration_ms).toBe(600);
106
217
  });
107
218
 
108
219
  it("uses segment-backed real model groups for the aggregate-only first fold", () => {
109
220
  const operations = {
110
- schema_version: 2, layout_version: 2, readonly: true, source: ".agents/records",
111
- filters: { from: null, to: null }, summary: { task_count: 0, overview_metrics: {}, usage: {} }, prds: [], specs: [], runs: [],
221
+ schema_version: 2,
222
+ layout_version: 2,
223
+ readonly: true,
224
+ source: ".agents/records",
225
+ filters: { from: null, to: null },
226
+ summary: { task_count: 0, overview_metrics: {}, usage: {} },
227
+ prds: [],
228
+ specs: [],
229
+ runs: [],
112
230
  } as unknown as OperationsProjection;
113
231
  const group = (key: string, brl: number) => ({
114
- key, label: key, latest_started_at: "", run_count: 0, task_count: 0,
115
- prd_count: 0, spec_count: 0, evidence_count: 0, test_count: 0, event_count: 0,
116
- total_tokens: 1, estimated_usd: brl / 5, estimated_brl: brl, duration_ms: null,
232
+ key,
233
+ label: key,
234
+ latest_started_at: "",
235
+ run_count: 0,
236
+ task_count: 0,
237
+ prd_count: 0,
238
+ spec_count: 0,
239
+ evidence_count: 0,
240
+ test_count: 0,
241
+ event_count: 0,
242
+ total_tokens: 1,
243
+ estimated_usd: brl / 5,
244
+ estimated_brl: brl,
245
+ duration_ms: null,
117
246
  duration: { known_sum: 0, unknown: 0, complete: true, coverage_ratio: 1 },
118
247
  coverage: { events: 0, tokens: 0, usd: 0, brl: 0 },
119
248
  });
120
- const projection = buildCostSummaryProjection({
121
- periods: { daily: {} },
122
- model_groups: [group("gpt-real", 10), group("claude-real", 5)],
123
- }, operations, "BRL", null);
249
+ const projection = buildCostSummaryProjection(
250
+ {
251
+ periods: { daily: {} },
252
+ model_groups: [group("gpt-real", 10), group("claude-real", 5)],
253
+ },
254
+ operations,
255
+ "BRL",
256
+ null,
257
+ );
124
258
 
125
259
  expect(projection.groups.models.map((row) => [row.key, row.estimated_brl])).toEqual([
126
- ["gpt-real", 10], ["claude-real", 5],
260
+ ["gpt-real", 10],
261
+ ["claude-real", 5],
127
262
  ]);
128
263
  });
129
264
 
130
265
  it("excludes mixed and unavailable residuals from the model chart", () => {
131
266
  const operations = {
132
- schema_version: 2, layout_version: 2, readonly: true, source: ".agents/records",
133
- filters: { from: null, to: null }, summary: { task_count: 0, overview_metrics: {}, usage: {} }, prds: [], specs: [], runs: [],
267
+ schema_version: 2,
268
+ layout_version: 2,
269
+ readonly: true,
270
+ source: ".agents/records",
271
+ filters: { from: null, to: null },
272
+ summary: { task_count: 0, overview_metrics: {}, usage: {} },
273
+ prds: [],
274
+ specs: [],
275
+ runs: [],
134
276
  } as unknown as OperationsProjection;
135
277
  const group = (key: string) => ({
136
- key, label: key, latest_started_at: "", run_count: 0, task_count: null,
137
- prd_count: 0, spec_count: 0, evidence_count: 0, test_count: 0, event_count: 0,
138
- total_tokens: 1, estimated_usd: 1, estimated_brl: 5, duration_ms: null,
278
+ key,
279
+ label: key,
280
+ latest_started_at: "",
281
+ run_count: 0,
282
+ task_count: null,
283
+ prd_count: 0,
284
+ spec_count: 0,
285
+ evidence_count: 0,
286
+ test_count: 0,
287
+ event_count: 0,
288
+ total_tokens: 1,
289
+ estimated_usd: 1,
290
+ estimated_brl: 5,
291
+ duration_ms: null,
139
292
  duration: { known_sum: 0, unknown: 0, complete: true, coverage_ratio: 1 },
140
293
  coverage: { events: 0, tokens: 0, usd: 0, brl: 0 },
141
294
  });
142
- const projection = buildCostSummaryProjection({
143
- periods: { daily: {} },
144
- model_groups: [group("gpt-real"), group("mixed"), group("unknown"), group("unavailable")],
145
- }, operations, "BRL", null);
295
+ const projection = buildCostSummaryProjection(
296
+ {
297
+ periods: { daily: {} },
298
+ model_groups: [group("gpt-real"), group("mixed"), group("unknown"), group("unavailable")],
299
+ },
300
+ operations,
301
+ "BRL",
302
+ null,
303
+ );
146
304
 
147
305
  expect(projection.groups.models.map((row) => row.key)).toEqual(["gpt-real"]);
148
306
  });
@@ -596,361 +754,4 @@ describe("buildCostSummaryProjection", () => {
596
754
  expect(row.duration.coverage_ratio).toBe(1);
597
755
  expect(row.run_count).toBe(3);
598
756
  });
599
-
600
- it("unions overlapping root execution intervals like Operations", () => {
601
- const summary: CostSummarySource = {
602
- periods: {
603
- daily: {
604
- "2026-08-07": {
605
- prds: 0,
606
- specs: 0,
607
- tasks: 0,
608
- validations: 0,
609
- evidences: 0,
610
- runs: 2,
611
- usage: {
612
- total_tokens: { known_sum: 0, unknown: 2, complete: false, coverage_ratio: 0 },
613
- cost: {
614
- known_sum: 0,
615
- unknown: 2,
616
- complete: false,
617
- coverage_ratio: 0,
618
- currency: "BRL",
619
- },
620
- },
621
- duration: { known_sum: 5_400_000, unknown: 0, complete: true, coverage_ratio: 1 },
622
- },
623
- },
624
- },
625
- run_metrics: [
626
- {
627
- id: "LEFT",
628
- started_at: "2026-08-07T12:00:00.000Z",
629
- finished_at: null,
630
- task_id: null,
631
- phase: "execution",
632
- parent_run_id: null,
633
- status: null,
634
- duration_ms: 3_600_000,
635
- duration_started_at: "2026-08-07T12:00:00.000Z",
636
- total_tokens: null,
637
- cost: null,
638
- currency: null,
639
- events: null,
640
- },
641
- {
642
- id: "RIGHT",
643
- started_at: "2026-08-07T12:30:00.000Z",
644
- finished_at: null,
645
- task_id: null,
646
- phase: "execution",
647
- parent_run_id: null,
648
- status: null,
649
- duration_ms: 3_600_000,
650
- duration_started_at: "2026-08-07T12:30:00.000Z",
651
- total_tokens: null,
652
- cost: null,
653
- currency: null,
654
- events: null,
655
- },
656
- ],
657
- };
658
- const operations = {
659
- filters: { from: null, to: null },
660
- summary: { task_count: 0 },
661
- prds: [],
662
- specs: [],
663
- } as unknown as OperationsProjection;
664
- expect(
665
- buildCostSummaryProjection(summary, operations, "BRL", null).groups.daily[0]?.duration
666
- .known_sum,
667
- ).toBe(5_400_000);
668
- });
669
-
670
- it("keeps canonical root coverage without injecting the legacy baseline", () => {
671
- const period = (runs: number) => ({
672
- prds: 0,
673
- specs: 0,
674
- tasks: 0,
675
- validations: 0,
676
- evidences: 0,
677
- runs,
678
- usage: {
679
- total_tokens: { known_sum: 0, unknown: runs, complete: false, coverage_ratio: 0 },
680
- cost: { known_sum: 0, unknown: runs, complete: false, coverage_ratio: 0, currency: "BRL" },
681
- },
682
- });
683
- const summary: CostSummarySource = {
684
- periods: {
685
- daily: {
686
- "2026-08-02": {
687
- ...period(2),
688
- duration: { known_sum: 2_000, unknown: 0, complete: true, coverage_ratio: 1 },
689
- },
690
- "2026-08-03": {
691
- ...period(1),
692
- duration: { known_sum: 0, unknown: 1, complete: false, coverage_ratio: 0 },
693
- },
694
- },
695
- },
696
- run_metrics: [
697
- {
698
- id: "PRE",
699
- started_at: "2026-08-02T03:00:00.000Z",
700
- finished_at: null,
701
- task_id: null,
702
- phase: "execution",
703
- parent_run_id: null,
704
- status: null,
705
- duration_ms: 99_000,
706
- total_tokens: null,
707
- cost: null,
708
- currency: null,
709
- events: null,
710
- },
711
- {
712
- id: "POST",
713
- started_at: "2026-08-02T04:00:00.000Z",
714
- finished_at: null,
715
- task_id: null,
716
- phase: "execution",
717
- parent_run_id: null,
718
- status: null,
719
- duration_ms: 2_000,
720
- total_tokens: null,
721
- cost: null,
722
- currency: null,
723
- events: null,
724
- },
725
- {
726
- id: "UNKNOWN",
727
- started_at: "2026-08-03T12:00:00.000Z",
728
- finished_at: null,
729
- task_id: null,
730
- phase: "execution",
731
- parent_run_id: null,
732
- status: null,
733
- duration_ms: null,
734
- total_tokens: null,
735
- cost: null,
736
- currency: null,
737
- events: null,
738
- },
739
- ],
740
- canonical_daily_duration_ms: { "2026-08-02": 101_000 },
741
- };
742
- const operations = {
743
- filters: { from: null, to: null },
744
- summary: { task_count: 0 },
745
- prds: [],
746
- specs: [],
747
- } as unknown as OperationsProjection;
748
- const projection = buildCostSummaryProjection(summary, operations, "BRL", null);
749
- const cutoffDay = projection.groups.daily.find((row) => row.key === "2026-08-02")!;
750
- const unknownDay = projection.groups.daily.find((row) => row.key === "2026-08-03")!;
751
-
752
- expect(cutoffDay).toMatchObject({
753
- run_count: 2,
754
- duration: {
755
- known_sum: 101_000,
756
- unknown: 0,
757
- coverage_ratio: 1,
758
- },
759
- coverage_counts: {
760
- metrics: { duration: { eligible_runs: 2, known_runs: 2, unknown_runs: 0 } },
761
- },
762
- });
763
- expect(projection.groups.daily.reduce((total, row) => total + row.duration.known_sum, 0)).toBe(
764
- 101_000,
765
- );
766
- expect(unknownDay.duration).toMatchObject({
767
- known_sum: 0,
768
- unknown: 0,
769
- complete: true,
770
- coverage_ratio: 1,
771
- });
772
- expect(projection.groups.monthly.find((row) => row.key === "2026-08")?.duration).toMatchObject({
773
- unknown: 0,
774
- complete: true,
775
- coverage_ratio: 1,
776
- });
777
- expect(
778
- projection.groups.monthly.find((row) => row.key === "2026-08")?.coverage_counts?.metrics
779
- ?.duration,
780
- ).toEqual({
781
- eligible_runs: 2,
782
- known_runs: 2,
783
- unknown_runs: 0,
784
- });
785
- expect(projection.overview.average_run_duration_ms).toBe(2_000);
786
- expect(projection.legacy_effort_baseline).toBeNull();
787
-
788
- const filtered = buildCostSummaryProjection(
789
- summary,
790
- { ...operations, filters: { from: "2026-08-03", to: "2026-08-03" } },
791
- "BRL",
792
- null,
793
- );
794
- expect(filtered.legacy_effort_baseline).toBeNull();
795
- expect(filtered.groups.daily).toHaveLength(1);
796
- });
797
-
798
- it("preserves each canonical SQLite day instead of redistributing duration by tokens", () => {
799
- const period = (tokens: number) => ({
800
- prds: 0,
801
- specs: 0,
802
- tasks: 0,
803
- validations: 0,
804
- evidences: 0,
805
- runs: 1,
806
- usage: {
807
- total_tokens: { known_sum: tokens, unknown: 0, complete: true, coverage_ratio: 1 },
808
- cost: { known_sum: 1, unknown: 0, complete: true, coverage_ratio: 1, currency: "BRL" as const },
809
- },
810
- });
811
- const summary: CostSummarySource = {
812
- periods: {
813
- daily: {
814
- "2026-08-01": period(1_000),
815
- "2026-08-02": period(9_000),
816
- },
817
- },
818
- canonical_daily_duration_ms: {
819
- "2026-08-01": 9_000,
820
- "2026-08-02": 1_000,
821
- },
822
- };
823
- const operations = {
824
- filters: { from: null, to: null },
825
- summary: { task_count: 0 },
826
- prds: [],
827
- specs: [],
828
- } as unknown as OperationsProjection;
829
-
830
- const daily = buildCostSummaryProjection(summary, operations, "BRL", null).groups.daily;
831
-
832
- expect(daily.find((row) => row.key === "2026-08-01")?.duration.known_sum).toBe(9_000);
833
- expect(daily.find((row) => row.key === "2026-08-02")?.duration.known_sum).toBe(1_000);
834
- });
835
-
836
- it("uses São Paulo timestamp bounds for Cost daily labels and preserves the interval total", () => {
837
- const period = () => ({
838
- prds: 0,
839
- specs: 0,
840
- tasks: 0,
841
- validations: 0,
842
- evidences: 0,
843
- runs: 0,
844
- usage: {
845
- total_tokens: { known_sum: 0, unknown: 0, complete: true, coverage_ratio: 1 },
846
- cost: { known_sum: 0, unknown: 0, complete: true, coverage_ratio: 1, currency: "BRL" },
847
- },
848
- });
849
- const summary: CostSummarySource = {
850
- periods: {
851
- daily: Object.fromEntries(
852
- [
853
- "2026-08-02",
854
- "2026-08-03",
855
- "2026-08-04",
856
- "2026-08-05",
857
- "2026-08-06",
858
- "2026-08-07",
859
- "2026-08-08",
860
- ].map((day) => [day, period()]),
861
- ),
862
- },
863
- run_metrics: [
864
- {
865
- id: "LEFT",
866
- started_at: "2026-08-07T12:00:00.000Z",
867
- finished_at: null,
868
- task_id: null,
869
- phase: "execution",
870
- parent_run_id: null,
871
- status: null,
872
- duration_ms: 3_600_000,
873
- total_tokens: null,
874
- cost: null,
875
- currency: null,
876
- events: null,
877
- },
878
- {
879
- id: "RIGHT",
880
- started_at: "2026-08-07T12:30:00.000Z",
881
- finished_at: null,
882
- task_id: null,
883
- phase: "execution",
884
- parent_run_id: null,
885
- status: null,
886
- duration_ms: 3_600_000,
887
- total_tokens: null,
888
- cost: null,
889
- currency: null,
890
- events: null,
891
- },
892
- ],
893
- };
894
- const operations = {
895
- filters: { from: "2026-08-02T03:00:00.000Z", to: "2026-08-08T02:59:59.999Z" },
896
- summary: { task_count: 0 },
897
- prds: [],
898
- specs: [],
899
- } as unknown as OperationsProjection;
900
- summary.periods.daily["2026-08-07"] = {
901
- ...period(),
902
- duration: { known_sum: 5_400_000, unknown: 0, complete: true, coverage_ratio: 1 },
903
- };
904
- const daily = buildCostSummaryProjection(summary, operations, "BRL", null).groups.daily;
905
-
906
- expect(daily.map((row) => row.key)).not.toContain("2026-08-08");
907
- expect(daily.map((row) => row.key)).toEqual(
908
- expect.arrayContaining(["2026-08-02", "2026-08-07"]),
909
- );
910
- expect(daily.reduce((total, row) => total + row.duration.known_sum, 0)).toBe(5_400_000);
911
- });
912
- it("keeps factual duration visible while retaining partial financial coverage", () => {
913
- const known = (known_sum: number) => ({ known_sum, unknown: 0, complete: true, coverage_ratio: 1 });
914
- const period = {
915
- prds: 0, specs: 0, tasks: 0, validations: 0, evidences: 0, runs: 2,
916
- usage: { total_tokens: known(100), cost: { ...known(10), currency: "BRL" } },
917
- };
918
- const operations = {
919
- filters: { from: null, to: null }, summary: { task_count: 0 }, prds: [], specs: [],
920
- } as unknown as OperationsProjection;
921
- const partial = buildCostSummaryProjection({
922
- periods: { daily: { "2026-08-12": period } },
923
- cost_monitor_daily_duration: {
924
- "2026-08-12": { known_sum: 60_000, eligible_runs: 2, known_runs: 1 },
925
- },
926
- }, operations, "BRL", null).groups.daily[0]!;
927
- expect(partial).toMatchObject({ total_tokens: 100, estimated_brl: 10, duration_ms: 60_000 });
928
- expect(partial.duration).toMatchObject({ known_sum: 60_000, unknown: 1, complete: false });
929
-
930
- const observedZero = buildCostSummaryProjection({
931
- periods: { daily: { "2026-08-12": { ...period, runs: 1 } } },
932
- cost_monitor_daily_duration: {
933
- "2026-08-12": { known_sum: 0, eligible_runs: 1, known_runs: 1 },
934
- },
935
- }, operations, "BRL", null).groups.daily[0]!;
936
- expect(observedZero.duration_ms).toBe(0);
937
- });
938
- it("keeps monthly and annual duration unavailable when any financial day is incomplete", () => {
939
- const known = (known_sum: number) => ({ known_sum, unknown: 0, complete: true, coverage_ratio: 1 });
940
- const period = (tokens: number) => ({
941
- prds: 0, specs: 0, tasks: 0, validations: 0, evidences: 0, runs: 1,
942
- usage: { total_tokens: known(tokens), cost: { ...known(tokens), currency: "BRL" as const } },
943
- });
944
- const operations = { filters: { from: null, to: null }, summary: { task_count: 0 }, prds: [], specs: [] } as unknown as OperationsProjection;
945
- const groups = buildCostSummaryProjection({
946
- periods: { daily: { "2026-07-23": period(10), "2026-07-24": period(20) } },
947
- cost_monitor_daily_duration: {
948
- "2026-07-23": { known_sum: 20_000, eligible_runs: 1, known_runs: 1 },
949
- "2026-07-24": { known_sum: 0, eligible_runs: 1, known_runs: 0 },
950
- },
951
- }, operations, "BRL", null).groups;
952
- expect(groups.daily.map((row) => row.duration_ms)).toEqual([20_000, null]);
953
- expect(groups.monthly[0]?.duration_ms).toBeNull();
954
- expect(groups.annual[0]?.duration_ms).toBeNull();
955
- });
956
757
  });