@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
@@ -0,0 +1,691 @@
1
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
2
+ import { join, resolve } from "node:path";
3
+ import { DatabaseSync } from "node:sqlite";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { expectFastCostPagesMatchCanonical } from "./sqlite-cost-fast-page-parity.test-support.js";
6
+ import { rebuildSqliteReadModel, SqliteReadModelFileSystem } from "./sqlite-read-model.js";
7
+ import { prepareMultiProviderFixture } from "./sqlite-read-model-multi-provider-fixture.js";
8
+
9
+ const roots: string[] = [];
10
+ const sqliteTestTempRoot = join(
11
+ resolve(import.meta.dirname, "../../../../../.."),
12
+ ".tmp",
13
+ "sqlite-read-model-tests",
14
+ );
15
+ async function createSqliteTestRoot(): Promise<string> {
16
+ await mkdir(sqliteTestTempRoot, { recursive: true });
17
+ return mkdtemp(join(sqliteTestTempRoot, "fixture-"));
18
+ }
19
+ afterEach(async () => {
20
+ await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
21
+ });
22
+
23
+ describe("SQLite dashboard read model multi-provider", () => {
24
+ it("publishes a cache from a long fixture path with a short temporary filename", async () => {
25
+ const root = await createSqliteTestRoot();
26
+ roots.push(root);
27
+ await prepareMultiProviderFixture(root);
28
+ const cacheDirectory = join(root, `cache-${"x".repeat(Math.max(1, 175 - root.length - 6))}`);
29
+ const previousCacheDirectory = process.env.ZAIP_SQLITE_CACHE_DIR;
30
+ process.env.ZAIP_SQLITE_CACHE_DIR = cacheDirectory;
31
+ try {
32
+ await expect(rebuildSqliteReadModel(root)).resolves.toMatchObject({ cache: "rebuilt" });
33
+ } finally {
34
+ if (previousCacheDirectory === undefined) delete process.env.ZAIP_SQLITE_CACHE_DIR;
35
+ else process.env.ZAIP_SQLITE_CACHE_DIR = previousCacheDirectory;
36
+ }
37
+ });
38
+
39
+ it("keeps a multi-provider and multi-model Run visible to both filtered financial and duration facts", async () => {
40
+ const root = await createSqliteTestRoot();
41
+ roots.push(root);
42
+ const { started, usage, finished } = await prepareMultiProviderFixture(root);
43
+ await rebuildSqliteReadModel(root);
44
+ const aggregateDatabase = new DatabaseSync(
45
+ resolve(root, ".local/dashboard-sqlite/read-model.sqlite"),
46
+ {
47
+ readOnly: true,
48
+ },
49
+ );
50
+ try {
51
+ const aggregates = aggregateDatabase
52
+ .prepare(`SELECT
53
+ json_extract(payload_json, '$.dimension') AS dimension,
54
+ json_extract(payload_json, '$.key') AS key,
55
+ json_extract(payload_json, '$.schema_version') AS schema_version,
56
+ json_extract(payload_json, '$.total_cost_brl') AS total_cost_brl
57
+ FROM zaip_aios_activities
58
+ WHERE payload_type = 'cost_dimension_aggregate_v1'`)
59
+ .all();
60
+ expect(aggregates).toEqual(
61
+ expect.arrayContaining([
62
+ expect.objectContaining({
63
+ dimension: "provider",
64
+ key: "openai",
65
+ schema_version: 1,
66
+ total_cost_brl: 505,
67
+ }),
68
+ expect.objectContaining({
69
+ dimension: "model",
70
+ key: "gpt-a",
71
+ schema_version: 1,
72
+ total_cost_brl: 505,
73
+ }),
74
+ ]),
75
+ );
76
+ expect(aggregates.map((row) => row.key)).toEqual(expect.arrayContaining(["unavailable"]));
77
+ } finally {
78
+ aggregateDatabase.close();
79
+ }
80
+ const filesystem = new SqliteReadModelFileSystem(root);
81
+ expectFastCostPagesMatchCanonical(root, filesystem);
82
+ expect(
83
+ filesystem.viewPage("cost_monitor_daily", { from: "2026-08-04", to: "2026-08-04" }).rows[0],
84
+ ).toMatchObject({ total_tokens: 1_030, total_cost_brl: 515 });
85
+ // The public overview view backs /api/v2/sqlite-views. It must not leak
86
+ // Cost Monitor retains all measurable financial activities, including
87
+ // historical/unassisted telemetry without an Agent Invocation id.
88
+ const publicOverview = filesystem.viewPage("cost_monitor_overview_view", {});
89
+ expect(publicOverview.rows).toHaveLength(3);
90
+ expect(publicOverview.rows).toEqual(
91
+ expect.arrayContaining([
92
+ expect.objectContaining({
93
+ period_kind: "day",
94
+ total_run_count: 3,
95
+ invocation_count: 3,
96
+ total_tokens: 1_030,
97
+ total_cost_brl: 515,
98
+ }),
99
+ expect.objectContaining({
100
+ period_kind: "month",
101
+ total_run_count: 3,
102
+ invocation_count: 3,
103
+ total_tokens: 1_030,
104
+ total_cost_brl: 515,
105
+ }),
106
+ expect.objectContaining({
107
+ period_kind: "year",
108
+ total_run_count: 3,
109
+ invocation_count: 3,
110
+ total_tokens: 1_030,
111
+ total_cost_brl: 515,
112
+ }),
113
+ ]),
114
+ );
115
+ const allAgentGroups = filesystem.viewPage("cost_monitor_zaip_agents", {
116
+ limit: 20,
117
+ offset: 0,
118
+ });
119
+ const allCostTotals = publicOverview.rows.find((row) => row.period_kind === "day");
120
+ if (allCostTotals === undefined) throw new Error("Expected the daily Cost Monitor overview");
121
+ expect(
122
+ allAgentGroups.rows.reduce((total, row) => total + Number(row.invocation_count ?? 0), 0),
123
+ ).toBe(allCostTotals.total_run_count);
124
+ expect(
125
+ allAgentGroups.rows.reduce((total, row) => total + Number(row.total_tokens ?? 0), 0),
126
+ ).toBe(allCostTotals?.total_tokens);
127
+ expect(
128
+ allAgentGroups.rows.reduce((total, row) => total + Number(row.total_cost_brl ?? 0), 0),
129
+ ).toBe(allCostTotals?.total_cost_brl);
130
+ expect(
131
+ allAgentGroups.rows.reduce((total, row) => total + Number(row.total_cost_usd ?? 0), 0),
132
+ ).toBe(allCostTotals.total_cost_usd);
133
+ // Shared Cost Tempo is factual at the activity grain. It remains available
134
+ // in the agent-table total even where a multi-dimension invocation cannot
135
+ // be assigned to an individual Agent row.
136
+ expect(allCostTotals.cost_monitor_total_duration).toBe(120_000);
137
+ expect(allAgentGroups.totals).toMatchObject({
138
+ invocation_count: allCostTotals.total_run_count,
139
+ total_duration: 120_000,
140
+ total_tokens: allCostTotals.total_tokens,
141
+ total_cost_usd: allCostTotals.total_cost_usd,
142
+ total_cost_brl: allCostTotals.total_cost_brl,
143
+ });
144
+ for (const [providers, models] of [
145
+ [["openai"], ["gpt-a"]],
146
+ [["anthropic"], ["claude-b"]],
147
+ ] as const) {
148
+ const rows = filesystem.invocationCostRows({ from: null, to: null, providers, models });
149
+ expect(rows).toHaveLength(1);
150
+ // Membership is segment-based; once the invocation matches, its
151
+ // canonical invocation totals remain intact rather than being split.
152
+ expect(rows[0]).toMatchObject({ total_tokens: 30, cost_brl: 15 });
153
+ expect([
154
+ ...filesystem.executionDurationByDay({ from: null, to: null, providers, models }).values(),
155
+ ]).toEqual([60_000]);
156
+ expect([
157
+ ...filesystem.canonicalRunCountByDay({ from: null, to: null, providers, models }).values(),
158
+ ]).toEqual([1]);
159
+ for (const view of [
160
+ "cost_monitor_daily",
161
+ "cost_monitor_monthly",
162
+ "cost_monitor_annual",
163
+ ] as const) {
164
+ const page = filesystem.viewPage(view, {
165
+ provider: providers[0],
166
+ model: models[0],
167
+ limit: 20,
168
+ offset: 0,
169
+ });
170
+ expect(page.rows[0]).toMatchObject({
171
+ total_run_count: 1,
172
+ total_tokens: 30,
173
+ total_cost_brl: 15,
174
+ });
175
+ }
176
+ const agents = filesystem.viewPage("cost_monitor_zaip_agents", {
177
+ provider: providers[0],
178
+ model: models[0],
179
+ query: "agent",
180
+ });
181
+ const financialRows = filesystem.costMonitorFinancialActivityRows({
182
+ from: null,
183
+ to: null,
184
+ providers,
185
+ models,
186
+ });
187
+ const financialTotals = financialRows.reduce<{
188
+ invocation_count: number;
189
+ total_tokens: number;
190
+ total_cost_brl: number;
191
+ }>(
192
+ (total, row) => ({
193
+ invocation_count: total.invocation_count + 1,
194
+ total_tokens: total.total_tokens + Number(row.total_tokens ?? 0),
195
+ total_cost_brl: total.total_cost_brl + Number(row.cost_brl ?? 0),
196
+ }),
197
+ { invocation_count: 0, total_tokens: 0, total_cost_brl: 0 },
198
+ );
199
+ expect(agents.rows[0]).toMatchObject({
200
+ key: "agent",
201
+ persona: "ana",
202
+ job: "quality_engineer",
203
+ task_count: 1,
204
+ ...financialTotals,
205
+ });
206
+ expect(agents.totals).toMatchObject(financialTotals);
207
+ }
208
+ const crossed = { from: null, to: null, providers: ["openai"], models: ["claude-b"] };
209
+ expect(filesystem.invocationCostRows(crossed)).toHaveLength(0);
210
+ expect([...filesystem.executionDurationByDay(crossed).values()]).toEqual([]);
211
+ expect([...filesystem.canonicalRunCountByDay(crossed).values()]).toEqual([]);
212
+ expect(
213
+ filesystem.viewPage("cost_monitor_agent_invocations", {
214
+ provider: "openai",
215
+ model: "claude-b",
216
+ }).total_count,
217
+ ).toBe(0);
218
+ expect(
219
+ filesystem.viewPage("cost_monitor_zaip_agents", { provider: "openai", model: "claude-b" })
220
+ .total_count,
221
+ ).toBe(0);
222
+ for (const view of [
223
+ "cost_monitor_daily",
224
+ "cost_monitor_monthly",
225
+ "cost_monitor_annual",
226
+ ] as const) {
227
+ // Lifecycle buckets can remain present independently, but the crossed
228
+ // pair must contribute no invocation financial or Run facts.
229
+ const row = filesystem.viewPage(view, { provider: "openai", model: "claude-b" }).rows[0];
230
+ expect(row).toMatchObject({
231
+ total_run_count: 0,
232
+ total_duration: null,
233
+ total_tokens: null,
234
+ total_cost_brl: null,
235
+ });
236
+ }
237
+ for (const view of [
238
+ "cost_monitor_daily",
239
+ "cost_monitor_monthly",
240
+ "cost_monitor_annual",
241
+ ] as const) {
242
+ const originFiltered = filesystem.viewPage(view, { origin: "task" });
243
+ expect(originFiltered.rows[0]).toMatchObject({
244
+ prd_count: null,
245
+ spec_count: null,
246
+ task_count: null,
247
+ validation_count: null,
248
+ evidence_count: null,
249
+ });
250
+ expect(filesystem.viewPage(view, { workType: "new" }).total_count).toBe(0);
251
+ }
252
+ expect(filesystem.viewPage("cost_monitor_zaip_agents", { priority: "high" })).toMatchObject({
253
+ total_count: 0,
254
+ rows: [],
255
+ });
256
+ const providerGroups = filesystem.viewPage("cost_monitor_providers", { limit: 20, offset: 0 });
257
+ expect(providerGroups.rows).toEqual(
258
+ expect.arrayContaining([
259
+ expect.objectContaining({ key: "openai", total_tokens: 1_010, total_cost_brl: 505 }),
260
+ expect.objectContaining({ key: "anthropic", total_tokens: 20, total_cost_brl: 10 }),
261
+ ]),
262
+ );
263
+ expect(providerGroups.rows.map((row) => row.key)).toEqual(
264
+ expect.arrayContaining(["unavailable"]),
265
+ );
266
+ expect(
267
+ filesystem
268
+ .viewPage("cost_monitor_providers", { provider: "openai", model: "gpt-a" })
269
+ .rows.find((row) => row.key === "openai"),
270
+ ).toMatchObject({ total_tokens: 10, total_cost_brl: 5 });
271
+ expect(
272
+ filesystem.viewPage("cost_monitor_providers", { provider: "openai", model: "claude-b" }),
273
+ ).toMatchObject({ total_count: 0, rows: [] });
274
+ // A source segment can prove its financial facts, but an invocation with
275
+ // multiple observed providers cannot prove a provider-specific elapsed
276
+ // time. It must not manufacture a "mixed" bucket for that remainder.
277
+ const queriedProviderRows = filesystem.viewPage("cost_monitor_providers", {
278
+ query: "openai",
279
+ }).rows;
280
+ expect(queriedProviderRows).toEqual([
281
+ expect.objectContaining({ key: "openai", total_tokens: 10, total_cost_brl: 5 }),
282
+ ]);
283
+ const modelGroups = filesystem.viewPage("cost_monitor_models", { limit: 20, offset: 0 });
284
+ expect(modelGroups.rows).toEqual(
285
+ expect.arrayContaining([
286
+ expect.objectContaining({ key: "gpt-a", total_tokens: 1_010, total_cost_brl: 505 }),
287
+ expect.objectContaining({ key: "claude-b", total_tokens: 20, total_cost_brl: 10 }),
288
+ ]),
289
+ );
290
+ // First-fold transport is aggregate-only, but its overview chart must
291
+ // retain the segment-backed model rows instead of falling back to the
292
+ // empty availability metadata.
293
+ expect(filesystem.costMonitorSummaryAggregate({ from: null, to: null }).model_groups).toEqual(
294
+ expect.arrayContaining([
295
+ expect.objectContaining({ key: "gpt-a", total_tokens: 1_010, estimated_brl: 505 }),
296
+ expect.objectContaining({ key: "claude-b", total_tokens: 20, estimated_brl: 10 }),
297
+ ]),
298
+ );
299
+ expect(modelGroups.rows.map((row) => row.key)).toEqual(expect.arrayContaining(["unavailable"]));
300
+ const modelTotals = modelGroups.rows.reduce<{
301
+ invocations: number;
302
+ tasks: number;
303
+ duration: number;
304
+ tokens: number;
305
+ brl: number;
306
+ }>(
307
+ (total, row) => ({
308
+ invocations: total.invocations + Number(row.invocation_count ?? 0),
309
+ tasks: total.tasks + Number(row.task_count ?? 0),
310
+ duration: total.duration + Number(row.total_duration ?? 0),
311
+ tokens: total.tokens + Number(row.total_tokens ?? 0),
312
+ brl: total.brl + Number(row.total_cost_brl ?? 0),
313
+ }),
314
+ { invocations: 0, tasks: 0, duration: 0, tokens: 0, brl: 0 },
315
+ );
316
+ expect(modelTotals).toEqual({
317
+ invocations: 2,
318
+ tasks: 3,
319
+ duration: 60_000,
320
+ tokens: 1030,
321
+ brl: 515,
322
+ });
323
+ expect(filesystem.viewPage("cost_monitor_models", { query: "gpt-a" }).rows).toHaveLength(1);
324
+ expect(
325
+ filesystem.viewPage("cost_monitor_models", { provider: "openai", model: "gpt-a" }).rows[0],
326
+ ).toMatchObject({ key: "gpt-a", total_tokens: 1010, total_cost_brl: 505 });
327
+ expect(
328
+ filesystem.viewPage("cost_monitor_models", { provider: "openai", model: "claude-b" }),
329
+ ).toMatchObject({ total_count: 0, rows: [] });
330
+ expect(filesystem.viewPage("cost_monitor_models", { priority: "high" })).toMatchObject({
331
+ total_count: 0,
332
+ rows: [],
333
+ });
334
+ const unavailable = {
335
+ from: null,
336
+ to: null,
337
+ providers: ["unavailable"],
338
+ models: ["unavailable"],
339
+ };
340
+ const unavailableRows = filesystem.invocationCostRows(unavailable);
341
+ expect(unavailableRows).toHaveLength(1);
342
+ // Observed zero telemetry stays zero, while the missing provider/model
343
+ // attribute selects this segment rather than a literal sentinel value.
344
+ expect(unavailableRows[0]).toMatchObject({ total_tokens: 0, cost_brl: 0 });
345
+ // Execution-duration is an Operations compatibility aggregate and still
346
+ // includes the unassisted canonical Run. Cost Monitor retains its
347
+ // measurable financial activity as an unavailable historical fact.
348
+ expect([...filesystem.executionDurationByDay(unavailable).values()]).toEqual([60_000]);
349
+ expect([...filesystem.canonicalRunCountByDay(unavailable).values()]).toEqual([2]);
350
+ const unavailableInvocation = filesystem.viewPage("cost_monitor_agent_invocations", {
351
+ provider: "unavailable",
352
+ model: "unavailable",
353
+ });
354
+ expect(unavailableInvocation).toMatchObject({ total_count: 1 });
355
+ expect(unavailableInvocation.rows[0]).toMatchObject({ input_tokens: 0 });
356
+ for (const view of [
357
+ "cost_monitor_daily",
358
+ "cost_monitor_monthly",
359
+ "cost_monitor_annual",
360
+ ] as const) {
361
+ const row = filesystem.viewPage(view, { provider: "unavailable", model: "unavailable" })
362
+ .rows[0];
363
+ expect(row).toMatchObject({ total_run_count: 2, total_tokens: 1_000, total_cost_brl: 500 });
364
+ }
365
+
366
+ filesystem.close();
367
+ const sameModelStarted = {
368
+ ...started,
369
+ event_id: "RUN-SAME-MODEL:1",
370
+ run_id: "RUN-SAME-MODEL",
371
+ occurred_at: "2026-08-05T12:00:00.000Z",
372
+ client_turn_id: "same-model",
373
+ conversation_id: "CONV-SAME-MODEL",
374
+ execution_id: "EXEC-SAME-MODEL",
375
+ task_id: "TASK-SAME-MODEL",
376
+ agent_invocation_id: "AINV-SAME-MODEL",
377
+ root_agent_invocation_id: "AINV-SAME-MODEL",
378
+ provider: "mixed",
379
+ model: "gpt-a",
380
+ };
381
+ const sameModelUsage = (sequence: number, provider: string, tokens: number, brl: number) => ({
382
+ ...usage(sequence, provider, "gpt-a", tokens, brl),
383
+ event_id: `RUN-SAME-MODEL:${sequence}`,
384
+ run_id: "RUN-SAME-MODEL",
385
+ occurred_at: "2026-08-05T12:00:01.000Z",
386
+ source_started_at: "2026-08-05T12:00:00.000Z",
387
+ source_finished_at: "2026-08-05T12:01:00.000Z",
388
+ });
389
+ const sameModelFinished = {
390
+ ...finished,
391
+ event_id: "RUN-SAME-MODEL:4",
392
+ run_id: "RUN-SAME-MODEL",
393
+ sequence: 4,
394
+ occurred_at: "2026-08-05T12:01:00.000Z",
395
+ };
396
+ await writeFile(
397
+ join(root, ".agents", "records", "runs", "2026", "08", "RUN-SAME-MODEL.jsonl"),
398
+ `${[sameModelStarted, sameModelUsage(2, "openai", 3, 1.5), sameModelUsage(3, "anthropic", 4, 2), sameModelFinished].map((row) => JSON.stringify(row)).join("\n")}\n`,
399
+ );
400
+ const durationRun = (
401
+ id: string,
402
+ day: string,
403
+ duration: number | null,
404
+ provenance: "reconciled" | "estimated",
405
+ ) => {
406
+ const start = {
407
+ ...sameModelStarted,
408
+ event_id: `${id}:1`,
409
+ run_id: id,
410
+ occurred_at: `${day}T12:00:00.000Z`,
411
+ client_turn_id: id,
412
+ conversation_id: `CONV-${id}`,
413
+ execution_id: `EXEC-${id}`,
414
+ task_id: `TASK-${id}`,
415
+ agent_invocation_id: `AINV-${id}`,
416
+ root_agent_invocation_id: `AINV-${id}`,
417
+ };
418
+ const measured = {
419
+ ...usage(
420
+ 2,
421
+ "openai",
422
+ "gpt-a",
423
+ provenance === "estimated" ? 4_000_000 : 9,
424
+ provenance === "estimated" ? 0 : 4.5,
425
+ ),
426
+ event_id: `${id}:2`,
427
+ run_id: id,
428
+ occurred_at: `${day}T12:00:01.000Z`,
429
+ source_started_at: `${day}T12:00:00.000Z`,
430
+ source_finished_at: `${day}T12:01:00.000Z`,
431
+ ...(duration === null ? {} : { duration_ms: duration, duration_provenance: provenance }),
432
+ };
433
+ const end = {
434
+ ...finished,
435
+ event_id: `${id}:3`,
436
+ run_id: id,
437
+ sequence: 3,
438
+ occurred_at: `${day}T12:01:00.000Z`,
439
+ ...(provenance === "estimated"
440
+ ? { duration_ms: null, duration_provenance: "unavailable" }
441
+ : {}),
442
+ };
443
+ return [start, measured, end];
444
+ };
445
+ await writeFile(
446
+ join(root, ".agents", "records", "runs", "2026", "08", "RUN-RECONCILED-MODEL.jsonl"),
447
+ `${durationRun("RUN-RECONCILED-MODEL", "2026-08-06", 45_000, "reconciled")
448
+ .map((row) => JSON.stringify(row))
449
+ .join("\n")}\n`,
450
+ );
451
+ await writeFile(
452
+ join(root, ".agents", "records", "runs", "2026", "08", "RUN-ESTIMATED-MODEL.jsonl"),
453
+ `${durationRun("RUN-ESTIMATED-MODEL", "2026-08-07", null, "estimated")
454
+ .map((row) => JSON.stringify(row))
455
+ .join("\n")}\n`,
456
+ );
457
+ const sharedTaskRun = (id: string, model: string, tokens: number, brl: number) => [
458
+ {
459
+ ...sameModelStarted,
460
+ event_id: `${id}:1`,
461
+ run_id: id,
462
+ occurred_at: "2026-08-08T12:00:00.000Z",
463
+ client_turn_id: id,
464
+ conversation_id: `CONV-${id}`,
465
+ execution_id: `EXEC-${id}`,
466
+ task_id: "TASK-CROSS-MODEL",
467
+ agent_invocation_id: `AINV-${id}`,
468
+ root_agent_invocation_id: `AINV-${id}`,
469
+ provider: "openai",
470
+ model,
471
+ },
472
+ {
473
+ ...usage(2, "openai", model, tokens, brl),
474
+ event_id: `${id}:2`,
475
+ run_id: id,
476
+ occurred_at: "2026-08-08T12:00:01.000Z",
477
+ source_started_at: "2026-08-08T12:00:00.000Z",
478
+ source_finished_at: "2026-08-08T12:01:00.000Z",
479
+ },
480
+ {
481
+ ...finished,
482
+ event_id: `${id}:3`,
483
+ run_id: id,
484
+ sequence: 3,
485
+ occurred_at: "2026-08-08T12:01:00.000Z",
486
+ },
487
+ ];
488
+ await writeFile(
489
+ join(root, ".agents", "records", "runs", "2026", "08", "RUN-TASK-GPT.jsonl"),
490
+ `${sharedTaskRun("RUN-TASK-GPT", "gpt-a", 5, 2.5)
491
+ .map((row) => JSON.stringify(row))
492
+ .join("\n")}\n`,
493
+ );
494
+ await writeFile(
495
+ join(root, ".agents", "records", "runs", "2026", "08", "RUN-TASK-CLAUDE.jsonl"),
496
+ `${sharedTaskRun("RUN-TASK-CLAUDE", "claude-b", 6, 3)
497
+ .map((row) => JSON.stringify(row))
498
+ .join("\n")}\n`,
499
+ );
500
+ const subrunStarted = {
501
+ ...sameModelStarted,
502
+ event_id: "RUN-PROVIDER-SUBRUN:1",
503
+ run_id: "RUN-PROVIDER-SUBRUN",
504
+ occurred_at: "2026-08-09T12:00:00.000Z",
505
+ client_turn_id: "provider-subrun",
506
+ conversation_id: "CONV-PROVIDER-SUBRUN",
507
+ execution_id: "EXEC-PROVIDER-SUBRUN",
508
+ task_id: "TASK-PROVIDER-SUBRUN",
509
+ agent_invocation_id: "AINV-PROVIDER-SUBRUN",
510
+ root_agent_invocation_id: "AINV-SAME-MODEL",
511
+ parent_agent_invocation_id: "AINV-SAME-MODEL",
512
+ parent_run_id: "RUN-SAME-MODEL",
513
+ run_role: "subagent",
514
+ invocation_kind: "delegated",
515
+ delegation_depth: 1,
516
+ provider: "openai",
517
+ model: "gpt-a",
518
+ };
519
+ const subrunUsage = {
520
+ ...usage(2, "openai", "gpt-a", 8, 4),
521
+ event_id: "RUN-PROVIDER-SUBRUN:2",
522
+ run_id: "RUN-PROVIDER-SUBRUN",
523
+ occurred_at: "2026-08-09T12:00:01.000Z",
524
+ source_started_at: "2026-08-09T12:00:00.000Z",
525
+ source_finished_at: "2026-08-09T12:00:30.000Z",
526
+ };
527
+ const subrunFinished = {
528
+ ...finished,
529
+ event_id: "RUN-PROVIDER-SUBRUN:3",
530
+ run_id: "RUN-PROVIDER-SUBRUN",
531
+ sequence: 3,
532
+ occurred_at: "2026-08-09T12:00:30.000Z",
533
+ duration_ms: 30_000,
534
+ duration_provenance: "observed",
535
+ };
536
+ await writeFile(
537
+ join(root, ".agents", "records", "runs", "2026", "08", "RUN-PROVIDER-SUBRUN.jsonl"),
538
+ `${[subrunStarted, subrunUsage, subrunFinished].map((row) => JSON.stringify(row)).join("\n")}\n`,
539
+ );
540
+ await rebuildSqliteReadModel(root);
541
+ const sameModelFs = new SqliteReadModelFileSystem(root);
542
+ const modelRow = (filter: Record<string, string>) =>
543
+ sameModelFs
544
+ .viewPage("cost_monitor_models", { from: "2026-08-05", to: "2026-08-05", ...filter })
545
+ .rows.find((row) => row.key === "gpt-a");
546
+ expect(modelRow({ provider: "openai", model: "gpt-a" })).toMatchObject({
547
+ invocation_count: 1,
548
+ task_count: 1,
549
+ total_duration: 60_000,
550
+ total_tokens: 3,
551
+ total_cost_brl: 1.5,
552
+ });
553
+ expect(modelRow({ provider: "anthropic", model: "gpt-a" })).toMatchObject({
554
+ invocation_count: 1,
555
+ task_count: 1,
556
+ total_duration: 60_000,
557
+ total_tokens: 4,
558
+ total_cost_brl: 2,
559
+ });
560
+ expect(modelRow({})).toMatchObject({
561
+ invocation_count: 1,
562
+ task_count: 1,
563
+ total_duration: 60_000,
564
+ total_tokens: 7,
565
+ total_cost_brl: 3.5,
566
+ });
567
+ expect(
568
+ sameModelFs.viewPage("cost_monitor_models", {
569
+ from: "2026-08-05",
570
+ to: "2026-08-05",
571
+ provider: "openai",
572
+ model: "claude-b",
573
+ }),
574
+ ).toMatchObject({ total_count: 0, rows: [] });
575
+ for (const day of ["2026-08-06", "2026-08-07"]) {
576
+ const effective = sameModelFs
577
+ .invocationCostRows({ from: day, to: day })
578
+ .reduce((sum, row) => sum + Number(row.duration_ms ?? 0), 0);
579
+ const modelDuration = sameModelFs
580
+ .viewPage("cost_monitor_models", { from: day, to: day })
581
+ .rows.reduce((sum, row) => sum + Number(row.total_duration ?? 0), 0);
582
+ expect(modelDuration).toBe(effective);
583
+ }
584
+ for (const day of ["2026-08-06", "2026-08-07"]) {
585
+ const population = sameModelFs.invocationCostRows({ from: day, to: day });
586
+ const providerRows = sameModelFs.viewPage("cost_monitor_providers", {
587
+ from: day,
588
+ to: day,
589
+ }).rows;
590
+ const providerTotals = providerRows.reduce<{
591
+ invocations: number;
592
+ tasks: number;
593
+ duration: number;
594
+ tokens: number;
595
+ brl: number;
596
+ }>(
597
+ (total, row) => ({
598
+ invocations: total.invocations + Number(row.invocation_count ?? 0),
599
+ tasks: total.tasks + Number(row.task_count ?? 0),
600
+ duration: total.duration + Number(row.total_duration ?? 0),
601
+ tokens: total.tokens + Number(row.total_tokens ?? 0),
602
+ brl: total.brl + Number(row.total_cost_brl ?? 0),
603
+ }),
604
+ { invocations: 0, tasks: 0, duration: 0, tokens: 0, brl: 0 },
605
+ );
606
+ expect(providerTotals).toEqual({
607
+ invocations: population.length,
608
+ tasks: new Set(
609
+ population.map((row) => row.task_id).filter((id): id is string => typeof id === "string"),
610
+ ).size,
611
+ duration: population.reduce((sum, row) => sum + Number(row.duration_ms ?? 0), 0),
612
+ tokens: population.reduce((sum, row) => sum + Number(row.total_tokens ?? 0), 0),
613
+ brl: population.reduce((sum, row) => sum + Number(row.cost_brl ?? 0), 0),
614
+ });
615
+ }
616
+ const sharedTaskRows = sameModelFs.viewPage("cost_monitor_models", {
617
+ from: "2026-08-08",
618
+ to: "2026-08-08",
619
+ }).rows;
620
+ expect(sharedTaskRows).toEqual(
621
+ expect.arrayContaining([
622
+ expect.objectContaining({
623
+ key: "gpt-a",
624
+ invocation_count: 1,
625
+ task_count: 1,
626
+ total_duration: 30_000,
627
+ total_tokens: 5,
628
+ total_cost_brl: 2.5,
629
+ }),
630
+ expect.objectContaining({
631
+ key: "claude-b",
632
+ invocation_count: 1,
633
+ task_count: 1,
634
+ total_duration: 30_000,
635
+ total_tokens: 6,
636
+ total_cost_brl: 3,
637
+ }),
638
+ ]),
639
+ );
640
+ expect(sharedTaskRows.map((row) => row.key)).not.toContain("mixed");
641
+ expect(sharedTaskRows.reduce((sum, row) => sum + Number(row.task_count ?? 0), 0)).toBe(2);
642
+ const subrunPopulation = sameModelFs.invocationCostRows({
643
+ from: "2026-08-09",
644
+ to: "2026-08-09",
645
+ providers: ["openai"],
646
+ models: ["gpt-a"],
647
+ });
648
+ const subrunProviderRows = sameModelFs.viewPage("cost_monitor_providers", {
649
+ from: "2026-08-09",
650
+ to: "2026-08-09",
651
+ provider: "openai",
652
+ model: "gpt-a",
653
+ }).rows;
654
+ const subrunProviderTotals = subrunProviderRows.reduce<{
655
+ invocations: number;
656
+ tasks: number;
657
+ duration: number;
658
+ tokens: number;
659
+ brl: number;
660
+ }>(
661
+ (total, row) => ({
662
+ invocations: total.invocations + Number(row.invocation_count ?? 0),
663
+ tasks: total.tasks + Number(row.task_count ?? 0),
664
+ duration: total.duration + Number(row.total_duration ?? 0),
665
+ tokens: total.tokens + Number(row.total_tokens ?? 0),
666
+ brl: total.brl + Number(row.total_cost_brl ?? 0),
667
+ }),
668
+ { invocations: 0, tasks: 0, duration: 0, tokens: 0, brl: 0 },
669
+ );
670
+ expect(subrunProviderTotals).toEqual({
671
+ invocations: subrunPopulation.length,
672
+ tasks: new Set(
673
+ subrunPopulation
674
+ .map((row) => row.task_id)
675
+ .filter((id): id is string => typeof id === "string"),
676
+ ).size,
677
+ duration: subrunPopulation.reduce((sum, row) => sum + Number(row.duration_ms ?? 0), 0),
678
+ tokens: subrunPopulation.reduce((sum, row) => sum + Number(row.total_tokens ?? 0), 0),
679
+ brl: subrunPopulation.reduce((sum, row) => sum + Number(row.cost_brl ?? 0), 0),
680
+ });
681
+ expect(
682
+ sameModelFs.viewPage("cost_monitor_providers", {
683
+ from: "2026-08-09",
684
+ to: "2026-08-09",
685
+ provider: "openai",
686
+ model: "claude-b",
687
+ }),
688
+ ).toMatchObject({ total_count: 0, rows: [] });
689
+ sameModelFs.close();
690
+ });
691
+ });