crca 1.4.0__py3-none-any.whl
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.
- .github/ISSUE_TEMPLATE/bug_report.md +65 -0
- .github/ISSUE_TEMPLATE/feature_request.md +41 -0
- .github/PULL_REQUEST_TEMPLATE.md +20 -0
- .github/workflows/publish-manual.yml +61 -0
- .github/workflows/publish.yml +64 -0
- .gitignore +214 -0
- CRCA.py +4156 -0
- LICENSE +201 -0
- MANIFEST.in +43 -0
- PKG-INFO +5035 -0
- README.md +4959 -0
- __init__.py +17 -0
- branches/CRCA-Q.py +2728 -0
- branches/crca_cg/corposwarm.py +9065 -0
- branches/crca_cg/fix_rancher_docker_creds.ps1 +155 -0
- branches/crca_cg/package.json +5 -0
- branches/crca_cg/test_bolt_integration.py +446 -0
- branches/crca_cg/test_corposwarm_comprehensive.py +773 -0
- branches/crca_cg/test_new_features.py +163 -0
- branches/crca_sd/__init__.py +149 -0
- branches/crca_sd/crca_sd_core.py +770 -0
- branches/crca_sd/crca_sd_governance.py +1325 -0
- branches/crca_sd/crca_sd_mpc.py +1130 -0
- branches/crca_sd/crca_sd_realtime.py +1844 -0
- branches/crca_sd/crca_sd_tui.py +1133 -0
- crca-1.4.0.dist-info/METADATA +5035 -0
- crca-1.4.0.dist-info/RECORD +501 -0
- crca-1.4.0.dist-info/WHEEL +4 -0
- crca-1.4.0.dist-info/licenses/LICENSE +201 -0
- docs/CRCA-Q.md +2333 -0
- examples/config.yaml.example +25 -0
- examples/crca_sd_example.py +513 -0
- examples/data_broker_example.py +294 -0
- examples/logistics_corporation.py +861 -0
- examples/palantir_example.py +299 -0
- examples/policy_bench.py +934 -0
- examples/pridnestrovia-sd.py +705 -0
- examples/pridnestrovia_realtime.py +1902 -0
- prompts/__init__.py +10 -0
- prompts/default_crca.py +101 -0
- pyproject.toml +151 -0
- requirements.txt +76 -0
- schemas/__init__.py +43 -0
- schemas/mcpSchemas.py +51 -0
- schemas/policy.py +458 -0
- templates/__init__.py +38 -0
- templates/base_specialized_agent.py +195 -0
- templates/drift_detection.py +325 -0
- templates/examples/causal_agent_template.py +309 -0
- templates/examples/drag_drop_example.py +213 -0
- templates/examples/logistics_agent_template.py +207 -0
- templates/examples/trading_agent_template.py +206 -0
- templates/feature_mixins.py +253 -0
- templates/graph_management.py +442 -0
- templates/llm_integration.py +194 -0
- templates/module_registry.py +276 -0
- templates/mpc_planner.py +280 -0
- templates/policy_loop.py +1168 -0
- templates/prediction_framework.py +448 -0
- templates/statistical_methods.py +778 -0
- tests/sanity.yml +31 -0
- tests/sanity_check +406 -0
- tests/test_core.py +47 -0
- tests/test_crca_excel.py +166 -0
- tests/test_crca_sd.py +780 -0
- tests/test_data_broker.py +424 -0
- tests/test_palantir.py +349 -0
- tools/__init__.py +38 -0
- tools/actuators.py +437 -0
- tools/bolt.diy/Dockerfile +103 -0
- tools/bolt.diy/app/components/@settings/core/AvatarDropdown.tsx +175 -0
- tools/bolt.diy/app/components/@settings/core/ControlPanel.tsx +345 -0
- tools/bolt.diy/app/components/@settings/core/constants.tsx +108 -0
- tools/bolt.diy/app/components/@settings/core/types.ts +114 -0
- tools/bolt.diy/app/components/@settings/index.ts +12 -0
- tools/bolt.diy/app/components/@settings/shared/components/TabTile.tsx +151 -0
- tools/bolt.diy/app/components/@settings/shared/service-integration/ConnectionForm.tsx +193 -0
- tools/bolt.diy/app/components/@settings/shared/service-integration/ConnectionTestIndicator.tsx +60 -0
- tools/bolt.diy/app/components/@settings/shared/service-integration/ErrorState.tsx +102 -0
- tools/bolt.diy/app/components/@settings/shared/service-integration/LoadingState.tsx +94 -0
- tools/bolt.diy/app/components/@settings/shared/service-integration/ServiceHeader.tsx +72 -0
- tools/bolt.diy/app/components/@settings/shared/service-integration/index.ts +6 -0
- tools/bolt.diy/app/components/@settings/tabs/data/DataTab.tsx +721 -0
- tools/bolt.diy/app/components/@settings/tabs/data/DataVisualization.tsx +384 -0
- tools/bolt.diy/app/components/@settings/tabs/event-logs/EventLogsTab.tsx +1013 -0
- tools/bolt.diy/app/components/@settings/tabs/features/FeaturesTab.tsx +295 -0
- tools/bolt.diy/app/components/@settings/tabs/github/GitHubTab.tsx +281 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubAuthDialog.tsx +173 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubCacheManager.tsx +367 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubConnection.tsx +233 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubErrorBoundary.tsx +105 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubProgressiveLoader.tsx +266 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubRepositoryCard.tsx +121 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubRepositorySelector.tsx +312 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubStats.tsx +291 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubUserProfile.tsx +46 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/shared/GitHubStateIndicators.tsx +264 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/shared/RepositoryCard.tsx +361 -0
- tools/bolt.diy/app/components/@settings/tabs/github/components/shared/index.ts +11 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/GitLabTab.tsx +305 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/GitLabAuthDialog.tsx +186 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/GitLabConnection.tsx +253 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/GitLabRepositorySelector.tsx +358 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/RepositoryCard.tsx +79 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/RepositoryList.tsx +142 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/StatsDisplay.tsx +91 -0
- tools/bolt.diy/app/components/@settings/tabs/gitlab/components/index.ts +4 -0
- tools/bolt.diy/app/components/@settings/tabs/mcp/McpServerList.tsx +99 -0
- tools/bolt.diy/app/components/@settings/tabs/mcp/McpServerListItem.tsx +70 -0
- tools/bolt.diy/app/components/@settings/tabs/mcp/McpStatusBadge.tsx +37 -0
- tools/bolt.diy/app/components/@settings/tabs/mcp/McpTab.tsx +239 -0
- tools/bolt.diy/app/components/@settings/tabs/netlify/NetlifyTab.tsx +1393 -0
- tools/bolt.diy/app/components/@settings/tabs/netlify/components/NetlifyConnection.tsx +990 -0
- tools/bolt.diy/app/components/@settings/tabs/netlify/components/index.ts +1 -0
- tools/bolt.diy/app/components/@settings/tabs/notifications/NotificationsTab.tsx +300 -0
- tools/bolt.diy/app/components/@settings/tabs/profile/ProfileTab.tsx +181 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/cloud/CloudProvidersTab.tsx +308 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/ErrorBoundary.tsx +68 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/HealthStatusBadge.tsx +64 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/LoadingSkeleton.tsx +107 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/LocalProvidersTab.tsx +556 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/ModelCard.tsx +106 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/ProviderCard.tsx +120 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/SetupGuide.tsx +671 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/StatusDashboard.tsx +91 -0
- tools/bolt.diy/app/components/@settings/tabs/providers/local/types.ts +44 -0
- tools/bolt.diy/app/components/@settings/tabs/settings/SettingsTab.tsx +215 -0
- tools/bolt.diy/app/components/@settings/tabs/supabase/SupabaseTab.tsx +1089 -0
- tools/bolt.diy/app/components/@settings/tabs/vercel/VercelTab.tsx +909 -0
- tools/bolt.diy/app/components/@settings/tabs/vercel/components/VercelConnection.tsx +368 -0
- tools/bolt.diy/app/components/@settings/tabs/vercel/components/index.ts +1 -0
- tools/bolt.diy/app/components/@settings/utils/tab-helpers.ts +54 -0
- tools/bolt.diy/app/components/chat/APIKeyManager.tsx +169 -0
- tools/bolt.diy/app/components/chat/Artifact.tsx +296 -0
- tools/bolt.diy/app/components/chat/AssistantMessage.tsx +192 -0
- tools/bolt.diy/app/components/chat/BaseChat.module.scss +47 -0
- tools/bolt.diy/app/components/chat/BaseChat.tsx +522 -0
- tools/bolt.diy/app/components/chat/Chat.client.tsx +670 -0
- tools/bolt.diy/app/components/chat/ChatAlert.tsx +108 -0
- tools/bolt.diy/app/components/chat/ChatBox.tsx +334 -0
- tools/bolt.diy/app/components/chat/CodeBlock.module.scss +10 -0
- tools/bolt.diy/app/components/chat/CodeBlock.tsx +85 -0
- tools/bolt.diy/app/components/chat/DicussMode.tsx +17 -0
- tools/bolt.diy/app/components/chat/ExamplePrompts.tsx +37 -0
- tools/bolt.diy/app/components/chat/FilePreview.tsx +38 -0
- tools/bolt.diy/app/components/chat/GitCloneButton.tsx +327 -0
- tools/bolt.diy/app/components/chat/ImportFolderButton.tsx +141 -0
- tools/bolt.diy/app/components/chat/LLMApiAlert.tsx +109 -0
- tools/bolt.diy/app/components/chat/MCPTools.tsx +129 -0
- tools/bolt.diy/app/components/chat/Markdown.module.scss +171 -0
- tools/bolt.diy/app/components/chat/Markdown.spec.ts +48 -0
- tools/bolt.diy/app/components/chat/Markdown.tsx +252 -0
- tools/bolt.diy/app/components/chat/Messages.client.tsx +102 -0
- tools/bolt.diy/app/components/chat/ModelSelector.tsx +797 -0
- tools/bolt.diy/app/components/chat/NetlifyDeploymentLink.client.tsx +51 -0
- tools/bolt.diy/app/components/chat/ProgressCompilation.tsx +110 -0
- tools/bolt.diy/app/components/chat/ScreenshotStateManager.tsx +33 -0
- tools/bolt.diy/app/components/chat/SendButton.client.tsx +39 -0
- tools/bolt.diy/app/components/chat/SpeechRecognition.tsx +28 -0
- tools/bolt.diy/app/components/chat/StarterTemplates.tsx +38 -0
- tools/bolt.diy/app/components/chat/SupabaseAlert.tsx +199 -0
- tools/bolt.diy/app/components/chat/SupabaseConnection.tsx +339 -0
- tools/bolt.diy/app/components/chat/ThoughtBox.tsx +43 -0
- tools/bolt.diy/app/components/chat/ToolInvocations.tsx +409 -0
- tools/bolt.diy/app/components/chat/UserMessage.tsx +101 -0
- tools/bolt.diy/app/components/chat/VercelDeploymentLink.client.tsx +158 -0
- tools/bolt.diy/app/components/chat/chatExportAndImport/ExportChatButton.tsx +49 -0
- tools/bolt.diy/app/components/chat/chatExportAndImport/ImportButtons.tsx +96 -0
- tools/bolt.diy/app/components/deploy/DeployAlert.tsx +197 -0
- tools/bolt.diy/app/components/deploy/DeployButton.tsx +277 -0
- tools/bolt.diy/app/components/deploy/GitHubDeploy.client.tsx +171 -0
- tools/bolt.diy/app/components/deploy/GitHubDeploymentDialog.tsx +1041 -0
- tools/bolt.diy/app/components/deploy/GitLabDeploy.client.tsx +171 -0
- tools/bolt.diy/app/components/deploy/GitLabDeploymentDialog.tsx +764 -0
- tools/bolt.diy/app/components/deploy/NetlifyDeploy.client.tsx +246 -0
- tools/bolt.diy/app/components/deploy/VercelDeploy.client.tsx +235 -0
- tools/bolt.diy/app/components/editor/codemirror/BinaryContent.tsx +7 -0
- tools/bolt.diy/app/components/editor/codemirror/CodeMirrorEditor.tsx +555 -0
- tools/bolt.diy/app/components/editor/codemirror/EnvMasking.ts +80 -0
- tools/bolt.diy/app/components/editor/codemirror/cm-theme.ts +192 -0
- tools/bolt.diy/app/components/editor/codemirror/indent.ts +68 -0
- tools/bolt.diy/app/components/editor/codemirror/languages.ts +112 -0
- tools/bolt.diy/app/components/git/GitUrlImport.client.tsx +147 -0
- tools/bolt.diy/app/components/header/Header.tsx +42 -0
- tools/bolt.diy/app/components/header/HeaderActionButtons.client.tsx +54 -0
- tools/bolt.diy/app/components/mandate/MandateSubmission.tsx +167 -0
- tools/bolt.diy/app/components/observability/DeploymentStatus.tsx +168 -0
- tools/bolt.diy/app/components/observability/EventTimeline.tsx +119 -0
- tools/bolt.diy/app/components/observability/FileDiffViewer.tsx +121 -0
- tools/bolt.diy/app/components/observability/GovernanceStatus.tsx +197 -0
- tools/bolt.diy/app/components/observability/GovernorMetrics.tsx +246 -0
- tools/bolt.diy/app/components/observability/LogStream.tsx +244 -0
- tools/bolt.diy/app/components/observability/MandateDetails.tsx +201 -0
- tools/bolt.diy/app/components/observability/ObservabilityDashboard.tsx +200 -0
- tools/bolt.diy/app/components/sidebar/HistoryItem.tsx +187 -0
- tools/bolt.diy/app/components/sidebar/Menu.client.tsx +536 -0
- tools/bolt.diy/app/components/sidebar/date-binning.ts +59 -0
- tools/bolt.diy/app/components/txt +1 -0
- tools/bolt.diy/app/components/ui/BackgroundRays/index.tsx +18 -0
- tools/bolt.diy/app/components/ui/BackgroundRays/styles.module.scss +246 -0
- tools/bolt.diy/app/components/ui/Badge.tsx +53 -0
- tools/bolt.diy/app/components/ui/BranchSelector.tsx +270 -0
- tools/bolt.diy/app/components/ui/Breadcrumbs.tsx +101 -0
- tools/bolt.diy/app/components/ui/Button.tsx +46 -0
- tools/bolt.diy/app/components/ui/Card.tsx +55 -0
- tools/bolt.diy/app/components/ui/Checkbox.tsx +32 -0
- tools/bolt.diy/app/components/ui/CloseButton.tsx +49 -0
- tools/bolt.diy/app/components/ui/CodeBlock.tsx +103 -0
- tools/bolt.diy/app/components/ui/Collapsible.tsx +9 -0
- tools/bolt.diy/app/components/ui/ColorSchemeDialog.tsx +378 -0
- tools/bolt.diy/app/components/ui/Dialog.tsx +449 -0
- tools/bolt.diy/app/components/ui/Dropdown.tsx +63 -0
- tools/bolt.diy/app/components/ui/EmptyState.tsx +154 -0
- tools/bolt.diy/app/components/ui/FileIcon.tsx +346 -0
- tools/bolt.diy/app/components/ui/FilterChip.tsx +92 -0
- tools/bolt.diy/app/components/ui/GlowingEffect.tsx +192 -0
- tools/bolt.diy/app/components/ui/GradientCard.tsx +100 -0
- tools/bolt.diy/app/components/ui/IconButton.tsx +84 -0
- tools/bolt.diy/app/components/ui/Input.tsx +22 -0
- tools/bolt.diy/app/components/ui/Label.tsx +20 -0
- tools/bolt.diy/app/components/ui/LoadingDots.tsx +27 -0
- tools/bolt.diy/app/components/ui/LoadingOverlay.tsx +32 -0
- tools/bolt.diy/app/components/ui/PanelHeader.tsx +20 -0
- tools/bolt.diy/app/components/ui/PanelHeaderButton.tsx +36 -0
- tools/bolt.diy/app/components/ui/Popover.tsx +29 -0
- tools/bolt.diy/app/components/ui/Progress.tsx +22 -0
- tools/bolt.diy/app/components/ui/RepositoryStats.tsx +87 -0
- tools/bolt.diy/app/components/ui/ScrollArea.tsx +41 -0
- tools/bolt.diy/app/components/ui/SearchInput.tsx +80 -0
- tools/bolt.diy/app/components/ui/SearchResultItem.tsx +134 -0
- tools/bolt.diy/app/components/ui/Separator.tsx +22 -0
- tools/bolt.diy/app/components/ui/SettingsButton.tsx +35 -0
- tools/bolt.diy/app/components/ui/Slider.tsx +73 -0
- tools/bolt.diy/app/components/ui/StatusIndicator.tsx +90 -0
- tools/bolt.diy/app/components/ui/Switch.tsx +37 -0
- tools/bolt.diy/app/components/ui/Tabs.tsx +52 -0
- tools/bolt.diy/app/components/ui/TabsWithSlider.tsx +112 -0
- tools/bolt.diy/app/components/ui/ThemeSwitch.tsx +29 -0
- tools/bolt.diy/app/components/ui/Tooltip.tsx +122 -0
- tools/bolt.diy/app/components/ui/index.ts +38 -0
- tools/bolt.diy/app/components/ui/use-toast.ts +66 -0
- tools/bolt.diy/app/components/workbench/DiffView.tsx +796 -0
- tools/bolt.diy/app/components/workbench/EditorPanel.tsx +174 -0
- tools/bolt.diy/app/components/workbench/ExpoQrModal.tsx +55 -0
- tools/bolt.diy/app/components/workbench/FileBreadcrumb.tsx +150 -0
- tools/bolt.diy/app/components/workbench/FileTree.tsx +565 -0
- tools/bolt.diy/app/components/workbench/Inspector.tsx +126 -0
- tools/bolt.diy/app/components/workbench/InspectorPanel.tsx +146 -0
- tools/bolt.diy/app/components/workbench/LockManager.tsx +262 -0
- tools/bolt.diy/app/components/workbench/PortDropdown.tsx +91 -0
- tools/bolt.diy/app/components/workbench/Preview.tsx +1049 -0
- tools/bolt.diy/app/components/workbench/ScreenshotSelector.tsx +293 -0
- tools/bolt.diy/app/components/workbench/Search.tsx +257 -0
- tools/bolt.diy/app/components/workbench/Workbench.client.tsx +506 -0
- tools/bolt.diy/app/components/workbench/terminal/Terminal.tsx +131 -0
- tools/bolt.diy/app/components/workbench/terminal/TerminalManager.tsx +68 -0
- tools/bolt.diy/app/components/workbench/terminal/TerminalTabs.tsx +277 -0
- tools/bolt.diy/app/components/workbench/terminal/theme.ts +36 -0
- tools/bolt.diy/app/components/workflow/WorkflowPhase.tsx +109 -0
- tools/bolt.diy/app/components/workflow/WorkflowStatus.tsx +60 -0
- tools/bolt.diy/app/components/workflow/WorkflowTimeline.tsx +150 -0
- tools/bolt.diy/app/entry.client.tsx +7 -0
- tools/bolt.diy/app/entry.server.tsx +80 -0
- tools/bolt.diy/app/root.tsx +156 -0
- tools/bolt.diy/app/routes/_index.tsx +175 -0
- tools/bolt.diy/app/routes/api.bug-report.ts +254 -0
- tools/bolt.diy/app/routes/api.chat.ts +463 -0
- tools/bolt.diy/app/routes/api.check-env-key.ts +41 -0
- tools/bolt.diy/app/routes/api.configured-providers.ts +110 -0
- tools/bolt.diy/app/routes/api.corporate-swarm-status.ts +55 -0
- tools/bolt.diy/app/routes/api.enhancer.ts +137 -0
- tools/bolt.diy/app/routes/api.export-api-keys.ts +44 -0
- tools/bolt.diy/app/routes/api.git-info.ts +69 -0
- tools/bolt.diy/app/routes/api.git-proxy.$.ts +178 -0
- tools/bolt.diy/app/routes/api.github-branches.ts +166 -0
- tools/bolt.diy/app/routes/api.github-deploy.ts +67 -0
- tools/bolt.diy/app/routes/api.github-stats.ts +198 -0
- tools/bolt.diy/app/routes/api.github-template.ts +242 -0
- tools/bolt.diy/app/routes/api.github-user.ts +287 -0
- tools/bolt.diy/app/routes/api.gitlab-branches.ts +143 -0
- tools/bolt.diy/app/routes/api.gitlab-deploy.ts +67 -0
- tools/bolt.diy/app/routes/api.gitlab-projects.ts +105 -0
- tools/bolt.diy/app/routes/api.health.ts +8 -0
- tools/bolt.diy/app/routes/api.llmcall.ts +298 -0
- tools/bolt.diy/app/routes/api.mandate.ts +351 -0
- tools/bolt.diy/app/routes/api.mcp-check.ts +16 -0
- tools/bolt.diy/app/routes/api.mcp-update-config.ts +23 -0
- tools/bolt.diy/app/routes/api.models.$provider.ts +2 -0
- tools/bolt.diy/app/routes/api.models.ts +90 -0
- tools/bolt.diy/app/routes/api.netlify-deploy.ts +240 -0
- tools/bolt.diy/app/routes/api.netlify-user.ts +142 -0
- tools/bolt.diy/app/routes/api.supabase-user.ts +199 -0
- tools/bolt.diy/app/routes/api.supabase.query.ts +92 -0
- tools/bolt.diy/app/routes/api.supabase.ts +56 -0
- tools/bolt.diy/app/routes/api.supabase.variables.ts +32 -0
- tools/bolt.diy/app/routes/api.system.diagnostics.ts +142 -0
- tools/bolt.diy/app/routes/api.system.disk-info.ts +311 -0
- tools/bolt.diy/app/routes/api.system.git-info.ts +332 -0
- tools/bolt.diy/app/routes/api.update.ts +21 -0
- tools/bolt.diy/app/routes/api.vercel-deploy.ts +497 -0
- tools/bolt.diy/app/routes/api.vercel-user.ts +161 -0
- tools/bolt.diy/app/routes/api.workflow-status.$proposalId.ts +309 -0
- tools/bolt.diy/app/routes/chat.$id.tsx +8 -0
- tools/bolt.diy/app/routes/execute.$mandateId.tsx +432 -0
- tools/bolt.diy/app/routes/git.tsx +25 -0
- tools/bolt.diy/app/routes/observability.$mandateId.tsx +50 -0
- tools/bolt.diy/app/routes/webcontainer.connect.$id.tsx +32 -0
- tools/bolt.diy/app/routes/webcontainer.preview.$id.tsx +97 -0
- tools/bolt.diy/app/routes/workflow.$proposalId.tsx +170 -0
- tools/bolt.diy/app/styles/animations.scss +49 -0
- tools/bolt.diy/app/styles/components/code.scss +9 -0
- tools/bolt.diy/app/styles/components/editor.scss +135 -0
- tools/bolt.diy/app/styles/components/resize-handle.scss +30 -0
- tools/bolt.diy/app/styles/components/terminal.scss +3 -0
- tools/bolt.diy/app/styles/components/toast.scss +23 -0
- tools/bolt.diy/app/styles/diff-view.css +72 -0
- tools/bolt.diy/app/styles/index.scss +73 -0
- tools/bolt.diy/app/styles/variables.scss +255 -0
- tools/bolt.diy/app/styles/z-index.scss +37 -0
- tools/bolt.diy/app/types/GitHub.ts +182 -0
- tools/bolt.diy/app/types/GitLab.ts +103 -0
- tools/bolt.diy/app/types/actions.ts +85 -0
- tools/bolt.diy/app/types/artifact.ts +5 -0
- tools/bolt.diy/app/types/context.ts +26 -0
- tools/bolt.diy/app/types/design-scheme.ts +93 -0
- tools/bolt.diy/app/types/global.d.ts +13 -0
- tools/bolt.diy/app/types/mandate.ts +333 -0
- tools/bolt.diy/app/types/model.ts +25 -0
- tools/bolt.diy/app/types/netlify.ts +94 -0
- tools/bolt.diy/app/types/supabase.ts +54 -0
- tools/bolt.diy/app/types/template.ts +8 -0
- tools/bolt.diy/app/types/terminal.ts +9 -0
- tools/bolt.diy/app/types/theme.ts +1 -0
- tools/bolt.diy/app/types/vercel.ts +67 -0
- tools/bolt.diy/app/utils/buffer.ts +29 -0
- tools/bolt.diy/app/utils/classNames.ts +65 -0
- tools/bolt.diy/app/utils/constants.ts +147 -0
- tools/bolt.diy/app/utils/debounce.ts +13 -0
- tools/bolt.diy/app/utils/debugLogger.ts +1284 -0
- tools/bolt.diy/app/utils/diff.spec.ts +11 -0
- tools/bolt.diy/app/utils/diff.ts +117 -0
- tools/bolt.diy/app/utils/easings.ts +3 -0
- tools/bolt.diy/app/utils/fileLocks.ts +96 -0
- tools/bolt.diy/app/utils/fileUtils.ts +121 -0
- tools/bolt.diy/app/utils/folderImport.ts +73 -0
- tools/bolt.diy/app/utils/formatSize.ts +12 -0
- tools/bolt.diy/app/utils/getLanguageFromExtension.ts +24 -0
- tools/bolt.diy/app/utils/githubStats.ts +9 -0
- tools/bolt.diy/app/utils/gitlabStats.ts +54 -0
- tools/bolt.diy/app/utils/logger.ts +162 -0
- tools/bolt.diy/app/utils/markdown.ts +155 -0
- tools/bolt.diy/app/utils/mobile.ts +4 -0
- tools/bolt.diy/app/utils/os.ts +4 -0
- tools/bolt.diy/app/utils/path.ts +19 -0
- tools/bolt.diy/app/utils/projectCommands.ts +197 -0
- tools/bolt.diy/app/utils/promises.ts +19 -0
- tools/bolt.diy/app/utils/react.ts +6 -0
- tools/bolt.diy/app/utils/sampler.ts +49 -0
- tools/bolt.diy/app/utils/selectStarterTemplate.ts +255 -0
- tools/bolt.diy/app/utils/shell.ts +384 -0
- tools/bolt.diy/app/utils/stacktrace.ts +27 -0
- tools/bolt.diy/app/utils/stripIndent.ts +23 -0
- tools/bolt.diy/app/utils/terminal.ts +11 -0
- tools/bolt.diy/app/utils/unreachable.ts +3 -0
- tools/bolt.diy/app/vite-env.d.ts +2 -0
- tools/bolt.diy/assets/entitlements.mac.plist +25 -0
- tools/bolt.diy/assets/icons/icon.icns +0 -0
- tools/bolt.diy/assets/icons/icon.ico +0 -0
- tools/bolt.diy/assets/icons/icon.png +0 -0
- tools/bolt.diy/bindings.js +78 -0
- tools/bolt.diy/bindings.sh +33 -0
- tools/bolt.diy/docker-compose.yaml +145 -0
- tools/bolt.diy/electron/main/index.ts +201 -0
- tools/bolt.diy/electron/main/tsconfig.json +30 -0
- tools/bolt.diy/electron/main/ui/menu.ts +29 -0
- tools/bolt.diy/electron/main/ui/window.ts +54 -0
- tools/bolt.diy/electron/main/utils/auto-update.ts +110 -0
- tools/bolt.diy/electron/main/utils/constants.ts +4 -0
- tools/bolt.diy/electron/main/utils/cookie.ts +40 -0
- tools/bolt.diy/electron/main/utils/reload.ts +35 -0
- tools/bolt.diy/electron/main/utils/serve.ts +71 -0
- tools/bolt.diy/electron/main/utils/store.ts +3 -0
- tools/bolt.diy/electron/main/utils/vite-server.ts +44 -0
- tools/bolt.diy/electron/main/vite.config.ts +44 -0
- tools/bolt.diy/electron/preload/index.ts +22 -0
- tools/bolt.diy/electron/preload/tsconfig.json +7 -0
- tools/bolt.diy/electron/preload/vite.config.ts +31 -0
- tools/bolt.diy/electron-builder.yml +64 -0
- tools/bolt.diy/electron-update.yml +4 -0
- tools/bolt.diy/eslint.config.mjs +57 -0
- tools/bolt.diy/functions/[[path]].ts +12 -0
- tools/bolt.diy/icons/angular.svg +1 -0
- tools/bolt.diy/icons/astro.svg +8 -0
- tools/bolt.diy/icons/chat.svg +1 -0
- tools/bolt.diy/icons/expo-brand.svg +1 -0
- tools/bolt.diy/icons/expo.svg +4 -0
- tools/bolt.diy/icons/logo-text.svg +1 -0
- tools/bolt.diy/icons/logo.svg +4 -0
- tools/bolt.diy/icons/mcp.svg +1 -0
- tools/bolt.diy/icons/nativescript.svg +1 -0
- tools/bolt.diy/icons/netlify.svg +10 -0
- tools/bolt.diy/icons/nextjs.svg +1 -0
- tools/bolt.diy/icons/nuxt.svg +1 -0
- tools/bolt.diy/icons/qwik.svg +1 -0
- tools/bolt.diy/icons/react.svg +1 -0
- tools/bolt.diy/icons/remix.svg +24 -0
- tools/bolt.diy/icons/remotion.svg +1 -0
- tools/bolt.diy/icons/shadcn.svg +21 -0
- tools/bolt.diy/icons/slidev.svg +60 -0
- tools/bolt.diy/icons/solidjs.svg +1 -0
- tools/bolt.diy/icons/stars.svg +1 -0
- tools/bolt.diy/icons/svelte.svg +1 -0
- tools/bolt.diy/icons/typescript.svg +1 -0
- tools/bolt.diy/icons/vite.svg +1 -0
- tools/bolt.diy/icons/vue.svg +1 -0
- tools/bolt.diy/load-context.ts +9 -0
- tools/bolt.diy/notarize.cjs +31 -0
- tools/bolt.diy/package.json +218 -0
- tools/bolt.diy/playwright.config.preview.ts +35 -0
- tools/bolt.diy/pre-start.cjs +26 -0
- tools/bolt.diy/public/apple-touch-icon-precomposed.png +0 -0
- tools/bolt.diy/public/apple-touch-icon.png +0 -0
- tools/bolt.diy/public/favicon.ico +0 -0
- tools/bolt.diy/public/favicon.svg +4 -0
- tools/bolt.diy/public/icons/AmazonBedrock.svg +1 -0
- tools/bolt.diy/public/icons/Anthropic.svg +4 -0
- tools/bolt.diy/public/icons/Cohere.svg +4 -0
- tools/bolt.diy/public/icons/Deepseek.svg +5 -0
- tools/bolt.diy/public/icons/Default.svg +4 -0
- tools/bolt.diy/public/icons/Google.svg +4 -0
- tools/bolt.diy/public/icons/Groq.svg +4 -0
- tools/bolt.diy/public/icons/HuggingFace.svg +4 -0
- tools/bolt.diy/public/icons/Hyperbolic.svg +3 -0
- tools/bolt.diy/public/icons/LMStudio.svg +5 -0
- tools/bolt.diy/public/icons/Mistral.svg +4 -0
- tools/bolt.diy/public/icons/Ollama.svg +4 -0
- tools/bolt.diy/public/icons/OpenAI.svg +4 -0
- tools/bolt.diy/public/icons/OpenAILike.svg +4 -0
- tools/bolt.diy/public/icons/OpenRouter.svg +4 -0
- tools/bolt.diy/public/icons/Perplexity.svg +4 -0
- tools/bolt.diy/public/icons/Together.svg +4 -0
- tools/bolt.diy/public/icons/xAI.svg +5 -0
- tools/bolt.diy/public/inspector-script.js +292 -0
- tools/bolt.diy/public/logo-dark-styled.png +0 -0
- tools/bolt.diy/public/logo-dark.png +0 -0
- tools/bolt.diy/public/logo-light-styled.png +0 -0
- tools/bolt.diy/public/logo-light.png +0 -0
- tools/bolt.diy/public/logo.svg +15 -0
- tools/bolt.diy/public/social_preview_index.jpg +0 -0
- tools/bolt.diy/scripts/clean.js +45 -0
- tools/bolt.diy/scripts/electron-dev.mjs +181 -0
- tools/bolt.diy/scripts/setup-env.sh +41 -0
- tools/bolt.diy/scripts/update-imports.sh +7 -0
- tools/bolt.diy/scripts/update.sh +52 -0
- tools/bolt.diy/services/execution-governor/Dockerfile +41 -0
- tools/bolt.diy/services/execution-governor/config.ts +42 -0
- tools/bolt.diy/services/execution-governor/index.ts +683 -0
- tools/bolt.diy/services/execution-governor/metrics.ts +141 -0
- tools/bolt.diy/services/execution-governor/package.json +31 -0
- tools/bolt.diy/services/execution-governor/priority-queue.ts +139 -0
- tools/bolt.diy/services/execution-governor/tsconfig.json +21 -0
- tools/bolt.diy/services/execution-governor/types.ts +145 -0
- tools/bolt.diy/services/headless-executor/Dockerfile +43 -0
- tools/bolt.diy/services/headless-executor/executor.ts +210 -0
- tools/bolt.diy/services/headless-executor/index.ts +323 -0
- tools/bolt.diy/services/headless-executor/package.json +27 -0
- tools/bolt.diy/services/headless-executor/tsconfig.json +21 -0
- tools/bolt.diy/services/headless-executor/types.ts +38 -0
- tools/bolt.diy/test-workflows.sh +240 -0
- tools/bolt.diy/tests/integration/corporate-swarm.test.ts +208 -0
- tools/bolt.diy/tests/mandates/budget-limited.json +34 -0
- tools/bolt.diy/tests/mandates/complex.json +53 -0
- tools/bolt.diy/tests/mandates/constraint-enforced.json +36 -0
- tools/bolt.diy/tests/mandates/simple.json +35 -0
- tools/bolt.diy/tsconfig.json +37 -0
- tools/bolt.diy/types/istextorbinary.d.ts +15 -0
- tools/bolt.diy/uno.config.ts +279 -0
- tools/bolt.diy/vite-electron.config.ts +76 -0
- tools/bolt.diy/vite.config.ts +112 -0
- tools/bolt.diy/worker-configuration.d.ts +22 -0
- tools/bolt.diy/wrangler.toml +6 -0
- tools/code_generator.py +461 -0
- tools/file_operations.py +465 -0
- tools/mandate_generator.py +337 -0
- tools/mcpClientUtils.py +1216 -0
- tools/sensors.py +285 -0
- utils/Agent_types.py +15 -0
- utils/AnyToStr.py +0 -0
- utils/HHCS.py +277 -0
- utils/__init__.py +30 -0
- utils/agent.py +3627 -0
- utils/aop.py +2948 -0
- utils/canonical.py +143 -0
- utils/conversation.py +1195 -0
- utils/doctrine_versioning +230 -0
- utils/formatter.py +474 -0
- utils/ledger.py +311 -0
- utils/out_types.py +16 -0
- utils/rollback.py +339 -0
- utils/router.py +929 -0
- utils/tui.py +1908 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Prediction framework module for specialized agents.
|
|
3
|
+
|
|
4
|
+
Provides prediction methods, standardization, caching, and counterfactual
|
|
5
|
+
scenario generation. Supports both linear and nonlinear prediction models.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Dict, List, Optional, Tuple, Any, Callable
|
|
9
|
+
import numpy as np
|
|
10
|
+
import threading
|
|
11
|
+
import logging
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class CounterfactualScenario:
|
|
19
|
+
"""
|
|
20
|
+
Represents a counterfactual scenario with interventions and expected outcomes.
|
|
21
|
+
"""
|
|
22
|
+
name: str
|
|
23
|
+
interventions: Dict[str, float]
|
|
24
|
+
expected_outcomes: Dict[str, float]
|
|
25
|
+
probability: float = 1.0
|
|
26
|
+
reasoning: str = ""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class PredictionFramework:
|
|
30
|
+
"""
|
|
31
|
+
Framework for making predictions and generating counterfactual scenarios.
|
|
32
|
+
|
|
33
|
+
Supports:
|
|
34
|
+
- Standardization/destandardization of variables
|
|
35
|
+
- Linear and nonlinear prediction models
|
|
36
|
+
- Caching of predictions
|
|
37
|
+
- Counterfactual scenario generation
|
|
38
|
+
- Abduction-action prediction (counterfactual reasoning)
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
graph_manager: Any, # GraphManager instance
|
|
44
|
+
standardization_stats: Optional[Dict[str, Dict[str, float]]] = None,
|
|
45
|
+
use_nonlinear: bool = True,
|
|
46
|
+
nonlinear_activation: str = "tanh",
|
|
47
|
+
interaction_terms: Optional[Dict[str, List[Tuple[str, str]]]] = None,
|
|
48
|
+
cache_enabled: bool = True,
|
|
49
|
+
cache_max_size: int = 1000,
|
|
50
|
+
):
|
|
51
|
+
"""
|
|
52
|
+
Initialize the prediction framework.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
graph_manager: GraphManager instance for graph operations
|
|
56
|
+
standardization_stats: Dictionary mapping variables to {mean, std}
|
|
57
|
+
use_nonlinear: Whether to use nonlinear prediction model
|
|
58
|
+
nonlinear_activation: Activation function ('tanh' or 'identity')
|
|
59
|
+
interaction_terms: Dictionary mapping nodes to interaction term pairs
|
|
60
|
+
cache_enabled: Whether to enable prediction caching
|
|
61
|
+
cache_max_size: Maximum cache size
|
|
62
|
+
"""
|
|
63
|
+
self.graph_manager = graph_manager
|
|
64
|
+
self.standardization_stats = standardization_stats or {}
|
|
65
|
+
self.use_nonlinear_scm = use_nonlinear
|
|
66
|
+
self.nonlinear_activation = nonlinear_activation
|
|
67
|
+
self.interaction_terms = interaction_terms or {}
|
|
68
|
+
self._cache_enabled = cache_enabled
|
|
69
|
+
self._prediction_cache: Dict[Tuple[Tuple[Tuple[str, float], ...], Tuple[Tuple[Tuple[str, float], ...]]], Dict[str, float]] = {}
|
|
70
|
+
self._prediction_cache_order: List[Tuple[Tuple[Tuple[str, float], ...], Tuple[Tuple[Tuple[str, float], ...]]]] = []
|
|
71
|
+
self._prediction_cache_max = cache_max_size
|
|
72
|
+
self._prediction_cache_lock = threading.Lock()
|
|
73
|
+
|
|
74
|
+
def standardize_state(self, state: Dict[str, float]) -> Dict[str, float]:
|
|
75
|
+
"""
|
|
76
|
+
Standardize a state dictionary using stored statistics.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
state: Dictionary mapping variables to values
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Dictionary mapping variables to standardized values
|
|
83
|
+
"""
|
|
84
|
+
z: Dict[str, float] = {}
|
|
85
|
+
for k, v in state.items():
|
|
86
|
+
s = self.standardization_stats.get(k)
|
|
87
|
+
if s and s.get("std", 0.0) > 0:
|
|
88
|
+
z[k] = (v - s["mean"]) / s["std"]
|
|
89
|
+
else:
|
|
90
|
+
z[k] = v
|
|
91
|
+
return z
|
|
92
|
+
|
|
93
|
+
def destandardize_value(self, var: str, z_value: float) -> float:
|
|
94
|
+
"""
|
|
95
|
+
Destandardize a single value.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
var: Variable name
|
|
99
|
+
z_value: Standardized value
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Destandardized value
|
|
103
|
+
"""
|
|
104
|
+
s = self.standardization_stats.get(var)
|
|
105
|
+
if s and s.get("std", 0.0) > 0:
|
|
106
|
+
return z_value * s["std"] + s["mean"]
|
|
107
|
+
return z_value
|
|
108
|
+
|
|
109
|
+
def set_standardization_stats(
|
|
110
|
+
self,
|
|
111
|
+
variable: str,
|
|
112
|
+
mean: float,
|
|
113
|
+
std: float
|
|
114
|
+
) -> None:
|
|
115
|
+
"""
|
|
116
|
+
Set standardization statistics for a variable.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
variable: Variable name
|
|
120
|
+
mean: Mean value
|
|
121
|
+
std: Standard deviation
|
|
122
|
+
"""
|
|
123
|
+
self.standardization_stats[variable] = {"mean": mean, "std": std if std > 0 else 1.0}
|
|
124
|
+
|
|
125
|
+
def ensure_standardization_stats(self, state: Dict[str, float]) -> None:
|
|
126
|
+
"""
|
|
127
|
+
Ensure standardization stats exist for all variables in state.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
state: State dictionary
|
|
131
|
+
"""
|
|
132
|
+
for var, val in state.items():
|
|
133
|
+
if var not in self.standardization_stats:
|
|
134
|
+
self.standardization_stats[var] = {"mean": float(val), "std": 1.0}
|
|
135
|
+
|
|
136
|
+
def predict_outcomes(
|
|
137
|
+
self,
|
|
138
|
+
factual_state: Dict[str, float],
|
|
139
|
+
interventions: Dict[str, float]
|
|
140
|
+
) -> Dict[str, float]:
|
|
141
|
+
"""
|
|
142
|
+
Predict outcomes given a factual state and interventions.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
factual_state: Current state
|
|
146
|
+
interventions: Interventions to apply
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
Dictionary of predicted outcomes
|
|
150
|
+
"""
|
|
151
|
+
if self.use_nonlinear_scm:
|
|
152
|
+
z_pred = self._predict_z(factual_state, interventions, use_noise=None)
|
|
153
|
+
return {v: self.destandardize_value(v, z_val) for v, z_val in z_pred.items()}
|
|
154
|
+
|
|
155
|
+
raw = factual_state.copy()
|
|
156
|
+
raw.update(interventions)
|
|
157
|
+
|
|
158
|
+
z_state = self.standardize_state(raw)
|
|
159
|
+
z_pred = dict(z_state)
|
|
160
|
+
|
|
161
|
+
for node in self.graph_manager.topological_sort():
|
|
162
|
+
if node in interventions:
|
|
163
|
+
if node not in z_pred:
|
|
164
|
+
z_pred[node] = z_state.get(node, 0.0)
|
|
165
|
+
continue
|
|
166
|
+
|
|
167
|
+
parents = self.graph_manager.get_parents(node)
|
|
168
|
+
if not parents:
|
|
169
|
+
continue
|
|
170
|
+
|
|
171
|
+
s = 0.0
|
|
172
|
+
for p in parents:
|
|
173
|
+
pz = z_pred.get(p, z_state.get(p, 0.0))
|
|
174
|
+
strength = self.graph_manager.edge_strength(p, node)
|
|
175
|
+
s += pz * strength
|
|
176
|
+
|
|
177
|
+
z_pred[node] = s
|
|
178
|
+
|
|
179
|
+
return {v: self.destandardize_value(v, z) for v, z in z_pred.items()}
|
|
180
|
+
|
|
181
|
+
def _predict_z(
|
|
182
|
+
self,
|
|
183
|
+
factual_state: Dict[str, float],
|
|
184
|
+
interventions: Dict[str, float],
|
|
185
|
+
use_noise: Optional[Dict[str, float]] = None
|
|
186
|
+
) -> Dict[str, float]:
|
|
187
|
+
"""
|
|
188
|
+
Predict outcomes in standardized space.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
factual_state: Current state
|
|
192
|
+
interventions: Interventions to apply
|
|
193
|
+
use_noise: Optional noise values to add
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
Dictionary of predicted standardized values
|
|
197
|
+
"""
|
|
198
|
+
raw = factual_state.copy()
|
|
199
|
+
raw.update(interventions)
|
|
200
|
+
z_state = self.standardize_state(raw)
|
|
201
|
+
z_pred: Dict[str, float] = dict(z_state)
|
|
202
|
+
|
|
203
|
+
for node in self.graph_manager.topological_sort():
|
|
204
|
+
if node in interventions:
|
|
205
|
+
z_pred[node] = z_state.get(node, 0.0)
|
|
206
|
+
continue
|
|
207
|
+
|
|
208
|
+
parents = self.graph_manager.get_parents(node)
|
|
209
|
+
if not parents:
|
|
210
|
+
z_val = float(use_noise.get(node, 0.0)) if use_noise else z_state.get(node, 0.0)
|
|
211
|
+
z_pred[node] = z_val
|
|
212
|
+
continue
|
|
213
|
+
|
|
214
|
+
linear_term = 0.0
|
|
215
|
+
for p in parents:
|
|
216
|
+
parent_z = z_pred.get(p, z_state.get(p, 0.0))
|
|
217
|
+
beta = self.graph_manager.edge_strength(p, node)
|
|
218
|
+
linear_term += parent_z * beta
|
|
219
|
+
|
|
220
|
+
interaction_term = 0.0
|
|
221
|
+
for (p1, p2) in self.interaction_terms.get(node, []):
|
|
222
|
+
if p1 in parents and p2 in parents:
|
|
223
|
+
z1 = z_pred.get(p1, z_state.get(p1, 0.0))
|
|
224
|
+
z2 = z_pred.get(p2, z_state.get(p2, 0.0))
|
|
225
|
+
gamma = 0.0
|
|
226
|
+
edge_data = self.graph_manager.graph.get(p1, {}).get(node, {})
|
|
227
|
+
if isinstance(edge_data, dict):
|
|
228
|
+
gamma = float(edge_data.get("interaction_strength", {}).get(p2, 0.0))
|
|
229
|
+
interaction_term += gamma * z1 * z2
|
|
230
|
+
|
|
231
|
+
model_z = linear_term + interaction_term
|
|
232
|
+
|
|
233
|
+
if use_noise:
|
|
234
|
+
model_z += float(use_noise.get(node, 0.0))
|
|
235
|
+
|
|
236
|
+
if self.nonlinear_activation == "tanh":
|
|
237
|
+
model_z_act = float(np.tanh(model_z) * 3.0) # scale to limit
|
|
238
|
+
else:
|
|
239
|
+
model_z_act = float(model_z)
|
|
240
|
+
|
|
241
|
+
observed_z = z_state.get(node, 0.0)
|
|
242
|
+
|
|
243
|
+
threshold = float(getattr(self, "shock_preserve_threshold", 1e-3))
|
|
244
|
+
if abs(observed_z) > threshold:
|
|
245
|
+
z_pred[node] = float(observed_z)
|
|
246
|
+
else:
|
|
247
|
+
z_pred[node] = float(model_z_act)
|
|
248
|
+
|
|
249
|
+
return z_pred
|
|
250
|
+
|
|
251
|
+
def predict_outcomes_cached(
|
|
252
|
+
self,
|
|
253
|
+
factual_state: Dict[str, float],
|
|
254
|
+
interventions: Dict[str, float],
|
|
255
|
+
) -> Dict[str, float]:
|
|
256
|
+
"""
|
|
257
|
+
Predict outcomes with caching.
|
|
258
|
+
|
|
259
|
+
Args:
|
|
260
|
+
factual_state: Current state
|
|
261
|
+
interventions: Interventions to apply
|
|
262
|
+
|
|
263
|
+
Returns:
|
|
264
|
+
Dictionary of predicted outcomes
|
|
265
|
+
"""
|
|
266
|
+
with self._prediction_cache_lock:
|
|
267
|
+
cache_enabled = self._cache_enabled
|
|
268
|
+
if not cache_enabled:
|
|
269
|
+
return self.predict_outcomes(factual_state, interventions)
|
|
270
|
+
|
|
271
|
+
state_key = tuple(sorted([(k, float(v)) for k, v in factual_state.items()]))
|
|
272
|
+
inter_key = tuple(sorted([(k, float(v)) for k, v in interventions.items()]))
|
|
273
|
+
cache_key = (state_key, inter_key)
|
|
274
|
+
|
|
275
|
+
with self._prediction_cache_lock:
|
|
276
|
+
if cache_key in self._prediction_cache:
|
|
277
|
+
return dict(self._prediction_cache[cache_key])
|
|
278
|
+
|
|
279
|
+
result = self.predict_outcomes(factual_state, interventions)
|
|
280
|
+
|
|
281
|
+
with self._prediction_cache_lock:
|
|
282
|
+
if len(self._prediction_cache_order) >= self._prediction_cache_max:
|
|
283
|
+
remove_count = max(1, self._prediction_cache_max // 10)
|
|
284
|
+
for _ in range(remove_count):
|
|
285
|
+
old = self._prediction_cache_order.pop(0)
|
|
286
|
+
if old in self._prediction_cache:
|
|
287
|
+
del self._prediction_cache[old]
|
|
288
|
+
|
|
289
|
+
self._prediction_cache_order.append(cache_key)
|
|
290
|
+
self._prediction_cache[cache_key] = dict(result)
|
|
291
|
+
return result
|
|
292
|
+
|
|
293
|
+
def counterfactual_abduction_action_prediction(
|
|
294
|
+
self,
|
|
295
|
+
factual_state: Dict[str, float],
|
|
296
|
+
interventions: Dict[str, float]
|
|
297
|
+
) -> Dict[str, float]:
|
|
298
|
+
"""
|
|
299
|
+
Perform counterfactual abduction-action prediction.
|
|
300
|
+
|
|
301
|
+
This method preserves the noise from the factual state when making
|
|
302
|
+
counterfactual predictions, enabling proper counterfactual reasoning.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
factual_state: The factual (observed) state
|
|
306
|
+
interventions: Interventions to apply in the counterfactual
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
Dictionary of counterfactual predictions
|
|
310
|
+
"""
|
|
311
|
+
z = self.standardize_state(factual_state)
|
|
312
|
+
|
|
313
|
+
noise: Dict[str, float] = {}
|
|
314
|
+
for node in self.graph_manager.topological_sort():
|
|
315
|
+
parents = self.graph_manager.get_parents(node)
|
|
316
|
+
if not parents:
|
|
317
|
+
noise[node] = float(z.get(node, 0.0))
|
|
318
|
+
continue
|
|
319
|
+
|
|
320
|
+
pred_z = 0.0
|
|
321
|
+
for p in parents:
|
|
322
|
+
pz = z.get(p, 0.0)
|
|
323
|
+
strength = self.graph_manager.edge_strength(p, node)
|
|
324
|
+
pred_z += pz * strength
|
|
325
|
+
|
|
326
|
+
noise[node] = float(z.get(node, 0.0) - pred_z)
|
|
327
|
+
|
|
328
|
+
cf_raw = factual_state.copy()
|
|
329
|
+
cf_raw.update(interventions)
|
|
330
|
+
z_cf = self.standardize_state(cf_raw)
|
|
331
|
+
|
|
332
|
+
z_pred: Dict[str, float] = {}
|
|
333
|
+
for node in self.graph_manager.topological_sort():
|
|
334
|
+
if node in interventions:
|
|
335
|
+
z_pred[node] = float(z_cf.get(node, 0.0))
|
|
336
|
+
continue
|
|
337
|
+
|
|
338
|
+
parents = self.graph_manager.get_parents(node)
|
|
339
|
+
if not parents:
|
|
340
|
+
z_pred[node] = float(noise.get(node, 0.0))
|
|
341
|
+
continue
|
|
342
|
+
|
|
343
|
+
val = 0.0
|
|
344
|
+
for p in parents:
|
|
345
|
+
parent_z = z_pred.get(p, z_cf.get(p, 0.0))
|
|
346
|
+
strength = self.graph_manager.edge_strength(p, node)
|
|
347
|
+
val += parent_z * strength
|
|
348
|
+
|
|
349
|
+
z_pred[node] = float(val + noise.get(node, 0.0))
|
|
350
|
+
|
|
351
|
+
return {v: self.destandardize_value(v, z_val) for v, z_val in z_pred.items()}
|
|
352
|
+
|
|
353
|
+
def calculate_scenario_probability(
|
|
354
|
+
self,
|
|
355
|
+
factual_state: Dict[str, float],
|
|
356
|
+
interventions: Dict[str, float]
|
|
357
|
+
) -> float:
|
|
358
|
+
"""
|
|
359
|
+
Calculate the probability of a counterfactual scenario.
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
factual_state: Current state
|
|
363
|
+
interventions: Proposed interventions
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
Probability value between 0.05 and 0.98
|
|
367
|
+
"""
|
|
368
|
+
z_sq = 0.0
|
|
369
|
+
for var, new in interventions.items():
|
|
370
|
+
s = self.standardization_stats.get(var, {"mean": 0.0, "std": 1.0})
|
|
371
|
+
mu, sd = s.get("mean", 0.0), s.get("std", 1.0) or 1.0
|
|
372
|
+
old = factual_state.get(var, mu)
|
|
373
|
+
dz = (new - mu) / sd - (old - mu) / sd
|
|
374
|
+
z_sq += float(dz) * float(dz)
|
|
375
|
+
|
|
376
|
+
p = 0.95 * float(np.exp(-0.5 * z_sq)) + 0.05
|
|
377
|
+
return float(max(0.05, min(0.98, p)))
|
|
378
|
+
|
|
379
|
+
def generate_counterfactual_scenarios(
|
|
380
|
+
self,
|
|
381
|
+
factual_state: Dict[str, float],
|
|
382
|
+
target_variables: List[str],
|
|
383
|
+
max_scenarios: int = 5
|
|
384
|
+
) -> List[CounterfactualScenario]:
|
|
385
|
+
"""
|
|
386
|
+
Generate counterfactual scenarios for target variables.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
factual_state: Current state
|
|
390
|
+
target_variables: Variables to generate scenarios for
|
|
391
|
+
max_scenarios: Maximum number of scenarios per variable
|
|
392
|
+
|
|
393
|
+
Returns:
|
|
394
|
+
List of CounterfactualScenario objects
|
|
395
|
+
"""
|
|
396
|
+
self.ensure_standardization_stats(factual_state)
|
|
397
|
+
|
|
398
|
+
scenarios: List[CounterfactualScenario] = []
|
|
399
|
+
z_steps = [-2.0, -1.0, -0.5, 0.5, 1.0, 2.0]
|
|
400
|
+
|
|
401
|
+
for i, tv in enumerate(target_variables[:max_scenarios]):
|
|
402
|
+
stats = self.standardization_stats.get(tv, {"mean": 0.0, "std": 1.0})
|
|
403
|
+
cur = factual_state.get(tv, stats.get("mean", 0.0))
|
|
404
|
+
|
|
405
|
+
if not stats or stats.get("std", 0.0) <= 0:
|
|
406
|
+
base = cur
|
|
407
|
+
abs_steps = [-2.0, -1.0, -0.5, 0.5, 1.0, 2.0]
|
|
408
|
+
vals = [base + step for step in abs_steps]
|
|
409
|
+
else:
|
|
410
|
+
mean = stats["mean"]
|
|
411
|
+
std = stats["std"]
|
|
412
|
+
cz = (cur - mean) / std
|
|
413
|
+
vals = [(cz + dz) * std + mean for dz in z_steps]
|
|
414
|
+
|
|
415
|
+
for j, v in enumerate(vals):
|
|
416
|
+
interventions = {tv: float(v)}
|
|
417
|
+
scenarios.append(
|
|
418
|
+
CounterfactualScenario(
|
|
419
|
+
name=f"scenario_{i}_{j}",
|
|
420
|
+
interventions=interventions,
|
|
421
|
+
expected_outcomes=self.predict_outcomes(
|
|
422
|
+
factual_state, interventions
|
|
423
|
+
),
|
|
424
|
+
probability=self.calculate_scenario_probability(
|
|
425
|
+
factual_state, interventions
|
|
426
|
+
),
|
|
427
|
+
reasoning=f"Intervention on {tv} with value {v}",
|
|
428
|
+
)
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
return scenarios
|
|
432
|
+
|
|
433
|
+
def clear_cache(self) -> None:
|
|
434
|
+
"""Clear the prediction cache."""
|
|
435
|
+
with self._prediction_cache_lock:
|
|
436
|
+
self._prediction_cache.clear()
|
|
437
|
+
self._prediction_cache_order.clear()
|
|
438
|
+
|
|
439
|
+
def enable_cache(self, flag: bool) -> None:
|
|
440
|
+
"""
|
|
441
|
+
Enable or disable caching.
|
|
442
|
+
|
|
443
|
+
Args:
|
|
444
|
+
flag: True to enable, False to disable
|
|
445
|
+
"""
|
|
446
|
+
with self._prediction_cache_lock:
|
|
447
|
+
self._cache_enabled = bool(flag)
|
|
448
|
+
|