@zaip-ai/cli 1.0.7 → 1.3.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.
- package/README.md +6 -4
- package/dist/services/adapters.d.ts +1 -1
- package/dist/services/adapters.d.ts.map +1 -1
- package/dist/services/adapters.js +15 -5
- package/dist/services/adapters.js.map +1 -1
- package/dist/services/adapters.test.js +1 -1
- package/dist/services/agent-adapters.d.ts +9 -0
- package/dist/services/agent-adapters.d.ts.map +1 -1
- package/dist/services/agent-adapters.js +39 -4
- package/dist/services/agent-adapters.js.map +1 -1
- package/dist/services/agent-adapters.test.js +13 -1
- package/dist/services/agent-adapters.test.js.map +1 -1
- package/dist/services/codex-config-template.d.ts +2 -1
- package/dist/services/codex-config-template.d.ts.map +1 -1
- package/dist/services/codex-config-template.js +13 -2
- package/dist/services/codex-config-template.js.map +1 -1
- package/dist/services/codex-rules.d.ts +1 -1
- package/dist/services/codex-rules.d.ts.map +1 -1
- package/dist/services/codex-rules.js +31 -7
- package/dist/services/codex-rules.js.map +1 -1
- package/dist/services/codex-subagent-hook-template.d.ts +1 -1
- package/dist/services/codex-subagent-hook-template.d.ts.map +1 -1
- package/dist/services/codex-subagent-hook-template.js +4 -1
- package/dist/services/codex-subagent-hook-template.js.map +1 -1
- package/dist/services/doctor.d.ts.map +1 -1
- package/dist/services/doctor.js +3 -1
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/global-codex-config.d.ts +6 -3
- package/dist/services/global-codex-config.d.ts.map +1 -1
- package/dist/services/global-codex-config.js +82 -13
- package/dist/services/global-codex-config.js.map +1 -1
- package/dist/services/global-codex-config.test.js +57 -10
- package/dist/services/global-codex-config.test.js.map +1 -1
- package/dist/services/install-agents-template.d.ts.map +1 -1
- package/dist/services/install-agents-template.js +15 -2
- package/dist/services/install-agents-template.js.map +1 -1
- package/dist/services/logger.js +1 -1
- package/dist/services/logger.js.map +1 -1
- package/dist/services/logger.test.js +3 -3
- package/dist/services/logger.test.js.map +1 -1
- package/dist/services/runtime-template.test.js +21 -5
- package/dist/services/runtime-template.test.js.map +1 -1
- package/dist/services/template-manifest.d.ts.map +1 -1
- package/dist/services/template-manifest.js +7 -0
- package/dist/services/template-manifest.js.map +1 -1
- package/package.json +1 -1
- package/templates/.agents/architecture/software-architecture.md +131 -0
- package/templates/.agents/branding/brandbook.docx +0 -0
- package/templates/.agents/branding/brandbook.md +60 -0
- package/templates/.agents/config/agents/catalog.yaml +310 -10
- package/templates/.agents/config/clients/codex/agents/zaip-agent-brand-strategist.toml +30 -0
- package/templates/.agents/config/clients/codex/agents/zaip-agent-designer.toml +5 -5
- package/templates/.agents/config/clients/codex/agents/zaip-agent-finalizer.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-general-operations.toml +30 -0
- package/templates/.agents/config/clients/codex/agents/zaip-agent-governance-compliance.toml +30 -0
- package/templates/.agents/config/clients/codex/agents/zaip-agent-growth-strategist.toml +30 -0
- package/templates/.agents/config/clients/codex/agents/zaip-agent-marketing-analyst.toml +8 -8
- package/templates/.agents/config/clients/codex/agents/zaip-agent-orchestrator.toml +5 -3
- package/templates/.agents/config/clients/codex/agents/zaip-agent-sales-specialist.toml +30 -0
- package/templates/.agents/config/project.yaml +1 -1
- package/templates/.agents/dashboard/.tmp-run-list.json +254 -0
- package/templates/.agents/dashboard/.zaip-managed.json +775 -163
- package/templates/.agents/dashboard/DATA-DICTIONARY.md +2227 -0
- package/templates/.agents/dashboard/README.md +48 -97
- package/templates/.agents/dashboard/apps/frontend/dist/assets/CostCalculationGuidePage-DxR_pgSV.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/DashboardHelpDialog-4jZLTWE_.js +2156 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/PricingSettingsDialog-CKcsqb-r.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-BomxqCBU.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-DmmJD2Th.js +3 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-BwtitWa_.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-CaKwQP43.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-BZ5WdaMN.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-N5Csr0RP.js +68 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{dashboard-localization-C98LGC-Q.js → dashboard-localization-CLJ0lT9v.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/icons-vendor-C0fj2uU9.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-C4aIB1PV.js +2 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DK_enB5Z.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/react-vendor-BEsJ-FYH.js +9 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/rolldown-runtime-D9-fqq9M.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-B6y6Gw12.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-DFY7ZDlu.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/index.html +9 -2
- package/templates/.agents/dashboard/apps/frontend/package.json +1 -1
- package/templates/.agents/dashboard/apps/frontend/src/App.tsx +1129 -600
- package/templates/.agents/dashboard/apps/frontend/src/AppLoadingBoundary.tsx +48 -0
- package/templates/.agents/dashboard/apps/frontend/src/AppLoadingPanels.tsx +2 -0
- package/templates/.agents/dashboard/apps/frontend/src/AppOverlays.tsx +247 -0
- package/templates/.agents/dashboard/apps/frontend/src/AppRequestGuards.tsx +95 -0
- package/templates/.agents/dashboard/apps/frontend/src/AppSetupRoutes.tsx +87 -0
- package/templates/.agents/dashboard/apps/frontend/src/CostCalculationGuidePage.tsx +641 -0
- package/templates/.agents/dashboard/apps/frontend/src/DashboardAlternateContent.tsx +159 -0
- package/templates/.agents/dashboard/apps/frontend/src/DashboardCapabilityNav.tsx +13 -13
- package/templates/.agents/dashboard/apps/frontend/src/DashboardGlobalSettings.tsx +56 -0
- package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.tsx +266 -315
- package/templates/.agents/dashboard/apps/frontend/src/ProjectStackEditor.tsx +151 -0
- package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.test.ts +37 -0
- package/templates/.agents/dashboard/apps/frontend/src/TraceabilityWorkspace.tsx +114 -12
- package/templates/.agents/dashboard/apps/frontend/src/app-preferences.ts +15 -0
- package/templates/.agents/dashboard/apps/frontend/src/app-session-token.ts +20 -0
- package/templates/.agents/dashboard/apps/frontend/src/cost-calculation-guide.css +267 -0
- package/templates/.agents/dashboard/apps/frontend/src/cost-calculation-guide.test.ts +69 -0
- package/templates/.agents/dashboard/apps/frontend/src/cost-period-refresh.test.ts +85 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.test.ts +133 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.ts +453 -13
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-localization.ts +1 -1
- package/templates/.agents/dashboard/apps/frontend/src/main.tsx +1 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-detail-hydration.test.ts +55 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-detail-hydration.ts +36 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-entity-page-projection.test.ts +126 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-entity-page-projection.ts +181 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-period-contract.test.ts +138 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-period-render.test.ts +105 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-period.test.ts +6 -3
- package/templates/.agents/dashboard/apps/frontend/src/operations-period.ts +9 -5
- package/templates/.agents/dashboard/apps/frontend/src/overview-status-page.test.ts +26 -0
- package/templates/.agents/dashboard/apps/frontend/src/period-transition-overlay.css +44 -0
- package/templates/.agents/dashboard/apps/frontend/src/project-settings-model.ts +121 -62
- package/templates/.agents/dashboard/apps/frontend/src/project-settings-page.css +482 -3
- package/templates/.agents/dashboard/apps/frontend/src/project-settings.test.ts +84 -17
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-banner-semantics.test.ts +78 -0
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-coherence.test.ts +234 -39
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-notice.ts +15 -0
- package/templates/.agents/dashboard/apps/frontend/src/sqlite-cost-adapters.ts +26 -0
- package/templates/.agents/dashboard/apps/frontend/src/styles.css +14 -2
- package/templates/.agents/dashboard/apps/frontend/src/traceability-workspace.css +38 -2
- package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.test.ts +253 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-app-cost-loaders.ts +380 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-app-effects.ts +175 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-app-operations-pages.ts +395 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-documents.ts +141 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-idle-cost-prefetch.ts +45 -0
- package/templates/.agents/dashboard/apps/frontend/src/work-list-pagination.test.ts +46 -0
- package/templates/.agents/dashboard/apps/frontend/src/work-list-pagination.ts +36 -0
- package/templates/.agents/dashboard/apps/frontend/vite.config.ts +58 -5
- package/templates/.agents/dashboard/modules/cost-monitor/package.json +1 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/contracts.ts +47 -6
- package/templates/.agents/dashboard/modules/cost-monitor/src/duration-estimate.ts +13 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CompactLifecycleCostTable.test.ts +134 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CompactLifecycleCostTable.tsx +290 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostCharts.test.ts +133 -19
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostCharts.tsx +134 -43
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostFilters.tsx +137 -19
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostModelsAuditTable.test.ts +2 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostModelsAuditTable.tsx +13 -10
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorContent.tsx +328 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.test.ts +302 -6
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.tsx +627 -400
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostSummary.tsx +5 -13
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.test.ts +370 -72
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.tsx +467 -326
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/MacroCostTable.test.ts +17 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/MacroCostTable.tsx +25 -6
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-copy.ts +0 -2
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-page-helpers.ts +17 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-responsive.css +6 -3
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-row-filters.ts +123 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-summary.ts +8 -3
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-views.ts +32 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor.css +55 -14
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-table-presentation.ts +121 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/index.ts +3 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/period-cost-groups.test.ts +68 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/period-cost-groups.ts +33 -5
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-compact-cost-page.ts +119 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.test.ts +12 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-group-page.ts +146 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/use-cost-run-page.ts +118 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/aggregate.test.ts +2 -2
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/aggregate.ts +5 -3
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-pricing-fallback.test.ts +53 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.basics.test.ts +34 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.test.ts +168 -161
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.ts +188 -29
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.test.ts +757 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-projection.ts +784 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-summary-terminal-day.test.ts +100 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/index.ts +1 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/refactor-map-xr9l.json +61 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/source-size-cost-server/build-cost-monitor-projection-agents.test.ts +31 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/source-size-cost-server/build-cost-summary-projection-duration.test.ts +414 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/task-cost-groups.test.ts +41 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/task-cost-groups.ts +55 -11
- package/templates/.agents/dashboard/modules/operations/package.json +2 -1
- package/templates/.agents/dashboard/modules/operations/src/contracts.ts +185 -0
- package/templates/.agents/dashboard/modules/operations/src/duration-population.test.ts +63 -1
- package/templates/.agents/dashboard/modules/operations/src/duration-population.ts +60 -5
- package/templates/.agents/dashboard/modules/operations/src/react/EntityDetailsDialog.tsx +14 -3
- package/templates/.agents/dashboard/modules/operations/src/react/EntityTables.test.ts +44 -1
- package/templates/.agents/dashboard/modules/operations/src/react/EntityTables.tsx +345 -18
- package/templates/.agents/dashboard/modules/operations/src/react/MacroPlanningDialog.tsx +1 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationDateFilters.test.ts +9 -5
- package/templates/.agents/dashboard/modules/operations/src/react/OperationDateFilters.tsx +2 -2
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsMainContent.tsx +168 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.helpers.tsx +95 -6
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.test.ts +367 -14
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.tsx +562 -131
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPage.tsx +353 -355
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageNavigation.tsx +65 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPageOverview.tsx +169 -0
- package/templates/.agents/dashboard/modules/operations/src/react/PeriodSummaryTable.tsx +73 -8
- package/templates/.agents/dashboard/modules/operations/src/react/PrdDocumentDialog.test.tsx +32 -0
- package/templates/.agents/dashboard/modules/operations/src/react/PrdDocumentDialog.tsx +62 -6
- package/templates/.agents/dashboard/modules/operations/src/react/TaskBoard.test.ts +55 -0
- package/templates/.agents/dashboard/modules/operations/src/react/TaskBoard.tsx +27 -19
- package/templates/.agents/dashboard/modules/operations/src/react/TaskDetailsDialog.tsx +105 -42
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkBoard.priority.test.ts +19 -0
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkBoard.tsx +265 -36
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.test.ts +171 -8
- package/templates/.agents/dashboard/modules/operations/src/react/UnifiedWorkList.tsx +98 -68
- package/templates/.agents/dashboard/modules/operations/src/react/conversation-rows.test.ts +72 -1
- package/templates/.agents/dashboard/modules/operations/src/react/conversation-rows.ts +78 -17
- package/templates/.agents/dashboard/modules/operations/src/react/execution-metrics.ts +6 -4
- package/templates/.agents/dashboard/modules/operations/src/react/export/ExcelExportAction.test.ts +431 -1
- package/templates/.agents/dashboard/modules/operations/src/react/export/ExcelExportAction.tsx +574 -20
- package/templates/.agents/dashboard/modules/operations/src/react/export/export-layout.test.ts +42 -4
- package/templates/.agents/dashboard/modules/operations/src/react/export/xlsx-runtime-e2e.test.ts +248 -0
- package/templates/.agents/dashboard/modules/operations/src/react/macro-planning-dialog-content.css +49 -0
- package/templates/.agents/dashboard/modules/operations/src/react/macro-planning-dialog.css +93 -50
- package/templates/.agents/dashboard/modules/operations/src/react/manual-work-priority.test.ts +82 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operation-date-range.test.ts +29 -2
- package/templates/.agents/dashboard/modules/operations/src/react/operation-date-range.ts +22 -1
- package/templates/.agents/dashboard/modules/operations/src/react/operation-duration.test.ts +77 -4
- package/templates/.agents/dashboard/modules/operations/src/react/operation-duration.ts +67 -5
- package/templates/.agents/dashboard/modules/operations/src/react/operations-coverage-toast.test.ts +54 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-global-filters.test.ts +22 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview-period-filter.test.ts +149 -12
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.status-cards.test.ts +27 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-page-contract.ts +176 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-period-scope.test.ts +160 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-period-scope.ts +47 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-query.ts +10 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-responsive.css +3 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-view-labels.ts +28 -0
- package/templates/.agents/dashboard/modules/operations/src/react/operations-view-order.test.ts +21 -7
- package/templates/.agents/dashboard/modules/operations/src/react/operations.css +42 -0
- package/templates/.agents/dashboard/modules/operations/src/react/period-summary-population.test.ts +54 -0
- package/templates/.agents/dashboard/modules/operations/src/react/period-summary-population.ts +32 -0
- package/templates/.agents/dashboard/modules/operations/src/react/period-summary.test.ts +241 -6
- package/templates/.agents/dashboard/modules/operations/src/react/period-summary.ts +148 -6
- package/templates/.agents/dashboard/modules/operations/src/react/popup-localization.test.ts +1 -1
- package/templates/.agents/dashboard/modules/operations/src/react/unified-work-board.css +132 -0
- package/templates/.agents/dashboard/modules/operations/src/react/unified-work-board.css.test.ts +13 -0
- package/templates/.agents/dashboard/modules/operations/src/react/unified-work-board.header.test.ts +16 -0
- package/templates/.agents/dashboard/modules/operations/src/react/use-infinite-column.ts +11 -5
- package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.test.ts +7 -4
- package/templates/.agents/dashboard/modules/operations/src/react/work-board-model.ts +5 -84
- package/templates/.agents/dashboard/modules/operations/src/server/build-operations-projection.test.ts +291 -15
- package/templates/.agents/dashboard/modules/operations/src/server/build-operations-projection.ts +182 -472
- package/templates/.agents/dashboard/modules/operations/src/server/canonical-compat.test.ts +40 -0
- package/templates/.agents/dashboard/modules/operations/src/server/canonical-compat.ts +19 -6
- package/templates/.agents/dashboard/modules/operations/src/server/canonical-run-projection.ts +31 -6
- package/templates/.agents/dashboard/modules/operations/src/server/daily-duration-projection.ts +220 -0
- package/templates/.agents/dashboard/modules/operations/src/server/execution-duration-projection.ts +28 -0
- package/templates/.agents/dashboard/modules/operations/src/server/execution-relationship-counts.test.ts +39 -2
- package/templates/.agents/dashboard/modules/operations/src/server/execution-relationship-counts.ts +25 -13
- package/templates/.agents/dashboard/modules/operations/src/server/filter.test.ts +3 -3
- package/templates/.agents/dashboard/modules/operations/src/server/filter.ts +7 -2
- package/templates/.agents/dashboard/modules/operations/src/server/index.ts +3 -0
- package/templates/.agents/dashboard/modules/operations/src/server/macro.ts +3 -12
- package/templates/.agents/dashboard/modules/operations/src/server/manifest-usage.ts +65 -0
- package/templates/.agents/dashboard/modules/operations/src/server/operations-projection-aggregates.ts +297 -0
- package/templates/.agents/dashboard/modules/operations/src/server/quick-daily-operations-projection.ts +330 -0
- package/templates/.agents/dashboard/modules/operations/src/server/quick-operations-projection.test.ts +505 -0
- package/templates/.agents/dashboard/modules/operations/src/server/quick-operations-projection.ts +609 -0
- package/templates/.agents/dashboard/modules/operations/src/server/runs.ts +18 -19
- package/templates/.agents/dashboard/modules/operations/src/work-board-model.ts +76 -0
- package/templates/.agents/dashboard/modules/traceability/package.json +1 -1
- package/templates/.agents/dashboard/modules/traceability/src/server/build-task-trace.ts +3 -1
- package/templates/.agents/dashboard/packages/branding/package.json +1 -1
- package/templates/.agents/dashboard/packages/branding/src/index.ts +1 -1
- package/templates/.agents/dashboard/packages/contracts/package.json +1 -1
- package/templates/.agents/dashboard/packages/contracts/src/index.ts +2 -0
- package/templates/.agents/dashboard/packages/data-export/package.json +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs +1759 -0
- package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs.metafile.json +7333 -0
- package/templates/.agents/dashboard/packages/local-runtime/dist/sqlite-read-model.cjs +1611 -0
- package/templates/.agents/dashboard/packages/local-runtime/package.json +8 -3
- package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-dashboard.mjs +20 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-runtime.mjs +114 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/rebuild-sqlite-read-model.mjs +31 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/source-size-runtime-scripts/sqlite-read-model-fixture.mjs +397 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/test-sqlite-read-model.mjs +589 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/test-unix-launchers.mjs +53 -0
- package/templates/.agents/dashboard/packages/local-runtime/scripts/validate-sqlite-read-model.mjs +203 -0
- package/templates/.agents/dashboard/packages/local-runtime/server.mjs +1646 -107
- package/templates/.agents/dashboard/packages/local-runtime/src/agent-adapter-sync.ts +30 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/agent-catalog-settings.test.ts +3 -2
- package/templates/.agents/dashboard/packages/local-runtime/src/agent-catalog-settings.ts +5 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/manifest-runs.ts +72 -33
- package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.test.ts +339 -4
- package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.ts +392 -1
- package/templates/.agents/dashboard/packages/local-runtime/src/runtime.mjs +5 -5
- package/templates/.agents/dashboard/packages/local-runtime/src/server-board.test.ts +110 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-board.ts +189 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-cross-layer-parity.test.ts +245 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-daily-read-models-route.ts +64 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-daily-read-models.test.ts +204 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-daily-read-models.ts +194 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-pages.test.ts +163 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-pages.ts +354 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-runs-route.test.ts +74 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-runs-route.ts +113 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-overview.test.ts +68 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-period.ts +47 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-projections.ts +483 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-settings.test.ts +5 -2
- package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot.test.ts +178 -84
- package/templates/.agents/dashboard/packages/local-runtime/src/server-workspace.ts +149 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server.test.ts +675 -267
- package/templates/.agents/dashboard/packages/local-runtime/src/server.ts +1212 -309
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-metric-contract.test.ts +53 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-metric-contract.ts +722 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.test.ts +3743 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.ts +7017 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/work-priority-contract.test.ts +33 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-history.mjs +41 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-processes.mjs +210 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.mjs +514 -190
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.test.mjs +324 -24
- package/templates/.agents/dashboard/packages/ui/package.json +1 -1
- package/templates/.agents/dashboard/packages/windows-launcher/LauncherVerificationBehaviorTests.cs +206 -0
- package/templates/.agents/dashboard/packages/windows-launcher/Program.cs +95 -8
- package/templates/.agents/dashboard/packages/windows-launcher/build-dashboard-launcher.ps1 +2 -2
- package/templates/.agents/dashboard/packages/windows-launcher/run-launcher-verification-tests.ps1 +22 -0
- package/templates/.agents/dashboard/read-model.dbml +2201 -0
- package/templates/.agents/dashboard/tests/e2e/package.json +1 -1
- package/templates/.agents/dashboard/tests/e2e/playwright.config.ts +1 -1
- package/templates/.agents/dashboard/tests/e2e/specs/dashboard.spec.ts +216 -41
- package/templates/.agents/dashboard/work-priority.json +34 -0
- package/templates/.agents/dashboard/zaip-dashboard-linux.sh +45 -0
- package/templates/.agents/dashboard/zaip-dashboard-mac.command +3 -0
- package/templates/.agents/dashboard/zaip-dashboard-windows.exe +0 -0
- package/templates/.agents/design/.zaip-managed.json +3 -3
- package/templates/.agents/design/apps/catalog/package.json +1 -1
- package/templates/.agents/design/packages/local-runtime/package.json +1 -1
- package/templates/.agents/growth/estrategia-bootstrap-90-dias.md +169 -0
- package/templates/.agents/growth/strategy.md +27 -0
- package/templates/.agents/marketing/estrategia-marketing-zaip-90-dias.md +197 -0
- package/templates/.agents/marketing/strategy.md +29 -0
- package/templates/.agents/requirements/autonomous-assurance.md +1 -1
- package/templates/.agents/requirements/comparative-audit.md +1 -1
- package/templates/.agents/requirements/context-engine.md +1 -1
- package/templates/.agents/requirements/cost-observability.md +1 -1
- package/templates/.agents/requirements/dashboard-launch.md +24 -0
- package/templates/.agents/requirements/data-export.md +1 -1
- package/templates/.agents/requirements/design-system.md +1 -1
- package/templates/.agents/requirements/execution-engine.md +1 -1
- package/templates/.agents/requirements/kanban-dashboard.md +4 -3
- package/templates/.agents/requirements/model-orchestration.md +1 -1
- package/templates/.agents/requirements/public-distribution.md +9 -6
- package/templates/.agents/requirements/software-architecture.md +1 -1
- package/templates/.agents/requirements/strategic-improvements.md +1 -1
- package/templates/.agents/requirements/work-lifecycle.md +9 -3
- package/templates/.agents/requirements/zaip-strategic-95.md +4 -4
- package/templates/.agents/rules/autonomy-decision.md +15 -0
- package/templates/.agents/rules/core.md +1 -1
- package/templates/.agents/rules/run-lifecycle-closure.md +1 -1
- package/templates/.agents/rules/specialist-routing.md +19 -0
- package/templates/.agents/rules/workflow.md +1 -1
- package/templates/.agents/runtime/VERSION +1 -1
- package/templates/.agents/runtime/bin/zaip.mjs +118 -67
- package/templates/.agents/runtime/checksums.sha256 +6 -4
- package/templates/.agents/runtime/manifest.json +3 -1
- package/templates/.agents/runtime/pnpm-lock.sha256 +1 -0
- package/templates/.agents/runtime/provenance.json +11 -0
- package/templates/.agents/runtime/sbom.cdx.json +1929 -39
- package/templates/.agents/sales/playbook.md +32 -0
- package/templates/.agents/sales/roteiro-comercial-zaip.md +252 -0
- package/templates/.agents/skills/zaip-aios/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-brand-governance/SKILL.md +22 -0
- package/templates/.agents/skills/zaip-skill-brand-governance/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-brand-governance/references/brandbook-framework.md +39 -0
- package/templates/.agents/skills/zaip-skill-brand-governance/references/brandbook-standards.md +30 -0
- package/templates/.agents/skills/zaip-skill-dashboard-sqlite/SKILL.md +25 -0
- package/templates/.agents/skills/zaip-skill-dashboard-sqlite/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-enforce-architecture/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-executar-fila-pronta/SKILL.md +18 -0
- package/templates/.agents/skills/zaip-skill-executar-fila-pronta/agents/openai.yaml +6 -0
- package/templates/.agents/skills/zaip-skill-executar-fila-pronta/scripts/ready-queue-fence.mjs +71 -0
- package/templates/.agents/skills/zaip-skill-executar-fila-pronta/scripts/ready-queue-fence.test.mjs +60 -0
- package/templates/.agents/skills/zaip-skill-executar-fila-pronta/scripts/scheduled-ready-queue-contract.test.mjs +111 -0
- package/templates/.agents/skills/zaip-skill-execution/SKILL.md +2 -2
- package/templates/.agents/skills/zaip-skill-frontend-launcher/references/launcher-contract.md +3 -1
- package/templates/.agents/skills/zaip-skill-general-operations/SKILL.md +12 -0
- package/templates/.agents/skills/zaip-skill-general-operations/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/SKILL.md +9 -7
- package/templates/.agents/skills/zaip-skill-github-deploy/agents/openai.yaml +2 -2
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-deploy-contract.test.mjs +11 -38
- package/templates/.agents/skills/zaip-skill-governance-compliance/SKILL.md +12 -0
- package/templates/.agents/skills/zaip-skill-governance-compliance/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-growth-strategy-revops/SKILL.md +21 -0
- package/templates/.agents/skills/zaip-skill-growth-strategy-revops/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-growth-strategy-revops/references/growth-revops-framework.md +25 -0
- package/templates/.agents/skills/zaip-skill-instalar-agendamento/SKILL.md +17 -0
- package/templates/.agents/skills/zaip-skill-instalar-agendamento/agents/openai.yaml +6 -0
- package/templates/.agents/skills/zaip-skill-marketing/SKILL.md +9 -3
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-local-telemetry.mjs +99 -93
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.mjs +132 -23
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.test.mjs +149 -1
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.mjs +76 -19
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.test.mjs +217 -7
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/source-size-telemetry/model-identity-reconciliation.mjs +77 -0
- package/templates/.agents/skills/zaip-skill-sales-methodology/SKILL.md +20 -0
- package/templates/.agents/skills/zaip-skill-sales-methodology/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-sales-methodology/references/sales-process-framework.md +77 -0
- package/templates/.agents/skills/zaip-skill-setup/SKILL.md +5 -0
- package/templates/.agents/skills/zaip-skill-sqlite-read-model/SKILL.md +96 -0
- package/templates/.agents/skills/zaip-skill-sqlite-read-model/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-sqlite-read-model/scripts/ensure-node.mjs +41 -0
- package/templates/.agents/zaip-aios/INDEX.md +11 -0
- package/templates/.agents/zaip-aios/README.md +38 -8
- package/templates/.agents/zaip-aios/VERSION +1 -1
- package/templates/.agents/zaip-aios/guides/09-agentes-e-squads.md +43 -6
- package/templates/.agents/zaip-aios/guides/10-seguranca.md +21 -7
- package/templates/.agents/zaip-aios/guides/17-como-o-custo-e-calculado.md +32 -0
- package/templates/.agents/zaip-aios/guides/18-catalogo-de-agentes.md +76 -0
- package/templates/.agents/zaip-aios/guides/19-assurance-e-autonomia.md +72 -0
- package/templates/.agents/zaip-aios/guides/20-instalacao-detalhada.md +330 -0
- package/templates/.agents/zaip-aios/guides/21-telemetria-monitor-custos.md +52 -0
- package/templates/.agents/zaip-aios/guides/22-fluxos-e-roteamento.md +69 -0
- package/templates/.agents/zaip-aios/guides/23-orquestracao-de-modelos.md +483 -0
- package/templates/.agents/zaip-aios/guides/24-calculo-de-custos-openai.md +85 -0
- package/templates/.agents/zaip-aios/guides/25-fontes-de-precos-openai.md +18 -0
- package/templates/.agents/zaip-aios/guides/26-qualidade-e-release.md +44 -0
- package/templates/.agents/zaip-aios/guides/27-telemetria-git-native.md +167 -0
- package/templates/.agents/zaip-aios/guides/28-lifecycle-completo.md +144 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/lifecycles-task-spec-prd.png +0 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/prd-lifecycle.png +0 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/spec-lifecycle.png +0 -0
- package/templates/.agents/zaip-aios/guides/assets/diagrams/task-lifecycle.png +0 -0
- package/templates/template-manifest.json +1082 -215
- package/templates/.agents/dashboard/apps/frontend/dist/assets/AgentCatalogSettingsPage-CLYIi7Vo.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/AgentCatalogSettingsPage-DTDNVQGX.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/DashboardHelpDialog-Cv-JcoxP.js +0 -1320
- package/templates/.agents/dashboard/apps/frontend/dist/assets/PricingSettingsDialog-CzEggcRb.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-05YKn6Z4.js +0 -3
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-YO3yqtgV.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-8AzCnl3a.js +0 -77
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DdBYQ_8D.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/src/AgentCatalogSettingsPage.tsx +0 -617
- package/templates/.agents/dashboard/apps/frontend/src/agent-catalog-settings-page.css +0 -660
- package/templates/.agents/dashboard/apps/frontend/src/agent-catalog-settings.test.ts +0 -249
- package/templates/.agents/dashboard/dashboard.config.json +0 -4
- package/templates/.agents/dashboard/zaip-dashboard.exe +0 -0
|
@@ -3,8 +3,10 @@ import { join, resolve } from "node:path";
|
|
|
3
3
|
import {
|
|
4
4
|
aggregate,
|
|
5
5
|
duplicateUsageAssignments,
|
|
6
|
+
duplicateUsageImpact,
|
|
6
7
|
exactCompletedSegment,
|
|
7
8
|
filesUnder,
|
|
9
|
+
isExactDuplicateUsageGroup,
|
|
8
10
|
jsonLines,
|
|
9
11
|
loadSegments,
|
|
10
12
|
pricingFor,
|
|
@@ -12,11 +14,16 @@ import {
|
|
|
12
14
|
recordSequence,
|
|
13
15
|
recordType,
|
|
14
16
|
sameCost,
|
|
17
|
+
supersedableUsageBeforeTerminal,
|
|
15
18
|
usageStatus,
|
|
16
19
|
usageView,
|
|
17
20
|
withSequence,
|
|
18
21
|
} from "./reconcile-telemetry-lib.mjs";
|
|
19
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
remeasureSelectedRuns,
|
|
24
|
+
timingEnrichmentRunIds,
|
|
25
|
+
} from "./reconcile-telemetry-remeasurement.mjs";
|
|
26
|
+
import { reconcileGenericModelIdentities } from "./source-size-telemetry/model-identity-reconciliation.mjs";
|
|
20
27
|
|
|
21
28
|
const workspace = resolve(process.cwd());
|
|
22
29
|
const apply = process.argv.includes("--apply");
|
|
@@ -39,9 +46,21 @@ const selectedRunIds = new Set(
|
|
|
39
46
|
: [],
|
|
40
47
|
),
|
|
41
48
|
);
|
|
49
|
+
const selectedSessionFiles = process.argv
|
|
50
|
+
.flatMap((argument, index, values) =>
|
|
51
|
+
argument === "--session-file"
|
|
52
|
+
? [String(values[index + 1] ?? "")]
|
|
53
|
+
: argument.startsWith("--session-file=")
|
|
54
|
+
? [argument.slice("--session-file=".length)]
|
|
55
|
+
: [],
|
|
56
|
+
)
|
|
57
|
+
.filter(Boolean);
|
|
42
58
|
if (remeasure && selectedRunIds.size === 0) {
|
|
43
59
|
throw new Error("--remeasure requires at least one explicit --run <RUN-ID>");
|
|
44
60
|
}
|
|
61
|
+
if (apply && deduplicate && selectedRunIds.size === 0) {
|
|
62
|
+
throw new Error("--apply --deduplicate requires at least one explicit --run <RUN-ID>");
|
|
63
|
+
}
|
|
45
64
|
const applyBackfill = apply && !deduplicate && !remeasure;
|
|
46
65
|
|
|
47
66
|
const runFiles = await filesUnder(join(workspace, ".agents", "records", "runs"), ".jsonl");
|
|
@@ -166,20 +185,35 @@ for (const file of runFiles) {
|
|
|
166
185
|
if (event.source_segment_key && event.tokens?.total !== null)
|
|
167
186
|
usedKeys.add(event.source_segment_key);
|
|
168
187
|
const { measured, deduplicated } = usageStatus(usage);
|
|
169
|
-
if (started) runs.push({ file, records, started, usage, measured, deduplicated });
|
|
188
|
+
if (started) runs.push({ file, records, started, usage, measured, deduplicated, nativeMeasured });
|
|
170
189
|
}
|
|
171
190
|
|
|
172
|
-
const allSegments = await loadSegments(
|
|
173
|
-
|
|
174
|
-
?
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
191
|
+
const allSegments = await loadSegments(
|
|
192
|
+
workspace,
|
|
193
|
+
selectedSessionFiles.length === 0 ? null : selectedSessionFiles,
|
|
194
|
+
);
|
|
195
|
+
// Native usage can be captured before the Codex session emits task_complete.
|
|
196
|
+
// A normal backfill must not replace those observed tokens or costs, but it can
|
|
197
|
+
// append an exact, timing-only correction once that terminal boundary appears.
|
|
198
|
+
const timingRunIds = timingEnrichmentRunIds({
|
|
199
|
+
remeasure,
|
|
200
|
+
applyBackfill,
|
|
201
|
+
selectedRunIds,
|
|
202
|
+
runs,
|
|
203
|
+
});
|
|
204
|
+
const remeasurement =
|
|
205
|
+
remeasure || (applyBackfill && timingRunIds.size > 0)
|
|
206
|
+
? await remeasureSelectedRuns({
|
|
207
|
+
apply,
|
|
208
|
+
allSegments,
|
|
209
|
+
runs,
|
|
210
|
+
selectedRunIds: timingRunIds,
|
|
211
|
+
// Automatic backfill is intentionally timing-only. Explicit remeasurement
|
|
212
|
+
// retains its existing token/cost correction behavior unless requested.
|
|
213
|
+
timingOnly: remeasure ? timingOnly : true,
|
|
214
|
+
workspace,
|
|
215
|
+
})
|
|
216
|
+
: [];
|
|
183
217
|
const unfinished = runs.filter(
|
|
184
218
|
(run) => !run.records.some((record) => recordType(record) === "run.finished"),
|
|
185
219
|
);
|
|
@@ -285,73 +319,36 @@ if (reprice) {
|
|
|
285
319
|
}
|
|
286
320
|
}
|
|
287
321
|
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
? (segmentsByKey.get(usage.source_segment_key) ?? null)
|
|
298
|
-
: null;
|
|
299
|
-
return segment?.model && !genericModel(segment.model) ? [{ usage, segment }] : [];
|
|
300
|
-
});
|
|
301
|
-
modelIdentityCorrections += corrections.length;
|
|
302
|
-
if (!applyBackfill || corrections.length === 0) continue;
|
|
303
|
-
|
|
304
|
-
const correctionByTarget = new Map(corrections.map((item) => [item.usage.event_id, item]));
|
|
305
|
-
const updated = [];
|
|
306
|
-
let correctionIndex = run.usage.filter(
|
|
307
|
-
(usage) => usage.activity_kind === "model_identity_reconciliation",
|
|
308
|
-
).length;
|
|
309
|
-
for (const record of run.records) {
|
|
310
|
-
updated.push(record);
|
|
311
|
-
const original = usageView(record);
|
|
312
|
-
const correction = original ? correctionByTarget.get(original.event_id) : null;
|
|
313
|
-
if (!correction) continue;
|
|
314
|
-
correctionIndex += 1;
|
|
315
|
-
const cost = await pricingFor(workspace, correction.segment.model, original.tokens);
|
|
316
|
-
updated.push({
|
|
317
|
-
schema_version: 2,
|
|
318
|
-
event_id: `${run.started.run_id}:model:${String(correctionIndex).padStart(6, "0")}`,
|
|
319
|
-
run_id: run.started.run_id,
|
|
320
|
-
sequence: 0,
|
|
321
|
-
occurred_at: original.occurred_at,
|
|
322
|
-
type: "usage.recorded",
|
|
323
|
-
phase: original.phase,
|
|
324
|
-
activity_kind: "model_identity_reconciliation",
|
|
325
|
-
classification_source: original.classification_source ?? "current_context",
|
|
326
|
-
tokens: original.tokens,
|
|
327
|
-
cost,
|
|
328
|
-
provider: original.provider ?? run.started.provider ?? "openai",
|
|
329
|
-
model: correction.segment.model,
|
|
330
|
-
source_segment_key: original.source_segment_key,
|
|
331
|
-
supersedes_event_id: original.event_id,
|
|
332
|
-
source_occurred_at:
|
|
333
|
-
original.source_occurred_at ??
|
|
334
|
-
correction.segment.finished_at ??
|
|
335
|
-
correction.segment.started_at,
|
|
336
|
-
...(original.context_stats === undefined ? {} : { context_stats: original.context_stats }),
|
|
337
|
-
runtime: {
|
|
338
|
-
reasoning_effort: correction.segment.effort ?? original.runtime?.reasoning_effort ?? null,
|
|
339
|
-
service_tier: correction.segment.service_tier ?? original.runtime?.service_tier ?? null,
|
|
340
|
-
},
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
const resequenced = updated.map((record, index) => withSequence(record, index + 1));
|
|
344
|
-
const temporary = `${run.file}.model.tmp`;
|
|
345
|
-
await writeFile(
|
|
346
|
-
temporary,
|
|
347
|
-
`${resequenced.map((record) => JSON.stringify(record)).join("\n")}\n`,
|
|
348
|
-
"utf8",
|
|
349
|
-
);
|
|
350
|
-
await rename(temporary, run.file);
|
|
351
|
-
}
|
|
322
|
+
const modelIdentityCorrections = await reconcileGenericModelIdentities({
|
|
323
|
+
applyBackfill,
|
|
324
|
+
pricingFor,
|
|
325
|
+
runs,
|
|
326
|
+
segments: allSegments,
|
|
327
|
+
usageView,
|
|
328
|
+
withSequence,
|
|
329
|
+
workspace,
|
|
330
|
+
});
|
|
352
331
|
|
|
353
332
|
const duplicateGroups = duplicateUsageAssignments(runs);
|
|
354
|
-
const
|
|
333
|
+
const exactDuplicateGroups = duplicateGroups.filter(isExactDuplicateUsageGroup);
|
|
334
|
+
const aliasReviewGroups = duplicateGroups.filter((group) => !isExactDuplicateUsageGroup(group));
|
|
335
|
+
const selectedDuplicateGroups =
|
|
336
|
+
selectedRunIds.size === 0
|
|
337
|
+
? exactDuplicateGroups
|
|
338
|
+
: exactDuplicateGroups.filter((group) =>
|
|
339
|
+
group.some(({ run }) => selectedRunIds.has(run.started.run_id)),
|
|
340
|
+
);
|
|
341
|
+
const selectedAliasReviewGroups =
|
|
342
|
+
selectedRunIds.size === 0
|
|
343
|
+
? aliasReviewGroups
|
|
344
|
+
: aliasReviewGroups.filter((group) =>
|
|
345
|
+
group.some(({ run }) => selectedRunIds.has(run.started.run_id)),
|
|
346
|
+
);
|
|
347
|
+
const duplicateAssignments = selectedDuplicateGroups.flatMap((group) =>
|
|
348
|
+
group
|
|
349
|
+
.slice(1)
|
|
350
|
+
.filter(({ run }) => selectedRunIds.size === 0 || selectedRunIds.has(run.started.run_id)),
|
|
351
|
+
);
|
|
355
352
|
let deduplicatedEvents = 0;
|
|
356
353
|
if (apply && deduplicate) {
|
|
357
354
|
for (const { run, usage } of duplicateAssignments) {
|
|
@@ -594,32 +591,36 @@ for (const candidate of candidates) {
|
|
|
594
591
|
}
|
|
595
592
|
const eligible = candidates.filter(
|
|
596
593
|
(candidate) =>
|
|
594
|
+
(selectedRunIds.size === 0 || selectedRunIds.has(candidate.run.started.run_id)) &&
|
|
597
595
|
byRun.get(candidate.run.started.run_id).length === 1 &&
|
|
598
596
|
bySegment.get(candidate.segment.key).length === 1,
|
|
599
597
|
);
|
|
600
598
|
|
|
601
599
|
if (applyBackfill) {
|
|
602
600
|
for (const { run, segment, confidence } of eligible) {
|
|
601
|
+
// Re-read each Run under the serial apply loop: a preceding timing repair may
|
|
602
|
+
// have reordered or appended a correction after the initial scan.
|
|
603
|
+
const persistedRecords = jsonLines(await readFile(run.file, "utf8"));
|
|
604
|
+
const finishIndex = persistedRecords.findIndex(
|
|
605
|
+
(record) => recordType(record) === "run.finished",
|
|
606
|
+
);
|
|
607
|
+
const insertAt = finishIndex < 0 ? persistedRecords.length : finishIndex;
|
|
603
608
|
const tokens = aggregate(segment);
|
|
604
609
|
const model = segment.model ?? run.started.model ?? null;
|
|
605
610
|
const cost = await pricingFor(workspace, model, tokens);
|
|
606
|
-
const superseded =
|
|
607
|
-
|
|
608
|
-
.find(
|
|
609
|
-
(event) =>
|
|
610
|
-
event.tokens?.total === null &&
|
|
611
|
-
!run.usage.some((other) => other.supersedes_event_id === event.event_id),
|
|
612
|
-
);
|
|
613
|
-
const sequence = Math.max(...run.records.map((record) => recordSequence(record) ?? 0)) + 1;
|
|
611
|
+
const superseded = supersedableUsageBeforeTerminal(persistedRecords);
|
|
612
|
+
const sequence = Math.max(...persistedRecords.map((record) => recordSequence(record) ?? 0)) + 1;
|
|
614
613
|
const event = {
|
|
615
614
|
schema_version: 2,
|
|
616
615
|
event_id: `${run.started.run_id}:reconcile:${String(sequence).padStart(6, "0")}`,
|
|
617
616
|
run_id: run.started.run_id,
|
|
618
617
|
sequence,
|
|
619
|
-
occurred_at:
|
|
618
|
+
occurred_at: persistedRecords.find((record) => recordType(record) === "run.finished")
|
|
620
619
|
? new Date(
|
|
621
620
|
Date.parse(
|
|
622
|
-
recordOccurredAt(
|
|
621
|
+
recordOccurredAt(
|
|
622
|
+
persistedRecords.find((record) => recordType(record) === "run.finished"),
|
|
623
|
+
),
|
|
623
624
|
) - 1,
|
|
624
625
|
).toISOString()
|
|
625
626
|
: new Date().toISOString(),
|
|
@@ -640,11 +641,11 @@ if (applyBackfill) {
|
|
|
640
641
|
...(segment.finished_at ? { source_finished_at: segment.finished_at } : {}),
|
|
641
642
|
runtime: { reasoning_effort: segment.effort, service_tier: segment.service_tier },
|
|
642
643
|
};
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
(
|
|
647
|
-
);
|
|
644
|
+
const updated = [
|
|
645
|
+
...persistedRecords.slice(0, insertAt),
|
|
646
|
+
event,
|
|
647
|
+
...persistedRecords.slice(insertAt),
|
|
648
|
+
].map((record, index) => withSequence(record, index + 1));
|
|
648
649
|
const temporary = `${run.file}.reconcile.tmp`;
|
|
649
650
|
await writeFile(
|
|
650
651
|
temporary,
|
|
@@ -722,6 +723,11 @@ console.log(
|
|
|
722
723
|
).length,
|
|
723
724
|
duplicated_correction_segments: correctionKeys.length - new Set(correctionKeys).size,
|
|
724
725
|
duplicate_segment_groups: duplicateGroups.length,
|
|
726
|
+
exact_source_key_groups: exactDuplicateGroups.length,
|
|
727
|
+
canonical_alias_review_groups: aliasReviewGroups.length,
|
|
728
|
+
selected_duplicate_segment_groups: selectedDuplicateGroups.length,
|
|
729
|
+
selected_canonical_alias_review_groups: selectedAliasReviewGroups.length,
|
|
730
|
+
selected_duplicate_segment_impact: duplicateUsageImpact(duplicateAssignments),
|
|
725
731
|
duplicate_segment_assignments: duplicateAssignments.length,
|
|
726
732
|
duplicate_segment_run_ids: duplicateGroups.map((group) =>
|
|
727
733
|
group.map(({ run }) => run.started.run_id),
|
package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.mjs
CHANGED
|
@@ -112,6 +112,21 @@ export function usageView(record) {
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export function supersedableUsageBeforeTerminal(records) {
|
|
116
|
+
const finishIndex = records.findIndex((record) => recordType(record) === "run.finished");
|
|
117
|
+
const beforeTerminal = records.slice(0, finishIndex < 0 ? records.length : finishIndex);
|
|
118
|
+
const usage = beforeTerminal.map(usageView).filter(Boolean);
|
|
119
|
+
return (
|
|
120
|
+
[...usage]
|
|
121
|
+
.reverse()
|
|
122
|
+
.find(
|
|
123
|
+
(event) =>
|
|
124
|
+
event.tokens?.total === null &&
|
|
125
|
+
!usage.some((other) => other.supersedes_event_id === event.event_id),
|
|
126
|
+
) ?? null
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
115
130
|
export function withSequence(record, sequence) {
|
|
116
131
|
if (!Array.isArray(record)) return { ...record, sequence };
|
|
117
132
|
const copy = [...record];
|
|
@@ -127,6 +142,10 @@ export function canonicalSegmentKey(sourceSegmentKey) {
|
|
|
127
142
|
return (sessionsMarker < 0 ? normalized : normalized.slice(sessionsMarker + 1)).toLowerCase();
|
|
128
143
|
}
|
|
129
144
|
|
|
145
|
+
function normalizedRawSegmentKey(sourceSegmentKey) {
|
|
146
|
+
return String(sourceSegmentKey).replaceAll("\\", "/").toLowerCase();
|
|
147
|
+
}
|
|
148
|
+
|
|
130
149
|
export function usageStatus(usage) {
|
|
131
150
|
const superseded = new Set(usage.map((event) => event.supersedes_event_id).filter(Boolean));
|
|
132
151
|
const effective = usage.filter((event) => !superseded.has(event.event_id));
|
|
@@ -153,18 +172,14 @@ export function duplicateUsageAssignments(runs) {
|
|
|
153
172
|
continue;
|
|
154
173
|
}
|
|
155
174
|
const baseSegmentKey = canonicalSegmentKey(usage.source_segment_key);
|
|
156
|
-
|
|
157
|
-
baseSegmentKey,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
]);
|
|
165
|
-
groups.set(signature, [
|
|
166
|
-
...(groups.get(signature) ?? []),
|
|
167
|
-
{ run, usage, base_segment_key: baseSegmentKey },
|
|
175
|
+
groups.set(baseSegmentKey, [
|
|
176
|
+
...(groups.get(baseSegmentKey) ?? []),
|
|
177
|
+
{
|
|
178
|
+
run,
|
|
179
|
+
usage,
|
|
180
|
+
base_segment_key: baseSegmentKey,
|
|
181
|
+
raw_segment_key: normalizedRawSegmentKey(usage.source_segment_key),
|
|
182
|
+
},
|
|
168
183
|
]);
|
|
169
184
|
}
|
|
170
185
|
}
|
|
@@ -173,13 +188,57 @@ export function duplicateUsageAssignments(runs) {
|
|
|
173
188
|
.map((group) =>
|
|
174
189
|
[...group].sort(
|
|
175
190
|
(left, right) =>
|
|
191
|
+
provenanceRank(left.usage) - provenanceRank(right.usage) ||
|
|
176
192
|
String(left.run.started.occurred_at).localeCompare(
|
|
177
193
|
String(right.run.started.occurred_at),
|
|
178
|
-
) ||
|
|
194
|
+
) ||
|
|
195
|
+
left.run.started.run_id.localeCompare(right.run.started.run_id),
|
|
179
196
|
),
|
|
180
197
|
);
|
|
181
198
|
}
|
|
182
199
|
|
|
200
|
+
export function isExactDuplicateUsageGroup(group) {
|
|
201
|
+
return new Set(group.map(({ raw_segment_key }) => raw_segment_key)).size === 1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function duplicateUsageImpact(assignments) {
|
|
205
|
+
const impact = {
|
|
206
|
+
assignments: assignments.length,
|
|
207
|
+
input_tokens: 0,
|
|
208
|
+
output_tokens: 0,
|
|
209
|
+
total_tokens: 0,
|
|
210
|
+
cost_usd: 0,
|
|
211
|
+
cost_brl: 0,
|
|
212
|
+
duration_ms: 0,
|
|
213
|
+
duration_assignments: 0,
|
|
214
|
+
};
|
|
215
|
+
for (const { usage } of assignments) {
|
|
216
|
+
for (const [key, value] of [
|
|
217
|
+
["input_tokens", usage.tokens?.input],
|
|
218
|
+
["output_tokens", usage.tokens?.output],
|
|
219
|
+
["total_tokens", usage.tokens?.total],
|
|
220
|
+
["cost_usd", usage.cost?.usd],
|
|
221
|
+
["cost_brl", usage.cost?.brl],
|
|
222
|
+
]) {
|
|
223
|
+
if (Number.isFinite(value)) impact[key] += value;
|
|
224
|
+
}
|
|
225
|
+
const start = Date.parse(usage.source_started_at ?? "");
|
|
226
|
+
const finish = Date.parse(usage.source_finished_at ?? "");
|
|
227
|
+
if (Number.isFinite(start) && Number.isFinite(finish) && finish >= start) {
|
|
228
|
+
impact.duration_ms += finish - start;
|
|
229
|
+
impact.duration_assignments += 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return impact;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function provenanceRank(usage) {
|
|
236
|
+
const source = usage.classification_source ?? "";
|
|
237
|
+
if (source === "current_context" || source.startsWith("exact_")) return 0;
|
|
238
|
+
if (usage.activity_kind !== "retrospective_local_reconciliation") return 1;
|
|
239
|
+
return source === "legacy_inferred" ? 2 : 1;
|
|
240
|
+
}
|
|
241
|
+
|
|
183
242
|
export function exactCompletedSegment(started, segments) {
|
|
184
243
|
if (!started?.client_turn_id) return { segment: null, ambiguous: false };
|
|
185
244
|
const runStartedAt = Date.parse(started.occurred_at ?? "");
|
|
@@ -198,7 +257,13 @@ export function exactCompletedSegment(started, segments) {
|
|
|
198
257
|
};
|
|
199
258
|
}
|
|
200
259
|
|
|
201
|
-
export function exactRemeasurementSegment(
|
|
260
|
+
export function exactRemeasurementSegment(
|
|
261
|
+
started,
|
|
262
|
+
sourceSegmentKey,
|
|
263
|
+
segments,
|
|
264
|
+
sourceOccurredAt = null,
|
|
265
|
+
sourceTokens = null,
|
|
266
|
+
) {
|
|
202
267
|
const turnMatch = exactCompletedSegment(started, segments);
|
|
203
268
|
if (turnMatch.segment !== null || turnMatch.ambiguous) return turnMatch;
|
|
204
269
|
if (typeof sourceSegmentKey !== "string") return turnMatch;
|
|
@@ -207,9 +272,50 @@ export function exactRemeasurementSegment(started, sourceSegmentKey, segments) {
|
|
|
207
272
|
segment.finished_at !== null &&
|
|
208
273
|
canonicalSegmentKey(segment.key) === canonicalSegmentKey(sourceSegmentKey),
|
|
209
274
|
);
|
|
275
|
+
if (matches.length === 1) return { segment: matches[0], ambiguous: false };
|
|
276
|
+
|
|
277
|
+
const sourceFinishedAt = Date.parse(sourceOccurredAt ?? "");
|
|
278
|
+
const sourceFile = canonicalSegmentKey(sourceSegmentKey).replace(/#\d+$/, "");
|
|
279
|
+
const timeMatches = Number.isFinite(sourceFinishedAt)
|
|
280
|
+
? segments.filter(
|
|
281
|
+
(segment) =>
|
|
282
|
+
segment.finished_at !== null &&
|
|
283
|
+
Date.parse(segment.finished_at) === sourceFinishedAt &&
|
|
284
|
+
canonicalSegmentKey(segment.key).replace(/#\d+$/, "") === sourceFile,
|
|
285
|
+
)
|
|
286
|
+
: [];
|
|
287
|
+
if (timeMatches.length === 1) return { segment: timeMatches[0], ambiguous: false };
|
|
288
|
+
|
|
289
|
+
const tokenMatches =
|
|
290
|
+
sourceTokens !== null
|
|
291
|
+
? segments.filter((segment) => {
|
|
292
|
+
if (canonicalSegmentKey(segment.key).replace(/#\d+$/, "") !== sourceFile) return false;
|
|
293
|
+
if (segment.finished_at === null || !Array.isArray(segment.usage)) return false;
|
|
294
|
+
const tokens = aggregate(segment);
|
|
295
|
+
const last = segment.usage.at(-1);
|
|
296
|
+
const lastTokens = last
|
|
297
|
+
? {
|
|
298
|
+
input: last.input_tokens,
|
|
299
|
+
cached_input: last.cached_input_tokens,
|
|
300
|
+
output: last.output_tokens,
|
|
301
|
+
reasoning: last.reasoning_output_tokens,
|
|
302
|
+
total: last.total_tokens,
|
|
303
|
+
}
|
|
304
|
+
: null;
|
|
305
|
+
const same = (candidate) =>
|
|
306
|
+
candidate !== null &&
|
|
307
|
+
["input", "cached_input", "output", "reasoning", "total"].every(
|
|
308
|
+
(key) => candidate[key] === sourceTokens[key],
|
|
309
|
+
);
|
|
310
|
+
return same(tokens) || same(lastTokens);
|
|
311
|
+
})
|
|
312
|
+
: [];
|
|
210
313
|
return {
|
|
211
|
-
segment:
|
|
212
|
-
ambiguous:
|
|
314
|
+
segment: tokenMatches.length === 1 ? tokenMatches[0] : null,
|
|
315
|
+
ambiguous:
|
|
316
|
+
timeMatches.length > 1 ||
|
|
317
|
+
tokenMatches.length > 1 ||
|
|
318
|
+
(timeMatches.length === 0 && tokenMatches.length === 0 && matches.length > 1),
|
|
213
319
|
};
|
|
214
320
|
}
|
|
215
321
|
|
|
@@ -217,11 +323,10 @@ function normalized(path) {
|
|
|
217
323
|
return resolve(path).replaceAll("\\", "/").toLowerCase();
|
|
218
324
|
}
|
|
219
325
|
|
|
220
|
-
export async function loadSegments(workspace) {
|
|
221
|
-
const
|
|
326
|
+
export async function loadSegments(workspace, sessionFiles = null) {
|
|
327
|
+
const files = sessionFiles ?? (await filesUnder(join(homedir(), ".codex", "sessions"), ".jsonl"));
|
|
222
328
|
const segments = [];
|
|
223
|
-
for (const file of
|
|
224
|
-
const fileSegmentStart = segments.length;
|
|
329
|
+
for (const file of files) {
|
|
225
330
|
let canonicalSessionMetaSeen = false;
|
|
226
331
|
let workspaceMatches = false;
|
|
227
332
|
let sessionId = null;
|
|
@@ -245,17 +350,21 @@ export async function loadSegments(workspace) {
|
|
|
245
350
|
}
|
|
246
351
|
const payload = record?.payload && typeof record.payload === "object" ? record.payload : null;
|
|
247
352
|
if (record.type === "session_meta" && typeof payload?.cwd === "string") {
|
|
353
|
+
const nextSessionId = canonicalSessionId(payload);
|
|
354
|
+
const sameSession = canonicalSessionMetaSeen && nextSessionId === sessionId;
|
|
355
|
+
if (sameSession) {
|
|
356
|
+
workspaceMatches = normalized(payload.cwd) === normalized(workspace);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
248
359
|
if (canonicalSessionMetaSeen) {
|
|
249
|
-
segments.splice(fileSegmentStart);
|
|
250
360
|
current = null;
|
|
251
361
|
index = 0;
|
|
252
362
|
latestCumulativeUsage = null;
|
|
253
363
|
latestIncrementalUsage = null;
|
|
254
|
-
continue;
|
|
255
364
|
}
|
|
256
365
|
canonicalSessionMetaSeen = true;
|
|
257
366
|
workspaceMatches = normalized(payload.cwd) === normalized(workspace);
|
|
258
|
-
sessionId =
|
|
367
|
+
sessionId = nextSessionId;
|
|
259
368
|
}
|
|
260
369
|
if (!workspaceMatches) continue;
|
|
261
370
|
const settings = payload?.type === "thread_settings_applied" ? payload.thread_settings : null;
|
|
@@ -8,13 +8,16 @@ import {
|
|
|
8
8
|
canonicalSessionId,
|
|
9
9
|
cumulativeSnapshotDelta,
|
|
10
10
|
duplicateUsageAssignments,
|
|
11
|
+
duplicateUsageImpact,
|
|
11
12
|
exactCompletedSegment,
|
|
12
13
|
exactRemeasurementSegment,
|
|
14
|
+
isExactDuplicateUsageGroup,
|
|
13
15
|
jsonLines,
|
|
14
16
|
pricingFor,
|
|
15
17
|
recordSequence,
|
|
16
18
|
recordType,
|
|
17
19
|
sameTokenSnapshot,
|
|
20
|
+
supersedableUsageBeforeTerminal,
|
|
18
21
|
usageStatus,
|
|
19
22
|
usageView,
|
|
20
23
|
withSequence,
|
|
@@ -23,6 +26,41 @@ import {
|
|
|
23
26
|
const roots = [];
|
|
24
27
|
after(async () => Promise.all(roots.map((root) => rm(root, { recursive: true, force: true }))));
|
|
25
28
|
|
|
29
|
+
test("sums duplicate assignment impact without inventing duration", () => {
|
|
30
|
+
assert.deepEqual(
|
|
31
|
+
duplicateUsageImpact([
|
|
32
|
+
{
|
|
33
|
+
usage: {
|
|
34
|
+
tokens: { input: 2, output: 3, total: 5 },
|
|
35
|
+
cost: { usd: 1, brl: 5 },
|
|
36
|
+
source_started_at: "2026-01-01T00:00:00Z",
|
|
37
|
+
source_finished_at: "2026-01-01T00:00:01Z",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
]),
|
|
41
|
+
{
|
|
42
|
+
assignments: 1,
|
|
43
|
+
input_tokens: 2,
|
|
44
|
+
output_tokens: 3,
|
|
45
|
+
total_tokens: 5,
|
|
46
|
+
cost_usd: 1,
|
|
47
|
+
cost_brl: 5,
|
|
48
|
+
duration_ms: 1000,
|
|
49
|
+
duration_assignments: 1,
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("never supersedes usage recorded after run.finished", () => {
|
|
55
|
+
const records = [
|
|
56
|
+
{ type: "run.started", sequence: 1 },
|
|
57
|
+
{ type: "usage.recorded", sequence: 2, event_id: "before", tokens: { total: null } },
|
|
58
|
+
{ type: "run.finished", sequence: 3 },
|
|
59
|
+
{ type: "usage.recorded", sequence: 4, event_id: "after", tokens: { total: null } },
|
|
60
|
+
];
|
|
61
|
+
assert.equal(supersedableUsageBeforeTerminal(records)?.event_id, "before");
|
|
62
|
+
});
|
|
63
|
+
|
|
26
64
|
test("normalizes compact and object Run records without changing usage totals", () => {
|
|
27
65
|
const compact = [
|
|
28
66
|
2,
|
|
@@ -193,6 +231,70 @@ test("remeasurement falls back only to the exact persisted source segment key",
|
|
|
193
231
|
),
|
|
194
232
|
{ segment: null, ambiguous: true },
|
|
195
233
|
);
|
|
234
|
+
|
|
235
|
+
const resumedTarget = {
|
|
236
|
+
...target,
|
|
237
|
+
key: "c:/users/test/.codex/sessions/2026/07/25/child.jsonl#18",
|
|
238
|
+
finished_at: "2026-07-25T04:15:30.000Z",
|
|
239
|
+
};
|
|
240
|
+
assert.deepEqual(
|
|
241
|
+
exactRemeasurementSegment(
|
|
242
|
+
{ client_turn_id: null, occurred_at: "2026-07-25T04:00:00.000Z" },
|
|
243
|
+
"sessions/2026/07/25/child.jsonl#2",
|
|
244
|
+
[target, resumedTarget],
|
|
245
|
+
"2026-07-25T04:15:30.000Z",
|
|
246
|
+
),
|
|
247
|
+
{ segment: resumedTarget, ambiguous: false },
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const tokenTarget = {
|
|
251
|
+
...resumedTarget,
|
|
252
|
+
finished_at: "2026-07-25T04:16:00.000Z",
|
|
253
|
+
usage: [
|
|
254
|
+
{
|
|
255
|
+
input_tokens: 90,
|
|
256
|
+
cached_input_tokens: 80,
|
|
257
|
+
output_tokens: 10,
|
|
258
|
+
reasoning_output_tokens: 2,
|
|
259
|
+
total_tokens: 100,
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
assert.deepEqual(
|
|
264
|
+
exactRemeasurementSegment(
|
|
265
|
+
{ client_turn_id: null, occurred_at: "2026-07-25T04:00:00.000Z" },
|
|
266
|
+
"sessions/2026/07/25/child.jsonl#2",
|
|
267
|
+
[target, tokenTarget],
|
|
268
|
+
"2026-07-25T04:15:59.000Z",
|
|
269
|
+
{ input: 90, cached_input: 80, output: 10, reasoning: 2, total: 100 },
|
|
270
|
+
),
|
|
271
|
+
{ segment: tokenTarget, ambiguous: false },
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
const cumulativeSnapshotTarget = {
|
|
275
|
+
...tokenTarget,
|
|
276
|
+
key: "c:/users/test/.codex/sessions/2026/07/25/child.jsonl#19",
|
|
277
|
+
usage: [
|
|
278
|
+
tokenTarget.usage[0],
|
|
279
|
+
{
|
|
280
|
+
input_tokens: 40,
|
|
281
|
+
cached_input_tokens: 30,
|
|
282
|
+
output_tokens: 4,
|
|
283
|
+
reasoning_output_tokens: 1,
|
|
284
|
+
total_tokens: 44,
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
};
|
|
288
|
+
assert.deepEqual(
|
|
289
|
+
exactRemeasurementSegment(
|
|
290
|
+
{ client_turn_id: null, occurred_at: "2026-07-25T04:00:00.000Z" },
|
|
291
|
+
"sessions/2026/07/25/child.jsonl#2",
|
|
292
|
+
[target, cumulativeSnapshotTarget],
|
|
293
|
+
null,
|
|
294
|
+
{ input: 40, cached_input: 30, output: 4, reasoning: 1, total: 44 },
|
|
295
|
+
),
|
|
296
|
+
{ segment: cumulativeSnapshotTarget, ambiguous: false },
|
|
297
|
+
);
|
|
196
298
|
});
|
|
197
299
|
|
|
198
300
|
test("detects only exact duplicate segment assignments across Runs", () => {
|
|
@@ -239,7 +341,7 @@ test("detects only exact duplicate segment assignments across Runs", () => {
|
|
|
239
341
|
assert.equal(groups.length, 1);
|
|
240
342
|
assert.deepEqual(
|
|
241
343
|
groups[0].map(({ run: item }) => item.started.run_id),
|
|
242
|
-
["RUN-FIRST", "RUN-DUPLICATE"],
|
|
344
|
+
["RUN-FIRST", "RUN-DUPLICATE", "RUN-DELTA"],
|
|
243
345
|
);
|
|
244
346
|
assert.equal(groups[0][0].base_segment_key, "sessions/2026/07/17/session.jsonl#1");
|
|
245
347
|
});
|
|
@@ -264,3 +366,49 @@ test("keeps duplicate reconciliation unavailable and protected from backfill", (
|
|
|
264
366
|
assert.equal(status.deduplicated, true);
|
|
265
367
|
assert.deepEqual(status.effective, [correction]);
|
|
266
368
|
});
|
|
369
|
+
|
|
370
|
+
test("prefers later current-context assignment over earlier legacy assignment", () => {
|
|
371
|
+
const run = (id, occurred_at, client_turn_id, classification_source, total) => ({
|
|
372
|
+
started: { run_id: id, occurred_at, client_turn_id },
|
|
373
|
+
usage: [
|
|
374
|
+
{
|
|
375
|
+
event_id: `${id}:usage`,
|
|
376
|
+
source_segment_key: "sessions/x.jsonl#1",
|
|
377
|
+
supersedes_event_id: null,
|
|
378
|
+
classification_source,
|
|
379
|
+
tokens: { input: total - 1, output: 1, total },
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
});
|
|
383
|
+
const [group] = duplicateUsageAssignments([
|
|
384
|
+
run("XCHW", "2026-07-01T00:00:00.000Z", "legacy-turn", "legacy_inferred", 9_278_701),
|
|
385
|
+
run("HF77", "2026-07-01T00:01:00.000Z", "exact-turn", "current_context", 577),
|
|
386
|
+
]);
|
|
387
|
+
assert.equal(group[0].run.started.run_id, "HF77");
|
|
388
|
+
assert.equal(group[1].run.started.run_id, "XCHW");
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("keeps canonical aliases in review instead of making them apply candidates", () => {
|
|
392
|
+
const run = (id, source_segment_key) => ({
|
|
393
|
+
started: { run_id: id, occurred_at: "2026-07-01T00:00:00.000Z" },
|
|
394
|
+
usage: [
|
|
395
|
+
{
|
|
396
|
+
event_id: `${id}:usage`,
|
|
397
|
+
source_segment_key,
|
|
398
|
+
supersedes_event_id: null,
|
|
399
|
+
tokens: { input: 1, output: 1, total: 2 },
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
});
|
|
403
|
+
const [aliasGroup] = duplicateUsageAssignments([
|
|
404
|
+
run("RUN-A", "sessions/x.jsonl#1@RUN-A"),
|
|
405
|
+
run("RUN-B", "sessions/x.jsonl#1@RUN-B"),
|
|
406
|
+
]);
|
|
407
|
+
const [exactGroup] = duplicateUsageAssignments([
|
|
408
|
+
run("RUN-C", "sessions/x.jsonl#2"),
|
|
409
|
+
run("RUN-D", "SESSIONS\\x.jsonl#2"),
|
|
410
|
+
]);
|
|
411
|
+
|
|
412
|
+
assert.equal(isExactDuplicateUsageGroup(aliasGroup), false);
|
|
413
|
+
assert.equal(isExactDuplicateUsageGroup(exactGroup), true);
|
|
414
|
+
});
|