@zaip-ai/cli 2.2.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.
- package/dist/services/adapters.d.ts +1 -1
- package/dist/services/adapters.d.ts.map +1 -1
- package/dist/services/adapters.js +23 -9
- package/dist/services/adapters.js.map +1 -1
- package/dist/services/agent-adapters.js +25 -9
- package/dist/services/agent-adapters.js.map +1 -1
- package/dist/services/agent-discovery.d.ts +27 -0
- package/dist/services/agent-discovery.d.ts.map +1 -0
- package/dist/services/agent-discovery.js +73 -0
- package/dist/services/agent-discovery.js.map +1 -0
- package/dist/services/codex-conversation-lifecycle-hook.d.ts.map +1 -1
- package/dist/services/codex-conversation-lifecycle-hook.js +153 -24
- package/dist/services/codex-conversation-lifecycle-hook.js.map +1 -1
- package/dist/services/codex-pre-tool-hook-template.d.ts.map +1 -1
- package/dist/services/codex-pre-tool-hook-template.js +146 -72
- package/dist/services/codex-pre-tool-hook-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 +3 -3
- 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 +117 -66
- package/dist/services/codex-subagent-hook-template.js.map +1 -1
- package/dist/services/install-agents-template.d.ts.map +1 -1
- package/dist/services/install-agents-template.js +56 -6
- 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 +22 -1
- package/dist/services/logger.test.js.map +1 -1
- package/dist/services/runtime-template.test.js +129 -0
- package/dist/services/runtime-template.test.js.map +1 -1
- package/package.json +1 -1
- package/templates/.agents/.env.example +9 -3
- package/templates/.agents/README-ENG.md +30 -5
- package/templates/.agents/README.md +30 -7
- package/templates/.agents/architecture/software-architecture.md +1 -59
- package/templates/.agents/branding/brandbook.md +3 -0
- package/templates/.agents/config/agents/catalog.yaml +22 -10
- package/templates/.agents/config/agents/discovery.json +319 -0
- package/templates/.agents/config/clients/codex/agents/zaip-agent-backend.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-builder.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-cloud-engineer.toml +11 -8
- package/templates/.agents/config/clients/codex/agents/zaip-agent-designer.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-frontend.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-task-executor.toml +2 -2
- package/templates/.agents/config/clients/codex/agents/zaip-agent-website-developer.toml +2 -2
- package/templates/.agents/config/pricing/models.json +9 -5
- package/templates/.agents/config/project.yaml +12 -1
- package/templates/.agents/dashboard/.zaip-managed.json +375 -95
- package/templates/.agents/dashboard/apps/frontend/dist/assets/CostCalculationGuidePage-CGxeQak4.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{DashboardHelpDialog-DaSllaJp.js → DashboardHelpDialog-tzS7YxYB.js} +57 -33
- package/templates/.agents/dashboard/apps/frontend/dist/assets/PricingSettingsDialog-DEbCi1gP.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-1L7Qw-Gq.js +3 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-EInWr641.css +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-t1Om0Abw.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-B6aZfo5f.js +68 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{icons-vendor-TPUT2IUt.js → icons-vendor-DiGC-dsJ.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-DgTmNHN5.js +2 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/{react-vendor-Ct48XHGL.js → react-vendor-kPO6yNed.js} +1 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/rolldown-runtime-Bh1tDfsg.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-DQpKX9c1.js +1 -0
- package/templates/.agents/dashboard/apps/frontend/dist/index.html +6 -6
- package/templates/.agents/dashboard/apps/frontend/package.json +1 -1
- package/templates/.agents/dashboard/apps/frontend/src/App.tsx +3 -1264
- package/templates/.agents/dashboard/apps/frontend/src/AppDashboardContent.tsx +363 -0
- package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.dom.test.ts +99 -0
- package/templates/.agents/dashboard/apps/frontend/src/ProjectSettingsPage.tsx +62 -6
- package/templates/.agents/dashboard/apps/frontend/src/ProjectStackEditor.tsx +3 -1
- package/templates/.agents/dashboard/apps/frontend/src/__tests__/app-composition-support.ts +7 -0
- package/templates/.agents/dashboard/apps/frontend/src/cost-period-refresh.test.ts +9 -7
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-api-settings.ts +151 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-api.ts +28 -153
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-app-shell.tsx +33 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-cost-facts.ts +30 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-project-overview.ts +7 -1
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-retry.ts +17 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-setup-route.ts +29 -0
- package/templates/.agents/dashboard/apps/frontend/src/dashboard-view-actions.ts +66 -0
- package/templates/.agents/dashboard/apps/frontend/src/operations-period-render.test.ts +3 -2
- package/templates/.agents/dashboard/apps/frontend/src/overview-status-page.test.ts +2 -2
- package/templates/.agents/dashboard/apps/frontend/src/project-installation-status.test.ts +48 -0
- package/templates/.agents/dashboard/apps/frontend/src/project-installation-status.ts +29 -0
- package/templates/.agents/dashboard/apps/frontend/src/project-settings-page.css +68 -0
- package/templates/.agents/dashboard/apps/frontend/src/project-settings.test.ts +2 -2
- package/templates/.agents/dashboard/apps/frontend/src/sao-paulo-day-rollover.test.ts +36 -0
- package/templates/.agents/dashboard/apps/frontend/src/sao-paulo-day-rollover.ts +30 -0
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-banner-semantics.test.ts +2 -5
- package/templates/.agents/dashboard/apps/frontend/src/snapshot-coherence.test.ts +30 -19
- package/templates/.agents/dashboard/apps/frontend/src/use-app-effects.ts +9 -1
- package/templates/.agents/dashboard/apps/frontend/src/use-app-trace-task-pagination.ts +77 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-app-work-board.ts +397 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-dashboard-app-model.tsx +782 -0
- package/templates/.agents/dashboard/apps/frontend/src/use-snapshot-notice.tsx +49 -0
- package/templates/.agents/dashboard/modules/cost-monitor/package.json +1 -1
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostDeveloperPanelSlot.tsx +16 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostGroupsTable.tsx +459 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.test.ts +27 -17
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorPage.tsx +62 -186
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostMonitorRunDialog.tsx +20 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables-hides-calls-that-have-no-collected.test.ts +80 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables-keeps-legacy-codex-identity-fields-blank.test.ts +455 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.test.ts +18 -525
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/CostTables.tsx +32 -508
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-export-sources.ts +74 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-page-actions.ts +19 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-monitor-page-selectors.ts +49 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/react/cost-table-formatters.ts +115 -0
- package/templates/.agents/dashboard/modules/cost-monitor/src/server/build-cost-monitor-projection.test-fixtures.ts +2 -0
- package/templates/.agents/dashboard/modules/operations/package.json +1 -1
- package/templates/.agents/dashboard/modules/operations/src/contracts.ts +4 -0
- package/templates/.agents/dashboard/modules/operations/src/react/EntityTableBadges.tsx +34 -0
- package/templates/.agents/dashboard/modules/operations/src/react/EntityTables.tsx +8 -38
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview-keeps-structure-classes-mutually-exclusive.test.ts +243 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.test.ts +27 -275
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverview.tsx +70 -247
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverviewCharts.tsx +171 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsOverviewPanels.tsx +64 -0
- package/templates/.agents/dashboard/modules/operations/src/react/OperationsPage.tsx +4 -3
- package/templates/.agents/dashboard/modules/operations/src/react/PrdDocumentDialog.test.tsx +2 -1
- package/templates/.agents/dashboard/modules/operations/src/react/manual-work-priority.test.ts +2 -1
- package/templates/.agents/dashboard/modules/operations/src/react/operations-coverage-toast.test.ts +6 -2
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview-period-filter.test.ts +6 -14
- package/templates/.agents/dashboard/modules/operations/src/react/operations-overview.status-cards.test.ts +3 -1
- package/templates/.agents/dashboard/modules/operations/src/react/operations-page-contract.ts +2 -0
- package/templates/.agents/dashboard/modules/operations/src/react/overview-metric-format.ts +32 -0
- package/templates/.agents/dashboard/modules/traceability/package.json +1 -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/data-export/package.json +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/dist/server.cjs +1458 -1458
- package/templates/.agents/dashboard/packages/local-runtime/dist/sqlite-read-model.cjs +1425 -1425
- package/templates/.agents/dashboard/packages/local-runtime/package.json +2 -1
- package/templates/.agents/dashboard/packages/local-runtime/scripts/build-sqlite-runtime.mjs +7 -3
- package/templates/.agents/dashboard/packages/local-runtime/server.mjs +1458 -1459
- package/templates/.agents/dashboard/packages/local-runtime/src/active-codex-telemetry.ts +25 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/agent-catalog-settings.test.ts +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.test.ts +53 -8
- package/templates/.agents/dashboard/packages/local-runtime/src/project-settings.ts +79 -24
- package/templates/.agents/dashboard/packages/local-runtime/src/projection-refresh-diagnostics.ts +35 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-costs-routes.ts +168 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-dual-reads-manifest-summaries-without-losing.test.ts +344 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-http-contracts.ts +31 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-operations-routes.ts +345 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-read-projections.ts +461 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-reconciliation-refresh.test.ts +78 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-route-context.ts +13 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-synchronization.test.ts +18 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot-synchronization.ts +19 -3
- package/templates/.agents/dashboard/packages/local-runtime/src/server-snapshot.test.ts +22 -21
- package/templates/.agents/dashboard/packages/local-runtime/src/server-sqlite-view-allowlist.test.ts +25 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-trace-routes.ts +64 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/server-work-reconciliation.test.ts +2 -30
- package/templates/.agents/dashboard/packages/local-runtime/src/server-work-reconciliation.ts +6 -23
- package/templates/.agents/dashboard/packages/local-runtime/src/server.test-fixtures.ts +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/src/server.test.ts +2 -330
- package/templates/.agents/dashboard/packages/local-runtime/src/server.ts +73 -1060
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-first-fold.ts +78 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-projections.ts +561 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-materialize-runs.ts +600 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-metric-contract.test.ts +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-agent-dimension.ts +269 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-context.ts +32 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-entity-group.ts +244 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-filtered-dimension.ts +292 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-financial.ts +547 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-model-dimension.ts +360 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-provider-dimension.ts +169 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-summary.ts +475 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-temporal-dimension.ts +132 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-timing.ts +299 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-query-view-page.ts +692 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-counts-every-root-execution-day-returns.test.ts +739 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-does-not-convert-delayed-historical-finalizer.test.ts +706 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-filesystem.ts +748 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-first-fold-types.ts +1 -1
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-keeps-orphan-telemetry-out-kanban-without.test.ts +710 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-marks-token-cost-telemetry-unavailable-when.test.ts +618 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-rebuild.ts +755 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-rebuilds-disposable-snapshot-serves-zaip-records.test.ts +276 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-schema.ts +193 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model-types.ts +123 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.test.ts +1 -2805
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-read-model.ts +17 -6930
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-schema-base-views.ts +385 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/sqlite-schema-dashboard-views.ts +412 -0
- package/templates/.agents/dashboard/packages/local-runtime/src/work-priority-contract.test.ts +4 -3
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-build.mjs +195 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-lifecycle.test.mjs +2 -7
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-logging.mjs +35 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-navigation.mjs +114 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard-paths.mjs +90 -0
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.mjs +89 -418
- package/templates/.agents/dashboard/packages/local-runtime/start-dashboard.test.mjs +22 -12
- package/templates/.agents/dashboard/packages/ui/package.json +1 -1
- package/templates/.agents/dashboard/tests/e2e/package.json +1 -1
- package/templates/.agents/dashboard/tests/e2e/playwright.config.ts +4 -1
- package/templates/.agents/design/.zaip-managed.json +5 -5
- package/templates/.agents/design/DESIGN.md +2 -186
- package/templates/.agents/design/README.md +12 -2
- 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/strategy.md +3 -0
- package/templates/.agents/marketing/strategy.md +3 -0
- package/templates/.agents/requirements/autonomous-assurance.md +2 -1
- package/templates/.agents/requirements/cloud-hostinger-autonomy.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 +1 -1
- package/templates/.agents/requirements/data-export.md +1 -1
- package/templates/.agents/requirements/design-system.md +13 -4
- package/templates/.agents/requirements/execution-engine.md +1 -1
- package/templates/.agents/requirements/kanban-dashboard.md +1 -1
- package/templates/.agents/requirements/model-orchestration.md +1 -1
- package/templates/.agents/requirements/public-distribution.md +4 -2
- 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 +3 -3
- package/templates/.agents/requirements/zaip-strategic-95.md +1 -1
- package/templates/.agents/rules/architecture.md +2 -0
- package/templates/.agents/rules/astra-diagnostic.md +1 -1
- package/templates/.agents/rules/autonomy-decision.md +3 -1
- package/templates/.agents/rules/cloud-hostinger-autonomy.md +2 -0
- package/templates/.agents/rules/context.md +2 -1
- package/templates/.agents/rules/core.md +3 -3
- package/templates/.agents/rules/design-system-central-contract.md +17 -0
- package/templates/.agents/rules/evolution.md +3 -1
- package/templates/.agents/rules/frontend-lite.md +3 -1
- package/templates/.agents/rules/local-sqlite-storage.md +2 -2
- package/templates/.agents/rules/meta-mcp.md +3 -1
- package/templates/.agents/rules/model-orchestration.md +1 -1
- package/templates/.agents/rules/run-lifecycle-closure.md +6 -4
- package/templates/.agents/rules/security.md +3 -1
- package/templates/.agents/rules/specialist-routing.md +3 -1
- package/templates/.agents/rules/text-writing-utf8.md +1 -1
- package/templates/.agents/rules/workflow.md +7 -5
- package/templates/.agents/runtime/VERSION +1 -1
- package/templates/.agents/runtime/bin/zaip.mjs +519 -247
- package/templates/.agents/runtime/checksums.sha256 +6 -6
- package/templates/.agents/runtime/manifest.json +1 -1
- package/templates/.agents/runtime/pnpm-lock.sha256 +1 -1
- package/templates/.agents/runtime/provenance.json +5 -5
- package/templates/.agents/runtime/sbom.cdx.json +1 -1
- package/templates/.agents/sales/playbook.md +3 -0
- package/templates/.agents/skills/zaip-aios/SKILL.md +5 -3
- package/templates/.agents/skills/zaip-skill-adapt-stack/SKILL.md +1 -0
- package/templates/.agents/skills/zaip-skill-api-contracts/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-api-contracts/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-application-observability/SKILL.md +15 -0
- package/templates/.agents/skills/zaip-skill-application-observability/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-application-observability/references/signal-design.md +3 -0
- package/templates/.agents/skills/zaip-skill-application-readiness/SKILL.md +15 -0
- package/templates/.agents/skills/zaip-skill-application-readiness/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-application-readiness/references/evidence-matrix.md +3 -0
- package/templates/.agents/skills/zaip-skill-architecture-design/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-architecture-design/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-async-jobs/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-async-jobs/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-auth-tenancy/SKILL.md +15 -0
- package/templates/.agents/skills/zaip-skill-auth-tenancy/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-auth-tenancy/references/data-access-paths.md +9 -0
- package/templates/.agents/skills/zaip-skill-auth-tenancy/references/worker-scenario.md +5 -0
- package/templates/.agents/skills/zaip-skill-auth-tenancy/scripts/worker-contract.test.mjs +27 -0
- package/templates/.agents/skills/zaip-skill-author-skills/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-author-skills/references/engineering-skill-index.md +9 -0
- package/templates/.agents/skills/zaip-skill-author-skills/scripts/audit-skill-catalog.mjs +5 -3
- package/templates/.agents/skills/zaip-skill-author-skills/scripts/author-skill-scripts.test.mjs +27 -0
- package/templates/.agents/skills/zaip-skill-backend/SKILL.md +4 -0
- package/templates/.agents/skills/zaip-skill-backend/references/deployment-environments.md +75 -0
- package/templates/.agents/skills/zaip-skill-backend/references/supabase-migration-contract.md +23 -0
- package/templates/.agents/skills/zaip-skill-brand-governance/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-cache-strategy/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-cache-strategy/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-change/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-cloud-engineering/SKILL.md +7 -0
- package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/SKILL.md +37 -0
- package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/agents/openai.yaml +6 -0
- package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/references/workers-static-assets.md +26 -0
- package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/references/workflow-templates.md +71 -0
- package/templates/.agents/skills/zaip-skill-cloudflare-github-deploy/scripts/cloudflare-github-deploy-contract.test.mjs +77 -0
- package/templates/.agents/skills/zaip-skill-config/SKILL.md +21 -11
- package/templates/.agents/skills/zaip-skill-config/agents/openai.yaml +2 -2
- package/templates/.agents/skills/zaip-skill-container-runtime/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-container-runtime/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-context/SKILL.md +6 -1
- package/templates/.agents/skills/zaip-skill-context/references/prd-spec-task-handoff.md +10 -0
- package/templates/.agents/skills/zaip-skill-context/references/rule-selection.md +20 -0
- package/templates/.agents/skills/zaip-skill-cqrs/SKILL.md +1 -0
- package/templates/.agents/skills/zaip-skill-cybersecurity/SKILL.md +18 -0
- package/templates/.agents/skills/zaip-skill-cybersecurity/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-cybersecurity/references/audit-contract.md +94 -0
- package/templates/.agents/skills/zaip-skill-cybersecurity/scripts/score-audit.mjs +185 -0
- package/templates/.agents/skills/zaip-skill-cybersecurity/scripts/score-audit.test.mjs +101 -0
- package/templates/.agents/skills/zaip-skill-data-modeling/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-data-modeling/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-database-migrations/SKILL.md +20 -0
- package/templates/.agents/skills/zaip-skill-database-migrations/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-database-migrations/references/manual-mode.md +15 -0
- package/templates/.agents/skills/zaip-skill-database-migrations/references/promotion-example.md +5 -0
- package/templates/.agents/skills/zaip-skill-database-migrations/scripts/export-manual-sql.mjs +145 -0
- package/templates/.agents/skills/zaip-skill-database-migrations/scripts/export-manual-sql.test.mjs +178 -0
- package/templates/.agents/skills/zaip-skill-dependency-upgrade/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-dependency-upgrade/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-deployment-pipeline/SKILL.md +15 -0
- package/templates/.agents/skills/zaip-skill-deployment-pipeline/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-deployment-pipeline/references/runtime-shapes.md +3 -0
- package/templates/.agents/skills/zaip-skill-design-system/SKILL.md +20 -9
- package/templates/.agents/skills/zaip-skill-dev-environment/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-dev-environment/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-dev-environment/references/inventory-contract.md +7 -0
- package/templates/.agents/skills/zaip-skill-dev-environment/scripts/inventory.mjs +77 -0
- package/templates/.agents/skills/zaip-skill-disaster-recovery/SKILL.md +15 -0
- package/templates/.agents/skills/zaip-skill-disaster-recovery/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-disaster-recovery/references/recovery-scope.md +3 -0
- package/templates/.agents/skills/zaip-skill-execution/SKILL.md +3 -3
- package/templates/.agents/skills/zaip-skill-execution/references/correction-cycle.md +7 -0
- package/templates/.agents/skills/zaip-skill-execution/references/runtime-governance.md +1 -5
- package/templates/.agents/skills/zaip-skill-external-integrations/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-external-integrations/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-frontend/SKILL.md +4 -0
- package/templates/.agents/skills/zaip-skill-frontend-componentization/SKILL.md +44 -0
- package/templates/.agents/skills/zaip-skill-frontend-componentization/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-frontend-data-flows/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-frontend-data-flows/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-general-operations/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/SKILL.md +36 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/references/cloudflare-pages.md +33 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/references/github.md +63 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/references/hostinger-vps.md +55 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/references/npm.md +30 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/check-skill.mjs +55 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/verify-cloudflare.mjs +61 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/verify-cloudflare.test.mjs +128 -0
- package/templates/.agents/skills/zaip-skill-github-actions-setup/scripts/verify-ssh.integration.test.mjs +106 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/SKILL.md +43 -76
- package/templates/.agents/skills/zaip-skill-github-deploy/references/deployment-workflow.md +131 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/references/github-release-workflow-template.md +31 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/references/release-gate-matrix.md +24 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/references/release-identity.md +44 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/references/release-notes.md +134 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/consumer-release-preparation.mjs +389 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/consumer-release-preparation.test.mjs +134 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-deploy-contract.test.mjs +25 -2
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-readiness-api.test.mjs +134 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-readiness.mjs +98 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/github-readiness.test.mjs +25 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/install-github-readiness-workflow.mjs +159 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/install-github-readiness-workflow.test.mjs +160 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/preflight.mjs +149 -12
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/preflight.test.mjs +64 -5
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/release-notes-coverage.test.mjs +126 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/resolve-release-identity.mjs +78 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/resolve-release-identity.test.mjs +51 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/validate-release-notes.mjs +184 -0
- package/templates/.agents/skills/zaip-skill-github-deploy/scripts/validate-release-notes.test.mjs +109 -0
- package/templates/.agents/skills/zaip-skill-growth-strategy-revops/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/SKILL.md +18 -10
- package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/agents/openai.yaml +3 -4
- package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/references/aws-cli-terraform.md +62 -0
- package/templates/.agents/skills/zaip-skill-hostinger-cloudflare-terraform/references/guia-iniciante-hostinger-vps.md +183 -0
- package/templates/.agents/skills/zaip-skill-marketing/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-module-scaffold/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-module-scaffold/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-module-scaffold/references/scaffold-contract.md +9 -0
- package/templates/.agents/skills/zaip-skill-module-scaffold/scripts/helpers.test.mjs +121 -0
- package/templates/.agents/skills/zaip-skill-module-scaffold/scripts/scaffold.mjs +169 -0
- package/templates/.agents/skills/zaip-skill-move-prd/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-move-spec/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-performance-engineering/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-performance-engineering/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-prd/SKILL.md +1 -1
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-local-telemetry.mjs +1 -0
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.mjs +26 -9
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-lib.test.mjs +39 -13
- package/templates/.agents/skills/zaip-skill-reconcile-telemetry/scripts/reconcile-telemetry-remeasurement.mjs +1 -0
- package/templates/.agents/skills/zaip-skill-refactor-landing-page/SKILL.md +66 -0
- package/templates/.agents/skills/zaip-skill-refactor-landing-page/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-refactor-landing-page/references/behavioral-dry-run.md +23 -0
- package/templates/.agents/skills/zaip-skill-release-qualification/SKILL.md +40 -1
- package/templates/.agents/skills/zaip-skill-release-qualification/references/local-preparation.md +98 -0
- package/templates/.agents/skills/zaip-skill-review/SKILL.md +1 -0
- package/templates/.agents/skills/zaip-skill-rules/SKILL.md +3 -3
- package/templates/.agents/skills/zaip-skill-sales-methodology/SKILL.md +2 -0
- package/templates/.agents/skills/zaip-skill-setup/SKILL.md +19 -21
- package/templates/.agents/skills/zaip-skill-setup/agents/openai.yaml +2 -2
- package/templates/.agents/skills/zaip-skill-spec/SKILL.md +3 -2
- package/templates/.agents/skills/zaip-skill-storage-uploads/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-storage-uploads/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-systematic-debugging/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-systematic-debugging/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-task/SKILL.md +16 -7
- package/templates/.agents/skills/zaip-skill-task/references/commit-policy.md +25 -0
- package/templates/.agents/skills/zaip-skill-test-data/SKILL.md +14 -0
- package/templates/.agents/skills/zaip-skill-test-data/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-test-data/scripts/generate.mjs +72 -0
- package/templates/.agents/skills/zaip-skill-testing-strategy/SKILL.md +15 -0
- package/templates/.agents/skills/zaip-skill-testing-strategy/agents/openai.yaml +4 -0
- package/templates/.agents/skills/zaip-skill-testing-strategy/references/example-map.md +3 -0
- package/templates/.agents/skills/zaip-skill-website-readiness/SKILL.md +8 -0
- package/templates/.agents/zaip-aios/VERSION +1 -1
- package/templates/.agents/zaip-aios/guides/10-seguranca.md +2 -1
- package/templates/.agents/zaip-aios/guides/20-instalacao-detalhada.md +5 -3
- package/templates/scripts/validate-cloud-hostinger-contract.mjs +34 -0
- package/templates/template-manifest.json +955 -211
- package/templates/.agents/branding/.gitkeep +0 -0
- package/templates/.agents/dashboard/apps/frontend/dist/assets/CostCalculationGuidePage-snUCQYTC.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/PricingSettingsDialog-BPtVUGgs.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-3Awyaovx.js +0 -3
- package/templates/.agents/dashboard/apps/frontend/dist/assets/ProjectSettingsPage-GgzpZ_PY.css +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/TraceabilityWorkspace-BCvZFMEf.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/cost-monitor-DbaLbU2q.js +0 -68
- package/templates/.agents/dashboard/apps/frontend/dist/assets/index-_MEktQNM.js +0 -2
- package/templates/.agents/dashboard/apps/frontend/dist/assets/rolldown-runtime-D9-fqq9M.js +0 -1
- package/templates/.agents/dashboard/apps/frontend/dist/assets/traceability-BDe4_Ubl.js +0 -1
- package/templates/.agents/growth/.gitkeep +0 -0
- package/templates/.agents/marketing/.gitkeep +0 -0
- package/templates/.agents/sales/.gitkeep +0 -0
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { SqliteParsedSourceCache } from "./sqlite-incremental-cache.js";
|
|
6
|
+
import { refreshFirstFoldPayloads } from "./sqlite-materialize-first-fold.js";
|
|
7
|
+
import { materializeDashboardProjections } from "./sqlite-materialize-projections.js";
|
|
8
|
+
import { materializeCanonicalRuns } from "./sqlite-materialize-runs.js";
|
|
9
|
+
import {
|
|
10
|
+
type CanonicalChange,
|
|
11
|
+
type CanonicalDecision,
|
|
12
|
+
type CanonicalEntity,
|
|
13
|
+
type CanonicalExecution,
|
|
14
|
+
readCanonicalArtifact,
|
|
15
|
+
readCanonicalEntities,
|
|
16
|
+
readCanonicalLifecycleRecords,
|
|
17
|
+
saoPauloDay,
|
|
18
|
+
type TemporalInterval,
|
|
19
|
+
} from "./sqlite-read-model-canonical.js";
|
|
20
|
+
import { reportSqliteReadModelLaunchProgress } from "./sqlite-read-model-launch-progress.js";
|
|
21
|
+
import {
|
|
22
|
+
hasReusableSnapshotPayloads,
|
|
23
|
+
persistedSourceCheckpoint,
|
|
24
|
+
readModelSchemaVersion,
|
|
25
|
+
requiredIndexes,
|
|
26
|
+
requiredPersistedTables,
|
|
27
|
+
requiredViews,
|
|
28
|
+
sqliteReadModelPath,
|
|
29
|
+
validateSqliteReadModelSchema,
|
|
30
|
+
} from "./sqlite-read-model-schema.js";
|
|
31
|
+
import { sourceFingerprint } from "./sqlite-read-model-source-fingerprint.js";
|
|
32
|
+
import { readSnapshotFileCount } from "./sqlite-snapshot-cache.js";
|
|
33
|
+
export async function rebuildSqliteReadModel(
|
|
34
|
+
workspaceRoot: string,
|
|
35
|
+
options: { forceCanonical?: boolean; preferExisting?: boolean } = {},
|
|
36
|
+
): Promise<{
|
|
37
|
+
files: number;
|
|
38
|
+
path: string;
|
|
39
|
+
cache: "generation" | "seed" | "stale_seed" | "rebuilt";
|
|
40
|
+
fingerprint_ms: number;
|
|
41
|
+
materialize_ms: number;
|
|
42
|
+
refresh: {
|
|
43
|
+
reused_sources: number;
|
|
44
|
+
processed_sources: number;
|
|
45
|
+
added_sources: number;
|
|
46
|
+
changed_sources: number;
|
|
47
|
+
removed_sources: number;
|
|
48
|
+
canonical_runs_refolded: number;
|
|
49
|
+
};
|
|
50
|
+
}> {
|
|
51
|
+
const path = sqliteReadModelPath(workspaceRoot);
|
|
52
|
+
// Bind immediately from the last complete transaction. The serving process
|
|
53
|
+
// checks canonical freshness in its worker before declaring this current.
|
|
54
|
+
if (options.preferExisting && !options.forceCanonical) {
|
|
55
|
+
try {
|
|
56
|
+
validateSqliteReadModelSchema(path);
|
|
57
|
+
const database = new DatabaseSync(path, { readOnly: true });
|
|
58
|
+
try {
|
|
59
|
+
if (hasReusableSnapshotPayloads(database)) {
|
|
60
|
+
const row = database
|
|
61
|
+
.prepare(
|
|
62
|
+
"SELECT value FROM zaip_vw_read_model_metadata WHERE key = 'source_file_count'",
|
|
63
|
+
)
|
|
64
|
+
.get() as { value: string };
|
|
65
|
+
return {
|
|
66
|
+
files: Number(row.value),
|
|
67
|
+
path,
|
|
68
|
+
cache: "stale_seed",
|
|
69
|
+
fingerprint_ms: 0,
|
|
70
|
+
materialize_ms: 0,
|
|
71
|
+
refresh: {
|
|
72
|
+
reused_sources: 0,
|
|
73
|
+
processed_sources: 0,
|
|
74
|
+
added_sources: 0,
|
|
75
|
+
changed_sources: 0,
|
|
76
|
+
removed_sources: 0,
|
|
77
|
+
canonical_runs_refolded: 0,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
} finally {
|
|
82
|
+
database.close();
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
// Missing, incompatible, or incomplete models require a canonical build.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const reportLaunchProgress = reportSqliteReadModelLaunchProgress;
|
|
89
|
+
const fingerprintStartedAt = performance.now();
|
|
90
|
+
reportLaunchProgress("source_fingerprint_started", 8, "Inventariando fontes canônicas.");
|
|
91
|
+
let sourceSnapshot = await sourceFingerprint(
|
|
92
|
+
workspaceRoot,
|
|
93
|
+
options.forceCanonical
|
|
94
|
+
? { verifyContent: true }
|
|
95
|
+
: { previous: persistedSourceCheckpoint(path) },
|
|
96
|
+
);
|
|
97
|
+
let refresh = {
|
|
98
|
+
reused_sources: sourceSnapshot.reusedFiles,
|
|
99
|
+
processed_sources: sourceSnapshot.hashedFiles,
|
|
100
|
+
added_sources: 0,
|
|
101
|
+
changed_sources: 0,
|
|
102
|
+
removed_sources: 0,
|
|
103
|
+
canonical_runs_refolded: 0,
|
|
104
|
+
};
|
|
105
|
+
reportLaunchProgress("source_fingerprint_ready", 20, "Inventário canônico concluído.");
|
|
106
|
+
// Revalidate date-dependent payloads on every São Paulo calendar day.
|
|
107
|
+
let fingerprint = `${sourceSnapshot.fingerprint}\ncurrent_day=${saoPauloDay(new Date().toISOString())}`;
|
|
108
|
+
const fingerprintMs = Math.round(performance.now() - fingerprintStartedAt);
|
|
109
|
+
const existingFiles = readSnapshotFileCount(
|
|
110
|
+
path,
|
|
111
|
+
fingerprint,
|
|
112
|
+
readModelSchemaVersion,
|
|
113
|
+
hasReusableSnapshotPayloads,
|
|
114
|
+
);
|
|
115
|
+
if (existingFiles !== null && !options.forceCanonical && sourceSnapshot.hashedFiles === 0) {
|
|
116
|
+
validateSqliteReadModelSchema(path);
|
|
117
|
+
return {
|
|
118
|
+
files: existingFiles,
|
|
119
|
+
path,
|
|
120
|
+
cache: "generation",
|
|
121
|
+
fingerprint_ms: fingerprintMs,
|
|
122
|
+
materialize_ms: 0,
|
|
123
|
+
refresh,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
reportLaunchProgress(
|
|
128
|
+
"source_inventory",
|
|
129
|
+
52,
|
|
130
|
+
`Encontradas ${sourceSnapshot.candidates.length} fontes canônicas.`,
|
|
131
|
+
);
|
|
132
|
+
await mkdir(dirname(path), { recursive: true });
|
|
133
|
+
const database = new DatabaseSync(path);
|
|
134
|
+
let completedFiles = 0;
|
|
135
|
+
try {
|
|
136
|
+
database.exec("PRAGMA busy_timeout=180000; PRAGMA journal_mode=WAL; BEGIN IMMEDIATE;");
|
|
137
|
+
try {
|
|
138
|
+
// Another process may have finished an update while this writer waited.
|
|
139
|
+
// Capture canonical inputs only after acquiring exclusive writer ownership.
|
|
140
|
+
sourceSnapshot = await sourceFingerprint(
|
|
141
|
+
workspaceRoot,
|
|
142
|
+
options.forceCanonical
|
|
143
|
+
? { verifyContent: true }
|
|
144
|
+
: { previous: persistedSourceCheckpoint(path) },
|
|
145
|
+
);
|
|
146
|
+
refresh = {
|
|
147
|
+
reused_sources: sourceSnapshot.reusedFiles,
|
|
148
|
+
processed_sources: sourceSnapshot.hashedFiles,
|
|
149
|
+
added_sources: 0,
|
|
150
|
+
changed_sources: 0,
|
|
151
|
+
removed_sources: 0,
|
|
152
|
+
canonical_runs_refolded: 0,
|
|
153
|
+
};
|
|
154
|
+
fingerprint = `${sourceSnapshot.fingerprint}\ncurrent_day=${saoPauloDay(new Date().toISOString())}`;
|
|
155
|
+
// Keep the previous canonical bytes available while the transaction
|
|
156
|
+
// decides which sources changed. `files` is a persisted view over
|
|
157
|
+
// typed technical payloads, so a matching checkpoint can be reused
|
|
158
|
+
// without touching the canonical filesystem again. A missing source
|
|
159
|
+
// is deliberately absent from `sourceSnapshot` and is therefore not
|
|
160
|
+
// copied into the next materialization.
|
|
161
|
+
const persistedFiles = new Map(
|
|
162
|
+
(() => {
|
|
163
|
+
try {
|
|
164
|
+
return database
|
|
165
|
+
.prepare("SELECT path, content, content_sha256 FROM zaip_vw_files")
|
|
166
|
+
.all() as Array<{ path: string; content: string; content_sha256: string }>;
|
|
167
|
+
} catch {
|
|
168
|
+
// An older or incomplete schema takes the bootstrap path below.
|
|
169
|
+
return [] as Array<{ path: string; content: string; content_sha256: string }>;
|
|
170
|
+
}
|
|
171
|
+
})().map((row) => [row.path, row] as const),
|
|
172
|
+
);
|
|
173
|
+
const existing = database
|
|
174
|
+
.prepare("SELECT name, type FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'")
|
|
175
|
+
.all() as Array<{ name: string; type: string }>;
|
|
176
|
+
const hasPersistentSchema =
|
|
177
|
+
!options.forceCanonical &&
|
|
178
|
+
requiredPersistedTables.every((name) =>
|
|
179
|
+
existing.some((entry) => entry.type === "table" && entry.name === name),
|
|
180
|
+
) &&
|
|
181
|
+
requiredIndexes.every((name) =>
|
|
182
|
+
existing.some((entry) => entry.type === "index" && entry.name === name),
|
|
183
|
+
) &&
|
|
184
|
+
requiredViews.every((name) =>
|
|
185
|
+
existing.some((entry) => entry.type === "view" && entry.name === name),
|
|
186
|
+
) &&
|
|
187
|
+
(() => {
|
|
188
|
+
try {
|
|
189
|
+
const schemaVersion = database
|
|
190
|
+
.prepare("SELECT value FROM zaip_vw_read_model_metadata WHERE key='schema_version'")
|
|
191
|
+
.get() as { value?: string } | undefined;
|
|
192
|
+
database
|
|
193
|
+
.prepare(
|
|
194
|
+
"SELECT source_path, ctime_ms, file_identity FROM zaip_vw_read_model_source_state LIMIT 1",
|
|
195
|
+
)
|
|
196
|
+
.all();
|
|
197
|
+
return schemaVersion?.value === readModelSchemaVersion;
|
|
198
|
+
} catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
})();
|
|
202
|
+
const persistedSourceHashes = new Map(
|
|
203
|
+
(() => {
|
|
204
|
+
try {
|
|
205
|
+
return database
|
|
206
|
+
.prepare("SELECT source_path, source_hash FROM zaip_vw_read_model_source_state")
|
|
207
|
+
.all() as Array<{ source_path: string; source_hash: string }>;
|
|
208
|
+
} catch {
|
|
209
|
+
return [] as Array<{ source_path: string; source_hash: string }>;
|
|
210
|
+
}
|
|
211
|
+
})().map((row) => [row.source_path, row.source_hash] as const),
|
|
212
|
+
);
|
|
213
|
+
refresh = {
|
|
214
|
+
...refresh,
|
|
215
|
+
added_sources: sourceSnapshot.candidates.filter(
|
|
216
|
+
(candidate) => !persistedSourceHashes.has(candidate.source),
|
|
217
|
+
).length,
|
|
218
|
+
changed_sources: sourceSnapshot.candidates.filter((candidate) => {
|
|
219
|
+
const previous = persistedSourceHashes.get(candidate.source);
|
|
220
|
+
return previous !== undefined && previous !== candidate.contentHash;
|
|
221
|
+
}).length,
|
|
222
|
+
removed_sources: [...persistedSourceHashes.keys()].filter(
|
|
223
|
+
(source) => !sourceSnapshot.candidates.some((candidate) => candidate.source === source),
|
|
224
|
+
).length,
|
|
225
|
+
};
|
|
226
|
+
const changedCandidates = sourceSnapshot.candidates.filter(
|
|
227
|
+
(candidate) => persistedSourceHashes.get(candidate.source) !== candidate.contentHash,
|
|
228
|
+
);
|
|
229
|
+
const removedSources = [...persistedSourceHashes.keys()].filter(
|
|
230
|
+
(source) => !sourceSnapshot.candidates.some((candidate) => candidate.source === source),
|
|
231
|
+
);
|
|
232
|
+
if (hasPersistentSchema && changedCandidates.length === 0 && removedSources.length === 0) {
|
|
233
|
+
const oldFingerprint = database
|
|
234
|
+
.prepare("SELECT value FROM zaip_vw_read_model_metadata WHERE key='source_fingerprint'")
|
|
235
|
+
.get() as { value: string };
|
|
236
|
+
const checkpoint = persistedSourceCheckpoint(path);
|
|
237
|
+
for (const candidate of sourceSnapshot.candidates) {
|
|
238
|
+
const old = checkpoint.get(candidate.source);
|
|
239
|
+
if (
|
|
240
|
+
old &&
|
|
241
|
+
(old.mtimeMs !== candidate.mtimeMs ||
|
|
242
|
+
old.ctimeMs !== candidate.ctimeMs ||
|
|
243
|
+
old.fileIdentity !== candidate.fileIdentity)
|
|
244
|
+
)
|
|
245
|
+
database
|
|
246
|
+
.prepare(`UPDATE zaip_aios_activities SET payload_json=json_set(payload_json,'$.mtime_ms',?,'$.ctime_ms',?,'$.file_identity',?,'$.size_bytes',?)
|
|
247
|
+
WHERE payload_type='source_state' AND activity_key=?`)
|
|
248
|
+
.run(
|
|
249
|
+
String(candidate.mtimeMs),
|
|
250
|
+
String(candidate.ctimeMs),
|
|
251
|
+
candidate.fileIdentity,
|
|
252
|
+
candidate.size,
|
|
253
|
+
`source_state:${candidate.source}`,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
database
|
|
257
|
+
.prepare(
|
|
258
|
+
"UPDATE zaip_aios_activities SET payload_json=json_set(payload_json,'$.value',?) WHERE payload_type='metadata' AND activity_key='metadata:source_fingerprint'",
|
|
259
|
+
)
|
|
260
|
+
.run(fingerprint);
|
|
261
|
+
if (
|
|
262
|
+
oldFingerprint.value.split("\ncurrent_day=")[1] !== fingerprint.split("\ncurrent_day=")[1]
|
|
263
|
+
) {
|
|
264
|
+
database.exec(
|
|
265
|
+
"DELETE FROM zaip_aios_activities WHERE payload_type IN ('cost_monitor_summary_month_cache','first_fold_monthly_quick_cache')",
|
|
266
|
+
);
|
|
267
|
+
refreshFirstFoldPayloads(workspaceRoot, database);
|
|
268
|
+
}
|
|
269
|
+
database.exec("COMMIT;");
|
|
270
|
+
return {
|
|
271
|
+
files: sourceSnapshot.candidates.length,
|
|
272
|
+
path,
|
|
273
|
+
cache: "rebuilt",
|
|
274
|
+
fingerprint_ms: fingerprintMs,
|
|
275
|
+
materialize_ms: Math.round(performance.now() - fingerprintStartedAt),
|
|
276
|
+
refresh,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const candidateBySource = new Map(
|
|
280
|
+
sourceSnapshot.candidates.map((candidate) => [candidate.source, candidate]),
|
|
281
|
+
);
|
|
282
|
+
const changedSources = new Set([
|
|
283
|
+
...changedCandidates.map((candidate) => candidate.source),
|
|
284
|
+
...removedSources,
|
|
285
|
+
]);
|
|
286
|
+
const previousActivities = hasPersistentSchema
|
|
287
|
+
? (database
|
|
288
|
+
.prepare("SELECT * FROM zaip_aios_activities WHERE payload_type IS NULL")
|
|
289
|
+
.all() as Array<Record<string, any>>)
|
|
290
|
+
: [];
|
|
291
|
+
const previousRunIndex = hasPersistentSchema
|
|
292
|
+
? (database.prepare("SELECT * FROM zaip_vw_canonical_run_index").all() as Array<
|
|
293
|
+
Record<string, any>
|
|
294
|
+
>)
|
|
295
|
+
: [];
|
|
296
|
+
const previousUsage = hasPersistentSchema
|
|
297
|
+
? (database.prepare("SELECT * FROM zaip_vw_invocation_usage_segments").all() as Array<
|
|
298
|
+
Record<string, any>
|
|
299
|
+
>)
|
|
300
|
+
: [];
|
|
301
|
+
const previousDurations = hasPersistentSchema
|
|
302
|
+
? (database.prepare("SELECT * FROM zaip_vw_attributed_token_active_facts").all() as Array<
|
|
303
|
+
Record<string, any>
|
|
304
|
+
>)
|
|
305
|
+
: [];
|
|
306
|
+
const durationByRun = new Map(previousRunIndex.map((row) => [row.run_id, row.duration_ms]));
|
|
307
|
+
const intervalFor = (
|
|
308
|
+
row: Record<string, any>,
|
|
309
|
+
duration: number | null,
|
|
310
|
+
): TemporalInterval | null => {
|
|
311
|
+
if (!(row.total_tokens > 0) || duration === null || duration < 0) return null;
|
|
312
|
+
const startMs = Date.parse(row.source_started_at ?? row.occurred_at);
|
|
313
|
+
const endMs = Date.parse(row.source_finished_at ?? "") || startMs + duration;
|
|
314
|
+
return Number.isFinite(startMs) && Number.isFinite(endMs) && endMs > startMs
|
|
315
|
+
? { activityRowId: row.activity_row_id, startMs, endMs }
|
|
316
|
+
: null;
|
|
317
|
+
};
|
|
318
|
+
const oldIntervals = previousActivities.flatMap((row) => {
|
|
319
|
+
const interval = intervalFor(row, durationByRun.get(row.run_id) ?? null);
|
|
320
|
+
return interval ? [interval] : [];
|
|
321
|
+
});
|
|
322
|
+
const configurationChanged = [...changedSources].some(
|
|
323
|
+
(source) =>
|
|
324
|
+
source.startsWith(".agents/config/pricing/") ||
|
|
325
|
+
source === ".agents/config/agents/catalog.yaml" ||
|
|
326
|
+
source === ".agents/config/clients.yaml" ||
|
|
327
|
+
source.includes("/historical-developer-attribution/"),
|
|
328
|
+
);
|
|
329
|
+
const entityChanged = [...changedSources].some((source) =>
|
|
330
|
+
/^\.agents\/(?:data|records)\/(tasks|specs|prds)\//.test(source),
|
|
331
|
+
);
|
|
332
|
+
const changedCreationRunIds = new Set<string>();
|
|
333
|
+
if (hasPersistentSchema)
|
|
334
|
+
for (const source of changedSources) {
|
|
335
|
+
if (!/^\.agents\/(?:data|records)\/specs\//.test(source)) continue;
|
|
336
|
+
const cached = database
|
|
337
|
+
.prepare(
|
|
338
|
+
"SELECT payload_json FROM zaip_aios_activities WHERE payload_type='parsed_source' AND activity_key=?",
|
|
339
|
+
)
|
|
340
|
+
.get(`parsed_source:entities:${source}`) as { payload_json: string } | undefined;
|
|
341
|
+
if (cached)
|
|
342
|
+
for (const [, entity] of JSON.parse(cached.payload_json) as Array<
|
|
343
|
+
[string, CanonicalEntity]
|
|
344
|
+
>)
|
|
345
|
+
if (entity.creationRunId) changedCreationRunIds.add(entity.creationRunId);
|
|
346
|
+
}
|
|
347
|
+
const dirtyRunIds = new Set(
|
|
348
|
+
previousActivities
|
|
349
|
+
.filter((row) => configurationChanged || changedSources.has(row.source_path))
|
|
350
|
+
.map((row) => String(row.run_id)),
|
|
351
|
+
);
|
|
352
|
+
// A newly-added alternate layout has no prior activity row, but can name
|
|
353
|
+
// the same Run already materialized from the current layout. Mark that
|
|
354
|
+
// Run dirty before retaining canonical facts so the later preferred fold
|
|
355
|
+
// replaces it instead of colliding with a preserved run-index row.
|
|
356
|
+
for (const source of changedSources) {
|
|
357
|
+
const match = /^\.agents\/(?:data|records)\/runs\/.*\/([^/]+)\.jsonl$/.exec(source);
|
|
358
|
+
if (match?.[1]) dirtyRunIds.add(match[1]);
|
|
359
|
+
}
|
|
360
|
+
// A parent identity change may affect descendants even when their own bytes are unchanged.
|
|
361
|
+
let expanded = true;
|
|
362
|
+
while (expanded) {
|
|
363
|
+
expanded = false;
|
|
364
|
+
for (const row of previousActivities)
|
|
365
|
+
if (dirtyRunIds.has(row.parent_run_id) && !dirtyRunIds.has(row.run_id)) {
|
|
366
|
+
dirtyRunIds.add(row.run_id);
|
|
367
|
+
expanded = true;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const quote = (name: string) => `"${name.replaceAll('"', '""')}"`;
|
|
371
|
+
if (!hasPersistentSchema) {
|
|
372
|
+
for (const entry of existing.filter((entry) => entry.type === "view"))
|
|
373
|
+
database.exec(`DROP VIEW IF EXISTS ${quote(entry.name)}`);
|
|
374
|
+
for (const entry of existing.filter((entry) => entry.type === "table"))
|
|
375
|
+
database.exec(`DROP TABLE IF EXISTS ${quote(entry.name)}`);
|
|
376
|
+
} else {
|
|
377
|
+
// A refresh keeps the physical schema and source payload identities.
|
|
378
|
+
// Only derived facts are replaced; stable files/checkpoints survive
|
|
379
|
+
// untouched, while changed and removed sources are deleted below.
|
|
380
|
+
database.exec(`
|
|
381
|
+
DELETE FROM zaip_aios_activities
|
|
382
|
+
WHERE payload_type IS NOT NULL AND payload_type NOT IN ('file', 'source_state', 'parsed_source', 'usage_segment', 'run_index', 'duration_allocation', 'shared_creation_allocation', 'work_item', 'execution', 'change', 'decision', 'cost_dimension_aggregate_v1', 'cost_agent_invocation_projection_v1');
|
|
383
|
+
DELETE FROM zaip_dim_zaip_agent;
|
|
384
|
+
DELETE FROM zaip_dim_llm_model;
|
|
385
|
+
DELETE FROM zaip_dim_provider;
|
|
386
|
+
`);
|
|
387
|
+
try {
|
|
388
|
+
database.exec(
|
|
389
|
+
"DELETE FROM developer_cost_projection; DELETE FROM cost_invocation_dimension_facts;",
|
|
390
|
+
);
|
|
391
|
+
} catch {
|
|
392
|
+
// Older compatible models do not have every optional projection.
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
database.exec(`
|
|
396
|
+
CREATE TEMP TABLE files (path TEXT PRIMARY KEY, content TEXT NOT NULL, mtime_ms REAL NOT NULL, size_bytes INTEGER NOT NULL, content_sha256 TEXT NOT NULL, artifact_kind TEXT, artifact_id TEXT, artifact_occurred_at TEXT, artifact_occurred_day_sp TEXT, artifact_task_id TEXT, artifact_change_id TEXT, artifact_run_id TEXT);
|
|
397
|
+
CREATE TEMP TABLE read_model_source_state (source_path TEXT PRIMARY KEY, source_hash TEXT NOT NULL, mtime_ms TEXT NOT NULL, ctime_ms TEXT NOT NULL, size_bytes INTEGER NOT NULL, file_identity TEXT NOT NULL, source_kind TEXT NOT NULL, last_processed_at TEXT NOT NULL);
|
|
398
|
+
CREATE TEMP TABLE read_model_metadata (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
399
|
+
CREATE TEMP TABLE canonical_work_items (entity_kind TEXT NOT NULL, id TEXT NOT NULL, title TEXT, status TEXT, stage TEXT, risk TEXT, spec_id TEXT, change_id TEXT, creation_run_id TEXT, completed_run_id TEXT, occurred_at TEXT NOT NULL, occurred_day_sp TEXT NOT NULL, PRIMARY KEY(entity_kind, id));
|
|
400
|
+
CREATE TEMP TABLE canonical_executions (id TEXT PRIMARY KEY, status TEXT, kind TEXT, origin_type TEXT, origin_id TEXT, created_at TEXT NOT NULL, occurred_day_sp TEXT NOT NULL, finished_at TEXT, source_path TEXT NOT NULL);
|
|
401
|
+
CREATE TEMP TABLE canonical_changes (id TEXT PRIMARY KEY, title TEXT NOT NULL, status TEXT NOT NULL, risk TEXT NOT NULL, source_type TEXT NOT NULL, source_id TEXT NOT NULL, source_spec_id TEXT, source_prd_id TEXT, requirement_ids_json TEXT NOT NULL, acceptance_ids_json TEXT NOT NULL, task_ids_json TEXT NOT NULL, result TEXT, created_at TEXT NOT NULL, occurred_day_sp TEXT NOT NULL, source_path TEXT NOT NULL);
|
|
402
|
+
CREATE TEMP TABLE canonical_decisions (id TEXT PRIMARY KEY, title TEXT NOT NULL, origin TEXT NOT NULL, scope_type TEXT NOT NULL, scope_id TEXT NOT NULL, created_at TEXT NOT NULL, occurred_day_sp TEXT NOT NULL, source_path TEXT NOT NULL);
|
|
403
|
+
CREATE TEMP TABLE canonical_run_index (run_id TEXT PRIMARY KEY, occurred_at TEXT NOT NULL, occurred_day_sp TEXT NOT NULL, task_id TEXT, phase TEXT, run_role TEXT NOT NULL, duration_ms REAL, source_event_count INTEGER NOT NULL, zaip_agent TEXT, provider TEXT, model TEXT, status TEXT);
|
|
404
|
+
CREATE TEMP TABLE invocation_usage_segments (
|
|
405
|
+
agent_invocation_id TEXT NOT NULL, provider TEXT, model TEXT, service_tier TEXT, reasoning_effort TEXT,
|
|
406
|
+
input_tokens REAL, cached_input_tokens REAL, uncached_input_tokens REAL,
|
|
407
|
+
output_tokens REAL, reasoning_tokens REAL, visible_output_tokens REAL, total_tokens REAL,
|
|
408
|
+
input_rate_usd_per_million REAL, cached_input_rate_usd_per_million REAL,
|
|
409
|
+
output_rate_usd_per_million REAL, reasoning_rate_usd_per_million REAL,
|
|
410
|
+
context_input_multiplier REAL, context_output_multiplier REAL, speed_cost_multiplier REAL, pricing_scenario TEXT,
|
|
411
|
+
standard_cost_usd REAL, speed_uplift_usd REAL,
|
|
412
|
+
input_cost_usd REAL, cached_input_cost_usd REAL, output_cost_usd REAL, reasoning_cost_usd REAL,
|
|
413
|
+
calculated_cost_usd REAL, recorded_cost_usd REAL, cost_variance_usd REAL,
|
|
414
|
+
cost_usd REAL, cost_brl REAL, cost_method TEXT, pricing_model TEXT, pricing_source TEXT, fx_rate REAL
|
|
415
|
+
);
|
|
416
|
+
CREATE TABLE IF NOT EXISTS zaip_aios_activities (
|
|
417
|
+
activity_row_id TEXT PRIMARY KEY, activity_source_kind TEXT NOT NULL, activity_key TEXT NOT NULL,
|
|
418
|
+
source_path TEXT NOT NULL, source_hash TEXT NOT NULL, source_occurred_at TEXT, recorded_at TEXT NOT NULL, version_activity_id TEXT,
|
|
419
|
+
source_last_event_id TEXT, source_last_sequence INTEGER,
|
|
420
|
+
work_item_kind TEXT, title TEXT, work_item_status TEXT, work_stage TEXT, risk TEXT,
|
|
421
|
+
run_role TEXT NOT NULL, root_run_id TEXT NOT NULL, parent_run_id TEXT,
|
|
422
|
+
agent_run_id TEXT, root_agent_run_id TEXT, parent_agent_run_id TEXT, agent_run_role TEXT, delegation_depth INTEGER,
|
|
423
|
+
agent_invocation_id TEXT, root_agent_invocation_id TEXT, parent_agent_invocation_id TEXT, invocation_kind TEXT,
|
|
424
|
+
execution_id TEXT, task_id TEXT, spec_id TEXT, prd_id TEXT, change_id TEXT, conversation_id TEXT, run_id TEXT,
|
|
425
|
+
occurred_at TEXT, occurred_day_sp TEXT, execution_kind TEXT, entrypoint TEXT, work_type TEXT, phase TEXT, purpose TEXT, status TEXT, activity_kind TEXT,
|
|
426
|
+
zaip_agent TEXT, zaip_agent_persona TEXT, zaip_agent_job TEXT, zaip_agent_role TEXT, agent_catalog_id TEXT, agent_catalog_hash TEXT,
|
|
427
|
+
client TEXT, provider TEXT, model TEXT, service_tier TEXT, reasoning_effort TEXT,
|
|
428
|
+
developer_account_id TEXT, developer_login TEXT, developer_attribution_source TEXT,
|
|
429
|
+
source_duration_ms REAL, source_started_at TEXT, source_finished_at TEXT, duration_ms REAL, duration_provenance TEXT, input_tokens REAL, cached_input_tokens REAL, output_tokens REAL, reasoning_tokens REAL, total_tokens REAL, token_source TEXT, usage_event_count INTEGER, llm_call_count INTEGER,
|
|
430
|
+
cost_usd REAL, cost_brl REAL, cost_method TEXT, pricing_model TEXT, pricing_source TEXT, fx_rate REAL, source_event_count INTEGER,
|
|
431
|
+
root_run_duration REAL, sub_run_duration REAL,
|
|
432
|
+
payload_type TEXT, payload_json TEXT
|
|
433
|
+
);`);
|
|
434
|
+
database.exec(`
|
|
435
|
+
CREATE TABLE IF NOT EXISTS zaip_dim_zaip_agent (
|
|
436
|
+
zaip_agent TEXT PRIMARY KEY, catalog_id TEXT, persona TEXT, job TEXT, role TEXT, catalog_hash TEXT
|
|
437
|
+
);
|
|
438
|
+
CREATE TABLE IF NOT EXISTS zaip_dim_llm_model (
|
|
439
|
+
model TEXT PRIMARY KEY
|
|
440
|
+
);
|
|
441
|
+
CREATE TABLE IF NOT EXISTS zaip_dim_provider (
|
|
442
|
+
provider TEXT PRIMARY KEY
|
|
443
|
+
);
|
|
444
|
+
`);
|
|
445
|
+
// One materialized temporal fact at the activity (one canonical Run)
|
|
446
|
+
// grain. It is the only additive Tempo measure exposed to projections.
|
|
447
|
+
// NULL means the fact is genuinely unknown; 0 is an observed known zero.
|
|
448
|
+
database.exec(`CREATE TEMP TABLE attributed_token_active_facts (
|
|
449
|
+
activity_row_id TEXT NOT NULL,
|
|
450
|
+
occurred_day_sp TEXT NOT NULL,
|
|
451
|
+
attributed_token_active_ms REAL NOT NULL,
|
|
452
|
+
PRIMARY KEY(activity_row_id, occurred_day_sp)
|
|
453
|
+
);`);
|
|
454
|
+
database.exec(
|
|
455
|
+
"CREATE INDEX IF NOT EXISTS zaip_activities_payload ON zaip_aios_activities(payload_type, activity_key)",
|
|
456
|
+
);
|
|
457
|
+
const parsedSources = new SqliteParsedSourceCache(database);
|
|
458
|
+
const sourceHashFor = (source: string) => candidateBySource.get(source)?.contentHash ?? "";
|
|
459
|
+
const insertRows = (table: string, rows: Array<Record<string, any>>) => {
|
|
460
|
+
if (!rows.length) return;
|
|
461
|
+
const columns = Object.keys(rows[0]!);
|
|
462
|
+
const statement = database.prepare(
|
|
463
|
+
`INSERT INTO ${table}(${columns.join(",")}) VALUES (${columns.map(() => "?").join(",")})`,
|
|
464
|
+
);
|
|
465
|
+
for (const row of rows) statement.run(...columns.map((column) => row[column] ?? null));
|
|
466
|
+
};
|
|
467
|
+
insertRows(
|
|
468
|
+
"canonical_run_index",
|
|
469
|
+
previousRunIndex.filter((row) => !dirtyRunIds.has(row.run_id)),
|
|
470
|
+
);
|
|
471
|
+
const dirtyInvocationIds = new Set(
|
|
472
|
+
previousActivities
|
|
473
|
+
.filter((row) => dirtyRunIds.has(row.run_id))
|
|
474
|
+
.map((row) => row.agent_invocation_id),
|
|
475
|
+
);
|
|
476
|
+
insertRows(
|
|
477
|
+
"invocation_usage_segments",
|
|
478
|
+
previousUsage.filter((row) => !dirtyInvocationIds.has(row.agent_invocation_id)),
|
|
479
|
+
);
|
|
480
|
+
insertRows("attributed_token_active_facts", previousDurations);
|
|
481
|
+
for (const runId of dirtyRunIds)
|
|
482
|
+
database
|
|
483
|
+
.prepare("DELETE FROM zaip_aios_activities WHERE payload_type IS NULL AND run_id=?")
|
|
484
|
+
.run(runId);
|
|
485
|
+
for (const source of removedSources)
|
|
486
|
+
database
|
|
487
|
+
.prepare(
|
|
488
|
+
"DELETE FROM zaip_aios_activities WHERE payload_type='parsed_source' AND source_path=?",
|
|
489
|
+
)
|
|
490
|
+
.run(source);
|
|
491
|
+
const insert = database.prepare(
|
|
492
|
+
"INSERT INTO files(path, content, mtime_ms, size_bytes, content_sha256, artifact_kind, artifact_id, artifact_occurred_at, artifact_occurred_day_sp, artifact_task_id, artifact_change_id, artifact_run_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
493
|
+
);
|
|
494
|
+
const insertSourceState = database.prepare(
|
|
495
|
+
"INSERT INTO read_model_source_state(source_path, source_hash, mtime_ms, ctime_ms, size_bytes, file_identity, source_kind, last_processed_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
|
496
|
+
);
|
|
497
|
+
let files = 0;
|
|
498
|
+
const skipped = 0;
|
|
499
|
+
const sourceReadBatchSize = 32;
|
|
500
|
+
for (
|
|
501
|
+
let offset = 0;
|
|
502
|
+
offset < sourceSnapshot.candidates.length;
|
|
503
|
+
offset += sourceReadBatchSize
|
|
504
|
+
) {
|
|
505
|
+
const batch = sourceSnapshot.candidates.slice(offset, offset + sourceReadBatchSize);
|
|
506
|
+
// Parallel reads reduce cold I/O latency, while the following ordered
|
|
507
|
+
// loop retains deterministic SQLite inserts and canonical projections.
|
|
508
|
+
const contents = await Promise.all(
|
|
509
|
+
batch.map(async (candidate) => {
|
|
510
|
+
const previous = persistedFiles.get(candidate.source);
|
|
511
|
+
if (previous?.content_sha256 === candidate.contentHash) return previous.content;
|
|
512
|
+
// The fingerprint captured a stable stat/hash pair. Any read
|
|
513
|
+
// failure here must abort the transaction, preserving the prior
|
|
514
|
+
// complete model instead of treating an inaccessible file as a
|
|
515
|
+
// deletion.
|
|
516
|
+
const content = await readFile(candidate.path, "utf8");
|
|
517
|
+
if (createHash("sha256").update(content).digest("hex") !== candidate.contentHash)
|
|
518
|
+
throw new Error(`Canonical source changed during refresh: ${candidate.source}`);
|
|
519
|
+
return content;
|
|
520
|
+
}),
|
|
521
|
+
);
|
|
522
|
+
for (let index = 0; index < batch.length; index += 1) {
|
|
523
|
+
const candidate = batch[index];
|
|
524
|
+
const content = contents[index];
|
|
525
|
+
if (candidate === undefined || content === undefined) continue;
|
|
526
|
+
const { source, mtimeMs, ctimeMs, size, fileIdentity } = candidate;
|
|
527
|
+
const sourceHash = candidate.contentHash;
|
|
528
|
+
const sourceKind = source.includes("/runs/")
|
|
529
|
+
? "run"
|
|
530
|
+
: source.includes("/artifacts/evidence/")
|
|
531
|
+
? "evidence"
|
|
532
|
+
: source.includes("/artifacts/validations/") || source.includes("/artifacts/tests/")
|
|
533
|
+
? "validation"
|
|
534
|
+
: source.startsWith(".agents/config/")
|
|
535
|
+
? "config"
|
|
536
|
+
: "entity";
|
|
537
|
+
const artifact = parsedSources.read("artifact", source, sourceHash, () =>
|
|
538
|
+
readCanonicalArtifact(source, content),
|
|
539
|
+
);
|
|
540
|
+
insert.run(
|
|
541
|
+
source,
|
|
542
|
+
content,
|
|
543
|
+
mtimeMs,
|
|
544
|
+
size,
|
|
545
|
+
sourceHash,
|
|
546
|
+
artifact?.kind ?? null,
|
|
547
|
+
artifact?.id ?? null,
|
|
548
|
+
artifact?.occurredAt ?? null,
|
|
549
|
+
artifact?.occurredDaySp ?? null,
|
|
550
|
+
artifact?.taskId ?? null,
|
|
551
|
+
artifact?.changeId ?? null,
|
|
552
|
+
artifact?.runId ?? null,
|
|
553
|
+
);
|
|
554
|
+
insertSourceState.run(
|
|
555
|
+
source,
|
|
556
|
+
sourceHash,
|
|
557
|
+
String(mtimeMs),
|
|
558
|
+
String(ctimeMs),
|
|
559
|
+
size,
|
|
560
|
+
fileIdentity,
|
|
561
|
+
sourceKind,
|
|
562
|
+
new Date().toISOString(),
|
|
563
|
+
);
|
|
564
|
+
files += 1;
|
|
565
|
+
}
|
|
566
|
+
const completedPercent =
|
|
567
|
+
52 + Math.round(((offset + batch.length) / sourceSnapshot.candidates.length) * 20);
|
|
568
|
+
reportLaunchProgress(
|
|
569
|
+
"source_import",
|
|
570
|
+
completedPercent,
|
|
571
|
+
`Lidas ${Math.min(offset + batch.length, sourceSnapshot.candidates.length)} de ${sourceSnapshot.candidates.length} fontes.`,
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
reportLaunchProgress("projection_build", 74, "Organizando fatos e projeções do banco local.");
|
|
575
|
+
const canonicalRows = database
|
|
576
|
+
.prepare(
|
|
577
|
+
"SELECT path, content FROM files WHERE (path LIKE '.agents/data/%' OR path LIKE '.agents/records/%') AND path NOT LIKE '.agents/data/runs/%' AND path NOT LIKE '.agents/records/runs/%' ORDER BY CASE WHEN path LIKE '.agents/data/%' THEN 1 ELSE 0 END, path",
|
|
578
|
+
)
|
|
579
|
+
.all() as Array<{ path: string; content: string }>;
|
|
580
|
+
const canonicalEntities = new Map<string, CanonicalEntity>(
|
|
581
|
+
canonicalRows.flatMap((row) =>
|
|
582
|
+
parsedSources.read<Array<[string, CanonicalEntity]>>(
|
|
583
|
+
"entities",
|
|
584
|
+
row.path,
|
|
585
|
+
sourceHashFor(row.path),
|
|
586
|
+
() => [...readCanonicalEntities([row])],
|
|
587
|
+
),
|
|
588
|
+
),
|
|
589
|
+
);
|
|
590
|
+
for (const row of canonicalRows)
|
|
591
|
+
if (changedSources.has(row.path) && /^\.agents\/(?:data|records)\/specs\//.test(row.path))
|
|
592
|
+
for (const [, entity] of parsedSources.read<Array<[string, CanonicalEntity]>>(
|
|
593
|
+
"entities",
|
|
594
|
+
row.path,
|
|
595
|
+
sourceHashFor(row.path),
|
|
596
|
+
() => [...readCanonicalEntities([row])],
|
|
597
|
+
))
|
|
598
|
+
if (entity.creationRunId) changedCreationRunIds.add(entity.creationRunId);
|
|
599
|
+
const insertCanonicalWorkItem = database.prepare(
|
|
600
|
+
"INSERT INTO canonical_work_items(entity_kind, id, title, status, stage, risk, spec_id, change_id, creation_run_id, completed_run_id, occurred_at, occurred_day_sp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
601
|
+
);
|
|
602
|
+
for (const entity of canonicalEntities.values()) {
|
|
603
|
+
if (
|
|
604
|
+
(entity.kind !== "task" && entity.kind !== "spec" && entity.kind !== "prd") ||
|
|
605
|
+
entity.occurredAt === null ||
|
|
606
|
+
Number.isNaN(Date.parse(entity.occurredAt))
|
|
607
|
+
)
|
|
608
|
+
continue;
|
|
609
|
+
insertCanonicalWorkItem.run(
|
|
610
|
+
entity.kind,
|
|
611
|
+
entity.id,
|
|
612
|
+
entity.title,
|
|
613
|
+
entity.status,
|
|
614
|
+
entity.stage,
|
|
615
|
+
entity.risk,
|
|
616
|
+
entity.specId,
|
|
617
|
+
entity.changeId,
|
|
618
|
+
entity.creationRunId,
|
|
619
|
+
entity.completedRunId,
|
|
620
|
+
entity.occurredAt,
|
|
621
|
+
saoPauloDay(entity.occurredAt),
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
const canonicalLifecycle = {
|
|
625
|
+
executions: [] as CanonicalExecution[],
|
|
626
|
+
changes: [] as CanonicalChange[],
|
|
627
|
+
decisions: [] as CanonicalDecision[],
|
|
628
|
+
};
|
|
629
|
+
for (const row of canonicalRows) {
|
|
630
|
+
const parsed = parsedSources.read("lifecycle", row.path, sourceHashFor(row.path), () =>
|
|
631
|
+
readCanonicalLifecycleRecords([row]),
|
|
632
|
+
);
|
|
633
|
+
canonicalLifecycle.executions.push(...parsed.executions);
|
|
634
|
+
canonicalLifecycle.changes.push(...parsed.changes);
|
|
635
|
+
canonicalLifecycle.decisions.push(...parsed.decisions);
|
|
636
|
+
}
|
|
637
|
+
// Both supported layouts can coexist during an upgrade. SQL ordering puts
|
|
638
|
+
// .agents/data last, so the installed current record wins by stable ID.
|
|
639
|
+
canonicalLifecycle.executions = [
|
|
640
|
+
...new Map(canonicalLifecycle.executions.map((item) => [item.id, item])).values(),
|
|
641
|
+
];
|
|
642
|
+
canonicalLifecycle.changes = [
|
|
643
|
+
...new Map(canonicalLifecycle.changes.map((item) => [item.id, item])).values(),
|
|
644
|
+
];
|
|
645
|
+
canonicalLifecycle.decisions = [
|
|
646
|
+
...new Map(canonicalLifecycle.decisions.map((item) => [item.id, item])).values(),
|
|
647
|
+
];
|
|
648
|
+
const insertCanonicalExecution = database.prepare(
|
|
649
|
+
"INSERT INTO canonical_executions(id, status, kind, origin_type, origin_id, created_at, occurred_day_sp, finished_at, source_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
650
|
+
);
|
|
651
|
+
for (const entity of canonicalLifecycle.executions)
|
|
652
|
+
insertCanonicalExecution.run(
|
|
653
|
+
entity.id,
|
|
654
|
+
entity.status,
|
|
655
|
+
entity.kind,
|
|
656
|
+
entity.originType,
|
|
657
|
+
entity.originId,
|
|
658
|
+
entity.createdAt,
|
|
659
|
+
saoPauloDay(entity.createdAt),
|
|
660
|
+
entity.finishedAt,
|
|
661
|
+
entity.sourcePath,
|
|
662
|
+
);
|
|
663
|
+
const insertCanonicalChange = database.prepare(
|
|
664
|
+
"INSERT INTO canonical_changes(id, title, status, risk, source_type, source_id, source_spec_id, source_prd_id, requirement_ids_json, acceptance_ids_json, task_ids_json, result, created_at, occurred_day_sp, source_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
665
|
+
);
|
|
666
|
+
for (const entity of canonicalLifecycle.changes)
|
|
667
|
+
insertCanonicalChange.run(
|
|
668
|
+
entity.id,
|
|
669
|
+
entity.title,
|
|
670
|
+
entity.status,
|
|
671
|
+
entity.risk,
|
|
672
|
+
entity.sourceType,
|
|
673
|
+
entity.sourceId,
|
|
674
|
+
entity.sourceSpecId,
|
|
675
|
+
entity.sourcePrdId,
|
|
676
|
+
JSON.stringify(entity.requirementIds),
|
|
677
|
+
JSON.stringify(entity.acceptanceIds),
|
|
678
|
+
JSON.stringify(entity.taskIds),
|
|
679
|
+
entity.result,
|
|
680
|
+
entity.createdAt,
|
|
681
|
+
saoPauloDay(entity.createdAt),
|
|
682
|
+
entity.sourcePath,
|
|
683
|
+
);
|
|
684
|
+
const insertCanonicalDecision = database.prepare(
|
|
685
|
+
"INSERT INTO canonical_decisions(id, title, origin, scope_type, scope_id, created_at, occurred_day_sp, source_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
|
686
|
+
);
|
|
687
|
+
for (const entity of canonicalLifecycle.decisions)
|
|
688
|
+
insertCanonicalDecision.run(
|
|
689
|
+
entity.id,
|
|
690
|
+
entity.title,
|
|
691
|
+
entity.origin,
|
|
692
|
+
entity.scopeType,
|
|
693
|
+
entity.scopeId,
|
|
694
|
+
entity.createdAt,
|
|
695
|
+
saoPauloDay(entity.createdAt),
|
|
696
|
+
entity.sourcePath,
|
|
697
|
+
);
|
|
698
|
+
const runMaterialization = materializeCanonicalRuns({
|
|
699
|
+
database,
|
|
700
|
+
previousActivities,
|
|
701
|
+
parsedSources,
|
|
702
|
+
refresh,
|
|
703
|
+
hasPersistentSchema,
|
|
704
|
+
dirtyRunIds,
|
|
705
|
+
changedSources,
|
|
706
|
+
oldIntervals,
|
|
707
|
+
canonicalEntities,
|
|
708
|
+
entityChanged,
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// A single authoring sub-Run can create several sibling SPECs. Keep the
|
|
712
|
+
// Run canonical and attach deterministic shares only to the macro read
|
|
713
|
+
// model. Payload rows stay outside `activities`, preventing global
|
|
714
|
+
// Run/Cost totals from counting that Run more than once.
|
|
715
|
+
materializeDashboardProjections({
|
|
716
|
+
...runMaterialization,
|
|
717
|
+
database,
|
|
718
|
+
canonicalEntities,
|
|
719
|
+
changedCreationRunIds,
|
|
720
|
+
hasPersistentSchema,
|
|
721
|
+
files,
|
|
722
|
+
skipped,
|
|
723
|
+
fingerprint,
|
|
724
|
+
});
|
|
725
|
+
refreshFirstFoldPayloads(workspaceRoot, database);
|
|
726
|
+
database.exec("COMMIT;");
|
|
727
|
+
reportLaunchProgress(
|
|
728
|
+
"projection_finalize",
|
|
729
|
+
80,
|
|
730
|
+
"Finalizando índices do banco persistente do dashboard.",
|
|
731
|
+
);
|
|
732
|
+
completedFiles = files;
|
|
733
|
+
} catch (error) {
|
|
734
|
+
database.exec("ROLLBACK;");
|
|
735
|
+
throw error;
|
|
736
|
+
}
|
|
737
|
+
// Reclaim the transaction log when no reader pins an older snapshot.
|
|
738
|
+
// With the default zero busy timeout this never waits on a dashboard read;
|
|
739
|
+
// a busy checkpoint leaves the valid WAL for the next synchronization.
|
|
740
|
+
database.exec("PRAGMA busy_timeout=0; PRAGMA wal_checkpoint(TRUNCATE);");
|
|
741
|
+
} finally {
|
|
742
|
+
database.close();
|
|
743
|
+
}
|
|
744
|
+
const materializeStartedAt = fingerprintStartedAt + fingerprintMs;
|
|
745
|
+
reportLaunchProgress("snapshot_ready", 86, "O banco SQLite persistente está pronto.");
|
|
746
|
+
validateSqliteReadModelSchema(path);
|
|
747
|
+
return {
|
|
748
|
+
files: completedFiles,
|
|
749
|
+
path,
|
|
750
|
+
cache: "rebuilt",
|
|
751
|
+
fingerprint_ms: fingerprintMs,
|
|
752
|
+
materialize_ms: Math.round(performance.now() - materializeStartedAt),
|
|
753
|
+
refresh,
|
|
754
|
+
};
|
|
755
|
+
}
|