@zaip-ai/cli 2.0.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (460) hide show
  1. package/README.md +33 -14
  2. package/dist/services/adapters.d.ts +1 -1
  3. package/dist/services/adapters.d.ts.map +1 -1
  4. package/dist/services/adapters.js +30 -25
  5. package/dist/services/adapters.js.map +1 -1
  6. package/dist/services/agent-adapters.js +45 -15
  7. package/dist/services/agent-adapters.js.map +1 -1
  8. package/dist/services/agent-adapters.test.js +13 -7
  9. package/dist/services/agent-adapters.test.js.map +1 -1
  10. package/dist/services/agent-discovery.d.ts +27 -0
  11. package/dist/services/agent-discovery.d.ts.map +1 -0
  12. package/dist/services/agent-discovery.js +73 -0
  13. package/dist/services/agent-discovery.js.map +1 -0
  14. package/dist/services/codex-conversation-lifecycle-hook.d.ts.map +1 -1
  15. package/dist/services/codex-conversation-lifecycle-hook.js +153 -24
  16. package/dist/services/codex-conversation-lifecycle-hook.js.map +1 -1
  17. package/dist/services/codex-pre-tool-hook-template.d.ts.map +1 -1
  18. package/dist/services/codex-pre-tool-hook-template.js +146 -72
  19. package/dist/services/codex-pre-tool-hook-template.js.map +1 -1
  20. package/dist/services/codex-rules.d.ts +1 -1
  21. package/dist/services/codex-rules.d.ts.map +1 -1
  22. package/dist/services/codex-rules.js +3 -3
  23. package/dist/services/codex-subagent-hook-template.d.ts +1 -1
  24. package/dist/services/codex-subagent-hook-template.d.ts.map +1 -1
  25. package/dist/services/codex-subagent-hook-template.js +117 -66
  26. package/dist/services/codex-subagent-hook-template.js.map +1 -1
  27. package/dist/services/install-agents-template.d.ts.map +1 -1
  28. package/dist/services/install-agents-template.js +56 -6
  29. package/dist/services/install-agents-template.js.map +1 -1
  30. package/dist/services/logger.js +1 -1
  31. package/dist/services/logger.js.map +1 -1
  32. package/dist/services/logger.test.js +24 -3
  33. package/dist/services/logger.test.js.map +1 -1
  34. package/dist/services/runtime-template.test.js +138 -1
  35. package/dist/services/runtime-template.test.js.map +1 -1
  36. package/package.json +1 -1
  37. package/templates/.agents/.env.example +9 -3
  38. package/templates/.agents/README-ENG.md +47 -5
  39. package/templates/.agents/README.md +38 -9
  40. package/templates/.agents/architecture/software-architecture.md +1 -59
  41. package/templates/.agents/branding/brandbook.md +3 -0
  42. package/templates/.agents/config/agents/catalog.yaml +40 -28
  43. package/templates/.agents/config/agents/discovery.json +319 -0
  44. package/templates/.agents/config/clients/codex/agents/zaip-agent-analyst.toml +3 -6
  45. package/templates/.agents/config/clients/codex/agents/zaip-agent-auditor.toml +3 -6
  46. package/templates/.agents/config/clients/codex/agents/zaip-agent-backend.toml +4 -7
  47. package/templates/.agents/config/clients/codex/agents/zaip-agent-brand-strategist.toml +6 -8
  48. package/templates/.agents/config/clients/codex/agents/zaip-agent-builder.toml +4 -7
  49. package/templates/.agents/config/clients/codex/agents/zaip-agent-cloud-engineer.toml +13 -13
  50. package/templates/.agents/config/clients/codex/agents/zaip-agent-data-analyst.toml +5 -7
  51. package/templates/.agents/config/clients/codex/agents/zaip-agent-designer.toml +4 -7
  52. package/templates/.agents/config/clients/codex/agents/zaip-agent-finalizer.toml +3 -6
  53. package/templates/.agents/config/clients/codex/agents/zaip-agent-frontend.toml +4 -7
  54. package/templates/.agents/config/clients/codex/agents/zaip-agent-general-operations.toml +6 -8
  55. package/templates/.agents/config/clients/codex/agents/zaip-agent-governance-compliance.toml +3 -6
  56. package/templates/.agents/config/clients/codex/agents/zaip-agent-growth-strategist.toml +6 -8
  57. package/templates/.agents/config/clients/codex/agents/zaip-agent-integrator.toml +3 -6
  58. package/templates/.agents/config/clients/codex/agents/zaip-agent-marketing-analyst.toml +6 -8
  59. package/templates/.agents/config/clients/codex/agents/zaip-agent-orchestrator.toml +4 -5
  60. package/templates/.agents/config/clients/codex/agents/zaip-agent-refactoring-specialist.toml +3 -6
  61. package/templates/.agents/config/clients/codex/agents/zaip-agent-reviewer.toml +3 -6
  62. package/templates/.agents/config/clients/codex/agents/zaip-agent-sales-specialist.toml +6 -8
  63. package/templates/.agents/config/clients/codex/agents/zaip-agent-security-auditor.toml +3 -6
  64. package/templates/.agents/config/clients/codex/agents/zaip-agent-task-executor.toml +4 -7
  65. package/templates/.agents/config/clients/codex/agents/zaip-agent-website-developer.toml +4 -7
  66. package/templates/.agents/config/clients/codex/agents/zaip-agent-writer.toml +3 -6
  67. package/templates/.agents/config/pricing/models.json +57 -33
  68. package/templates/.agents/config/project.yaml +12 -1
  69. package/templates/.agents/dashboard/.zaip-managed.json +378 -98
  70. package/templates/.agents/dashboard/apps/frontend/dist/assets/CostCalculationGuidePage-CGxeQak4.js +1 -0
  71. package/templates/.agents/dashboard/apps/frontend/dist/assets/{DashboardHelpDialog-CYfpYsTr.js → DashboardHelpDialog-tzS7YxYB.js} +173 -47
  72. package/templates/.agents/dashboard/apps/frontend/dist/assets/PricingSettingsDialog-DEbCi1gP.js +1 -0
  73. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-1L7Qw-Gq.js +3 -0
  74. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-EInWr641.css +1 -0
  75. package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-t1Om0Abw.js +1 -0
  76. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-B6aZfo5f.js +68 -0
  77. package/templates/.agents/dashboard/apps/frontend/dist/assets/{icons-vendor-TPUT2IUt.js → icons-vendor-DiGC-dsJ.js} +1 -1
  78. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DgTmNHN5.js +2 -0
  79. package/templates/.agents/dashboard/apps/frontend/dist/assets/{react-vendor-Ct48XHGL.js → react-vendor-kPO6yNed.js} +1 -1
  80. package/templates/.agents/dashboard/apps/frontend/dist/assets/rolldown-runtime-Bh1tDfsg.js +1 -0
  81. package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-DQpKX9c1.js +1 -0
  82. package/templates/.agents/dashboard/apps/frontend/dist/index.html +6 -6
  83. package/templates/.agents/dashboard/apps/frontend/package.json +1 -1
  84. package/templates/.agents/dashboard/apps/frontend/src/App.tsx +3 -1264
  85. package/templates/.agents/dashboard/apps/frontend/src/AppDashboardContent.tsx +363 -0
  86. package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.dom.test.ts +99 -0
  87. package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.tsx +62 -6
  88. package/templates/.agents/dashboard/apps/frontend/src/ProjectStackEditor.tsx +3 -1
  89. package/templates/.agents/dashboard/apps/frontend/src/__tests__/app-composition-support.ts +7 -0
  90. package/templates/.agents/dashboard/apps/frontend/src/cost-period-refresh.test.ts +9 -7
  91. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api-settings.ts +151 -0
  92. package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.ts +28 -153
  93. package/templates/.agents/dashboard/apps/frontend/src/dashboard-app-shell.tsx +33 -0
  94. package/templates/.agents/dashboard/apps/frontend/src/dashboard-cost-facts.ts +30 -0
  95. package/templates/.agents/dashboard/apps/frontend/src/dashboard-project-overview.ts +7 -1
  96. package/templates/.agents/dashboard/apps/frontend/src/dashboard-retry.ts +17 -0
  97. package/templates/.agents/dashboard/apps/frontend/src/dashboard-setup-route.ts +29 -0
  98. package/templates/.agents/dashboard/apps/frontend/src/dashboard-view-actions.ts +66 -0
  99. package/templates/.agents/dashboard/apps/frontend/src/operations-period-render.test.ts +3 -2
  100. package/templates/.agents/dashboard/apps/frontend/src/overview-status-page.test.ts +2 -2
  101. package/templates/.agents/dashboard/apps/frontend/src/project-installation-status.test.ts +48 -0
  102. package/templates/.agents/dashboard/apps/frontend/src/project-installation-status.ts +29 -0
  103. package/templates/.agents/dashboard/apps/frontend/src/project-settings-page.css +68 -0
  104. package/templates/.agents/dashboard/apps/frontend/src/project-settings.test.ts +2 -2
  105. package/templates/.agents/dashboard/apps/frontend/src/sao-paulo-day-rollover.test.ts +36 -0
  106. package/templates/.agents/dashboard/apps/frontend/src/sao-paulo-day-rollover.ts +30 -0
  107. package/templates/.agents/dashboard/apps/frontend/src/snapshot-banner-semantics.test.ts +2 -5
  108. package/templates/.agents/dashboard/apps/frontend/src/snapshot-coherence.test.ts +30 -19
  109. package/templates/.agents/dashboard/apps/frontend/src/use-app-effects.ts +9 -1
  110. package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-task-pagination.ts +77 -0
  111. package/templates/.agents/dashboard/apps/frontend/src/use-app-work-board.ts +397 -0
  112. package/templates/.agents/dashboard/apps/frontend/src/use-dashboard-app-model.tsx +782 -0
  113. package/templates/.agents/dashboard/apps/frontend/src/use-snapshot-notice.tsx +49 -0
  114. package/templates/.agents/dashboard/modules/cost-monitor/package.json +1 -1
  115. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostDeveloperPanelSlot.tsx +16 -0
  116. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostGroupsTable.tsx +459 -0
  117. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.test.ts +27 -17
  118. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.tsx +62 -186
  119. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorRunDialog.tsx +20 -0
  120. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables-hides-calls-that-have-no-collected.test.ts +80 -0
  121. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables-keeps-legacy-codex-identity-fields-blank.test.ts +455 -0
  122. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.test.ts +18 -525
  123. package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.tsx +32 -508
  124. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-export-sources.ts +74 -0
  125. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-page-actions.ts +19 -0
  126. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-page-selectors.ts +49 -0
  127. package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-table-formatters.ts +115 -0
  128. package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.test-fixtures.ts +2 -0
  129. package/templates/.agents/dashboard/modules/operations/package.json +1 -1
  130. package/templates/.agents/dashboard/modules/operations/src/contracts.ts +4 -0
  131. package/templates/.agents/dashboard/modules/operations/src/react/EntityTableBadges.tsx +34 -0
  132. package/templates/.agents/dashboard/modules/operations/src/react/EntityTables.tsx +8 -38
  133. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview-keeps-structure-classes-mutually-exclusive.test.ts +243 -0
  134. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.test.ts +27 -275
  135. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.tsx +70 -247
  136. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverviewCharts.tsx +171 -0
  137. package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverviewPanels.tsx +64 -0
  138. package/templates/.agents/dashboard/modules/operations/src/react/OperationsPage.tsx +4 -3
  139. package/templates/.agents/dashboard/modules/operations/src/react/PrdDocumentDialog.test.tsx +2 -1
  140. package/templates/.agents/dashboard/modules/operations/src/react/manual-work-priority.test.ts +2 -1
  141. package/templates/.agents/dashboard/modules/operations/src/react/operations-coverage-toast.test.ts +6 -2
  142. package/templates/.agents/dashboard/modules/operations/src/react/operations-overview-period-filter.test.ts +6 -14
  143. package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.status-cards.test.ts +3 -1
  144. package/templates/.agents/dashboard/modules/operations/src/react/operations-page-contract.ts +2 -0
  145. package/templates/.agents/dashboard/modules/operations/src/react/overview-metric-format.ts +32 -0
  146. package/templates/.agents/dashboard/modules/traceability/package.json +1 -1
  147. package/templates/.agents/dashboard/packages/branding/package.json +1 -1
  148. package/templates/.agents/dashboard/packages/branding/src/index.ts +1 -1
  149. package/templates/.agents/dashboard/packages/contracts/package.json +1 -1
  150. package/templates/.agents/dashboard/packages/data-export/package.json +1 -1
  151. package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs +1458 -1458
  152. package/templates/.agents/dashboard/packages/local-runtime/dist/sqlite-read-model.cjs +1425 -1425
  153. package/templates/.agents/dashboard/packages/local-runtime/package.json +2 -1
  154. package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-runtime.mjs +7 -3
  155. package/templates/.agents/dashboard/packages/local-runtime/server.mjs +1458 -1459
  156. package/templates/.agents/dashboard/packages/local-runtime/src/active-codex-telemetry.ts +25 -0
  157. package/templates/.agents/dashboard/packages/local-runtime/src/agent-catalog-settings.test.ts +1 -1
  158. package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.test.ts +53 -8
  159. package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.ts +79 -24
  160. package/templates/.agents/dashboard/packages/local-runtime/src/projection-refresh-diagnostics.ts +35 -0
  161. package/templates/.agents/dashboard/packages/local-runtime/src/server-costs-routes.ts +168 -0
  162. package/templates/.agents/dashboard/packages/local-runtime/src/server-dual-reads-manifest-summaries-without-losing.test.ts +344 -0
  163. package/templates/.agents/dashboard/packages/local-runtime/src/server-http-contracts.ts +31 -0
  164. package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-routes.ts +345 -0
  165. package/templates/.agents/dashboard/packages/local-runtime/src/server-read-projections.ts +461 -0
  166. package/templates/.agents/dashboard/packages/local-runtime/src/server-reconciliation-refresh.test.ts +78 -0
  167. package/templates/.agents/dashboard/packages/local-runtime/src/server-route-context.ts +13 -0
  168. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-synchronization.test.ts +18 -0
  169. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-synchronization.ts +19 -3
  170. package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot.test.ts +22 -21
  171. package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-task-trace.ts +1 -1
  172. package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-view-allowlist.test.ts +25 -0
  173. package/templates/.agents/dashboard/packages/local-runtime/src/server-trace-routes.ts +64 -0
  174. package/templates/.agents/dashboard/packages/local-runtime/src/server-work-reconciliation.test.ts +2 -30
  175. package/templates/.agents/dashboard/packages/local-runtime/src/server-work-reconciliation.ts +6 -23
  176. package/templates/.agents/dashboard/packages/local-runtime/src/server.test-fixtures.ts +1 -1
  177. package/templates/.agents/dashboard/packages/local-runtime/src/server.test.ts +2 -330
  178. package/templates/.agents/dashboard/packages/local-runtime/src/server.ts +73 -1060
  179. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-first-fold.ts +78 -0
  180. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-projections.ts +561 -0
  181. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-runs.ts +600 -0
  182. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-metric-contract.test.ts +1 -1
  183. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-agent-dimension.ts +269 -0
  184. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-context.ts +32 -0
  185. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-entity-group.ts +244 -0
  186. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-filtered-dimension.ts +292 -0
  187. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-financial.ts +547 -0
  188. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-model-dimension.ts +360 -0
  189. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-provider-dimension.ts +169 -0
  190. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-summary.ts +475 -0
  191. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-temporal-dimension.ts +132 -0
  192. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-timing.ts +299 -0
  193. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-view-page.ts +692 -0
  194. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-counts-every-root-execution-day-returns.test.ts +739 -0
  195. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-does-not-convert-delayed-historical-finalizer.test.ts +706 -0
  196. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-filesystem.ts +748 -0
  197. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-first-fold-types.ts +1 -1
  198. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-keeps-orphan-telemetry-out-kanban-without.test.ts +710 -0
  199. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-marks-token-cost-telemetry-unavailable-when.test.ts +618 -0
  200. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-rebuild.ts +755 -0
  201. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-rebuilds-disposable-snapshot-serves-zaip-records.test.ts +276 -0
  202. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-schema.ts +193 -0
  203. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-types.ts +123 -0
  204. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.test.ts +1 -2805
  205. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.ts +17 -6930
  206. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-schema-base-views.ts +385 -0
  207. package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-schema-dashboard-views.ts +412 -0
  208. package/templates/.agents/dashboard/packages/local-runtime/src/work-priority-contract.test.ts +4 -3
  209. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-build.mjs +195 -0
  210. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-lifecycle.test.mjs +2 -7
  211. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-logging.mjs +35 -0
  212. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-navigation.mjs +114 -0
  213. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-paths.mjs +90 -0
  214. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.mjs +89 -418
  215. package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.test.mjs +22 -12
  216. package/templates/.agents/dashboard/packages/ui/package.json +1 -1
  217. package/templates/.agents/dashboard/tests/e2e/package.json +1 -1
  218. package/templates/.agents/dashboard/tests/e2e/playwright.config.ts +4 -1
  219. package/templates/.agents/design/.zaip-managed.json +5 -5
  220. package/templates/.agents/design/DESIGN.md +2 -186
  221. package/templates/.agents/design/README.md +12 -2
  222. package/templates/.agents/design/apps/catalog/package.json +1 -1
  223. package/templates/.agents/design/packages/local-runtime/package.json +1 -1
  224. package/templates/.agents/growth/strategy.md +3 -0
  225. package/templates/.agents/marketing/strategy.md +3 -0
  226. package/templates/.agents/requirements/autonomous-assurance.md +2 -1
  227. package/templates/.agents/requirements/cloud-hostinger-autonomy.md +1 -1
  228. package/templates/.agents/requirements/comparative-audit.md +1 -1
  229. package/templates/.agents/requirements/context-engine.md +1 -1
  230. package/templates/.agents/requirements/cost-observability.md +1 -1
  231. package/templates/.agents/requirements/dashboard-launch.md +1 -1
  232. package/templates/.agents/requirements/data-export.md +1 -1
  233. package/templates/.agents/requirements/design-system.md +13 -4
  234. package/templates/.agents/requirements/execution-engine.md +1 -1
  235. package/templates/.agents/requirements/kanban-dashboard.md +1 -1
  236. package/templates/.agents/requirements/model-orchestration.md +15 -5
  237. package/templates/.agents/requirements/public-distribution.md +5 -3
  238. package/templates/.agents/requirements/software-architecture.md +1 -1
  239. package/templates/.agents/requirements/strategic-improvements.md +1 -1
  240. package/templates/.agents/requirements/work-lifecycle.md +3 -3
  241. package/templates/.agents/requirements/zaip-strategic-95.md +1 -1
  242. package/templates/.agents/rules/architecture.md +2 -0
  243. package/templates/.agents/rules/astra-diagnostic.md +20 -0
  244. package/templates/.agents/rules/autonomy-decision.md +3 -1
  245. package/templates/.agents/rules/cloud-hostinger-autonomy.md +2 -0
  246. package/templates/.agents/rules/context.md +2 -1
  247. package/templates/.agents/rules/core.md +9 -14
  248. package/templates/.agents/rules/design-system-central-contract.md +17 -0
  249. package/templates/.agents/rules/evolution.md +3 -1
  250. package/templates/.agents/rules/frontend-lite.md +3 -1
  251. package/templates/.agents/rules/local-sqlite-storage.md +2 -2
  252. package/templates/.agents/rules/meta-mcp.md +4 -1
  253. package/templates/.agents/rules/model-orchestration.md +1 -1
  254. package/templates/.agents/rules/run-lifecycle-closure.md +7 -5
  255. package/templates/.agents/rules/security.md +3 -1
  256. package/templates/.agents/rules/specialist-routing.md +6 -2
  257. package/templates/.agents/rules/text-writing-utf8.md +1 -1
  258. package/templates/.agents/rules/workflow.md +7 -5
  259. package/templates/.agents/runtime/VERSION +1 -1
  260. package/templates/.agents/runtime/bin/zaip.mjs +534 -266
  261. package/templates/.agents/runtime/checksums.sha256 +6 -6
  262. package/templates/.agents/runtime/manifest.json +1 -1
  263. package/templates/.agents/runtime/pnpm-lock.sha256 +1 -1
  264. package/templates/.agents/runtime/provenance.json +5 -5
  265. package/templates/.agents/runtime/sbom.cdx.json +1 -1
  266. package/templates/.agents/sales/playbook.md +3 -0
  267. package/templates/.agents/skills/zaip-aios/SKILL.md +5 -3
  268. package/templates/.agents/skills/zaip-skill-adapt-stack/SKILL.md +1 -0
  269. package/templates/.agents/skills/zaip-skill-api-contracts/SKILL.md +14 -0
  270. package/templates/.agents/skills/zaip-skill-api-contracts/agents/openai.yaml +4 -0
  271. package/templates/.agents/skills/zaip-skill-application-observability/SKILL.md +15 -0
  272. package/templates/.agents/skills/zaip-skill-application-observability/agents/openai.yaml +4 -0
  273. package/templates/.agents/skills/zaip-skill-application-observability/references/signal-design.md +3 -0
  274. package/templates/.agents/skills/zaip-skill-application-readiness/SKILL.md +15 -0
  275. package/templates/.agents/skills/zaip-skill-application-readiness/agents/openai.yaml +4 -0
  276. package/templates/.agents/skills/zaip-skill-application-readiness/references/evidence-matrix.md +3 -0
  277. package/templates/.agents/skills/zaip-skill-architecture-design/SKILL.md +14 -0
  278. package/templates/.agents/skills/zaip-skill-architecture-design/agents/openai.yaml +4 -0
  279. package/templates/.agents/skills/zaip-skill-async-jobs/SKILL.md +14 -0
  280. package/templates/.agents/skills/zaip-skill-async-jobs/agents/openai.yaml +4 -0
  281. package/templates/.agents/skills/zaip-skill-auth-tenancy/SKILL.md +15 -0
  282. package/templates/.agents/skills/zaip-skill-auth-tenancy/agents/openai.yaml +4 -0
  283. package/templates/.agents/skills/zaip-skill-auth-tenancy/references/data-access-paths.md +9 -0
  284. package/templates/.agents/skills/zaip-skill-auth-tenancy/references/worker-scenario.md +5 -0
  285. package/templates/.agents/skills/zaip-skill-auth-tenancy/scripts/worker-contract.test.mjs +27 -0
  286. package/templates/.agents/skills/zaip-skill-author-skills/SKILL.md +2 -0
  287. package/templates/.agents/skills/zaip-skill-author-skills/references/engineering-skill-index.md +9 -0
  288. package/templates/.agents/skills/zaip-skill-author-skills/scripts/audit-skill-catalog.mjs +5 -3
  289. package/templates/.agents/skills/zaip-skill-author-skills/scripts/author-skill-scripts.test.mjs +27 -0
  290. package/templates/.agents/skills/zaip-skill-backend/SKILL.md +4 -0
  291. package/templates/.agents/skills/zaip-skill-backend/references/deployment-environments.md +75 -0
  292. package/templates/.agents/skills/zaip-skill-backend/references/supabase-migration-contract.md +23 -0
  293. package/templates/.agents/skills/zaip-skill-brand-governance/SKILL.md +2 -0
  294. package/templates/.agents/skills/zaip-skill-cache-strategy/SKILL.md +14 -0
  295. package/templates/.agents/skills/zaip-skill-cache-strategy/agents/openai.yaml +4 -0
  296. package/templates/.agents/skills/zaip-skill-change/SKILL.md +1 -1
  297. package/templates/.agents/skills/zaip-skill-cloud-engineering/SKILL.md +7 -0
  298. package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/SKILL.md +37 -0
  299. package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/agents/openai.yaml +6 -0
  300. package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/references/workers-static-assets.md +26 -0
  301. package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/references/workflow-templates.md +71 -0
  302. package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/scripts/cloudflare-github-deploy-contract.test.mjs +77 -0
  303. package/templates/.agents/skills/zaip-skill-config/SKILL.md +21 -11
  304. package/templates/.agents/skills/zaip-skill-config/agents/openai.yaml +2 -2
  305. package/templates/.agents/skills/zaip-skill-container-runtime/SKILL.md +14 -0
  306. package/templates/.agents/skills/zaip-skill-container-runtime/agents/openai.yaml +4 -0
  307. package/templates/.agents/skills/zaip-skill-context/SKILL.md +6 -1
  308. package/templates/.agents/skills/zaip-skill-context/references/prd-spec-task-handoff.md +10 -0
  309. package/templates/.agents/skills/zaip-skill-context/references/rule-selection.md +20 -0
  310. package/templates/.agents/skills/zaip-skill-cqrs/SKILL.md +1 -0
  311. package/templates/.agents/skills/zaip-skill-cybersecurity/SKILL.md +18 -0
  312. package/templates/.agents/skills/zaip-skill-cybersecurity/agents/openai.yaml +4 -0
  313. package/templates/.agents/skills/zaip-skill-cybersecurity/references/audit-contract.md +94 -0
  314. package/templates/.agents/skills/zaip-skill-cybersecurity/scripts/score-audit.mjs +185 -0
  315. package/templates/.agents/skills/zaip-skill-cybersecurity/scripts/score-audit.test.mjs +101 -0
  316. package/templates/.agents/skills/zaip-skill-data-modeling/SKILL.md +14 -0
  317. package/templates/.agents/skills/zaip-skill-data-modeling/agents/openai.yaml +4 -0
  318. package/templates/.agents/skills/zaip-skill-database-migrations/SKILL.md +20 -0
  319. package/templates/.agents/skills/zaip-skill-database-migrations/agents/openai.yaml +4 -0
  320. package/templates/.agents/skills/zaip-skill-database-migrations/references/manual-mode.md +15 -0
  321. package/templates/.agents/skills/zaip-skill-database-migrations/references/promotion-example.md +5 -0
  322. package/templates/.agents/skills/zaip-skill-database-migrations/scripts/export-manual-sql.mjs +145 -0
  323. package/templates/.agents/skills/zaip-skill-database-migrations/scripts/export-manual-sql.test.mjs +178 -0
  324. package/templates/.agents/skills/zaip-skill-dependency-upgrade/SKILL.md +14 -0
  325. package/templates/.agents/skills/zaip-skill-dependency-upgrade/agents/openai.yaml +4 -0
  326. package/templates/.agents/skills/zaip-skill-deployment-pipeline/SKILL.md +15 -0
  327. package/templates/.agents/skills/zaip-skill-deployment-pipeline/agents/openai.yaml +4 -0
  328. package/templates/.agents/skills/zaip-skill-deployment-pipeline/references/runtime-shapes.md +3 -0
  329. package/templates/.agents/skills/zaip-skill-design-system/SKILL.md +20 -9
  330. package/templates/.agents/skills/zaip-skill-dev-environment/SKILL.md +14 -0
  331. package/templates/.agents/skills/zaip-skill-dev-environment/agents/openai.yaml +4 -0
  332. package/templates/.agents/skills/zaip-skill-dev-environment/references/inventory-contract.md +7 -0
  333. package/templates/.agents/skills/zaip-skill-dev-environment/scripts/inventory.mjs +77 -0
  334. package/templates/.agents/skills/zaip-skill-disaster-recovery/SKILL.md +15 -0
  335. package/templates/.agents/skills/zaip-skill-disaster-recovery/agents/openai.yaml +4 -0
  336. package/templates/.agents/skills/zaip-skill-disaster-recovery/references/recovery-scope.md +3 -0
  337. package/templates/.agents/skills/zaip-skill-execution/SKILL.md +5 -3
  338. package/templates/.agents/skills/zaip-skill-execution/references/correction-cycle.md +7 -0
  339. package/templates/.agents/skills/zaip-skill-execution/references/runtime-governance.md +13 -0
  340. package/templates/.agents/skills/zaip-skill-external-integrations/SKILL.md +14 -0
  341. package/templates/.agents/skills/zaip-skill-external-integrations/agents/openai.yaml +4 -0
  342. package/templates/.agents/skills/zaip-skill-frontend/SKILL.md +4 -0
  343. package/templates/.agents/skills/zaip-skill-frontend-componentization/SKILL.md +44 -0
  344. package/templates/.agents/skills/zaip-skill-frontend-componentization/agents/openai.yaml +4 -0
  345. package/templates/.agents/skills/zaip-skill-frontend-data-flows/SKILL.md +14 -0
  346. package/templates/.agents/skills/zaip-skill-frontend-data-flows/agents/openai.yaml +4 -0
  347. package/templates/.agents/skills/zaip-skill-general-operations/SKILL.md +8 -7
  348. package/templates/.agents/skills/zaip-skill-general-operations/references/extended-workflow.md +7 -0
  349. package/templates/.agents/skills/zaip-skill-github-actions-setup/SKILL.md +36 -0
  350. package/templates/.agents/skills/zaip-skill-github-actions-setup/agents/openai.yaml +4 -0
  351. package/templates/.agents/skills/zaip-skill-github-actions-setup/references/cloudflare-pages.md +33 -0
  352. package/templates/.agents/skills/zaip-skill-github-actions-setup/references/github.md +63 -0
  353. package/templates/.agents/skills/zaip-skill-github-actions-setup/references/hostinger-vps.md +55 -0
  354. package/templates/.agents/skills/zaip-skill-github-actions-setup/references/npm.md +30 -0
  355. package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/check-skill.mjs +55 -0
  356. package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/verify-cloudflare.mjs +61 -0
  357. package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/verify-cloudflare.test.mjs +128 -0
  358. package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/verify-ssh.integration.test.mjs +106 -0
  359. package/templates/.agents/skills/zaip-skill-github-deploy/SKILL.md +43 -76
  360. package/templates/.agents/skills/zaip-skill-github-deploy/references/deployment-workflow.md +131 -0
  361. package/templates/.agents/skills/zaip-skill-github-deploy/references/github-release-workflow-template.md +31 -0
  362. package/templates/.agents/skills/zaip-skill-github-deploy/references/release-gate-matrix.md +24 -0
  363. package/templates/.agents/skills/zaip-skill-github-deploy/references/release-identity.md +44 -0
  364. package/templates/.agents/skills/zaip-skill-github-deploy/references/release-notes.md +134 -0
  365. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/consumer-release-preparation.mjs +389 -0
  366. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/consumer-release-preparation.test.mjs +134 -0
  367. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-deploy-contract.test.mjs +25 -2
  368. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-readiness-api.test.mjs +134 -0
  369. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-readiness.mjs +98 -0
  370. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-readiness.test.mjs +25 -0
  371. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/install-github-readiness-workflow.mjs +159 -0
  372. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/install-github-readiness-workflow.test.mjs +160 -0
  373. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/preflight.mjs +149 -12
  374. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/preflight.test.mjs +64 -5
  375. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/release-notes-coverage.test.mjs +126 -0
  376. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/resolve-release-identity.mjs +78 -0
  377. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/resolve-release-identity.test.mjs +51 -0
  378. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/validate-release-notes.mjs +184 -0
  379. package/templates/.agents/skills/zaip-skill-github-deploy/scripts/validate-release-notes.test.mjs +109 -0
  380. package/templates/.agents/skills/zaip-skill-github-setup/SKILL.md +5 -0
  381. package/templates/.agents/skills/zaip-skill-github-setup-ssh-folder/SKILL.md +54 -0
  382. package/templates/.agents/skills/zaip-skill-github-setup-ssh-folder/agents/openai.yaml +4 -0
  383. package/templates/.agents/skills/zaip-skill-github-setup-ssh-folder/assets/.env.example +9 -0
  384. package/templates/.agents/skills/zaip-skill-github-setup-ssh-folder/references/operational-procedure.md +137 -0
  385. package/templates/.agents/skills/zaip-skill-growth-strategy-revops/SKILL.md +8 -18
  386. package/templates/.agents/skills/zaip-skill-growth-strategy-revops/references/extended-workflow.md +21 -0
  387. package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/SKILL.md +18 -10
  388. package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/agents/openai.yaml +3 -4
  389. package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/references/aws-cli-terraform.md +62 -0
  390. package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/references/guia-iniciante-hostinger-vps.md +183 -0
  391. package/templates/.agents/skills/zaip-skill-marketing/SKILL.md +8 -13
  392. package/templates/.agents/skills/zaip-skill-marketing/references/extended-workflow.md +16 -0
  393. package/templates/.agents/skills/zaip-skill-meta-ads-setup/SKILL.md +2 -0
  394. package/templates/.agents/skills/zaip-skill-meta-token-onboarding/SKILL.md +17 -0
  395. package/templates/.agents/skills/zaip-skill-meta-token-onboarding/agents/openai.yaml +4 -0
  396. package/templates/.agents/skills/zaip-skill-meta-token-onboarding/references/onboarding-manual.md +96 -0
  397. package/templates/.agents/skills/zaip-skill-module-scaffold/SKILL.md +14 -0
  398. package/templates/.agents/skills/zaip-skill-module-scaffold/agents/openai.yaml +4 -0
  399. package/templates/.agents/skills/zaip-skill-module-scaffold/references/scaffold-contract.md +9 -0
  400. package/templates/.agents/skills/zaip-skill-module-scaffold/scripts/helpers.test.mjs +121 -0
  401. package/templates/.agents/skills/zaip-skill-module-scaffold/scripts/scaffold.mjs +169 -0
  402. package/templates/.agents/skills/zaip-skill-move-prd/SKILL.md +1 -1
  403. package/templates/.agents/skills/zaip-skill-move-spec/SKILL.md +1 -1
  404. package/templates/.agents/skills/zaip-skill-performance-engineering/SKILL.md +14 -0
  405. package/templates/.agents/skills/zaip-skill-performance-engineering/agents/openai.yaml +4 -0
  406. package/templates/.agents/skills/zaip-skill-prd/SKILL.md +1 -1
  407. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-local-telemetry.mjs +1 -0
  408. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.mjs +26 -9
  409. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.test.mjs +39 -13
  410. package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.mjs +1 -0
  411. package/templates/.agents/skills/zaip-skill-refactor-landing-page/SKILL.md +66 -0
  412. package/templates/.agents/skills/zaip-skill-refactor-landing-page/agents/openai.yaml +4 -0
  413. package/templates/.agents/skills/zaip-skill-refactor-landing-page/references/behavioral-dry-run.md +23 -0
  414. package/templates/.agents/skills/zaip-skill-release-qualification/SKILL.md +44 -1
  415. package/templates/.agents/skills/zaip-skill-release-qualification/references/local-preparation.md +98 -0
  416. package/templates/.agents/skills/zaip-skill-review/SKILL.md +1 -0
  417. package/templates/.agents/skills/zaip-skill-rules/SKILL.md +3 -3
  418. package/templates/.agents/skills/zaip-skill-sales-methodology/SKILL.md +9 -17
  419. package/templates/.agents/skills/zaip-skill-sales-methodology/references/extended-workflow.md +20 -0
  420. package/templates/.agents/skills/zaip-skill-setup/SKILL.md +22 -21
  421. package/templates/.agents/skills/zaip-skill-setup/agents/openai.yaml +2 -2
  422. package/templates/.agents/skills/zaip-skill-spec/SKILL.md +3 -2
  423. package/templates/.agents/skills/zaip-skill-storage-uploads/SKILL.md +14 -0
  424. package/templates/.agents/skills/zaip-skill-storage-uploads/agents/openai.yaml +4 -0
  425. package/templates/.agents/skills/zaip-skill-systematic-debugging/SKILL.md +14 -0
  426. package/templates/.agents/skills/zaip-skill-systematic-debugging/agents/openai.yaml +4 -0
  427. package/templates/.agents/skills/zaip-skill-task/SKILL.md +16 -7
  428. package/templates/.agents/skills/zaip-skill-task/references/commit-policy.md +25 -0
  429. package/templates/.agents/skills/zaip-skill-test-data/SKILL.md +14 -0
  430. package/templates/.agents/skills/zaip-skill-test-data/agents/openai.yaml +4 -0
  431. package/templates/.agents/skills/zaip-skill-test-data/scripts/generate.mjs +72 -0
  432. package/templates/.agents/skills/zaip-skill-testing-strategy/SKILL.md +15 -0
  433. package/templates/.agents/skills/zaip-skill-testing-strategy/agents/openai.yaml +4 -0
  434. package/templates/.agents/skills/zaip-skill-testing-strategy/references/example-map.md +3 -0
  435. package/templates/.agents/skills/zaip-skill-text-encoding/SKILL.md +1 -1
  436. package/templates/.agents/skills/zaip-skill-website-readiness/SKILL.md +8 -0
  437. package/templates/.agents/zaip-aios/INDEX.md +1 -1
  438. package/templates/.agents/zaip-aios/README.md +6 -0
  439. package/templates/.agents/zaip-aios/VERSION +1 -1
  440. package/templates/.agents/zaip-aios/guides/08-contexto-e-tokens.md +19 -3
  441. package/templates/.agents/zaip-aios/guides/10-seguranca.md +2 -1
  442. package/templates/.agents/zaip-aios/guides/12-instalacao-e-upgrade.md +37 -7
  443. package/templates/.agents/zaip-aios/guides/20-instalacao-detalhada.md +19 -4
  444. package/templates/.agents/zaip-aios/guides/23-orquestracao-de-modelos.md +32 -3
  445. package/templates/.agents/zaip-aios/guides/26-qualidade-e-release.md +21 -0
  446. package/templates/scripts/validate-cloud-hostinger-contract.mjs +34 -0
  447. package/templates/template-manifest.json +1031 -235
  448. package/templates/.agents/branding/.gitkeep +0 -0
  449. package/templates/.agents/dashboard/apps/frontend/dist/assets/CostCalculationGuidePage-snUCQYTC.js +0 -1
  450. package/templates/.agents/dashboard/apps/frontend/dist/assets/PricingSettingsDialog-BPtVUGgs.js +0 -1
  451. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-3Awyaovx.js +0 -3
  452. package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-GgzpZ_PY.css +0 -1
  453. package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-DHDrd5rE.js +0 -1
  454. package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-DbaLbU2q.js +0 -68
  455. package/templates/.agents/dashboard/apps/frontend/dist/assets/index-BYbpmqmM.js +0 -2
  456. package/templates/.agents/dashboard/apps/frontend/dist/assets/rolldown-runtime-D9-fqq9M.js +0 -1
  457. package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-BDe4_Ubl.js +0 -1
  458. package/templates/.agents/growth/.gitkeep +0 -0
  459. package/templates/.agents/marketing/.gitkeep +0 -0
  460. package/templates/.agents/sales/.gitkeep +0 -0
