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.
Files changed (501) hide show
  1. .github/ISSUE_TEMPLATE/bug_report.md +65 -0
  2. .github/ISSUE_TEMPLATE/feature_request.md +41 -0
  3. .github/PULL_REQUEST_TEMPLATE.md +20 -0
  4. .github/workflows/publish-manual.yml +61 -0
  5. .github/workflows/publish.yml +64 -0
  6. .gitignore +214 -0
  7. CRCA.py +4156 -0
  8. LICENSE +201 -0
  9. MANIFEST.in +43 -0
  10. PKG-INFO +5035 -0
  11. README.md +4959 -0
  12. __init__.py +17 -0
  13. branches/CRCA-Q.py +2728 -0
  14. branches/crca_cg/corposwarm.py +9065 -0
  15. branches/crca_cg/fix_rancher_docker_creds.ps1 +155 -0
  16. branches/crca_cg/package.json +5 -0
  17. branches/crca_cg/test_bolt_integration.py +446 -0
  18. branches/crca_cg/test_corposwarm_comprehensive.py +773 -0
  19. branches/crca_cg/test_new_features.py +163 -0
  20. branches/crca_sd/__init__.py +149 -0
  21. branches/crca_sd/crca_sd_core.py +770 -0
  22. branches/crca_sd/crca_sd_governance.py +1325 -0
  23. branches/crca_sd/crca_sd_mpc.py +1130 -0
  24. branches/crca_sd/crca_sd_realtime.py +1844 -0
  25. branches/crca_sd/crca_sd_tui.py +1133 -0
  26. crca-1.4.0.dist-info/METADATA +5035 -0
  27. crca-1.4.0.dist-info/RECORD +501 -0
  28. crca-1.4.0.dist-info/WHEEL +4 -0
  29. crca-1.4.0.dist-info/licenses/LICENSE +201 -0
  30. docs/CRCA-Q.md +2333 -0
  31. examples/config.yaml.example +25 -0
  32. examples/crca_sd_example.py +513 -0
  33. examples/data_broker_example.py +294 -0
  34. examples/logistics_corporation.py +861 -0
  35. examples/palantir_example.py +299 -0
  36. examples/policy_bench.py +934 -0
  37. examples/pridnestrovia-sd.py +705 -0
  38. examples/pridnestrovia_realtime.py +1902 -0
  39. prompts/__init__.py +10 -0
  40. prompts/default_crca.py +101 -0
  41. pyproject.toml +151 -0
  42. requirements.txt +76 -0
  43. schemas/__init__.py +43 -0
  44. schemas/mcpSchemas.py +51 -0
  45. schemas/policy.py +458 -0
  46. templates/__init__.py +38 -0
  47. templates/base_specialized_agent.py +195 -0
  48. templates/drift_detection.py +325 -0
  49. templates/examples/causal_agent_template.py +309 -0
  50. templates/examples/drag_drop_example.py +213 -0
  51. templates/examples/logistics_agent_template.py +207 -0
  52. templates/examples/trading_agent_template.py +206 -0
  53. templates/feature_mixins.py +253 -0
  54. templates/graph_management.py +442 -0
  55. templates/llm_integration.py +194 -0
  56. templates/module_registry.py +276 -0
  57. templates/mpc_planner.py +280 -0
  58. templates/policy_loop.py +1168 -0
  59. templates/prediction_framework.py +448 -0
  60. templates/statistical_methods.py +778 -0
  61. tests/sanity.yml +31 -0
  62. tests/sanity_check +406 -0
  63. tests/test_core.py +47 -0
  64. tests/test_crca_excel.py +166 -0
  65. tests/test_crca_sd.py +780 -0
  66. tests/test_data_broker.py +424 -0
  67. tests/test_palantir.py +349 -0
  68. tools/__init__.py +38 -0
  69. tools/actuators.py +437 -0
  70. tools/bolt.diy/Dockerfile +103 -0
  71. tools/bolt.diy/app/components/@settings/core/AvatarDropdown.tsx +175 -0
  72. tools/bolt.diy/app/components/@settings/core/ControlPanel.tsx +345 -0
  73. tools/bolt.diy/app/components/@settings/core/constants.tsx +108 -0
  74. tools/bolt.diy/app/components/@settings/core/types.ts +114 -0
  75. tools/bolt.diy/app/components/@settings/index.ts +12 -0
  76. tools/bolt.diy/app/components/@settings/shared/components/TabTile.tsx +151 -0
  77. tools/bolt.diy/app/components/@settings/shared/service-integration/ConnectionForm.tsx +193 -0
  78. tools/bolt.diy/app/components/@settings/shared/service-integration/ConnectionTestIndicator.tsx +60 -0
  79. tools/bolt.diy/app/components/@settings/shared/service-integration/ErrorState.tsx +102 -0
  80. tools/bolt.diy/app/components/@settings/shared/service-integration/LoadingState.tsx +94 -0
  81. tools/bolt.diy/app/components/@settings/shared/service-integration/ServiceHeader.tsx +72 -0
  82. tools/bolt.diy/app/components/@settings/shared/service-integration/index.ts +6 -0
  83. tools/bolt.diy/app/components/@settings/tabs/data/DataTab.tsx +721 -0
  84. tools/bolt.diy/app/components/@settings/tabs/data/DataVisualization.tsx +384 -0
  85. tools/bolt.diy/app/components/@settings/tabs/event-logs/EventLogsTab.tsx +1013 -0
  86. tools/bolt.diy/app/components/@settings/tabs/features/FeaturesTab.tsx +295 -0
  87. tools/bolt.diy/app/components/@settings/tabs/github/GitHubTab.tsx +281 -0
  88. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubAuthDialog.tsx +173 -0
  89. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubCacheManager.tsx +367 -0
  90. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubConnection.tsx +233 -0
  91. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubErrorBoundary.tsx +105 -0
  92. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubProgressiveLoader.tsx +266 -0
  93. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubRepositoryCard.tsx +121 -0
  94. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubRepositorySelector.tsx +312 -0
  95. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubStats.tsx +291 -0
  96. tools/bolt.diy/app/components/@settings/tabs/github/components/GitHubUserProfile.tsx +46 -0
  97. tools/bolt.diy/app/components/@settings/tabs/github/components/shared/GitHubStateIndicators.tsx +264 -0
  98. tools/bolt.diy/app/components/@settings/tabs/github/components/shared/RepositoryCard.tsx +361 -0
  99. tools/bolt.diy/app/components/@settings/tabs/github/components/shared/index.ts +11 -0
  100. tools/bolt.diy/app/components/@settings/tabs/gitlab/GitLabTab.tsx +305 -0
  101. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/GitLabAuthDialog.tsx +186 -0
  102. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/GitLabConnection.tsx +253 -0
  103. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/GitLabRepositorySelector.tsx +358 -0
  104. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/RepositoryCard.tsx +79 -0
  105. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/RepositoryList.tsx +142 -0
  106. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/StatsDisplay.tsx +91 -0
  107. tools/bolt.diy/app/components/@settings/tabs/gitlab/components/index.ts +4 -0
  108. tools/bolt.diy/app/components/@settings/tabs/mcp/McpServerList.tsx +99 -0
  109. tools/bolt.diy/app/components/@settings/tabs/mcp/McpServerListItem.tsx +70 -0
  110. tools/bolt.diy/app/components/@settings/tabs/mcp/McpStatusBadge.tsx +37 -0
  111. tools/bolt.diy/app/components/@settings/tabs/mcp/McpTab.tsx +239 -0
  112. tools/bolt.diy/app/components/@settings/tabs/netlify/NetlifyTab.tsx +1393 -0
  113. tools/bolt.diy/app/components/@settings/tabs/netlify/components/NetlifyConnection.tsx +990 -0
  114. tools/bolt.diy/app/components/@settings/tabs/netlify/components/index.ts +1 -0
  115. tools/bolt.diy/app/components/@settings/tabs/notifications/NotificationsTab.tsx +300 -0
  116. tools/bolt.diy/app/components/@settings/tabs/profile/ProfileTab.tsx +181 -0
  117. tools/bolt.diy/app/components/@settings/tabs/providers/cloud/CloudProvidersTab.tsx +308 -0
  118. tools/bolt.diy/app/components/@settings/tabs/providers/local/ErrorBoundary.tsx +68 -0
  119. tools/bolt.diy/app/components/@settings/tabs/providers/local/HealthStatusBadge.tsx +64 -0
  120. tools/bolt.diy/app/components/@settings/tabs/providers/local/LoadingSkeleton.tsx +107 -0
  121. tools/bolt.diy/app/components/@settings/tabs/providers/local/LocalProvidersTab.tsx +556 -0
  122. tools/bolt.diy/app/components/@settings/tabs/providers/local/ModelCard.tsx +106 -0
  123. tools/bolt.diy/app/components/@settings/tabs/providers/local/ProviderCard.tsx +120 -0
  124. tools/bolt.diy/app/components/@settings/tabs/providers/local/SetupGuide.tsx +671 -0
  125. tools/bolt.diy/app/components/@settings/tabs/providers/local/StatusDashboard.tsx +91 -0
  126. tools/bolt.diy/app/components/@settings/tabs/providers/local/types.ts +44 -0
  127. tools/bolt.diy/app/components/@settings/tabs/settings/SettingsTab.tsx +215 -0
  128. tools/bolt.diy/app/components/@settings/tabs/supabase/SupabaseTab.tsx +1089 -0
  129. tools/bolt.diy/app/components/@settings/tabs/vercel/VercelTab.tsx +909 -0
  130. tools/bolt.diy/app/components/@settings/tabs/vercel/components/VercelConnection.tsx +368 -0
  131. tools/bolt.diy/app/components/@settings/tabs/vercel/components/index.ts +1 -0
  132. tools/bolt.diy/app/components/@settings/utils/tab-helpers.ts +54 -0
  133. tools/bolt.diy/app/components/chat/APIKeyManager.tsx +169 -0
  134. tools/bolt.diy/app/components/chat/Artifact.tsx +296 -0
  135. tools/bolt.diy/app/components/chat/AssistantMessage.tsx +192 -0
  136. tools/bolt.diy/app/components/chat/BaseChat.module.scss +47 -0
  137. tools/bolt.diy/app/components/chat/BaseChat.tsx +522 -0
  138. tools/bolt.diy/app/components/chat/Chat.client.tsx +670 -0
  139. tools/bolt.diy/app/components/chat/ChatAlert.tsx +108 -0
  140. tools/bolt.diy/app/components/chat/ChatBox.tsx +334 -0
  141. tools/bolt.diy/app/components/chat/CodeBlock.module.scss +10 -0
  142. tools/bolt.diy/app/components/chat/CodeBlock.tsx +85 -0
  143. tools/bolt.diy/app/components/chat/DicussMode.tsx +17 -0
  144. tools/bolt.diy/app/components/chat/ExamplePrompts.tsx +37 -0
  145. tools/bolt.diy/app/components/chat/FilePreview.tsx +38 -0
  146. tools/bolt.diy/app/components/chat/GitCloneButton.tsx +327 -0
  147. tools/bolt.diy/app/components/chat/ImportFolderButton.tsx +141 -0
  148. tools/bolt.diy/app/components/chat/LLMApiAlert.tsx +109 -0
  149. tools/bolt.diy/app/components/chat/MCPTools.tsx +129 -0
  150. tools/bolt.diy/app/components/chat/Markdown.module.scss +171 -0
  151. tools/bolt.diy/app/components/chat/Markdown.spec.ts +48 -0
  152. tools/bolt.diy/app/components/chat/Markdown.tsx +252 -0
  153. tools/bolt.diy/app/components/chat/Messages.client.tsx +102 -0
  154. tools/bolt.diy/app/components/chat/ModelSelector.tsx +797 -0
  155. tools/bolt.diy/app/components/chat/NetlifyDeploymentLink.client.tsx +51 -0
  156. tools/bolt.diy/app/components/chat/ProgressCompilation.tsx +110 -0
  157. tools/bolt.diy/app/components/chat/ScreenshotStateManager.tsx +33 -0
  158. tools/bolt.diy/app/components/chat/SendButton.client.tsx +39 -0
  159. tools/bolt.diy/app/components/chat/SpeechRecognition.tsx +28 -0
  160. tools/bolt.diy/app/components/chat/StarterTemplates.tsx +38 -0
  161. tools/bolt.diy/app/components/chat/SupabaseAlert.tsx +199 -0
  162. tools/bolt.diy/app/components/chat/SupabaseConnection.tsx +339 -0
  163. tools/bolt.diy/app/components/chat/ThoughtBox.tsx +43 -0
  164. tools/bolt.diy/app/components/chat/ToolInvocations.tsx +409 -0
  165. tools/bolt.diy/app/components/chat/UserMessage.tsx +101 -0
  166. tools/bolt.diy/app/components/chat/VercelDeploymentLink.client.tsx +158 -0
  167. tools/bolt.diy/app/components/chat/chatExportAndImport/ExportChatButton.tsx +49 -0
  168. tools/bolt.diy/app/components/chat/chatExportAndImport/ImportButtons.tsx +96 -0
  169. tools/bolt.diy/app/components/deploy/DeployAlert.tsx +197 -0
  170. tools/bolt.diy/app/components/deploy/DeployButton.tsx +277 -0
  171. tools/bolt.diy/app/components/deploy/GitHubDeploy.client.tsx +171 -0
  172. tools/bolt.diy/app/components/deploy/GitHubDeploymentDialog.tsx +1041 -0
  173. tools/bolt.diy/app/components/deploy/GitLabDeploy.client.tsx +171 -0
  174. tools/bolt.diy/app/components/deploy/GitLabDeploymentDialog.tsx +764 -0
  175. tools/bolt.diy/app/components/deploy/NetlifyDeploy.client.tsx +246 -0
  176. tools/bolt.diy/app/components/deploy/VercelDeploy.client.tsx +235 -0
  177. tools/bolt.diy/app/components/editor/codemirror/BinaryContent.tsx +7 -0
  178. tools/bolt.diy/app/components/editor/codemirror/CodeMirrorEditor.tsx +555 -0
  179. tools/bolt.diy/app/components/editor/codemirror/EnvMasking.ts +80 -0
  180. tools/bolt.diy/app/components/editor/codemirror/cm-theme.ts +192 -0
  181. tools/bolt.diy/app/components/editor/codemirror/indent.ts +68 -0
  182. tools/bolt.diy/app/components/editor/codemirror/languages.ts +112 -0
  183. tools/bolt.diy/app/components/git/GitUrlImport.client.tsx +147 -0
  184. tools/bolt.diy/app/components/header/Header.tsx +42 -0
  185. tools/bolt.diy/app/components/header/HeaderActionButtons.client.tsx +54 -0
  186. tools/bolt.diy/app/components/mandate/MandateSubmission.tsx +167 -0
  187. tools/bolt.diy/app/components/observability/DeploymentStatus.tsx +168 -0
  188. tools/bolt.diy/app/components/observability/EventTimeline.tsx +119 -0
  189. tools/bolt.diy/app/components/observability/FileDiffViewer.tsx +121 -0
  190. tools/bolt.diy/app/components/observability/GovernanceStatus.tsx +197 -0
  191. tools/bolt.diy/app/components/observability/GovernorMetrics.tsx +246 -0
  192. tools/bolt.diy/app/components/observability/LogStream.tsx +244 -0
  193. tools/bolt.diy/app/components/observability/MandateDetails.tsx +201 -0
  194. tools/bolt.diy/app/components/observability/ObservabilityDashboard.tsx +200 -0
  195. tools/bolt.diy/app/components/sidebar/HistoryItem.tsx +187 -0
  196. tools/bolt.diy/app/components/sidebar/Menu.client.tsx +536 -0
  197. tools/bolt.diy/app/components/sidebar/date-binning.ts +59 -0
  198. tools/bolt.diy/app/components/txt +1 -0
  199. tools/bolt.diy/app/components/ui/BackgroundRays/index.tsx +18 -0
  200. tools/bolt.diy/app/components/ui/BackgroundRays/styles.module.scss +246 -0
  201. tools/bolt.diy/app/components/ui/Badge.tsx +53 -0
  202. tools/bolt.diy/app/components/ui/BranchSelector.tsx +270 -0
  203. tools/bolt.diy/app/components/ui/Breadcrumbs.tsx +101 -0
  204. tools/bolt.diy/app/components/ui/Button.tsx +46 -0
  205. tools/bolt.diy/app/components/ui/Card.tsx +55 -0
  206. tools/bolt.diy/app/components/ui/Checkbox.tsx +32 -0
  207. tools/bolt.diy/app/components/ui/CloseButton.tsx +49 -0
  208. tools/bolt.diy/app/components/ui/CodeBlock.tsx +103 -0
  209. tools/bolt.diy/app/components/ui/Collapsible.tsx +9 -0
  210. tools/bolt.diy/app/components/ui/ColorSchemeDialog.tsx +378 -0
  211. tools/bolt.diy/app/components/ui/Dialog.tsx +449 -0
  212. tools/bolt.diy/app/components/ui/Dropdown.tsx +63 -0
  213. tools/bolt.diy/app/components/ui/EmptyState.tsx +154 -0
  214. tools/bolt.diy/app/components/ui/FileIcon.tsx +346 -0
  215. tools/bolt.diy/app/components/ui/FilterChip.tsx +92 -0
  216. tools/bolt.diy/app/components/ui/GlowingEffect.tsx +192 -0
  217. tools/bolt.diy/app/components/ui/GradientCard.tsx +100 -0
  218. tools/bolt.diy/app/components/ui/IconButton.tsx +84 -0
  219. tools/bolt.diy/app/components/ui/Input.tsx +22 -0
  220. tools/bolt.diy/app/components/ui/Label.tsx +20 -0
  221. tools/bolt.diy/app/components/ui/LoadingDots.tsx +27 -0
  222. tools/bolt.diy/app/components/ui/LoadingOverlay.tsx +32 -0
  223. tools/bolt.diy/app/components/ui/PanelHeader.tsx +20 -0
  224. tools/bolt.diy/app/components/ui/PanelHeaderButton.tsx +36 -0
  225. tools/bolt.diy/app/components/ui/Popover.tsx +29 -0
  226. tools/bolt.diy/app/components/ui/Progress.tsx +22 -0
  227. tools/bolt.diy/app/components/ui/RepositoryStats.tsx +87 -0
  228. tools/bolt.diy/app/components/ui/ScrollArea.tsx +41 -0
  229. tools/bolt.diy/app/components/ui/SearchInput.tsx +80 -0
  230. tools/bolt.diy/app/components/ui/SearchResultItem.tsx +134 -0
  231. tools/bolt.diy/app/components/ui/Separator.tsx +22 -0
  232. tools/bolt.diy/app/components/ui/SettingsButton.tsx +35 -0
  233. tools/bolt.diy/app/components/ui/Slider.tsx +73 -0
  234. tools/bolt.diy/app/components/ui/StatusIndicator.tsx +90 -0
  235. tools/bolt.diy/app/components/ui/Switch.tsx +37 -0
  236. tools/bolt.diy/app/components/ui/Tabs.tsx +52 -0
  237. tools/bolt.diy/app/components/ui/TabsWithSlider.tsx +112 -0
  238. tools/bolt.diy/app/components/ui/ThemeSwitch.tsx +29 -0
  239. tools/bolt.diy/app/components/ui/Tooltip.tsx +122 -0
  240. tools/bolt.diy/app/components/ui/index.ts +38 -0
  241. tools/bolt.diy/app/components/ui/use-toast.ts +66 -0
  242. tools/bolt.diy/app/components/workbench/DiffView.tsx +796 -0
  243. tools/bolt.diy/app/components/workbench/EditorPanel.tsx +174 -0
  244. tools/bolt.diy/app/components/workbench/ExpoQrModal.tsx +55 -0
  245. tools/bolt.diy/app/components/workbench/FileBreadcrumb.tsx +150 -0
  246. tools/bolt.diy/app/components/workbench/FileTree.tsx +565 -0
  247. tools/bolt.diy/app/components/workbench/Inspector.tsx +126 -0
  248. tools/bolt.diy/app/components/workbench/InspectorPanel.tsx +146 -0
  249. tools/bolt.diy/app/components/workbench/LockManager.tsx +262 -0
  250. tools/bolt.diy/app/components/workbench/PortDropdown.tsx +91 -0
  251. tools/bolt.diy/app/components/workbench/Preview.tsx +1049 -0
  252. tools/bolt.diy/app/components/workbench/ScreenshotSelector.tsx +293 -0
  253. tools/bolt.diy/app/components/workbench/Search.tsx +257 -0
  254. tools/bolt.diy/app/components/workbench/Workbench.client.tsx +506 -0
  255. tools/bolt.diy/app/components/workbench/terminal/Terminal.tsx +131 -0
  256. tools/bolt.diy/app/components/workbench/terminal/TerminalManager.tsx +68 -0
  257. tools/bolt.diy/app/components/workbench/terminal/TerminalTabs.tsx +277 -0
  258. tools/bolt.diy/app/components/workbench/terminal/theme.ts +36 -0
  259. tools/bolt.diy/app/components/workflow/WorkflowPhase.tsx +109 -0
  260. tools/bolt.diy/app/components/workflow/WorkflowStatus.tsx +60 -0
  261. tools/bolt.diy/app/components/workflow/WorkflowTimeline.tsx +150 -0
  262. tools/bolt.diy/app/entry.client.tsx +7 -0
  263. tools/bolt.diy/app/entry.server.tsx +80 -0
  264. tools/bolt.diy/app/root.tsx +156 -0
  265. tools/bolt.diy/app/routes/_index.tsx +175 -0
  266. tools/bolt.diy/app/routes/api.bug-report.ts +254 -0
  267. tools/bolt.diy/app/routes/api.chat.ts +463 -0
  268. tools/bolt.diy/app/routes/api.check-env-key.ts +41 -0
  269. tools/bolt.diy/app/routes/api.configured-providers.ts +110 -0
  270. tools/bolt.diy/app/routes/api.corporate-swarm-status.ts +55 -0
  271. tools/bolt.diy/app/routes/api.enhancer.ts +137 -0
  272. tools/bolt.diy/app/routes/api.export-api-keys.ts +44 -0
  273. tools/bolt.diy/app/routes/api.git-info.ts +69 -0
  274. tools/bolt.diy/app/routes/api.git-proxy.$.ts +178 -0
  275. tools/bolt.diy/app/routes/api.github-branches.ts +166 -0
  276. tools/bolt.diy/app/routes/api.github-deploy.ts +67 -0
  277. tools/bolt.diy/app/routes/api.github-stats.ts +198 -0
  278. tools/bolt.diy/app/routes/api.github-template.ts +242 -0
  279. tools/bolt.diy/app/routes/api.github-user.ts +287 -0
  280. tools/bolt.diy/app/routes/api.gitlab-branches.ts +143 -0
  281. tools/bolt.diy/app/routes/api.gitlab-deploy.ts +67 -0
  282. tools/bolt.diy/app/routes/api.gitlab-projects.ts +105 -0
  283. tools/bolt.diy/app/routes/api.health.ts +8 -0
  284. tools/bolt.diy/app/routes/api.llmcall.ts +298 -0
  285. tools/bolt.diy/app/routes/api.mandate.ts +351 -0
  286. tools/bolt.diy/app/routes/api.mcp-check.ts +16 -0
  287. tools/bolt.diy/app/routes/api.mcp-update-config.ts +23 -0
  288. tools/bolt.diy/app/routes/api.models.$provider.ts +2 -0
  289. tools/bolt.diy/app/routes/api.models.ts +90 -0
  290. tools/bolt.diy/app/routes/api.netlify-deploy.ts +240 -0
  291. tools/bolt.diy/app/routes/api.netlify-user.ts +142 -0
  292. tools/bolt.diy/app/routes/api.supabase-user.ts +199 -0
  293. tools/bolt.diy/app/routes/api.supabase.query.ts +92 -0
  294. tools/bolt.diy/app/routes/api.supabase.ts +56 -0
  295. tools/bolt.diy/app/routes/api.supabase.variables.ts +32 -0
  296. tools/bolt.diy/app/routes/api.system.diagnostics.ts +142 -0
  297. tools/bolt.diy/app/routes/api.system.disk-info.ts +311 -0
  298. tools/bolt.diy/app/routes/api.system.git-info.ts +332 -0
  299. tools/bolt.diy/app/routes/api.update.ts +21 -0
  300. tools/bolt.diy/app/routes/api.vercel-deploy.ts +497 -0
  301. tools/bolt.diy/app/routes/api.vercel-user.ts +161 -0
  302. tools/bolt.diy/app/routes/api.workflow-status.$proposalId.ts +309 -0
  303. tools/bolt.diy/app/routes/chat.$id.tsx +8 -0
  304. tools/bolt.diy/app/routes/execute.$mandateId.tsx +432 -0
  305. tools/bolt.diy/app/routes/git.tsx +25 -0
  306. tools/bolt.diy/app/routes/observability.$mandateId.tsx +50 -0
  307. tools/bolt.diy/app/routes/webcontainer.connect.$id.tsx +32 -0
  308. tools/bolt.diy/app/routes/webcontainer.preview.$id.tsx +97 -0
  309. tools/bolt.diy/app/routes/workflow.$proposalId.tsx +170 -0
  310. tools/bolt.diy/app/styles/animations.scss +49 -0
  311. tools/bolt.diy/app/styles/components/code.scss +9 -0
  312. tools/bolt.diy/app/styles/components/editor.scss +135 -0
  313. tools/bolt.diy/app/styles/components/resize-handle.scss +30 -0
  314. tools/bolt.diy/app/styles/components/terminal.scss +3 -0
  315. tools/bolt.diy/app/styles/components/toast.scss +23 -0
  316. tools/bolt.diy/app/styles/diff-view.css +72 -0
  317. tools/bolt.diy/app/styles/index.scss +73 -0
  318. tools/bolt.diy/app/styles/variables.scss +255 -0
  319. tools/bolt.diy/app/styles/z-index.scss +37 -0
  320. tools/bolt.diy/app/types/GitHub.ts +182 -0
  321. tools/bolt.diy/app/types/GitLab.ts +103 -0
  322. tools/bolt.diy/app/types/actions.ts +85 -0
  323. tools/bolt.diy/app/types/artifact.ts +5 -0
  324. tools/bolt.diy/app/types/context.ts +26 -0
  325. tools/bolt.diy/app/types/design-scheme.ts +93 -0
  326. tools/bolt.diy/app/types/global.d.ts +13 -0
  327. tools/bolt.diy/app/types/mandate.ts +333 -0
  328. tools/bolt.diy/app/types/model.ts +25 -0
  329. tools/bolt.diy/app/types/netlify.ts +94 -0
  330. tools/bolt.diy/app/types/supabase.ts +54 -0
  331. tools/bolt.diy/app/types/template.ts +8 -0
  332. tools/bolt.diy/app/types/terminal.ts +9 -0
  333. tools/bolt.diy/app/types/theme.ts +1 -0
  334. tools/bolt.diy/app/types/vercel.ts +67 -0
  335. tools/bolt.diy/app/utils/buffer.ts +29 -0
  336. tools/bolt.diy/app/utils/classNames.ts +65 -0
  337. tools/bolt.diy/app/utils/constants.ts +147 -0
  338. tools/bolt.diy/app/utils/debounce.ts +13 -0
  339. tools/bolt.diy/app/utils/debugLogger.ts +1284 -0
  340. tools/bolt.diy/app/utils/diff.spec.ts +11 -0
  341. tools/bolt.diy/app/utils/diff.ts +117 -0
  342. tools/bolt.diy/app/utils/easings.ts +3 -0
  343. tools/bolt.diy/app/utils/fileLocks.ts +96 -0
  344. tools/bolt.diy/app/utils/fileUtils.ts +121 -0
  345. tools/bolt.diy/app/utils/folderImport.ts +73 -0
  346. tools/bolt.diy/app/utils/formatSize.ts +12 -0
  347. tools/bolt.diy/app/utils/getLanguageFromExtension.ts +24 -0
  348. tools/bolt.diy/app/utils/githubStats.ts +9 -0
  349. tools/bolt.diy/app/utils/gitlabStats.ts +54 -0
  350. tools/bolt.diy/app/utils/logger.ts +162 -0
  351. tools/bolt.diy/app/utils/markdown.ts +155 -0
  352. tools/bolt.diy/app/utils/mobile.ts +4 -0
  353. tools/bolt.diy/app/utils/os.ts +4 -0
  354. tools/bolt.diy/app/utils/path.ts +19 -0
  355. tools/bolt.diy/app/utils/projectCommands.ts +197 -0
  356. tools/bolt.diy/app/utils/promises.ts +19 -0
  357. tools/bolt.diy/app/utils/react.ts +6 -0
  358. tools/bolt.diy/app/utils/sampler.ts +49 -0
  359. tools/bolt.diy/app/utils/selectStarterTemplate.ts +255 -0
  360. tools/bolt.diy/app/utils/shell.ts +384 -0
  361. tools/bolt.diy/app/utils/stacktrace.ts +27 -0
  362. tools/bolt.diy/app/utils/stripIndent.ts +23 -0
  363. tools/bolt.diy/app/utils/terminal.ts +11 -0
  364. tools/bolt.diy/app/utils/unreachable.ts +3 -0
  365. tools/bolt.diy/app/vite-env.d.ts +2 -0
  366. tools/bolt.diy/assets/entitlements.mac.plist +25 -0
  367. tools/bolt.diy/assets/icons/icon.icns +0 -0
  368. tools/bolt.diy/assets/icons/icon.ico +0 -0
  369. tools/bolt.diy/assets/icons/icon.png +0 -0
  370. tools/bolt.diy/bindings.js +78 -0
  371. tools/bolt.diy/bindings.sh +33 -0
  372. tools/bolt.diy/docker-compose.yaml +145 -0
  373. tools/bolt.diy/electron/main/index.ts +201 -0
  374. tools/bolt.diy/electron/main/tsconfig.json +30 -0
  375. tools/bolt.diy/electron/main/ui/menu.ts +29 -0
  376. tools/bolt.diy/electron/main/ui/window.ts +54 -0
  377. tools/bolt.diy/electron/main/utils/auto-update.ts +110 -0
  378. tools/bolt.diy/electron/main/utils/constants.ts +4 -0
  379. tools/bolt.diy/electron/main/utils/cookie.ts +40 -0
  380. tools/bolt.diy/electron/main/utils/reload.ts +35 -0
  381. tools/bolt.diy/electron/main/utils/serve.ts +71 -0
  382. tools/bolt.diy/electron/main/utils/store.ts +3 -0
  383. tools/bolt.diy/electron/main/utils/vite-server.ts +44 -0
  384. tools/bolt.diy/electron/main/vite.config.ts +44 -0
  385. tools/bolt.diy/electron/preload/index.ts +22 -0
  386. tools/bolt.diy/electron/preload/tsconfig.json +7 -0
  387. tools/bolt.diy/electron/preload/vite.config.ts +31 -0
  388. tools/bolt.diy/electron-builder.yml +64 -0
  389. tools/bolt.diy/electron-update.yml +4 -0
  390. tools/bolt.diy/eslint.config.mjs +57 -0
  391. tools/bolt.diy/functions/[[path]].ts +12 -0
  392. tools/bolt.diy/icons/angular.svg +1 -0
  393. tools/bolt.diy/icons/astro.svg +8 -0
  394. tools/bolt.diy/icons/chat.svg +1 -0
  395. tools/bolt.diy/icons/expo-brand.svg +1 -0
  396. tools/bolt.diy/icons/expo.svg +4 -0
  397. tools/bolt.diy/icons/logo-text.svg +1 -0
  398. tools/bolt.diy/icons/logo.svg +4 -0
  399. tools/bolt.diy/icons/mcp.svg +1 -0
  400. tools/bolt.diy/icons/nativescript.svg +1 -0
  401. tools/bolt.diy/icons/netlify.svg +10 -0
  402. tools/bolt.diy/icons/nextjs.svg +1 -0
  403. tools/bolt.diy/icons/nuxt.svg +1 -0
  404. tools/bolt.diy/icons/qwik.svg +1 -0
  405. tools/bolt.diy/icons/react.svg +1 -0
  406. tools/bolt.diy/icons/remix.svg +24 -0
  407. tools/bolt.diy/icons/remotion.svg +1 -0
  408. tools/bolt.diy/icons/shadcn.svg +21 -0
  409. tools/bolt.diy/icons/slidev.svg +60 -0
  410. tools/bolt.diy/icons/solidjs.svg +1 -0
  411. tools/bolt.diy/icons/stars.svg +1 -0
  412. tools/bolt.diy/icons/svelte.svg +1 -0
  413. tools/bolt.diy/icons/typescript.svg +1 -0
  414. tools/bolt.diy/icons/vite.svg +1 -0
  415. tools/bolt.diy/icons/vue.svg +1 -0
  416. tools/bolt.diy/load-context.ts +9 -0
  417. tools/bolt.diy/notarize.cjs +31 -0
  418. tools/bolt.diy/package.json +218 -0
  419. tools/bolt.diy/playwright.config.preview.ts +35 -0
  420. tools/bolt.diy/pre-start.cjs +26 -0
  421. tools/bolt.diy/public/apple-touch-icon-precomposed.png +0 -0
  422. tools/bolt.diy/public/apple-touch-icon.png +0 -0
  423. tools/bolt.diy/public/favicon.ico +0 -0
  424. tools/bolt.diy/public/favicon.svg +4 -0
  425. tools/bolt.diy/public/icons/AmazonBedrock.svg +1 -0
  426. tools/bolt.diy/public/icons/Anthropic.svg +4 -0
  427. tools/bolt.diy/public/icons/Cohere.svg +4 -0
  428. tools/bolt.diy/public/icons/Deepseek.svg +5 -0
  429. tools/bolt.diy/public/icons/Default.svg +4 -0
  430. tools/bolt.diy/public/icons/Google.svg +4 -0
  431. tools/bolt.diy/public/icons/Groq.svg +4 -0
  432. tools/bolt.diy/public/icons/HuggingFace.svg +4 -0
  433. tools/bolt.diy/public/icons/Hyperbolic.svg +3 -0
  434. tools/bolt.diy/public/icons/LMStudio.svg +5 -0
  435. tools/bolt.diy/public/icons/Mistral.svg +4 -0
  436. tools/bolt.diy/public/icons/Ollama.svg +4 -0
  437. tools/bolt.diy/public/icons/OpenAI.svg +4 -0
  438. tools/bolt.diy/public/icons/OpenAILike.svg +4 -0
  439. tools/bolt.diy/public/icons/OpenRouter.svg +4 -0
  440. tools/bolt.diy/public/icons/Perplexity.svg +4 -0
  441. tools/bolt.diy/public/icons/Together.svg +4 -0
  442. tools/bolt.diy/public/icons/xAI.svg +5 -0
  443. tools/bolt.diy/public/inspector-script.js +292 -0
  444. tools/bolt.diy/public/logo-dark-styled.png +0 -0
  445. tools/bolt.diy/public/logo-dark.png +0 -0
  446. tools/bolt.diy/public/logo-light-styled.png +0 -0
  447. tools/bolt.diy/public/logo-light.png +0 -0
  448. tools/bolt.diy/public/logo.svg +15 -0
  449. tools/bolt.diy/public/social_preview_index.jpg +0 -0
  450. tools/bolt.diy/scripts/clean.js +45 -0
  451. tools/bolt.diy/scripts/electron-dev.mjs +181 -0
  452. tools/bolt.diy/scripts/setup-env.sh +41 -0
  453. tools/bolt.diy/scripts/update-imports.sh +7 -0
  454. tools/bolt.diy/scripts/update.sh +52 -0
  455. tools/bolt.diy/services/execution-governor/Dockerfile +41 -0
  456. tools/bolt.diy/services/execution-governor/config.ts +42 -0
  457. tools/bolt.diy/services/execution-governor/index.ts +683 -0
  458. tools/bolt.diy/services/execution-governor/metrics.ts +141 -0
  459. tools/bolt.diy/services/execution-governor/package.json +31 -0
  460. tools/bolt.diy/services/execution-governor/priority-queue.ts +139 -0
  461. tools/bolt.diy/services/execution-governor/tsconfig.json +21 -0
  462. tools/bolt.diy/services/execution-governor/types.ts +145 -0
  463. tools/bolt.diy/services/headless-executor/Dockerfile +43 -0
  464. tools/bolt.diy/services/headless-executor/executor.ts +210 -0
  465. tools/bolt.diy/services/headless-executor/index.ts +323 -0
  466. tools/bolt.diy/services/headless-executor/package.json +27 -0
  467. tools/bolt.diy/services/headless-executor/tsconfig.json +21 -0
  468. tools/bolt.diy/services/headless-executor/types.ts +38 -0
  469. tools/bolt.diy/test-workflows.sh +240 -0
  470. tools/bolt.diy/tests/integration/corporate-swarm.test.ts +208 -0
  471. tools/bolt.diy/tests/mandates/budget-limited.json +34 -0
  472. tools/bolt.diy/tests/mandates/complex.json +53 -0
  473. tools/bolt.diy/tests/mandates/constraint-enforced.json +36 -0
  474. tools/bolt.diy/tests/mandates/simple.json +35 -0
  475. tools/bolt.diy/tsconfig.json +37 -0
  476. tools/bolt.diy/types/istextorbinary.d.ts +15 -0
  477. tools/bolt.diy/uno.config.ts +279 -0
  478. tools/bolt.diy/vite-electron.config.ts +76 -0
  479. tools/bolt.diy/vite.config.ts +112 -0
  480. tools/bolt.diy/worker-configuration.d.ts +22 -0
  481. tools/bolt.diy/wrangler.toml +6 -0
  482. tools/code_generator.py +461 -0
  483. tools/file_operations.py +465 -0
  484. tools/mandate_generator.py +337 -0
  485. tools/mcpClientUtils.py +1216 -0
  486. tools/sensors.py +285 -0
  487. utils/Agent_types.py +15 -0
  488. utils/AnyToStr.py +0 -0
  489. utils/HHCS.py +277 -0
  490. utils/__init__.py +30 -0
  491. utils/agent.py +3627 -0
  492. utils/aop.py +2948 -0
  493. utils/canonical.py +143 -0
  494. utils/conversation.py +1195 -0
  495. utils/doctrine_versioning +230 -0
  496. utils/formatter.py +474 -0
  497. utils/ledger.py +311 -0
  498. utils/out_types.py +16 -0
  499. utils/rollback.py +339 -0
  500. utils/router.py +929 -0
  501. utils/tui.py +1908 -0
