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,25 @@
|
|
|
1
|
+
# Pridnestrovia Real-Time Control System Configuration
|
|
2
|
+
#
|
|
3
|
+
# Copy this file to config.yaml and fill in your actual API keys.
|
|
4
|
+
# DO NOT commit config.yaml to version control!
|
|
5
|
+
|
|
6
|
+
# Treasury API Configuration
|
|
7
|
+
treasury_api_url: "https://api.pridnestrovia.gov/treasury"
|
|
8
|
+
treasury_api_key: "YOUR_TREASURY_API_KEY_HERE"
|
|
9
|
+
|
|
10
|
+
# Ministries API Configuration
|
|
11
|
+
ministries_api_url: "https://api.pridnestrovia.gov/ministries"
|
|
12
|
+
ministries_api_key: "YOUR_MINISTRIES_API_KEY_HERE"
|
|
13
|
+
|
|
14
|
+
# Central Bank API Configuration
|
|
15
|
+
central_bank_api_url: "https://api.pridnestrovia.gov/centralbank"
|
|
16
|
+
central_bank_api_key: "YOUR_CENTRAL_BANK_API_KEY_HERE"
|
|
17
|
+
|
|
18
|
+
# Optional: Custom update frequencies (in seconds)
|
|
19
|
+
# data_update_frequency: 86400 # Daily (default)
|
|
20
|
+
# monitoring_frequency: 300 # Every 5 minutes (default)
|
|
21
|
+
|
|
22
|
+
# Optional: Safety thresholds
|
|
23
|
+
# major_change_threshold: 0.10 # 10% (default)
|
|
24
|
+
# confidence_threshold: 0.95 # 95% (default)
|
|
25
|
+
|
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CRCA-SD Example: Complete System Workflow Demonstration
|
|
3
|
+
|
|
4
|
+
This example demonstrates:
|
|
5
|
+
- Phase A: Initialize state, sample policies, simulate forward, check feasibility
|
|
6
|
+
- Phase B: Run MPC solver, extract Pareto frontier, compute CVaR risk
|
|
7
|
+
- Phase C: State estimation with noisy observations, board evaluation, arbitration
|
|
8
|
+
- Phase D: Logistics network optimization, visualization, metrics collection
|
|
9
|
+
- Full workflow: End-to-end example showing all phases integrated
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import List, Dict
|
|
13
|
+
import numpy as np
|
|
14
|
+
from loguru import logger
|
|
15
|
+
|
|
16
|
+
# Import CRCA-SD components
|
|
17
|
+
from crca_sd.crca_sd_core import (
|
|
18
|
+
StateVector,
|
|
19
|
+
ControlVector,
|
|
20
|
+
DynamicsModel,
|
|
21
|
+
ConstraintChecker,
|
|
22
|
+
ForwardSimulator,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from crca_sd.crca_sd_mpc import (
|
|
26
|
+
ObjectiveVector,
|
|
27
|
+
CVaRComputer,
|
|
28
|
+
MPCSolver,
|
|
29
|
+
ScenarioGenerator,
|
|
30
|
+
StabilityEnforcer,
|
|
31
|
+
ParetoExtractor,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from crca_sd.crca_sd_governance import (
|
|
35
|
+
BoardMember,
|
|
36
|
+
Board,
|
|
37
|
+
BoardType,
|
|
38
|
+
Arbitration,
|
|
39
|
+
GovernanceSystem,
|
|
40
|
+
LogisticsNetwork,
|
|
41
|
+
Visualization,
|
|
42
|
+
MetricsCollector,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def phase_a_basic_simulation():
|
|
47
|
+
"""
|
|
48
|
+
Phase A: Minimal viable "toy world" demonstration.
|
|
49
|
+
|
|
50
|
+
- Initialize state with 15 variables
|
|
51
|
+
- Sample budget policies
|
|
52
|
+
- Simulate forward 10 steps
|
|
53
|
+
- Check feasibility
|
|
54
|
+
"""
|
|
55
|
+
logger.info("=== Phase A: Basic Simulation ===")
|
|
56
|
+
|
|
57
|
+
# Initialize state
|
|
58
|
+
x_0 = StateVector(
|
|
59
|
+
P=1000000.0, # 1 million population
|
|
60
|
+
L=500000.0, # 500k labor force
|
|
61
|
+
U=0.05, # 5% unemployment
|
|
62
|
+
W=1.0, # Wage proxy
|
|
63
|
+
S=0.8, # 80% stability
|
|
64
|
+
literacy=0.7, # 70% literacy
|
|
65
|
+
Ecap=10000.0, # Education capacity
|
|
66
|
+
Hcap=5000.0, # Healthcare capacity
|
|
67
|
+
K=1000000.0, # Capital stock
|
|
68
|
+
I=0.8, # 80% infrastructure health
|
|
69
|
+
Tcap=10000.0, # Transport capacity
|
|
70
|
+
E_stock=50000.0, # Energy stock
|
|
71
|
+
F_stock=30000.0, # Food stock
|
|
72
|
+
M_stock=20000.0, # Materials stock
|
|
73
|
+
C=0.0, # No ecological damage yet
|
|
74
|
+
Y=1000000.0, # GDP proxy
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
logger.info(f"Initial state: P={x_0.P:,.0f}, U={x_0.U:.1%}, Y={x_0.Y:,.0f}")
|
|
78
|
+
|
|
79
|
+
# Initialize dynamics and constraints
|
|
80
|
+
dynamics = DynamicsModel()
|
|
81
|
+
checker = ConstraintChecker()
|
|
82
|
+
simulator = ForwardSimulator(dynamics, checker)
|
|
83
|
+
|
|
84
|
+
# Sample 5 budget policies
|
|
85
|
+
budget_categories = ["energy", "food", "infrastructure", "education", "healthcare", "R&D", "welfare"]
|
|
86
|
+
policies = [
|
|
87
|
+
ControlVector.sample_budget_simplex(budget_categories)
|
|
88
|
+
for _ in range(5)
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
logger.info(f"Sampled {len(policies)} policies")
|
|
92
|
+
|
|
93
|
+
# Simulate each policy forward 10 steps
|
|
94
|
+
results = []
|
|
95
|
+
for i, policy in enumerate(policies):
|
|
96
|
+
trajectory, feasibility_flags, first_violation = simulator.simulate_scenario(
|
|
97
|
+
x_0, policy, [{}] * 10, horizon=10
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
feasible_count = sum(feasibility_flags)
|
|
101
|
+
final_state = trajectory[-1]
|
|
102
|
+
|
|
103
|
+
results.append({
|
|
104
|
+
"policy_id": i,
|
|
105
|
+
"feasible_steps": feasible_count,
|
|
106
|
+
"first_violation": first_violation,
|
|
107
|
+
"final_U": final_state.U,
|
|
108
|
+
"final_Y": final_state.Y,
|
|
109
|
+
"final_C": final_state.C,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
logger.info(
|
|
113
|
+
f"Policy {i}: {feasible_count}/10 feasible steps, "
|
|
114
|
+
f"final U={final_state.U:.1%}, Y={final_state.Y:,.0f}"
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Check feasibility of initial state
|
|
118
|
+
is_feasible, violations = checker.check_feasible(x_0, policies[0])
|
|
119
|
+
logger.info(f"Initial state feasible: {is_feasible}")
|
|
120
|
+
if violations:
|
|
121
|
+
logger.warning(f"Violations: {violations[:2]}")
|
|
122
|
+
|
|
123
|
+
return results
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def phase_b_mpc_optimization():
|
|
127
|
+
"""
|
|
128
|
+
Phase B: MPC optimization with risk and Pareto frontier.
|
|
129
|
+
|
|
130
|
+
- Run MPC solver
|
|
131
|
+
- Extract Pareto frontier
|
|
132
|
+
- Compute CVaR risk
|
|
133
|
+
"""
|
|
134
|
+
logger.info("=== Phase B: MPC Optimization ===")
|
|
135
|
+
|
|
136
|
+
# Setup
|
|
137
|
+
dynamics = DynamicsModel()
|
|
138
|
+
checker = ConstraintChecker()
|
|
139
|
+
obj_computer = ObjectiveVector(horizon=10)
|
|
140
|
+
stability = StabilityEnforcer()
|
|
141
|
+
solver = MPCSolver(dynamics, checker, obj_computer, horizon=10, stability_enforcer=stability)
|
|
142
|
+
|
|
143
|
+
# Generate scenarios
|
|
144
|
+
scenario_gen = ScenarioGenerator()
|
|
145
|
+
scenarios = scenario_gen.generate_gaussian(n_scenarios=10, horizon=10)
|
|
146
|
+
logger.info(f"Generated {len(scenarios)} Gaussian scenarios")
|
|
147
|
+
|
|
148
|
+
# Initial state
|
|
149
|
+
x_t = StateVector()
|
|
150
|
+
|
|
151
|
+
# Solve MPC
|
|
152
|
+
policy, solver_info = solver.solve(x_t, scenarios)
|
|
153
|
+
logger.info(f"MPC solved: best_score={solver_info.get('best_score', 'N/A'):.4f}")
|
|
154
|
+
|
|
155
|
+
# Simulate optimal policy
|
|
156
|
+
simulator = ForwardSimulator(dynamics, checker)
|
|
157
|
+
trajectory, feasibility, _ = simulator.simulate_scenario(
|
|
158
|
+
x_t, policy, scenarios[0], horizon=10
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# Compute objectives
|
|
162
|
+
objectives = obj_computer.compute(trajectory, [policy] * 10)
|
|
163
|
+
logger.info(f"Objectives: J_U={objectives[0]:.2f}, J_Y={objectives[2]:.2f}, J_C={objectives[4]:.2f}")
|
|
164
|
+
|
|
165
|
+
# Compute CVaR
|
|
166
|
+
cvar_computer = CVaRComputer(alpha=0.05)
|
|
167
|
+
collapse_proxies = [
|
|
168
|
+
cvar_computer.collapse_proxy(traj)
|
|
169
|
+
for traj in [trajectory] # In practice, use all scenario trajectories
|
|
170
|
+
]
|
|
171
|
+
cvar = cvar_computer.compute_cvar(np.array(collapse_proxies))
|
|
172
|
+
logger.info(f"CVaR (α=0.05): {cvar:.4f}")
|
|
173
|
+
|
|
174
|
+
# Extract Pareto frontier (sample multiple policies)
|
|
175
|
+
candidate_policies = [
|
|
176
|
+
ControlVector.sample_budget_simplex(["energy", "food", "infrastructure"])
|
|
177
|
+
for _ in range(10)
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
objective_matrix = []
|
|
181
|
+
for pol in candidate_policies:
|
|
182
|
+
traj, _, _ = simulator.simulate_scenario(x_t, pol, scenarios[0], horizon=10)
|
|
183
|
+
obj = obj_computer.compute(traj, [pol] * 10)
|
|
184
|
+
objective_matrix.append(obj)
|
|
185
|
+
|
|
186
|
+
objective_matrix = np.array(objective_matrix)
|
|
187
|
+
pareto_policies, pareto_obj = ParetoExtractor.extract_pareto_frontier(
|
|
188
|
+
candidate_policies, objective_matrix
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
logger.info(f"Pareto frontier: {len(pareto_policies)} policies")
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
"optimal_policy": policy,
|
|
195
|
+
"objectives": objectives,
|
|
196
|
+
"cvar": cvar,
|
|
197
|
+
"pareto_policies": pareto_policies,
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def phase_c_governance():
|
|
202
|
+
"""
|
|
203
|
+
Phase C: Board governance and arbitration.
|
|
204
|
+
|
|
205
|
+
- State estimation with noisy observations
|
|
206
|
+
- Board evaluation
|
|
207
|
+
- Arbitration
|
|
208
|
+
"""
|
|
209
|
+
logger.info("=== Phase C: Board Governance ===")
|
|
210
|
+
|
|
211
|
+
# Create boards
|
|
212
|
+
growth_board = Board(
|
|
213
|
+
board_id="growth_1",
|
|
214
|
+
board_type=BoardType.GROWTH,
|
|
215
|
+
members=[
|
|
216
|
+
BoardMember(
|
|
217
|
+
name="Growth Director",
|
|
218
|
+
board_type=BoardType.GROWTH,
|
|
219
|
+
expertise_areas=["economics", "productivity"],
|
|
220
|
+
voting_weight=2.0
|
|
221
|
+
)
|
|
222
|
+
]
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
welfare_board = Board(
|
|
226
|
+
board_id="welfare_1",
|
|
227
|
+
board_type=BoardType.WELFARE,
|
|
228
|
+
members=[
|
|
229
|
+
BoardMember(
|
|
230
|
+
name="Welfare Director",
|
|
231
|
+
board_type=BoardType.WELFARE,
|
|
232
|
+
expertise_areas=["social_policy", "inequality"],
|
|
233
|
+
voting_weight=2.0
|
|
234
|
+
)
|
|
235
|
+
]
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
sustainability_board = Board(
|
|
239
|
+
board_id="sustainability_1",
|
|
240
|
+
board_type=BoardType.SUSTAINABILITY,
|
|
241
|
+
members=[
|
|
242
|
+
BoardMember(
|
|
243
|
+
name="Sustainability Director",
|
|
244
|
+
board_type=BoardType.SUSTAINABILITY,
|
|
245
|
+
expertise_areas=["environment", "long_term"],
|
|
246
|
+
voting_weight=2.0
|
|
247
|
+
)
|
|
248
|
+
]
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
stability_board = Board(
|
|
252
|
+
board_id="stability_1",
|
|
253
|
+
board_type=BoardType.STABILITY,
|
|
254
|
+
members=[
|
|
255
|
+
BoardMember(
|
|
256
|
+
name="Stability Director",
|
|
257
|
+
board_type=BoardType.STABILITY,
|
|
258
|
+
expertise_areas=["risk_management", "volatility"],
|
|
259
|
+
voting_weight=2.0
|
|
260
|
+
)
|
|
261
|
+
]
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
boards = [growth_board, welfare_board, sustainability_board, stability_board]
|
|
265
|
+
logger.info(f"Created {len(boards)} governance boards")
|
|
266
|
+
|
|
267
|
+
# Generate candidate policies
|
|
268
|
+
dynamics = DynamicsModel()
|
|
269
|
+
checker = ConstraintChecker()
|
|
270
|
+
obj_computer = ObjectiveVector(horizon=5)
|
|
271
|
+
simulator = ForwardSimulator(dynamics, checker)
|
|
272
|
+
|
|
273
|
+
x_t = StateVector()
|
|
274
|
+
candidate_policies = [
|
|
275
|
+
ControlVector.sample_budget_simplex(["energy", "food", "infrastructure", "education"])
|
|
276
|
+
for _ in range(5)
|
|
277
|
+
]
|
|
278
|
+
|
|
279
|
+
# Evaluate policies under scenarios
|
|
280
|
+
scenario_gen = ScenarioGenerator()
|
|
281
|
+
scenarios = scenario_gen.generate_gaussian(n_scenarios=3, horizon=5)
|
|
282
|
+
|
|
283
|
+
objective_matrix = []
|
|
284
|
+
for policy in candidate_policies:
|
|
285
|
+
# Aggregate objectives across scenarios
|
|
286
|
+
scenario_objectives = []
|
|
287
|
+
for scenario in scenarios:
|
|
288
|
+
traj, _, _ = simulator.simulate_scenario(x_t, policy, scenario, horizon=5)
|
|
289
|
+
obj = obj_computer.compute(traj, [policy] * 5)
|
|
290
|
+
scenario_objectives.append(obj)
|
|
291
|
+
expected_obj = np.mean(scenario_objectives, axis=0)
|
|
292
|
+
objective_matrix.append(expected_obj)
|
|
293
|
+
|
|
294
|
+
objective_matrix = np.array(objective_matrix)
|
|
295
|
+
|
|
296
|
+
# Each board evaluates policies
|
|
297
|
+
for board in boards:
|
|
298
|
+
ranked = board.evaluate_policies(candidate_policies, objective_matrix)
|
|
299
|
+
logger.info(f"{board.board_type.value} board top policy score: {ranked[0][1]:.4f}")
|
|
300
|
+
|
|
301
|
+
# Arbitration: weighted vote
|
|
302
|
+
governance = GovernanceSystem(boards, arbitration_method="weighted_vote")
|
|
303
|
+
selected_policy = governance.select_policy(candidate_policies, objective_matrix)
|
|
304
|
+
|
|
305
|
+
logger.info(f"Governance selected policy via weighted vote")
|
|
306
|
+
|
|
307
|
+
# Test other arbitration methods
|
|
308
|
+
consensus = Arbitration.pareto_intersection(boards, candidate_policies, objective_matrix)
|
|
309
|
+
logger.info(f"Pareto intersection: {len(consensus)} consensus policies")
|
|
310
|
+
|
|
311
|
+
minimax_policy = Arbitration.minimax_regret(boards, candidate_policies, objective_matrix)
|
|
312
|
+
logger.info(f"Minimax regret policy selected")
|
|
313
|
+
|
|
314
|
+
borda_policy = Arbitration.borda_vote(boards, candidate_policies, objective_matrix)
|
|
315
|
+
logger.info(f"Borda vote policy selected")
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
"selected_policy": selected_policy,
|
|
319
|
+
"consensus_policies": consensus,
|
|
320
|
+
"minimax_policy": minimax_policy,
|
|
321
|
+
"borda_policy": borda_policy,
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def phase_d_logistics_visualization():
|
|
326
|
+
"""
|
|
327
|
+
Phase D: Logistics network and visualization.
|
|
328
|
+
|
|
329
|
+
- Logistics network optimization
|
|
330
|
+
- Visualization
|
|
331
|
+
- Metrics collection
|
|
332
|
+
"""
|
|
333
|
+
logger.info("=== Phase D: Logistics & Visualization ===")
|
|
334
|
+
|
|
335
|
+
# Create logistics network
|
|
336
|
+
nodes = ["Region_A", "Region_B", "Port_C", "Warehouse_D"]
|
|
337
|
+
edges = [
|
|
338
|
+
("Region_A", "Port_C"),
|
|
339
|
+
("Region_B", "Port_C"),
|
|
340
|
+
("Port_C", "Warehouse_D"),
|
|
341
|
+
]
|
|
342
|
+
|
|
343
|
+
capacities = {
|
|
344
|
+
("Region_A", "Port_C"): 1000.0,
|
|
345
|
+
("Region_B", "Port_C"): 800.0,
|
|
346
|
+
("Port_C", "Warehouse_D"): 1500.0,
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
costs = {
|
|
350
|
+
("Region_A", "Port_C"): 1.0,
|
|
351
|
+
("Region_B", "Port_C"): 1.2,
|
|
352
|
+
("Port_C", "Warehouse_D"): 0.8,
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
network = LogisticsNetwork(nodes, edges, capacities, costs)
|
|
356
|
+
logger.info(f"Created logistics network: {len(nodes)} nodes, {len(edges)} edges")
|
|
357
|
+
|
|
358
|
+
# Solve flow problem
|
|
359
|
+
demands = {
|
|
360
|
+
"Warehouse_D": {"food": 500.0, "energy": 300.0}
|
|
361
|
+
}
|
|
362
|
+
commodities = ["food", "energy"]
|
|
363
|
+
|
|
364
|
+
flows = network.solve_flow_problem(demands, commodities)
|
|
365
|
+
logger.info(f"Solved flow problem: {len(flows)} flow variables")
|
|
366
|
+
|
|
367
|
+
# Visualization
|
|
368
|
+
x_t = StateVector()
|
|
369
|
+
dashboard = Visualization.state_dashboard(x_t)
|
|
370
|
+
logger.info("State dashboard generated")
|
|
371
|
+
print(dashboard)
|
|
372
|
+
|
|
373
|
+
# Metrics collection
|
|
374
|
+
dynamics = DynamicsModel()
|
|
375
|
+
checker = ConstraintChecker()
|
|
376
|
+
simulator = ForwardSimulator(dynamics, checker)
|
|
377
|
+
|
|
378
|
+
trajectories = []
|
|
379
|
+
policies = []
|
|
380
|
+
for _ in range(3):
|
|
381
|
+
policy = ControlVector.sample_budget_simplex(["energy", "food"])
|
|
382
|
+
traj, _, _ = simulator.simulate_scenario(x_t, policy, [{}] * 5, horizon=5)
|
|
383
|
+
trajectories.append(traj)
|
|
384
|
+
policies.append(policy)
|
|
385
|
+
|
|
386
|
+
collector = MetricsCollector()
|
|
387
|
+
metrics = collector.compute_all_metrics(trajectories, policies)
|
|
388
|
+
logger.info(f"Computed metrics: feasibility_rate={metrics.get('feasibility_rate', 0.0):.1%}")
|
|
389
|
+
|
|
390
|
+
report = collector.generate_report()
|
|
391
|
+
print(report)
|
|
392
|
+
|
|
393
|
+
return {
|
|
394
|
+
"flows": flows,
|
|
395
|
+
"metrics": metrics,
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def full_workflow_example():
|
|
400
|
+
"""
|
|
401
|
+
Full end-to-end workflow example.
|
|
402
|
+
|
|
403
|
+
Demonstrates complete CRCA-SD system:
|
|
404
|
+
1. Initialize state and dynamics
|
|
405
|
+
2. Generate scenarios
|
|
406
|
+
3. Solve MPC for candidate policies
|
|
407
|
+
4. Evaluate with boards
|
|
408
|
+
5. Arbitrate to select final policy
|
|
409
|
+
6. Simulate and collect metrics
|
|
410
|
+
"""
|
|
411
|
+
logger.info("=== Full Workflow Example ===")
|
|
412
|
+
|
|
413
|
+
# 1. Initialize
|
|
414
|
+
x_0 = StateVector()
|
|
415
|
+
dynamics = DynamicsModel()
|
|
416
|
+
checker = ConstraintChecker()
|
|
417
|
+
obj_computer = ObjectiveVector(horizon=10)
|
|
418
|
+
stability = StabilityEnforcer()
|
|
419
|
+
solver = MPCSolver(dynamics, checker, obj_computer, horizon=10, stability_enforcer=stability)
|
|
420
|
+
simulator = ForwardSimulator(dynamics, checker)
|
|
421
|
+
|
|
422
|
+
# 2. Generate scenarios
|
|
423
|
+
scenario_gen = ScenarioGenerator()
|
|
424
|
+
scenarios = scenario_gen.generate_gaussian(n_scenarios=5, horizon=10)
|
|
425
|
+
logger.info(f"Generated {len(scenarios)} scenarios")
|
|
426
|
+
|
|
427
|
+
# 3. Solve MPC
|
|
428
|
+
policy_candidates, solver_info = solver.solve(x_0, scenarios)
|
|
429
|
+
logger.info("MPC solved, obtained candidate policy")
|
|
430
|
+
|
|
431
|
+
# Generate additional candidates for board evaluation
|
|
432
|
+
budget_categories = ["energy", "food", "infrastructure", "education", "healthcare"]
|
|
433
|
+
additional_candidates = [
|
|
434
|
+
ControlVector.sample_budget_simplex(budget_categories)
|
|
435
|
+
for _ in range(4)
|
|
436
|
+
]
|
|
437
|
+
all_candidates = [policy_candidates] + additional_candidates
|
|
438
|
+
|
|
439
|
+
# 4. Evaluate with boards
|
|
440
|
+
boards = [
|
|
441
|
+
Board(
|
|
442
|
+
board_id=f"board_{i}",
|
|
443
|
+
board_type=bt,
|
|
444
|
+
members=[BoardMember(name=f"Member_{i}", board_type=bt, voting_weight=1.0)]
|
|
445
|
+
)
|
|
446
|
+
for i, bt in enumerate([BoardType.GROWTH, BoardType.WELFARE, BoardType.SUSTAINABILITY, BoardType.STABILITY])
|
|
447
|
+
]
|
|
448
|
+
|
|
449
|
+
# Compute objectives for all candidates
|
|
450
|
+
objective_matrix = []
|
|
451
|
+
for policy in all_candidates:
|
|
452
|
+
scenario_objectives = []
|
|
453
|
+
for scenario in scenarios[:3]: # Use subset for speed
|
|
454
|
+
traj, _, _ = simulator.simulate_scenario(x_0, policy, scenario, horizon=10)
|
|
455
|
+
obj = obj_computer.compute(traj, [policy] * 10)
|
|
456
|
+
scenario_objectives.append(obj)
|
|
457
|
+
expected_obj = np.mean(scenario_objectives, axis=0)
|
|
458
|
+
objective_matrix.append(expected_obj)
|
|
459
|
+
|
|
460
|
+
objective_matrix = np.array(objective_matrix)
|
|
461
|
+
|
|
462
|
+
# 5. Arbitrate
|
|
463
|
+
governance = GovernanceSystem(boards, arbitration_method="weighted_vote")
|
|
464
|
+
final_policy = governance.select_policy(all_candidates, objective_matrix)
|
|
465
|
+
logger.info("Governance selected final policy")
|
|
466
|
+
|
|
467
|
+
# 6. Simulate final policy
|
|
468
|
+
final_traj, final_feasibility, _ = simulator.simulate_scenario(
|
|
469
|
+
x_0, final_policy, scenarios[0], horizon=10
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
# 7. Collect metrics
|
|
473
|
+
collector = MetricsCollector()
|
|
474
|
+
metrics = collector.compute_all_metrics([final_traj], [final_policy])
|
|
475
|
+
|
|
476
|
+
logger.info("=== Workflow Complete ===")
|
|
477
|
+
logger.info(f"Final state: U={final_traj[-1].U:.1%}, Y={final_traj[-1].Y:,.0f}, C={final_traj[-1].C:,.0f}")
|
|
478
|
+
logger.info(f"Feasibility: {sum(final_feasibility)}/10 steps")
|
|
479
|
+
logger.info(f"Metrics: {metrics.get('feasibility_rate', 0.0):.1%} feasibility rate")
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
"final_policy": final_policy,
|
|
483
|
+
"final_trajectory": final_traj,
|
|
484
|
+
"metrics": metrics,
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
if __name__ == "__main__":
|
|
489
|
+
"""Run all example phases."""
|
|
490
|
+
logger.info("Starting CRCA-SD Examples")
|
|
491
|
+
|
|
492
|
+
# Phase A
|
|
493
|
+
phase_a_results = phase_a_basic_simulation()
|
|
494
|
+
logger.info(f"Phase A complete: {len(phase_a_results)} policies evaluated")
|
|
495
|
+
|
|
496
|
+
# Phase B
|
|
497
|
+
phase_b_results = phase_b_mpc_optimization()
|
|
498
|
+
logger.info("Phase B complete: MPC optimization done")
|
|
499
|
+
|
|
500
|
+
# Phase C
|
|
501
|
+
phase_c_results = phase_c_governance()
|
|
502
|
+
logger.info("Phase C complete: Board governance done")
|
|
503
|
+
|
|
504
|
+
# Phase D
|
|
505
|
+
phase_d_results = phase_d_logistics_visualization()
|
|
506
|
+
logger.info("Phase D complete: Logistics and visualization done")
|
|
507
|
+
|
|
508
|
+
# Full workflow
|
|
509
|
+
full_results = full_workflow_example()
|
|
510
|
+
logger.info("Full workflow complete!")
|
|
511
|
+
|
|
512
|
+
logger.success("All examples completed successfully!")
|
|
513
|
+
|