@@ -0,0 +1,600 @@
1
+ import { createHash } from "node:crypto";
2
+ import type { DatabaseSync } from "node:sqlite";
3
+ import { pricingCatalogSchema, resolveHistoricalDeveloperAttribution } from "@zaip-ai/costs";
4
+ import {
5
+ foldRunV2Records,
6
+ parseRunV2JsonLines,
7
+ type RunV2Fold,
8
+ } from "../../../../../packages/decisions/src/index.js";
9
+ import {
10
+ affectedTemporalIntervals,
11
+ type SqliteParsedSourceCache,
12
+ } from "./sqlite-incremental-cache.js";
13
+ import {
14
+ activityKind,
15
+ aggregateCost,
16
+ allocateAttributedTokenActiveMs,
17
+ type CanonicalEntity,
18
+ canonicalProvider,
19
+ consolidatedValue,
20
+ knownSum,
21
+ latestFxRate,
22
+ readAgentProfiles,
23
+ recordValue,
24
+ resolveDurations,
25
+ saoPauloDay,
26
+ type TemporalInterval,
27
+ usagePricingAudit,
28
+ } from "./sqlite-read-model-canonical.js";
29
+ export interface RunMaterializationInput {
30
+ database: DatabaseSync;
31
+ previousActivities: Array<Record<string, any>>;
32
+ parsedSources: SqliteParsedSourceCache;
33
+ refresh: { canonical_runs_refolded: number };
34
+ hasPersistentSchema: boolean;
35
+ dirtyRunIds: Set<string>;
36
+ changedSources: Set<string>;
37
+ oldIntervals: TemporalInterval[];
38
+ canonicalEntities: Map<string, CanonicalEntity>;
39
+ entityChanged: boolean;
40
+ }
41
+ export function materializeCanonicalRuns(input: RunMaterializationInput) {
42
+ const {
43
+ database,
44
+ previousActivities,
45
+ parsedSources,
46
+ refresh,
47
+ hasPersistentSchema,
48
+ dirtyRunIds,
49
+ changedSources,
50
+ oldIntervals,
51
+ canonicalEntities,
52
+ entityChanged,
53
+ } = input;
54
+ const catalogContent = (
55
+ database
56
+ .prepare("SELECT content FROM files WHERE path = ?")
57
+ .get(".agents/config/agents/catalog.yaml") as { content?: string } | undefined
58
+ )?.content;
59
+ const clientProfilesContent = (
60
+ database
61
+ .prepare("SELECT content FROM files WHERE path = ?")
62
+ .get(".agents/config/clients.yaml") as { content?: string } | undefined
63
+ )?.content;
64
+ const agentProfiles = readAgentProfiles(catalogContent, clientProfilesContent);
65
+ const catalogHash =
66
+ catalogContent === undefined ? null : createHash("sha256").update(catalogContent).digest("hex");
67
+ const pricingContent = (
68
+ database
69
+ .prepare("SELECT content FROM files WHERE path = ?")
70
+ .get(".agents/config/pricing/models.json") as { content?: string } | undefined
71
+ )?.content;
72
+ const pricingCatalog = pricingCatalogSchema.parse(
73
+ JSON.parse(
74
+ pricingContent ??
75
+ '{"schema_version":1,"updated_at":"1970-01-01T00:00:00.000Z","source":"missing","disclaimer":"missing","models":[]}',
76
+ ),
77
+ );
78
+ const fxRate = latestFxRate(
79
+ database
80
+ .prepare("SELECT path, content FROM files WHERE path LIKE '.agents/config/pricing/fx/%.json'")
81
+ .all() as Array<{ path: string; content: string }>,
82
+ );
83
+ const runRows = database
84
+ .prepare(
85
+ "SELECT path, content, content_sha256 FROM files WHERE (path LIKE '.agents/data/runs/%.jsonl' OR path LIKE '.agents/records/runs/%.jsonl') ORDER BY CASE WHEN path LIKE '.agents/data/%' THEN 1 ELSE 0 END, path",
86
+ )
87
+ .all() as Array<{ path: string; content: string; content_sha256: string }>;
88
+
89
+ // Historical attribution is an append-only, self-verifying overlay. It
90
+ // never changes a Run stream and therefore participates only after the
91
+ // native identity carried by the Run itself.
92
+ const historicalDeveloperManifests = (
93
+ database
94
+ .prepare(
95
+ "SELECT content FROM files WHERE path LIKE '.agents/data/lifecycle/historical-developer-attribution/%.json' OR path LIKE '.agents/records/lifecycle/historical-developer-attribution/%.json'",
96
+ )
97
+ .all() as Array<{ content: string }>
98
+ ).flatMap((row) => {
99
+ try {
100
+ return [JSON.parse(row.content)];
101
+ } catch {
102
+ return [];
103
+ }
104
+ });
105
+ const resolveDeveloper = (row: { path: string; content: string }, identity: unknown) => {
106
+ const native = recordValue(identity);
107
+ if (
108
+ native !== null &&
109
+ typeof native.account_id === "string" &&
110
+ typeof native.login_snapshot === "string"
111
+ )
112
+ return {
113
+ accountId: native.account_id,
114
+ login: native.login_snapshot,
115
+ source:
116
+ typeof native.attribution_source === "string" ? native.attribution_source : "native",
117
+ };
118
+ for (const candidate of historicalDeveloperManifests) {
119
+ try {
120
+ const resolved = resolveHistoricalDeveloperAttribution({
121
+ manifest: candidate,
122
+ run_id: String(JSON.parse(row.content.split(/\r?\n/u)[0] ?? "{}").run_id ?? ""),
123
+ path: row.path,
124
+ content: row.content,
125
+ });
126
+ if (resolved !== null)
127
+ return {
128
+ accountId: resolved.account_id,
129
+ login: resolved.login_snapshot,
130
+ source: resolved.attribution_source,
131
+ };
132
+ } catch {
133
+ // A corrupt or non-matching historical manifest is not an
134
+ // attribution source. The consumer remains fail-closed.
135
+ }
136
+ }
137
+ return null;
138
+ };
139
+ const runRowsById = new Map(
140
+ runRows.map((row) => [
141
+ row.path
142
+ .split("/")
143
+ .at(-1)
144
+ ?.replace(/\.jsonl$/, ""),
145
+ row,
146
+ ]),
147
+ );
148
+ for (const previous of previousActivities) {
149
+ const row = runRows.find((row) => row.path === previous.source_path);
150
+ const selected = runRowsById.get(previous.run_id);
151
+ if (row && (selected === undefined || !selected.path.startsWith(".agents/data/")))
152
+ runRowsById.set(previous.run_id, row);
153
+ }
154
+ const folds = new Map<string, { row: (typeof runRows)[number]; fold: RunV2Fold }>();
155
+ const readFold = (row: (typeof runRows)[number]) =>
156
+ parsedSources.read("fold", row.path, row.content_sha256, () => {
157
+ refresh.canonical_runs_refolded += 1;
158
+ return foldRunV2Records(parseRunV2JsonLines(row.content));
159
+ });
160
+ const getFold = (runId: string) => {
161
+ const available = folds.get(runId);
162
+ if (available) return available;
163
+ const row = runRowsById.get(runId);
164
+ if (!row) return undefined;
165
+ return { row, fold: readFold(row) };
166
+ };
167
+ for (const row of runRows) {
168
+ const previous = previousActivities.find((activity) => activity.source_path === row.path);
169
+ if (
170
+ hasPersistentSchema &&
171
+ previous &&
172
+ !dirtyRunIds.has(previous.run_id) &&
173
+ !changedSources.has(row.path)
174
+ )
175
+ continue;
176
+ const fold = readFold(row);
177
+ dirtyRunIds.add(fold.run.run_id);
178
+ folds.set(fold.run.run_id, { row, fold });
179
+ }
180
+ const rootRunId = (fold: RunV2Fold): string => {
181
+ let current = fold;
182
+ const seen = new Set<string>();
183
+ while (current.run.parent_run_id !== null && !seen.has(current.run.run_id)) {
184
+ seen.add(current.run.run_id);
185
+ const parent = getFold(current.run.parent_run_id)?.fold;
186
+ if (parent === undefined) break;
187
+ current = parent;
188
+ }
189
+ return current.run.run_id;
190
+ };
191
+ const columns = [
192
+ "activity_row_id",
193
+ "activity_source_kind",
194
+ "activity_key",
195
+ "source_path",
196
+ "source_hash",
197
+ "source_occurred_at",
198
+ "recorded_at",
199
+ "version_activity_id",
200
+ "source_last_event_id",
201
+ "source_last_sequence",
202
+ "work_item_kind",
203
+ "title",
204
+ "work_item_status",
205
+ "work_stage",
206
+ "risk",
207
+ "run_role",
208
+ "root_run_id",
209
+ "parent_run_id",
210
+ "agent_run_id",
211
+ "root_agent_run_id",
212
+ "parent_agent_run_id",
213
+ "agent_run_role",
214
+ "delegation_depth",
215
+ "agent_invocation_id",
216
+ "root_agent_invocation_id",
217
+ "parent_agent_invocation_id",
218
+ "invocation_kind",
219
+ "execution_id",
220
+ "task_id",
221
+ "spec_id",
222
+ "prd_id",
223
+ "change_id",
224
+ "conversation_id",
225
+ "run_id",
226
+ "occurred_at",
227
+ "occurred_day_sp",
228
+ "execution_kind",
229
+ "entrypoint",
230
+ "work_type",
231
+ "phase",
232
+ "purpose",
233
+ "status",
234
+ "activity_kind",
235
+ "zaip_agent",
236
+ "zaip_agent_persona",
237
+ "zaip_agent_job",
238
+ "zaip_agent_role",
239
+ "agent_catalog_id",
240
+ "agent_catalog_hash",
241
+ "client",
242
+ "provider",
243
+ "model",
244
+ "service_tier",
245
+ "reasoning_effort",
246
+ "developer_account_id",
247
+ "developer_login",
248
+ "developer_attribution_source",
249
+ "source_duration_ms",
250
+ "source_started_at",
251
+ "source_finished_at",
252
+ "duration_ms",
253
+ "duration_provenance",
254
+ "input_tokens",
255
+ "cached_input_tokens",
256
+ "output_tokens",
257
+ "reasoning_tokens",
258
+ "total_tokens",
259
+ "token_source",
260
+ "usage_event_count",
261
+ "llm_call_count",
262
+ "cost_usd",
263
+ "cost_brl",
264
+ "cost_method",
265
+ "pricing_model",
266
+ "pricing_source",
267
+ "fx_rate",
268
+ "source_event_count",
269
+ "root_run_duration",
270
+ "sub_run_duration",
271
+ "payload_type",
272
+ "payload_json",
273
+ ] as const;
274
+ const canonicalInsertActivity = database.prepare(
275
+ `INSERT INTO zaip_aios_activities(${columns.join(",")}) VALUES (${columns.map(() => "?").join(",")})`,
276
+ );
277
+ const insertTemporalFact = database.prepare(
278
+ "INSERT INTO attributed_token_active_facts(activity_row_id, occurred_day_sp, attributed_token_active_ms) VALUES (?, ?, ?)",
279
+ );
280
+ const insertUsageSegment = database.prepare(
281
+ "INSERT INTO invocation_usage_segments VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
282
+ );
283
+ const insertCanonicalRun = database.prepare(
284
+ "INSERT INTO canonical_run_index(run_id, occurred_at, occurred_day_sp, task_id, phase, run_role, duration_ms, source_event_count, zaip_agent, provider, model, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
285
+ );
286
+ let unassistedActivityCount = previousActivities.filter(
287
+ (row) => !dirtyRunIds.has(row.run_id) && row.agent_invocation_id === null,
288
+ ).length;
289
+ const excludedUnknownTokenRunCount = 0;
290
+ const temporalIntervals: TemporalInterval[] = oldIntervals.filter(
291
+ (interval) =>
292
+ !previousActivities.some(
293
+ (row) => row.activity_row_id === interval.activityRowId && dirtyRunIds.has(row.run_id),
294
+ ),
295
+ );
296
+ const zeroDurationFacts: Array<{ activityRowId: string; day: string }> = [];
297
+ for (const { row, fold } of folds.values()) {
298
+ const started = fold.run;
299
+ const developer = resolveDeveloper(row, started.developer_identity ?? null);
300
+ const usage = fold.effective_usage_records;
301
+ const agentRunId = started.agent_invocation_id ?? null;
302
+ const isAgentRun = agentRunId !== null;
303
+ const runRole = started.parent_run_id === null ? "root" : "subrun";
304
+ const agentRunRole = !isAgentRun
305
+ ? null
306
+ : started.parent_agent_invocation_id === null
307
+ ? "root"
308
+ : "subagent";
309
+ const totalTokens = knownSum(usage, "total");
310
+ const durations = resolveDurations(usage, fold);
311
+ const cost = aggregateCost(usage, fold, pricingCatalog, fxRate);
312
+ // Provider/model dimensions are factual only when the same usage
313
+ // segment carries a recorded financial fact. A null-only secondary
314
+ // segment must not turn an otherwise attributable activity into
315
+ // "mixed".
316
+ const financialUsage = usage.filter(
317
+ (record) =>
318
+ typeof record.tokens.total === "number" ||
319
+ typeof record.cost.usd === "number" ||
320
+ typeof record.cost.brl === "number",
321
+ );
322
+ const model =
323
+ consolidatedValue(financialUsage.map((record) => record.model ?? started.model)) ??
324
+ (started.model === "unavailable" ? null : started.model);
325
+ const provider =
326
+ consolidatedValue(
327
+ financialUsage.map((record) =>
328
+ canonicalProvider(record.provider, record.model ?? started.model, started.client),
329
+ ),
330
+ ) ?? canonicalProvider(started.provider, model, started.client);
331
+ const zaipAgent = started.agent_name ?? started.agent;
332
+ insertCanonicalRun.run(
333
+ started.run_id,
334
+ started.occurred_at,
335
+ saoPauloDay(started.occurred_at),
336
+ started.task_id,
337
+ started.phase,
338
+ runRole,
339
+ durations.effective,
340
+ fold.records.length,
341
+ zaipAgent,
342
+ provider,
343
+ model,
344
+ fold.status,
345
+ );
346
+ // Preserve an attributed Run with absent telemetry as an analytical
347
+ // fact with NULL measures. This makes coverage visibly unknown rather
348
+ // than silently converting it to a known zero or erasing its owner.
349
+ const profile = agentProfiles.get(zaipAgent) ?? agentProfiles.get(started.agent);
350
+ const workItem =
351
+ started.task_id === null
352
+ ? started.spec_id === null
353
+ ? started.prd_id === null
354
+ ? null
355
+ : canonicalEntities.get(`prd:${started.prd_id}`)
356
+ : canonicalEntities.get(`spec:${started.spec_id}`)
357
+ : canonicalEntities.get(`task:${started.task_id}`);
358
+ const callIds = new Set([
359
+ ...fold.model_call_records.map((record) => record.call_id),
360
+ ...usage
361
+ .map((record) => record.model_call_id)
362
+ .filter((value): value is string => typeof value === "string"),
363
+ ]);
364
+ const lastRecord = fold.records.at(-1)!;
365
+ const activityRowId = `ACTV-${createHash("sha256").update(`run:${started.run_id}`).digest("hex").slice(0, 24)}`;
366
+ const activity = {
367
+ activity_row_id: activityRowId,
368
+ activity_source_kind: isAgentRun ? "agent_run" : "unassisted_turn",
369
+ activity_key: `run:${started.run_id}`,
370
+ source_path: row.path,
371
+ source_hash: row.content_sha256,
372
+ source_occurred_at:
373
+ usage
374
+ .map((record) => record.source_occurred_at)
375
+ .filter((value): value is string => typeof value === "string")
376
+ .sort()[0] ?? started.occurred_at,
377
+ recorded_at: lastRecord.occurred_at,
378
+ version_activity_id: null,
379
+ source_last_event_id: lastRecord.event_id,
380
+ source_last_sequence: lastRecord.sequence,
381
+ work_item_kind: workItem?.kind ?? null,
382
+ title: workItem?.title ?? null,
383
+ work_item_status: workItem?.status ?? null,
384
+ work_stage: workItem?.stage ?? null,
385
+ risk: workItem?.risk ?? null,
386
+ run_role: runRole,
387
+ root_run_id: rootRunId(fold),
388
+ parent_run_id: started.parent_run_id,
389
+ agent_run_id: agentRunId,
390
+ root_agent_run_id: started.root_agent_invocation_id ?? agentRunId,
391
+ parent_agent_run_id: started.parent_agent_invocation_id ?? null,
392
+ agent_run_role: agentRunRole,
393
+ delegation_depth: started.delegation_depth ?? null,
394
+ agent_invocation_id: agentRunId,
395
+ root_agent_invocation_id: started.root_agent_invocation_id ?? agentRunId,
396
+ parent_agent_invocation_id: started.parent_agent_invocation_id ?? null,
397
+ invocation_kind: started.invocation_kind ?? null,
398
+ execution_id: started.execution_id,
399
+ task_id: started.task_id,
400
+ spec_id: started.spec_id,
401
+ prd_id: started.prd_id,
402
+ change_id: started.change_id,
403
+ conversation_id: started.conversation_id,
404
+ run_id: started.run_id,
405
+ occurred_at: started.occurred_at,
406
+ occurred_day_sp: saoPauloDay(started.occurred_at),
407
+ execution_kind: started.execution_kind ?? null,
408
+ entrypoint: started.entrypoint,
409
+ work_type: started.work_type,
410
+ phase: started.phase,
411
+ purpose: started.run_purpose ?? null,
412
+ status: fold.status,
413
+ activity_kind: activityKind({
414
+ execution_id: started.execution_id,
415
+ task_id: started.task_id,
416
+ spec_id: started.spec_id,
417
+ prd_id: started.prd_id,
418
+ phase: started.phase,
419
+ purpose: started.run_purpose ?? null,
420
+ }),
421
+ zaip_agent: zaipAgent,
422
+ zaip_agent_persona: profile?.persona ?? null,
423
+ zaip_agent_job: profile?.job ?? null,
424
+ zaip_agent_role: profile?.role ?? null,
425
+ agent_catalog_id: profile?.catalogId ?? null,
426
+ agent_catalog_hash: catalogHash,
427
+ client: started.client,
428
+ provider,
429
+ model,
430
+ service_tier: consolidatedValue(usage.map((record) => record.runtime?.service_tier ?? null)),
431
+ reasoning_effort:
432
+ consolidatedValue(usage.map((record) => record.runtime?.reasoning_effort ?? null)) ??
433
+ started.reasoning_effort ??
434
+ null,
435
+ developer_account_id: developer?.accountId ?? null,
436
+ developer_login: developer?.login ?? null,
437
+ developer_attribution_source: developer?.source ?? null,
438
+ source_duration_ms: durations.source,
439
+ source_started_at: durations.sourceStartedAt,
440
+ source_finished_at: durations.sourceFinishedAt,
441
+ duration_ms: durations.effective,
442
+ duration_provenance: durations.provenance,
443
+ input_tokens: knownSum(usage, "input"),
444
+ cached_input_tokens: knownSum(usage, "cached_input"),
445
+ output_tokens: knownSum(usage, "output"),
446
+ reasoning_tokens: knownSum(usage, "reasoning"),
447
+ total_tokens: totalTokens,
448
+ token_source: consolidatedValue(usage.map((record) => record.tokens.source)),
449
+ usage_event_count: usage.length,
450
+ llm_call_count: callIds.size > 0 ? callIds.size : null,
451
+ cost_usd: cost.usd,
452
+ cost_brl: cost.brl,
453
+ cost_method: cost.method,
454
+ pricing_model: cost.pricingModel,
455
+ pricing_source: cost.pricingSource,
456
+ fx_rate: cost.fxRate,
457
+ source_event_count: fold.records.length,
458
+ root_run_duration: runRole === "root" ? durations.effective : null,
459
+ sub_run_duration: runRole === "subrun" ? durations.effective : null,
460
+ payload_type: null,
461
+ payload_json: null,
462
+ } satisfies Record<(typeof columns)[number], string | number | null>;
463
+ canonicalInsertActivity.run(...columns.map((column) => activity[column] ?? null));
464
+ if (
465
+ totalTokens !== null &&
466
+ totalTokens > 0 &&
467
+ durations.effective !== null &&
468
+ durations.effective >= 0
469
+ ) {
470
+ const startMs = Date.parse(durations.sourceStartedAt ?? started.occurred_at);
471
+ const endMs = Date.parse(durations.sourceFinishedAt ?? "") || startMs + durations.effective;
472
+ if (Number.isFinite(startMs) && Number.isFinite(endMs) && endMs > startMs)
473
+ temporalIntervals.push({ activityRowId, startMs, endMs });
474
+ else if (durations.effective === 0)
475
+ zeroDurationFacts.push({ activityRowId, day: saoPauloDay(started.occurred_at) });
476
+ }
477
+ if (agentRunId !== null) {
478
+ for (const record of usage) {
479
+ const tokens = record.tokens;
480
+ const audit = usagePricingAudit(record, fold, pricingCatalog, fxRate);
481
+ insertUsageSegment.run(
482
+ agentRunId,
483
+ record.provider ?? null,
484
+ record.model ?? null,
485
+ audit.serviceTier,
486
+ record.runtime?.reasoning_effort ?? null,
487
+ tokens.input,
488
+ tokens.cached_input,
489
+ audit.uncachedInputTokens,
490
+ tokens.output,
491
+ tokens.reasoning,
492
+ audit.visibleOutputTokens,
493
+ tokens.total,
494
+ audit.inputRate,
495
+ audit.cachedRate,
496
+ audit.outputRate,
497
+ audit.reasoningRate,
498
+ audit.contextInputMultiplier,
499
+ audit.contextOutputMultiplier,
500
+ audit.speedCostMultiplier,
501
+ audit.pricingScenario,
502
+ audit.standardUsd,
503
+ audit.speedUpliftUsd,
504
+ audit.inputUsd,
505
+ audit.cachedInputUsd,
506
+ audit.outputUsd,
507
+ audit.reasoningUsd,
508
+ audit.calculatedUsd,
509
+ audit.recordedUsd,
510
+ audit.varianceUsd,
511
+ audit.effectiveUsd,
512
+ audit.effectiveBrl,
513
+ audit.recordedUsd !== null ? "canonical_recorded" : "token_pricing_estimate",
514
+ audit.pricingModel,
515
+ audit.pricingSource,
516
+ audit.fxRate,
517
+ );
518
+ }
519
+ }
520
+ if (!isAgentRun) unassistedActivityCount += 1;
521
+ }
522
+ const dirtyActivityIds = new Set(
523
+ previousActivities
524
+ .filter((row) => dirtyRunIds.has(row.run_id))
525
+ .map((row) => String(row.activity_row_id)),
526
+ );
527
+ for (const row of database
528
+ .prepare("SELECT activity_row_id,run_id FROM zaip_aios_activities WHERE payload_type IS NULL")
529
+ .all() as Array<{ activity_row_id: string; run_id: string }>)
530
+ if (dirtyRunIds.has(row.run_id)) dirtyActivityIds.add(row.activity_row_id);
531
+ const temporalDelta = affectedTemporalIntervals(
532
+ oldIntervals,
533
+ temporalIntervals,
534
+ dirtyActivityIds,
535
+ );
536
+ for (const id of temporalDelta.ids)
537
+ database.prepare("DELETE FROM attributed_token_active_facts WHERE activity_row_id=?").run(id);
538
+ for (const fact of allocateAttributedTokenActiveMs(temporalDelta.intervals))
539
+ insertTemporalFact.run(fact.activityRowId, fact.day, fact.value);
540
+ for (const fact of zeroDurationFacts) insertTemporalFact.run(fact.activityRowId, fact.day, 0);
541
+ const updateDuration =
542
+ database.prepare(`UPDATE zaip_aios_activities SET duration_ms=?,duration_provenance=?
543
+ WHERE activity_row_id=? AND (duration_ms IS NOT ? OR duration_provenance IS NOT ?)`);
544
+ const temporalRuns = new Set(dirtyRunIds);
545
+ for (const id of temporalDelta.ids) {
546
+ const fact = database
547
+ .prepare(
548
+ "SELECT SUM(attributed_token_active_ms) value,COUNT(*) count FROM attributed_token_active_facts WHERE activity_row_id=?",
549
+ )
550
+ .get(id) as { value: number | null; count: number };
551
+ const provenance = fact.count ? "attributed_token_active" : null;
552
+ updateDuration.run(fact.value, provenance, id, fact.value, provenance);
553
+ const run = database
554
+ .prepare("SELECT run_id FROM zaip_aios_activities WHERE activity_row_id=?")
555
+ .get(id) as { run_id: string } | undefined;
556
+ if (run) temporalRuns.add(run.run_id);
557
+ }
558
+ // Entity links and titles are projections of canonical metadata, not new Run usage.
559
+ if (entityChanged)
560
+ for (const row of database
561
+ .prepare(
562
+ "SELECT activity_row_id,task_id,spec_id,prd_id,change_id,execution_id,conversation_id FROM zaip_aios_activities WHERE payload_type IS NULL",
563
+ )
564
+ .all() as Array<Record<string, any>>) {
565
+ const entity =
566
+ row.task_id !== null
567
+ ? canonicalEntities.get(`task:${row.task_id}`)
568
+ : row.spec_id !== null
569
+ ? canonicalEntities.get(`spec:${row.spec_id}`)
570
+ : row.prd_id !== null
571
+ ? canonicalEntities.get(`prd:${row.prd_id}`)
572
+ : null;
573
+ const values = [
574
+ entity?.kind ?? null,
575
+ entity?.title ?? null,
576
+ entity?.status ?? null,
577
+ entity?.stage ?? null,
578
+ entity?.risk ?? null,
579
+ ];
580
+ database
581
+ .prepare(
582
+ `UPDATE zaip_aios_activities SET work_item_kind=?,title=?,work_item_status=?,work_stage=?,risk=? WHERE activity_row_id=? AND (work_item_kind IS NOT ? OR title IS NOT ? OR work_item_status IS NOT ? OR work_stage IS NOT ? OR risk IS NOT ?)`,
583
+ )
584
+ .run(...values, row.activity_row_id, ...values);
585
+ }
586
+
587
+ return {
588
+ temporalRuns,
589
+ getFold,
590
+ pricingCatalog,
591
+ fxRate,
592
+ rootRunId,
593
+ catalogHash,
594
+ columns,
595
+ canonicalInsertActivity,
596
+ excludedUnknownTokenRunCount,
597
+ unassistedActivityCount,
598
+ agentProfiles,
599
+ };
600
+ }
@@ -27,7 +27,7 @@ describe("SQLite metric contract", () => {
27
27
  });
28
28
 
29
29
  it("covers every allowlisted SQLite view and the paginated read-model endpoints", () => {
30
- const server = readFileSync(new URL("server.ts", import.meta.url), "utf8");
30
+ const server = readFileSync(new URL("server-operations-routes.ts", import.meta.url), "utf8");
31
31
  const actualViews = Object.keys(sqliteViewMetadata);
32
32
  expect(SQLITE_VIEW_CONTRACTS.map(([view]) => view).sort()).toEqual(actualViews.sort());
33
33
  expect(server).toContain("${API_PREFIX}/sqlite-read-models");