@@ -0,0 +1,1284 @@
1
+ import { isMac, isWindows, isLinux } from './os';
2
+ import { isMobile } from './mobile';
3
+ import { PROVIDER_LIST, DEFAULT_MODEL } from './constants';
4
+ import { logger } from './logger';
5
+
6
+ // Lazy import to avoid circular dependencies
7
+ let logStore: any = null;
8
+ const getLogStore = () => {
9
+ if (!logStore && typeof window !== 'undefined') {
10
+ try {
11
+ // Import and set the logStore on first access
12
+ import('~/lib/stores/logs')
13
+ .then(({ logStore: store }) => {
14
+ logStore = store;
15
+ })
16
+ .catch(() => {
17
+ // Ignore import errors
18
+ });
19
+ } catch {
20
+ // Ignore errors
21
+ }
22
+ }
23
+
24
+ return logStore;
25
+ };
26
+
27
+ // Configuration interface for debug logger
28
+ export interface DebugLoggerConfig {
29
+ enabled: boolean;
30
+ maxEntries: number;
31
+ captureConsole: boolean;
32
+ captureNetwork: boolean;
33
+ captureErrors: boolean;
34
+ debounceTerminal: number; // ms
35
+ }
36
+
37
+ // Circular buffer implementation for memory efficiency
38
+ class CircularBuffer<T> {
39
+ private _buffer: (T | undefined)[];
40
+ private _head = 0;
41
+ private _tail = 0;
42
+ private _size = 0;
43
+
44
+ constructor(private _capacity: number) {
45
+ this._buffer = new Array(_capacity);
46
+ }
47
+
48
+ push(item: T): void {
49
+ this._buffer[this._tail] = item;
50
+ this._tail = (this._tail + 1) % this._capacity;
51
+
52
+ if (this._size < this._capacity) {
53
+ this._size++;
54
+ } else {
55
+ this._head = (this._head + 1) % this._capacity;
56
+ }
57
+ }
58
+
59
+ toArray(): T[] {
60
+ const result: T[] = [];
61
+ let current = this._head;
62
+
63
+ for (let i = 0; i < this._size; i++) {
64
+ const item = this._buffer[current];
65
+
66
+ if (item !== undefined) {
67
+ result.push(item);
68
+ }
69
+
70
+ current = (current + 1) % this._capacity;
71
+ }
72
+
73
+ return result;
74
+ }
75
+
76
+ clear(): void {
77
+ this._buffer = new Array(this._capacity);
78
+ this._head = 0;
79
+ this._tail = 0;
80
+ this._size = 0;
81
+ }
82
+
83
+ getSize(): number {
84
+ return this._size;
85
+ }
86
+ }
87
+
88
+ export interface DebugLogData {
89
+ timestamp: string;
90
+ sessionId: string;
91
+ systemInfo: SystemInfo;
92
+ appInfo: AppInfo;
93
+ logs: LogEntry[];
94
+ errors: ErrorEntry[];
95
+ networkRequests: NetworkEntry[];
96
+ performance: PerformanceEntry;
97
+ state: StateEntry;
98
+ userActions: UserActionEntry[];
99
+ terminalLogs: TerminalEntry[];
100
+ }
101
+
102
+ export interface SystemInfo {
103
+ platform: string;
104
+ userAgent: string;
105
+ screenResolution: string;
106
+ viewportSize: string;
107
+ isMobile: boolean;
108
+ timezone: string;
109
+ language: string;
110
+ cookiesEnabled: boolean;
111
+ localStorageEnabled: boolean;
112
+ sessionStorageEnabled: boolean;
113
+ }
114
+
115
+ export interface AppInfo {
116
+ version: string;
117
+ buildTime: string;
118
+ currentModel: string;
119
+ currentProvider: string;
120
+ projectType: string;
121
+ workbenchView: string;
122
+ hasActivePreview: boolean;
123
+ unsavedFiles: number;
124
+ workbenchState?: {
125
+ currentView: string;
126
+ showWorkbench: boolean;
127
+ showTerminal: boolean;
128
+ artifactsCount: number;
129
+ filesCount: number;
130
+ unsavedFiles: number;
131
+ hasActivePreview: boolean;
132
+ };
133
+ gitInfo?: {
134
+ branch: string;
135
+ commit: string;
136
+ isDirty: boolean;
137
+ remoteUrl?: string;
138
+ lastCommit?: {
139
+ message: string;
140
+ date: string;
141
+ author: string;
142
+ };
143
+ };
144
+ }
145
+
146
+ export interface LogEntry {
147
+ timestamp: string;
148
+ level: 'trace' | 'debug' | 'info' | 'warn' | 'error';
149
+ scope?: string;
150
+ message: string;
151
+ data?: any;
152
+ }
153
+
154
+ export interface ErrorEntry {
155
+ timestamp: string;
156
+ type: 'javascript' | 'react' | 'terminal' | 'network' | 'unknown';
157
+ message: string;
158
+ stack?: string;
159
+ url?: string;
160
+ line?: number;
161
+ column?: number;
162
+ userAgent?: string;
163
+ context?: any;
164
+ }
165
+
166
+ export interface NetworkEntry {
167
+ timestamp: string;
168
+ method: string;
169
+ url: string;
170
+ status?: number;
171
+ duration?: number;
172
+ requestSize?: number;
173
+ responseSize?: number;
174
+ error?: string;
175
+ }
176
+
177
+ export interface PerformanceEntry {
178
+ navigationStart: number;
179
+ loadTime: number;
180
+ domContentLoaded: number;
181
+ firstPaint?: number;
182
+ firstContentfulPaint?: number;
183
+ memoryUsage?: {
184
+ used: number;
185
+ total: number;
186
+ limit: number;
187
+ };
188
+ timing: any; // Using any instead of deprecated PerformanceTiming
189
+ }
190
+
191
+ export interface StateEntry {
192
+ currentView: string;
193
+ showWorkbench: boolean;
194
+ showTerminal: boolean;
195
+ artifactsCount: number;
196
+ filesCount: number;
197
+ alerts: Array<{
198
+ type: string;
199
+ title: string;
200
+ source?: string;
201
+ }>;
202
+ }
203
+
204
+ export interface UserActionEntry {
205
+ timestamp: string;
206
+ action: string;
207
+ target?: string;
208
+ data?: any;
209
+ }
210
+
211
+ export interface TerminalEntry {
212
+ timestamp: string;
213
+ type: 'input' | 'output' | 'error';
214
+ content: string;
215
+ command?: string;
216
+ }
217
+
218
+ class DebugLogger {
219
+ private _logs: CircularBuffer<LogEntry>;
220
+ private _errors: CircularBuffer<ErrorEntry>;
221
+ private _networkRequests: CircularBuffer<NetworkEntry>;
222
+ private _userActions: CircularBuffer<UserActionEntry>;
223
+ private _terminalLogs: CircularBuffer<TerminalEntry>;
224
+ private _config: DebugLoggerConfig;
225
+ private _isCapturing = false;
226
+ private _isInitialized = false;
227
+
228
+ // Store original functions
229
+ private _originalConsoleLog: typeof console.log;
230
+ private _originalConsoleError: typeof console.error;
231
+ private _originalConsoleWarn: typeof console.warn;
232
+ private _originalFetch: typeof window.fetch | null = null;
233
+
234
+ // Store bound event handlers for proper cleanup
235
+ private _boundErrorHandler: (event: ErrorEvent) => void;
236
+ private _boundRejectionHandler: (event: PromiseRejectionEvent) => void;
237
+ private _boundUnloadHandler: () => void;
238
+
239
+ // Debouncing for terminal logs
240
+ private _terminalLogQueue: TerminalEntry[] = [];
241
+ private _terminalLogTimer: NodeJS.Timeout | null = null;
242
+
243
+ // Helper for JSON replacer with seen tracking
244
+ private _seenObjects = new WeakSet();
245
+
246
+ constructor(config: Partial<DebugLoggerConfig> = {}) {
247
+ // Default configuration
248
+ this._config = {
249
+ enabled: false, // Start disabled for performance
250
+ maxEntries: 1000,
251
+ captureConsole: true,
252
+ captureNetwork: true,
253
+ captureErrors: true,
254
+ debounceTerminal: 100,
255
+ ...config,
256
+ };
257
+
258
+ // Initialize circular buffers
259
+ this._logs = new CircularBuffer<LogEntry>(this._config.maxEntries);
260
+ this._errors = new CircularBuffer<ErrorEntry>(this._config.maxEntries);
261
+ this._networkRequests = new CircularBuffer<NetworkEntry>(this._config.maxEntries);
262
+ this._userActions = new CircularBuffer<UserActionEntry>(this._config.maxEntries);
263
+ this._terminalLogs = new CircularBuffer<TerminalEntry>(this._config.maxEntries);
264
+
265
+ // Store original functions
266
+ this._originalConsoleLog = console.log;
267
+ this._originalConsoleError = console.error;
268
+ this._originalConsoleWarn = console.warn;
269
+
270
+ // Bind event handlers once to prevent memory leaks
271
+ this._boundErrorHandler = this._handleError.bind(this);
272
+ this._boundRejectionHandler = this._handleUnhandledRejection.bind(this);
273
+ this._boundUnloadHandler = this._cleanup.bind(this);
274
+
275
+ // Setup cleanup on page unload
276
+ if (typeof window !== 'undefined') {
277
+ window.addEventListener('beforeunload', this._boundUnloadHandler);
278
+ }
279
+ }
280
+
281
+ // Initialize the debug logger (lazy initialization for performance)
282
+ initialize(): void {
283
+ if (this._isInitialized) {
284
+ return;
285
+ }
286
+
287
+ try {
288
+ // Only initialize if we're in a browser environment
289
+ if (typeof window === 'undefined') {
290
+ return;
291
+ }
292
+
293
+ this._isInitialized = true;
294
+
295
+ // Start capturing if enabled
296
+ if (this._config.enabled) {
297
+ this.startCapture();
298
+ }
299
+
300
+ logger.info('Debug logger initialized');
301
+ } catch (error) {
302
+ logger.error('Failed to initialize debug logger:', error);
303
+ }
304
+ }
305
+
306
+ startCapture(): void {
307
+ if (this._isCapturing) {
308
+ return;
309
+ }
310
+
311
+ try {
312
+ this._isCapturing = true;
313
+ this._config.enabled = true;
314
+
315
+ if (this._config.captureConsole) {
316
+ this._interceptConsole();
317
+ }
318
+
319
+ if (this._config.captureErrors) {
320
+ this._interceptErrors();
321
+ }
322
+
323
+ if (this._config.captureNetwork) {
324
+ this._interceptNetwork();
325
+ }
326
+
327
+ logger.info('Debug logging started');
328
+ } catch (error) {
329
+ logger.error('Failed to start debug capture:', error);
330
+ this._isCapturing = false;
331
+ }
332
+ }
333
+
334
+ stopCapture(): void {
335
+ if (!this._isCapturing) {
336
+ return;
337
+ }
338
+
339
+ try {
340
+ this._isCapturing = false;
341
+ this._config.enabled = false;
342
+
343
+ this._restoreConsole();
344
+ this._restoreErrors();
345
+ this._restoreNetwork();
346
+
347
+ // Clear terminal log timer
348
+ if (this._terminalLogTimer) {
349
+ clearTimeout(this._terminalLogTimer);
350
+ this._terminalLogTimer = null;
351
+ this._flushTerminalLogs();
352
+ }
353
+
354
+ logger.info('Debug logging stopped');
355
+ } catch (error) {
356
+ logger.error('Failed to stop debug capture:', error);
357
+ }
358
+ }
359
+
360
+ // Public method to enable debug logging on demand
361
+ enableDebugMode(): void {
362
+ this._config.enabled = true;
363
+
364
+ if (!this._isInitialized) {
365
+ this.initialize();
366
+ } else if (!this._isCapturing) {
367
+ this.startCapture();
368
+ }
369
+ }
370
+
371
+ // Public method to disable debug logging
372
+ disableDebugMode(): void {
373
+ this.stopCapture();
374
+ }
375
+
376
+ // Get current status
377
+ getStatus(): { initialized: boolean; capturing: boolean; enabled: boolean } {
378
+ return {
379
+ initialized: this._isInitialized,
380
+ capturing: this._isCapturing,
381
+ enabled: this._config.enabled,
382
+ };
383
+ }
384
+
385
+ // Update configuration
386
+ updateConfig(newConfig: Partial<DebugLoggerConfig>): void {
387
+ const wasCapturing = this._isCapturing;
388
+
389
+ if (wasCapturing) {
390
+ this.stopCapture();
391
+ }
392
+
393
+ this._config = { ...this._config, ...newConfig };
394
+
395
+ // Recreate buffers if maxEntries changed
396
+ if (newConfig.maxEntries && newConfig.maxEntries !== this._config.maxEntries) {
397
+ const oldLogs = this._logs.toArray();
398
+ const oldErrors = this._errors.toArray();
399
+ const oldNetworkRequests = this._networkRequests.toArray();
400
+ const oldUserActions = this._userActions.toArray();
401
+ const oldTerminalLogs = this._terminalLogs.toArray();
402
+
403
+ this._logs = new CircularBuffer<LogEntry>(this._config.maxEntries);
404
+ this._errors = new CircularBuffer<ErrorEntry>(this._config.maxEntries);
405
+ this._networkRequests = new CircularBuffer<NetworkEntry>(this._config.maxEntries);
406
+ this._userActions = new CircularBuffer<UserActionEntry>(this._config.maxEntries);
407
+ this._terminalLogs = new CircularBuffer<TerminalEntry>(this._config.maxEntries);
408
+
409
+ // Re-add existing data
410
+ oldLogs.forEach((log) => this._logs.push(log));
411
+ oldErrors.forEach((error) => this._errors.push(error));
412
+ oldNetworkRequests.forEach((request) => this._networkRequests.push(request));
413
+ oldUserActions.forEach((action) => this._userActions.push(action));
414
+ oldTerminalLogs.forEach((log) => this._terminalLogs.push(log));
415
+ }
416
+
417
+ if (wasCapturing && this._config.enabled) {
418
+ this.startCapture();
419
+ }
420
+ }
421
+
422
+ // Cleanup method
423
+ private _cleanup(): void {
424
+ this.stopCapture();
425
+
426
+ if (typeof window !== 'undefined') {
427
+ window.removeEventListener('beforeunload', this._boundUnloadHandler);
428
+ }
429
+ }
430
+
431
+ private _interceptConsole(): void {
432
+ const self = this;
433
+
434
+ console.log = function (...args: any[]) {
435
+ self.captureLog('info', undefined, args);
436
+ self._originalConsoleLog.apply(console, args);
437
+ };
438
+
439
+ console.error = function (...args: any[]) {
440
+ self.captureLog('error', undefined, args);
441
+ self._originalConsoleError.apply(console, args);
442
+ };
443
+
444
+ console.warn = function (...args: any[]) {
445
+ self.captureLog('warn', undefined, args);
446
+ self._originalConsoleWarn.apply(console, args);
447
+ };
448
+ }
449
+
450
+ private _restoreConsole(): void {
451
+ console.log = this._originalConsoleLog;
452
+ console.error = this._originalConsoleError;
453
+ console.warn = this._originalConsoleWarn;
454
+ }
455
+
456
+ private _interceptErrors(): void {
457
+ try {
458
+ window.addEventListener('error', this._boundErrorHandler);
459
+ window.addEventListener('unhandledrejection', this._boundRejectionHandler);
460
+ } catch (error) {
461
+ logger.error('Failed to intercept errors:', error);
462
+ }
463
+ }
464
+
465
+ private _restoreErrors(): void {
466
+ try {
467
+ window.removeEventListener('error', this._boundErrorHandler);
468
+ window.removeEventListener('unhandledrejection', this._boundRejectionHandler);
469
+ } catch (error) {
470
+ logger.error('Failed to restore error handlers:', error);
471
+ }
472
+ }
473
+
474
+ private _interceptNetwork(): void {
475
+ try {
476
+ // Store original fetch if not already stored
477
+ if (!this._originalFetch && typeof window !== 'undefined') {
478
+ this._originalFetch = window.fetch;
479
+ }
480
+
481
+ if (!this._originalFetch) {
482
+ return;
483
+ }
484
+
485
+ const originalFetch = this._originalFetch;
486
+ const self = this;
487
+
488
+ window.fetch = async function (...args: Parameters<typeof fetch>) {
489
+ // Quick path for non-capturing mode
490
+ if (!self._isCapturing) {
491
+ return originalFetch.apply(this, args);
492
+ }
493
+
494
+ const startTime = performance.now();
495
+ const [resource, config] = args;
496
+
497
+ try {
498
+ const response = await originalFetch.apply(this, args);
499
+ const duration = Math.round(performance.now() - startTime);
500
+
501
+ // Only capture if still capturing (could have changed during request)
502
+ if (self._isCapturing) {
503
+ self.captureNetworkRequest({
504
+ timestamp: new Date().toISOString(),
505
+ method: config?.method || 'GET',
506
+ url: typeof resource === 'string' ? resource : (resource as Request).url,
507
+ status: response.status,
508
+ duration,
509
+ });
510
+ }
511
+
512
+ return response;
513
+ } catch (error) {
514
+ const duration = Math.round(performance.now() - startTime);
515
+
516
+ if (self._isCapturing) {
517
+ self.captureNetworkRequest({
518
+ timestamp: new Date().toISOString(),
519
+ method: config?.method || 'GET',
520
+ url: typeof resource === 'string' ? resource : (resource as Request).url,
521
+ duration,
522
+ error: error instanceof Error ? error.message : 'Network error',
523
+ });
524
+ }
525
+
526
+ throw error;
527
+ }
528
+ };
529
+ } catch (error) {
530
+ logger.error('Failed to intercept network requests:', error);
531
+ }
532
+ }
533
+
534
+ private _restoreNetwork(): void {
535
+ try {
536
+ if (this._originalFetch && typeof window !== 'undefined') {
537
+ window.fetch = this._originalFetch;
538
+ }
539
+ } catch (error) {
540
+ logger.error('Failed to restore network fetch:', error);
541
+ }
542
+ }
543
+
544
+ private _handleError(event: ErrorEvent): void {
545
+ this.captureError({
546
+ timestamp: new Date().toISOString(),
547
+ type: 'javascript',
548
+ message: event.message,
549
+ stack: event.error?.stack,
550
+ url: event.filename,
551
+ line: event.lineno,
552
+ column: event.colno,
553
+ userAgent: navigator.userAgent,
554
+ });
555
+ }
556
+
557
+ private _handleUnhandledRejection(event: PromiseRejectionEvent): void {
558
+ this.captureError({
559
+ timestamp: new Date().toISOString(),
560
+ type: 'javascript',
561
+ message: event.reason?.message || 'Unhandled promise rejection',
562
+ stack: event.reason?.stack,
563
+ userAgent: navigator.userAgent,
564
+ });
565
+ }
566
+
567
+ captureLog(level: LogEntry['level'], scope?: string, args: any[] = []): void {
568
+ if (!this._isCapturing) {
569
+ return;
570
+ }
571
+
572
+ try {
573
+ const entry: LogEntry = {
574
+ timestamp: new Date().toISOString(),
575
+ level,
576
+ scope,
577
+
578
+ /* Lazy stringification - only convert to string when needed */
579
+ message: this._formatMessage(args),
580
+ data: args.length === 1 && typeof args[0] === 'object' ? args[0] : undefined,
581
+ };
582
+
583
+ this._logs.push(entry);
584
+ } catch (error) {
585
+ // Fallback - don't let logging errors break the app
586
+ console.error('Debug logger failed to capture log:', error);
587
+ }
588
+ }
589
+
590
+ private _formatMessage(args: any[]): string {
591
+ this._seenObjects = new WeakSet(); // Reset for each message
592
+
593
+ return args
594
+ .map((arg) => {
595
+ if (typeof arg === 'object' && arg !== null) {
596
+ try {
597
+ // Prevent circular reference errors and limit depth
598
+ return JSON.stringify(arg, this._jsonReplacer.bind(this), 2);
599
+ } catch {
600
+ return '[Object]';
601
+ }
602
+ }
603
+
604
+ return String(arg);
605
+ })
606
+ .join(' ');
607
+ }
608
+
609
+ private _jsonReplacer(_key: string, value: any): any {
610
+ // Prevent circular references and limit object depth
611
+ if (typeof value === 'object' && value !== null) {
612
+ if (this._seenObjects.has(value)) {
613
+ return '[Circular]';
614
+ }
615
+
616
+ this._seenObjects.add(value);
617
+ }
618
+
619
+ return value;
620
+ }
621
+
622
+ captureError(error: ErrorEntry): void {
623
+ try {
624
+ this._errors.push(error);
625
+ } catch (err) {
626
+ console.error('Debug logger failed to capture error:', err);
627
+ }
628
+ }
629
+
630
+ captureNetworkRequest(request: NetworkEntry): void {
631
+ try {
632
+ this._networkRequests.push(request);
633
+ } catch (error) {
634
+ console.error('Debug logger failed to capture network request:', error);
635
+ }
636
+ }
637
+
638
+ captureUserAction(action: string, target?: string, data?: any): void {
639
+ if (!this._isCapturing) {
640
+ return;
641
+ }
642
+
643
+ try {
644
+ const entry: UserActionEntry = {
645
+ timestamp: new Date().toISOString(),
646
+ action,
647
+ target,
648
+ data,
649
+ };
650
+
651
+ this._userActions.push(entry);
652
+ } catch (error) {
653
+ console.error('Debug logger failed to capture user action:', error);
654
+ }
655
+ }
656
+
657
+ captureTerminalLog(entry: TerminalEntry): void {
658
+ try {
659
+ // Debounce terminal logs to prevent spam
660
+ if (this._config.debounceTerminal > 0) {
661
+ this._terminalLogQueue.push(entry);
662
+
663
+ if (this._terminalLogTimer) {
664
+ clearTimeout(this._terminalLogTimer);
665
+ }
666
+
667
+ this._terminalLogTimer = setTimeout(() => {
668
+ this._flushTerminalLogs();
669
+ }, this._config.debounceTerminal);
670
+ } else {
671
+ this._terminalLogs.push(entry);
672
+ }
673
+ } catch (error) {
674
+ console.error('Debug logger failed to capture terminal log:', error);
675
+ }
676
+ }
677
+
678
+ private _flushTerminalLogs(): void {
679
+ try {
680
+ while (this._terminalLogQueue.length > 0) {
681
+ const entry = this._terminalLogQueue.shift();
682
+
683
+ if (entry) {
684
+ this._terminalLogs.push(entry);
685
+ }
686
+ }
687
+ this._terminalLogTimer = null;
688
+ } catch (error) {
689
+ console.error('Debug logger failed to flush terminal logs:', error);
690
+ }
691
+ }
692
+
693
+ async generateDebugLog(): Promise<DebugLogData> {
694
+ try {
695
+ // Enable debug mode temporarily if not already enabled
696
+ const wasEnabled = this._config.enabled;
697
+
698
+ if (!wasEnabled) {
699
+ this.enableDebugMode();
700
+ }
701
+
702
+ // Flush any pending terminal logs
703
+ if (this._terminalLogTimer) {
704
+ clearTimeout(this._terminalLogTimer);
705
+ this._flushTerminalLogs();
706
+ }
707
+
708
+ const [systemInfo, appInfo, performanceInfo, state] = await Promise.all([
709
+ this._collectSystemInfo(),
710
+ this._collectAppInfo(),
711
+ Promise.resolve(this._collectPerformanceInfo()),
712
+ Promise.resolve(this._collectStateInfo()),
713
+ ]);
714
+
715
+ // Get logs from logStore with proper error handling
716
+ const logStoreLogs = await this._getLogStoreLogs();
717
+
718
+ const debugData: DebugLogData = {
719
+ timestamp: new Date().toISOString(),
720
+ sessionId: this._generateSessionId(),
721
+ systemInfo,
722
+ appInfo,
723
+ logs: [...this._logs.toArray(), ...logStoreLogs],
724
+ errors: this._errors.toArray(),
725
+ networkRequests: this._networkRequests.toArray(),
726
+ performance: performanceInfo,
727
+ state,
728
+ userActions: this._userActions.toArray(),
729
+ terminalLogs: this._terminalLogs.toArray(),
730
+ };
731
+
732
+ // Restore previous state
733
+ if (!wasEnabled) {
734
+ this.disableDebugMode();
735
+ }
736
+
737
+ return debugData;
738
+ } catch (error) {
739
+ logger.error('Failed to generate debug log:', error);
740
+ throw error;
741
+ }
742
+ }
743
+
744
+ private async _getLogStoreLogs(): Promise<LogEntry[]> {
745
+ try {
746
+ const store = getLogStore();
747
+
748
+ if (!store) {
749
+ // Try to load the store if not already loaded
750
+ try {
751
+ const { logStore: storeModule } = await import('~/lib/stores/logs');
752
+ logStore = storeModule;
753
+
754
+ return this._getLogStoreLogs();
755
+ } catch {
756
+ return [];
757
+ }
758
+ }
759
+
760
+ const logs = store.getLogs?.() || [];
761
+
762
+ return logs.slice(0, 500).map((log: any) => ({
763
+ timestamp: log.timestamp,
764
+ level: log.level as LogEntry['level'],
765
+ scope: log.category,
766
+ message: log.message,
767
+ data: log.details,
768
+ }));
769
+ } catch (error) {
770
+ logger.warn('Failed to get logStore logs:', error);
771
+ return [];
772
+ }
773
+ }
774
+
775
+ private async _collectSystemInfo(): Promise<SystemInfo> {
776
+ let platform = 'Unknown';
777
+
778
+ if (isMac) {
779
+ platform = 'macOS';
780
+ } else if (isWindows) {
781
+ platform = 'Windows';
782
+ } else if (isLinux) {
783
+ platform = 'Linux';
784
+ }
785
+
786
+ return {
787
+ platform,
788
+ userAgent: navigator.userAgent,
789
+ screenResolution: `${screen.width}x${screen.height}`,
790
+ viewportSize: `${window.innerWidth}x${window.innerHeight}`,
791
+ isMobile: isMobile(),
792
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
793
+ language: navigator.language,
794
+ cookiesEnabled: navigator.cookieEnabled,
795
+ localStorageEnabled: this._testLocalStorage(),
796
+ sessionStorageEnabled: this._testSessionStorage(),
797
+ };
798
+ }
799
+
800
+ private async _collectAppInfo(): Promise<AppInfo> {
801
+ let workbenchInfo = {
802
+ currentView: 'code',
803
+ showWorkbench: false,
804
+ showTerminal: true,
805
+ artifactsCount: 0,
806
+ filesCount: 0,
807
+ unsavedFiles: 0,
808
+ hasActivePreview: false,
809
+ };
810
+
811
+ // Try to get workbench information
812
+ try {
813
+ if (typeof window !== 'undefined') {
814
+ // Access stores if available
815
+ const workbenchStore = (window as any).__bolt_workbench_store;
816
+
817
+ if (workbenchStore) {
818
+ const state = workbenchStore.get?.() || {};
819
+ workbenchInfo = {
820
+ currentView: state.currentView || 'code',
821
+ showWorkbench: state.showWorkbench || false,
822
+ showTerminal: state.showTerminal !== undefined ? state.showTerminal : true,
823
+ artifactsCount: Object.keys(state.artifacts || {}).length,
824
+ filesCount: Object.keys(state.files || {}).length,
825
+ unsavedFiles: state.unsavedFiles?.size || 0,
826
+ hasActivePreview: (state.previews || []).length > 0,
827
+ };
828
+ }
829
+ }
830
+ } catch {
831
+ // Ignore errors when accessing stores
832
+ }
833
+
834
+ return {
835
+ version: this._getAppVersion(),
836
+ buildTime: new Date().toISOString(),
837
+ currentModel: this._getCurrentModel(),
838
+ currentProvider: this._getCurrentProvider(),
839
+ projectType: this._getProjectType(),
840
+ workbenchView: workbenchInfo.currentView,
841
+ hasActivePreview: workbenchInfo.hasActivePreview,
842
+ unsavedFiles: workbenchInfo.unsavedFiles,
843
+ workbenchState: workbenchInfo,
844
+ gitInfo: await this._getGitInfo(),
845
+ };
846
+ }
847
+
848
+ private _getAppVersion(): string {
849
+ try {
850
+ // Try to get version from environment or default
851
+ return import.meta.env?.VITE_APP_VERSION || '1.0.0';
852
+ } catch {
853
+ return '1.0.0';
854
+ }
855
+ }
856
+
857
+ private _getCurrentModel(): string {
858
+ try {
859
+ // Try to get from localStorage or environment
860
+ if (typeof window !== 'undefined') {
861
+ const stored = localStorage.getItem('bolt_current_model');
862
+
863
+ if (stored) {
864
+ return stored;
865
+ }
866
+ }
867
+
868
+ return DEFAULT_MODEL;
869
+ } catch {
870
+ return DEFAULT_MODEL;
871
+ }
872
+ }
873
+
874
+ private _getCurrentProvider(): string {
875
+ try {
876
+ if (typeof window !== 'undefined') {
877
+ const stored = localStorage.getItem('bolt_current_provider');
878
+
879
+ if (stored) {
880
+ return stored;
881
+ }
882
+ }
883
+
884
+ return PROVIDER_LIST[0]?.name || 'unknown';
885
+ } catch {
886
+ return PROVIDER_LIST[0]?.name || 'unknown';
887
+ }
888
+ }
889
+
890
+ private _getProjectType(): string {
891
+ try {
892
+ if (typeof window !== 'undefined') {
893
+ const stored = localStorage.getItem('bolt_project_type');
894
+
895
+ if (stored) {
896
+ return stored;
897
+ }
898
+ }
899
+
900
+ return 'unknown';
901
+ } catch {
902
+ return 'unknown';
903
+ }
904
+ }
905
+
906
+ private async _getGitInfo(): Promise<AppInfo['gitInfo']> {
907
+ try {
908
+ // Try to fetch git info from existing API endpoint
909
+ const response = await fetch('/api/system/git-info');
910
+
911
+ if (response.ok) {
912
+ const gitInfo = await response.json();
913
+
914
+ // Transform the API response to match our interface
915
+ const gitInfoTyped = gitInfo as any;
916
+
917
+ // Type assertion for API response
918
+ return {
919
+ branch: gitInfoTyped.local?.branch || 'unknown',
920
+ commit: gitInfoTyped.local?.commitHash || 'unknown',
921
+ isDirty: false, // The existing API doesn't provide this info
922
+ remoteUrl: gitInfoTyped.local?.remoteUrl,
923
+ lastCommit: gitInfoTyped.local
924
+ ? {
925
+ message: 'Latest commit',
926
+ date: gitInfoTyped.local.commitTime,
927
+ author: gitInfoTyped.local.author,
928
+ }
929
+ : undefined,
930
+ };
931
+ }
932
+ } catch {
933
+ // API not available, try client-side fallback
934
+ console.warn('Git info API not available, using fallback');
935
+ }
936
+
937
+ // Fallback: try to get basic git info from localStorage or known values
938
+ return this._getGitInfoFallback();
939
+ }
940
+
941
+ private _getGitInfoFallback(): AppInfo['gitInfo'] {
942
+ try {
943
+ // Try to get from localStorage (could be set by the app)
944
+ const stored = localStorage.getItem('bolt_git_info');
945
+
946
+ if (stored) {
947
+ return JSON.parse(stored);
948
+ }
949
+
950
+ // Try to get from environment/build variables
951
+ const branch = import.meta.env?.VITE_GIT_BRANCH || 'unknown';
952
+ const commit = import.meta.env?.VITE_GIT_COMMIT || 'unknown';
953
+
954
+ return {
955
+ branch,
956
+ commit,
957
+ isDirty: false, // Assume clean if we don't know
958
+ };
959
+ } catch {
960
+ return {
961
+ branch: 'unknown',
962
+ commit: 'unknown',
963
+ isDirty: false,
964
+ };
965
+ }
966
+ }
967
+
968
+ private _collectPerformanceInfo(): PerformanceEntry {
969
+ const timing = performance.timing as any;
970
+ const paintEntries = performance.getEntriesByType('paint');
971
+
972
+ return {
973
+ navigationStart: timing.navigationStart,
974
+ loadTime: timing.loadEventEnd - timing.navigationStart,
975
+ domContentLoaded: timing.domContentLoadedEventEnd - timing.navigationStart,
976
+ firstPaint: paintEntries.find((entry) => entry.name === 'first-paint')?.startTime,
977
+ firstContentfulPaint: paintEntries.find((entry) => entry.name === 'first-contentful-paint')?.startTime,
978
+ memoryUsage: (performance as any).memory
979
+ ? {
980
+ used: (performance as any).memory.usedJSHeapSize,
981
+ total: (performance as any).memory.totalJSHeapSize,
982
+ limit: (performance as any).memory.jsHeapSizeLimit,
983
+ }
984
+ : undefined,
985
+ timing,
986
+ };
987
+ }
988
+
989
+ private _collectStateInfo(): StateEntry {
990
+ const store = getLogStore();
991
+ let alerts: StateEntry['alerts'] = [];
992
+
993
+ // Get recent alerts from logStore
994
+ if (store) {
995
+ try {
996
+ const logs = store.getLogs?.() || [];
997
+ alerts = logs
998
+ .filter((log: any) => ['error', 'warning'].includes(log.level))
999
+ .slice(0, 10)
1000
+ .map((log: any) => ({
1001
+ type: log.level,
1002
+ title: log.message.substring(0, 100),
1003
+ source: log.category,
1004
+ }));
1005
+ } catch {
1006
+ // Ignore errors
1007
+ }
1008
+ }
1009
+
1010
+ // Get workbench state
1011
+ let workbenchState = {
1012
+ currentView: 'code',
1013
+ showWorkbench: false,
1014
+ showTerminal: true,
1015
+ artifactsCount: 0,
1016
+ filesCount: 0,
1017
+ };
1018
+
1019
+ try {
1020
+ if (typeof window !== 'undefined') {
1021
+ const workbenchStore = (window as any).__bolt_workbench_store;
1022
+
1023
+ if (workbenchStore) {
1024
+ const state = workbenchStore.get?.() || {};
1025
+ workbenchState = {
1026
+ currentView: state.currentView || 'code',
1027
+ showWorkbench: state.showWorkbench || false,
1028
+ showTerminal: state.showTerminal !== undefined ? state.showTerminal : true,
1029
+ artifactsCount: Object.keys(state.artifacts || {}).length,
1030
+ filesCount: Object.keys(state.files || {}).length,
1031
+ };
1032
+ }
1033
+ }
1034
+ } catch {
1035
+ // Ignore errors
1036
+ }
1037
+
1038
+ return {
1039
+ currentView: workbenchState.currentView,
1040
+ showWorkbench: workbenchState.showWorkbench,
1041
+ showTerminal: workbenchState.showTerminal,
1042
+ artifactsCount: workbenchState.artifactsCount,
1043
+ filesCount: workbenchState.filesCount,
1044
+ alerts,
1045
+ };
1046
+ }
1047
+
1048
+ private _testLocalStorage(): boolean {
1049
+ try {
1050
+ localStorage.setItem('test', 'test');
1051
+ localStorage.removeItem('test');
1052
+
1053
+ return true;
1054
+ } catch {
1055
+ return false;
1056
+ }
1057
+ }
1058
+
1059
+ private _testSessionStorage(): boolean {
1060
+ try {
1061
+ sessionStorage.setItem('test', 'test');
1062
+ sessionStorage.removeItem('test');
1063
+
1064
+ return true;
1065
+ } catch {
1066
+ return false;
1067
+ }
1068
+ }
1069
+
1070
+ private _generateSessionId(): string {
1071
+ return `session_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
1072
+ }
1073
+
1074
+ clearLogs(): void {
1075
+ try {
1076
+ this._logs.clear();
1077
+ this._errors.clear();
1078
+ this._networkRequests.clear();
1079
+ this._userActions.clear();
1080
+ this._terminalLogs.clear();
1081
+
1082
+ // Clear any pending terminal logs
1083
+ this._terminalLogQueue = [];
1084
+
1085
+ if (this._terminalLogTimer) {
1086
+ clearTimeout(this._terminalLogTimer);
1087
+ this._terminalLogTimer = null;
1088
+ }
1089
+
1090
+ logger.info('Debug logs cleared');
1091
+ } catch (error) {
1092
+ logger.error('Failed to clear logs:', error);
1093
+ }
1094
+ }
1095
+
1096
+ // Get current memory usage statistics
1097
+ getMemoryStats(): {
1098
+ logs: number;
1099
+ errors: number;
1100
+ networkRequests: number;
1101
+ userActions: number;
1102
+ terminalLogs: number;
1103
+ total: number;
1104
+ } {
1105
+ const stats = {
1106
+ logs: this._logs.getSize(),
1107
+ errors: this._errors.getSize(),
1108
+ networkRequests: this._networkRequests.getSize(),
1109
+ userActions: this._userActions.getSize(),
1110
+ terminalLogs: this._terminalLogs.getSize(),
1111
+ total: 0,
1112
+ };
1113
+
1114
+ stats.total = stats.logs + stats.errors + stats.networkRequests + stats.userActions + stats.terminalLogs;
1115
+
1116
+ return stats;
1117
+ }
1118
+ }
1119
+
1120
+ // Export singleton instance with default configuration
1121
+ export const debugLogger = new DebugLogger({
1122
+ enabled: false, // Start disabled for performance
1123
+ maxEntries: 1000,
1124
+ captureConsole: true,
1125
+ captureNetwork: true,
1126
+ captureErrors: true,
1127
+ debounceTerminal: 100,
1128
+ });
1129
+
1130
+ // Helper function to download debug log
1131
+ export async function downloadDebugLog(filename?: string): Promise<void> {
1132
+ try {
1133
+ const debugData = await debugLogger.generateDebugLog();
1134
+
1135
+ // Create a formatted summary
1136
+ const summary = createDebugSummary(debugData);
1137
+ const fullContent = `${summary}\n\n=== DETAILED DEBUG DATA ===\n\n${JSON.stringify(debugData, null, 2)}`;
1138
+
1139
+ const blob = new Blob([fullContent], { type: 'text/plain' });
1140
+ const url = URL.createObjectURL(blob);
1141
+
1142
+ const link = document.createElement('a');
1143
+ link.href = url;
1144
+ link.download = filename || `bolt-debug-${new Date().toISOString().split('T')[0]}.txt`;
1145
+ document.body.appendChild(link);
1146
+ link.click();
1147
+ document.body.removeChild(link);
1148
+
1149
+ URL.revokeObjectURL(url);
1150
+
1151
+ logger.info('Debug log downloaded successfully');
1152
+ } catch (error) {
1153
+ logger.error('Failed to download debug log:', error);
1154
+ }
1155
+ }
1156
+
1157
+ // Create a human-readable summary of the debug data
1158
+ function createDebugSummary(data: DebugLogData): string {
1159
+ const summary = [
1160
+ '=== BOLT DIY DEBUG LOG SUMMARY ===',
1161
+ `Generated: ${new Date(data.timestamp).toLocaleString()}`,
1162
+ `Session ID: ${data.sessionId}`,
1163
+ '',
1164
+ '=== SYSTEM INFORMATION ===',
1165
+ `Platform: ${data.systemInfo.platform}`,
1166
+ `Browser: ${data.systemInfo.userAgent.split(' ').slice(0, 2).join(' ')}`,
1167
+ `Screen: ${data.systemInfo.screenResolution}`,
1168
+ `Mobile: ${data.systemInfo.isMobile ? 'Yes' : 'No'}`,
1169
+ `Timezone: ${data.systemInfo.timezone}`,
1170
+ '',
1171
+ '=== APPLICATION INFORMATION ===',
1172
+ `Version: ${data.appInfo.version}`,
1173
+ `Current Model: ${data.appInfo.currentModel}`,
1174
+ `Current Provider: ${data.appInfo.currentProvider}`,
1175
+ `Project Type: ${data.appInfo.projectType}`,
1176
+ `Workbench View: ${data.appInfo.workbenchView}`,
1177
+ `Active Preview: ${data.appInfo.hasActivePreview ? 'Yes' : 'No'}`,
1178
+ `Unsaved Files: ${data.appInfo.unsavedFiles}`,
1179
+ '',
1180
+ '=== GIT INFORMATION ===',
1181
+ data.appInfo.gitInfo
1182
+ ? [
1183
+ `Branch: ${data.appInfo.gitInfo.branch}`,
1184
+ `Commit: ${data.appInfo.gitInfo.commit.substring(0, 8)}`,
1185
+ `Working Directory: ${data.appInfo.gitInfo.isDirty ? 'Dirty' : 'Clean'}`,
1186
+ data.appInfo.gitInfo.remoteUrl ? `Remote: ${data.appInfo.gitInfo.remoteUrl}` : '',
1187
+ data.appInfo.gitInfo.lastCommit
1188
+ ? `Last Commit: ${data.appInfo.gitInfo.lastCommit.message.substring(0, 50)}...`
1189
+ : '',
1190
+ ]
1191
+ .filter(Boolean)
1192
+ .join('\n')
1193
+ : 'Git information not available',
1194
+ '',
1195
+ '=== SESSION STATISTICS ===',
1196
+ `Total Logs: ${data.logs.length}`,
1197
+ `Errors: ${data.errors.length}`,
1198
+ `Network Requests: ${data.networkRequests.length}`,
1199
+ `User Actions: ${data.userActions.length}`,
1200
+ `Terminal Logs: ${data.terminalLogs.length}`,
1201
+ '',
1202
+ '=== RECENT ALERTS ===',
1203
+ ...data.state.alerts.slice(0, 5).map((alert) => `${alert.type.toUpperCase()}: ${alert.title}`),
1204
+ '',
1205
+ '=== PERFORMANCE ===',
1206
+ `Page Load Time: ${data.performance.loadTime}ms`,
1207
+ `DOM Content Loaded: ${data.performance.domContentLoaded}ms`,
1208
+ data.performance.memoryUsage
1209
+ ? `Memory Usage: ${(data.performance.memoryUsage.used / 1024 / 1024).toFixed(2)} MB`
1210
+ : 'Memory Usage: N/A',
1211
+ '',
1212
+ '=== WORKBENCH STATE ===',
1213
+ `Current View: ${data.state.currentView}`,
1214
+ `Show Workbench: ${data.state.showWorkbench}`,
1215
+ `Show Terminal: ${data.state.showTerminal}`,
1216
+ `Artifacts: ${data.state.artifactsCount}`,
1217
+ `Files: ${data.state.filesCount}`,
1218
+ ];
1219
+
1220
+ return summary.join('\n');
1221
+ }
1222
+
1223
+ // Utility functions for capturing additional data
1224
+ export function captureTerminalLog(
1225
+ content: string,
1226
+ type: 'input' | 'output' | 'error' = 'output',
1227
+ command?: string,
1228
+ ): void {
1229
+ // Only capture if content is meaningful (not just whitespace or control characters)
1230
+ if (!content || content.trim().length === 0) {
1231
+ return;
1232
+ }
1233
+
1234
+ try {
1235
+ debugLogger.captureTerminalLog({
1236
+ timestamp: new Date().toISOString(),
1237
+ type,
1238
+ content: content.trim(),
1239
+ command,
1240
+ });
1241
+ } catch (error) {
1242
+ console.error('Failed to capture terminal log:', error);
1243
+ }
1244
+ }
1245
+
1246
+ export function captureUserAction(action: string, target?: string, data?: any): void {
1247
+ try {
1248
+ debugLogger.captureUserAction(action, target, data);
1249
+ } catch (error) {
1250
+ console.error('Failed to capture user action:', error);
1251
+ }
1252
+ }
1253
+
1254
+ export function getDebugLogger(): DebugLogger {
1255
+ return debugLogger;
1256
+ }
1257
+
1258
+ // Utility function to enable debug mode on demand
1259
+ export function enableDebugMode(): void {
1260
+ debugLogger.enableDebugMode();
1261
+ }
1262
+
1263
+ // Utility function to disable debug mode
1264
+ export function disableDebugMode(): void {
1265
+ debugLogger.disableDebugMode();
1266
+ }
1267
+
1268
+ // Utility function to get debug logger status
1269
+ export function getDebugStatus(): { initialized: boolean; capturing: boolean; enabled: boolean } {
1270
+ return debugLogger.getStatus();
1271
+ }
1272
+
1273
+ // Utility function to update debug configuration
1274
+ export function updateDebugConfig(config: Partial<DebugLoggerConfig>): void {
1275
+ debugLogger.updateConfig(config);
1276
+ }
1277
+
1278
+ // Initialize debug logger when this module is imported
1279
+ if (typeof window !== 'undefined') {
1280
+ // Defer initialization to avoid blocking
1281
+ setTimeout(() => {
1282
+ debugLogger.initialize();
1283
+ }, 0);
1284
+ }