bub 0.6.0a3__tar.gz → 0.6.2__tar.gz

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 (144) hide show
  1. {bub-0.6.0a3 → bub-0.6.2}/PKG-INFO +9 -9
  2. {bub-0.6.0a3 → bub-0.6.2}/README.md +5 -5
  3. {bub-0.6.0a3 → bub-0.6.2}/pyproject.toml +2 -2
  4. {bub-0.6.0a3 → bub-0.6.2}/src/bub/_version.py +2 -2
  5. bub-0.6.2/src/bub/application.py +35 -0
  6. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/agent.py +46 -40
  7. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/auth.py +31 -4
  8. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/cli.py +50 -6
  9. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/codemode/__init__.py +6 -4
  10. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/hook_impl.py +24 -38
  11. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/model.py +31 -1
  12. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/settings.py +29 -2
  13. bub-0.6.2/src/bub/builtin/subagents.py +833 -0
  14. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/tools.py +84 -83
  15. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/cli/__init__.py +103 -20
  16. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/cli/terminal_output.py +8 -6
  17. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/handler.py +22 -8
  18. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/manager.py +82 -11
  19. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/message.py +39 -2
  20. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/telegram.py +20 -9
  21. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/__init__.py +2 -0
  22. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/agent.py +89 -42
  23. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/context.py +1 -1
  24. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/events.py +44 -11
  25. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/model.py +1 -1
  26. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/system_prompt.py +7 -7
  27. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/tape.py +13 -3
  28. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/tools.py +44 -10
  29. {bub-0.6.0a3 → bub-0.6.2}/src/bub/framework.py +146 -16
  30. bub-0.6.2/src/bub/hooks/agent.py +142 -0
  31. {bub-0.6.0a3 → bub-0.6.2}/src/bub/hooks/specs.py +6 -0
  32. bub-0.6.2/src/bub/inquirer.py +96 -0
  33. bub-0.6.2/src/bub/program_status.py +40 -0
  34. {bub-0.6.0a3 → bub-0.6.2}/src/bub/streaming.py +9 -2
  35. {bub-0.6.0a3 → bub-0.6.2}/src/bub/utils.py +9 -6
  36. {bub-0.6.0a3 → bub-0.6.2}/tests/model_fakes.py +4 -5
  37. {bub-0.6.0a3 → bub-0.6.2}/tests/test_agent_hooks.py +1 -1
  38. bub-0.6.2/tests/test_agent_plugins.py +146 -0
  39. {bub-0.6.0a3 → bub-0.6.2}/tests/test_builtin_agent.py +8 -10
  40. {bub-0.6.0a3 → bub-0.6.2}/tests/test_builtin_cli.py +199 -31
  41. {bub-0.6.0a3 → bub-0.6.2}/tests/test_builtin_hook_impl.py +76 -14
  42. {bub-0.6.0a3 → bub-0.6.2}/tests/test_builtin_tools.py +44 -34
  43. {bub-0.6.0a3 → bub-0.6.2}/tests/test_channels.py +317 -50
  44. {bub-0.6.0a3 → bub-0.6.2}/tests/test_codemode.py +1 -2
  45. {bub-0.6.0a3 → bub-0.6.2}/tests/test_core_agent.py +57 -2
  46. {bub-0.6.0a3 → bub-0.6.2}/tests/test_core_agent_step.py +89 -2
  47. {bub-0.6.0a3 → bub-0.6.2}/tests/test_environment.py +32 -0
  48. {bub-0.6.0a3 → bub-0.6.2}/tests/test_framework.py +72 -0
  49. {bub-0.6.0a3 → bub-0.6.2}/tests/test_install_scripts.py +3 -3
  50. bub-0.6.2/tests/test_program_status.py +129 -0
  51. {bub-0.6.0a3 → bub-0.6.2}/tests/test_sdk_isolation.py +3 -1
  52. {bub-0.6.0a3 → bub-0.6.2}/tests/test_settings.py +121 -0
  53. {bub-0.6.0a3 → bub-0.6.2}/tests/test_spill.py +22 -38
  54. bub-0.6.2/tests/test_subagent_tool.py +560 -0
  55. {bub-0.6.0a3 → bub-0.6.2}/tests/test_tool_loading.py +31 -3
  56. {bub-0.6.0a3 → bub-0.6.2}/tests/test_tools.py +16 -21
  57. {bub-0.6.0a3 → bub-0.6.2}/tests/test_tracing.py +3 -1
  58. {bub-0.6.0a3 → bub-0.6.2}/tests/test_utils.py +28 -0
  59. bub-0.6.2/tests/tool_fakes.py +10 -0
  60. bub-0.6.0a3/src/bub/inquirer.py +0 -86
  61. bub-0.6.0a3/tests/test_subagent_tool.py +0 -152
  62. {bub-0.6.0a3 → bub-0.6.2}/.gitignore +0 -0
  63. {bub-0.6.0a3 → bub-0.6.2}/LICENSE +0 -0
  64. {bub-0.6.0a3 → bub-0.6.2}/src/bub/__init__.py +0 -0
  65. {bub-0.6.0a3 → bub-0.6.2}/src/bub/__main__.py +0 -0
  66. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/__init__.py +0 -0
  67. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/archive.py +0 -0
  68. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/commands.py +0 -0
  69. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/context.py +0 -0
  70. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/environment.py +0 -0
  71. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/onboarding.py +0 -0
  72. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/shell_manager.py +0 -0
  73. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/spill.py +0 -0
  74. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/steering.py +0 -0
  75. {bub-0.6.0a3 → bub-0.6.2}/src/bub/builtin/store.py +0 -0
  76. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/__init__.py +0 -0
  77. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/admission.py +0 -0
  78. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/base.py +0 -0
  79. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/cli/ansi_bridge.py +0 -0
  80. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/cli/renderer.py +0 -0
  81. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/cli/writers.py +0 -0
  82. {bub-0.6.0a3 → bub-0.6.2}/src/bub/channels/contracts.py +0 -0
  83. {bub-0.6.0a3 → bub-0.6.2}/src/bub/configure.py +0 -0
  84. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/codemode/__init__.py +0 -0
  85. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/codemode/republic_bridge.py +0 -0
  86. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/codemode/runner.py +0 -0
  87. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/codemode/runner_child.py +0 -0
  88. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/codemode/stub.py +0 -0
  89. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/commands.py +0 -0
  90. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/recorder.py +0 -0
  91. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/sidecars.py +0 -0
  92. {bub-0.6.0a3 → bub-0.6.2}/src/bub/core/store.py +0 -0
  93. {bub-0.6.0a3 → bub-0.6.2}/src/bub/envelope.py +0 -0
  94. {bub-0.6.0a3 → bub-0.6.2}/src/bub/environment.py +0 -0
  95. {bub-0.6.0a3 → bub-0.6.2}/src/bub/errors.py +0 -0
  96. {bub-0.6.0a3 → bub-0.6.2}/src/bub/gateway_installer.py +0 -0
  97. {bub-0.6.0a3 → bub-0.6.2}/src/bub/hooks/__init__.py +0 -0
  98. {bub-0.6.0a3 → bub-0.6.2}/src/bub/hooks/interception.py +0 -0
  99. {bub-0.6.0a3 → bub-0.6.2}/src/bub/hooks/runtime.py +0 -0
  100. {bub-0.6.0a3 → bub-0.6.2}/src/bub/model_selection.py +0 -0
  101. {bub-0.6.0a3 → bub-0.6.2}/src/bub/prompt.py +0 -0
  102. {bub-0.6.0a3 → bub-0.6.2}/src/bub/sidecars.py +0 -0
  103. {bub-0.6.0a3 → bub-0.6.2}/src/bub/skills.py +0 -0
  104. {bub-0.6.0a3 → bub-0.6.2}/src/bub/store.py +0 -0
  105. {bub-0.6.0a3 → bub-0.6.2}/src/bub/tape.py +0 -0
  106. {bub-0.6.0a3 → bub-0.6.2}/src/bub/tools.py +0 -0
  107. {bub-0.6.0a3 → bub-0.6.2}/src/bub/tracing.py +0 -0
  108. {bub-0.6.0a3 → bub-0.6.2}/src/bub/turn.py +0 -0
  109. {bub-0.6.0a3 → bub-0.6.2}/src/skills/README.md +0 -0
  110. {bub-0.6.0a3 → bub-0.6.2}/src/skills/gh/SKILL.md +0 -0
  111. {bub-0.6.0a3 → bub-0.6.2}/src/skills/skill-creator/SKILL.md +0 -0
  112. {bub-0.6.0a3 → bub-0.6.2}/src/skills/skill-creator/license.txt +0 -0
  113. {bub-0.6.0a3 → bub-0.6.2}/src/skills/skill-creator/scripts/init_skill.py +0 -0
  114. {bub-0.6.0a3 → bub-0.6.2}/src/skills/skill-creator/scripts/quick_validate.py +0 -0
  115. {bub-0.6.0a3 → bub-0.6.2}/src/skills/telegram/SKILL.md +0 -0
  116. {bub-0.6.0a3 → bub-0.6.2}/src/skills/telegram/scripts/telegram_edit.py +0 -0
  117. {bub-0.6.0a3 → bub-0.6.2}/src/skills/telegram/scripts/telegram_rich.py +0 -0
  118. {bub-0.6.0a3 → bub-0.6.2}/src/skills/telegram/scripts/telegram_send.py +0 -0
  119. {bub-0.6.0a3 → bub-0.6.2}/tests/__init__.py +0 -0
  120. {bub-0.6.0a3 → bub-0.6.2}/tests/conftest.py +0 -0
  121. {bub-0.6.0a3 → bub-0.6.2}/tests/test_builtin_codex.py +0 -0
  122. {bub-0.6.0a3 → bub-0.6.2}/tests/test_cli_help.py +0 -0
  123. {bub-0.6.0a3 → bub-0.6.2}/tests/test_cli_main.py +0 -0
  124. {bub-0.6.0a3 → bub-0.6.2}/tests/test_cli_renderer.py +0 -0
  125. {bub-0.6.0a3 → bub-0.6.2}/tests/test_compat_aliases.py +0 -0
  126. {bub-0.6.0a3 → bub-0.6.2}/tests/test_configure.py +0 -0
  127. {bub-0.6.0a3 → bub-0.6.2}/tests/test_core_boundary.py +0 -0
  128. {bub-0.6.0a3 → bub-0.6.2}/tests/test_core_codemode.py +0 -0
  129. {bub-0.6.0a3 → bub-0.6.2}/tests/test_envelope.py +0 -0
  130. {bub-0.6.0a3 → bub-0.6.2}/tests/test_errors.py +0 -0
  131. {bub-0.6.0a3 → bub-0.6.2}/tests/test_file_tape_store_entry_ids.py +0 -0
  132. {bub-0.6.0a3 → bub-0.6.2}/tests/test_file_tape_store_search.py +0 -0
  133. {bub-0.6.0a3 → bub-0.6.2}/tests/test_fork_store_merge_back.py +0 -0
  134. {bub-0.6.0a3 → bub-0.6.2}/tests/test_gateway_installer.py +0 -0
  135. {bub-0.6.0a3 → bub-0.6.2}/tests/test_hook_runtime.py +0 -0
  136. {bub-0.6.0a3 → bub-0.6.2}/tests/test_image_message.py +0 -0
  137. {bub-0.6.0a3 → bub-0.6.2}/tests/test_onboarding.py +0 -0
  138. {bub-0.6.0a3 → bub-0.6.2}/tests/test_otlp.py +0 -0
  139. {bub-0.6.0a3 → bub-0.6.2}/tests/test_provider_messages.py +0 -0
  140. {bub-0.6.0a3 → bub-0.6.2}/tests/test_session_settings.py +0 -0
  141. {bub-0.6.0a3 → bub-0.6.2}/tests/test_shell_manager.py +0 -0
  142. {bub-0.6.0a3 → bub-0.6.2}/tests/test_skills.py +0 -0
  143. {bub-0.6.0a3 → bub-0.6.2}/tests/test_tape.py +0 -0
  144. {bub-0.6.0a3 → bub-0.6.2}/tests/test_tape_search_output.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bub
3
- Version: 0.6.0a3
3
+ Version: 0.6.2
4
4
  Summary: A tiny agent runtime, composable with plugins.
5
5
  Project-URL: Homepage, https://bub.build
6
6
  Project-URL: Repository, https://github.com/bubbuild/bub
@@ -18,10 +18,10 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
18
  Requires-Python: <4.0,>=3.12
19
19
  Requires-Dist: loguru>=0.7.3
20
20
  Requires-Dist: pydantic>=2.12.5
21
- Requires-Dist: republic>=0.6.0a1
21
+ Requires-Dist: republic>=0.6.0
22
22
  Requires-Dist: typing-extensions>=4.15.0
23
23
  Provides-Extra: app
24
- Requires-Dist: aiohttp>=3.14.3; extra == 'app'
24
+ Requires-Dist: aiohttp>=3.14.4; extra == 'app'
25
25
  Requires-Dist: httpx[socks]>=0.28.1; extra == 'app'
26
26
  Requires-Dist: inquirer-textual>=0.8.0; extra == 'app'
27
27
  Requires-Dist: pluggy>=1.6.0; extra == 'app'
@@ -33,7 +33,7 @@ Requires-Dist: rapidfuzz>=3.14.5; extra == 'app'
33
33
  Requires-Dist: rich>=14.3.4; extra == 'app'
34
34
  Requires-Dist: typer>=0.24.1; extra == 'app'
35
35
  Provides-Extra: logfire
36
- Requires-Dist: aiohttp>=3.14.3; extra == 'logfire'
36
+ Requires-Dist: aiohttp>=3.14.4; extra == 'logfire'
37
37
  Requires-Dist: httpx[socks]>=0.28.1; extra == 'logfire'
38
38
  Requires-Dist: inquirer-textual>=0.8.0; extra == 'logfire'
39
39
  Requires-Dist: logfire>=4.32.0; extra == 'logfire'
@@ -81,9 +81,9 @@ In a Python 3.12+ project:
81
81
  uv add bub
82
82
  ```
83
83
 
84
- Run your first agent with the [SDK guide](https://bub.build/docs/build/sdk/), then [serve it with FastAPI](https://bub.build/docs/tutorials/fastapi/) when you need an HTTP endpoint.
84
+ Run your first agent with the [SDK guide](https://bub.build/docs/sdk/), then [serve it with FastAPI](https://bub.build/docs/sdk/web-service/) when you need an HTTP endpoint.
85
85
 
86
- You can also embed `BubAgent` to reuse the application's settings and plugin hooks in your service. This uses `bub[app]`; [Reuse application plugins](https://bub.build/docs/build/reuse-plugins/) explains the integration choices and their requirements.
86
+ You can also embed `BubAgent` to reuse the application's settings and plugin hooks in your service. This uses `bub[app]`; [Reuse the Bub app](https://bub.build/docs/integrations/reuse-app/) explains the integration choices and their requirements.
87
87
 
88
88
  ## Customize the Bub app
89
89
 
@@ -107,13 +107,13 @@ Follow the prompts to choose plugins and configure your model, then start a conv
107
107
  bub chat
108
108
  ```
109
109
 
110
- [Run your first conversation](https://bub.build/docs/getting-started/first-turn/) walks through a task in your workspace. [Customize the Bub app](https://bub.build/docs/build/) covers tools, plugins, and packaging. For `uv tool install` and other setup options, see [Install Bub](https://bub.build/docs/getting-started/install/#app-install).
110
+ [Run your first conversation](https://bub.build/docs/getting-started/quickstart/#cli) walks through a task in your workspace. To customize the Bub app, see [tools](https://bub.build/docs/app/tools/), [plugins](https://bub.build/docs/app/plugins/), and [packaging](https://bub.build/docs/app/distribution/). For `uv tool install` and other setup options, see [Install Bub](https://bub.build/docs/getting-started/install/#app-install).
111
111
 
112
112
  ## Documentation
113
113
 
114
114
  - [Choose a starting point](https://bub.build/docs/getting-started/)
115
- - [Shared concepts and capabilities](https://bub.build/docs/concepts/)
116
- - [API and application reference](https://bub.build/docs/reference/)
115
+ - [Shared concepts and capabilities](https://bub.build/docs/concepts/agent/)
116
+ - [API and application reference](https://bub.build/docs/reference/python-api/)
117
117
 
118
118
  ## Background
119
119
 
@@ -25,9 +25,9 @@ In a Python 3.12+ project:
25
25
  uv add bub
26
26
  ```
27
27
 
28
- Run your first agent with the [SDK guide](https://bub.build/docs/build/sdk/), then [serve it with FastAPI](https://bub.build/docs/tutorials/fastapi/) when you need an HTTP endpoint.
28
+ Run your first agent with the [SDK guide](https://bub.build/docs/sdk/), then [serve it with FastAPI](https://bub.build/docs/sdk/web-service/) when you need an HTTP endpoint.
29
29
 
30
- You can also embed `BubAgent` to reuse the application's settings and plugin hooks in your service. This uses `bub[app]`; [Reuse application plugins](https://bub.build/docs/build/reuse-plugins/) explains the integration choices and their requirements.
30
+ You can also embed `BubAgent` to reuse the application's settings and plugin hooks in your service. This uses `bub[app]`; [Reuse the Bub app](https://bub.build/docs/integrations/reuse-app/) explains the integration choices and their requirements.
31
31
 
32
32
  ## Customize the Bub app
33
33
 
@@ -51,13 +51,13 @@ Follow the prompts to choose plugins and configure your model, then start a conv
51
51
  bub chat
52
52
  ```
53
53
 
54
- [Run your first conversation](https://bub.build/docs/getting-started/first-turn/) walks through a task in your workspace. [Customize the Bub app](https://bub.build/docs/build/) covers tools, plugins, and packaging. For `uv tool install` and other setup options, see [Install Bub](https://bub.build/docs/getting-started/install/#app-install).
54
+ [Run your first conversation](https://bub.build/docs/getting-started/quickstart/#cli) walks through a task in your workspace. To customize the Bub app, see [tools](https://bub.build/docs/app/tools/), [plugins](https://bub.build/docs/app/plugins/), and [packaging](https://bub.build/docs/app/distribution/). For `uv tool install` and other setup options, see [Install Bub](https://bub.build/docs/getting-started/install/#app-install).
55
55
 
56
56
  ## Documentation
57
57
 
58
58
  - [Choose a starting point](https://bub.build/docs/getting-started/)
59
- - [Shared concepts and capabilities](https://bub.build/docs/concepts/)
60
- - [API and application reference](https://bub.build/docs/reference/)
59
+ - [Shared concepts and capabilities](https://bub.build/docs/concepts/agent/)
60
+ - [API and application reference](https://bub.build/docs/reference/python-api/)
61
61
 
62
62
  ## Background
63
63
 
@@ -22,7 +22,7 @@ classifiers = [
22
22
 
23
23
  # The agent kernel, bub.core. Everything else (framework, CLI, channels, builtin agent) is in the `app` extra.
24
24
  dependencies = [
25
- "republic>=0.6.0a1",
25
+ "republic>=0.6.0",
26
26
  "pydantic>=2.12.5",
27
27
  "loguru>=0.7.3",
28
28
  "typing-extensions>=4.15.0",
@@ -47,7 +47,7 @@ app = [
47
47
  "prompt-toolkit>=3.0.52",
48
48
  "python-telegram-bot>=22.7",
49
49
  "rapidfuzz>=3.14.5",
50
- "aiohttp>=3.14.3",
50
+ "aiohttp>=3.14.4",
51
51
  "httpx[socks]>=0.28.1",
52
52
  ]
53
53
  trace = [
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.6.0a3'
22
- __version_tuple__ = version_tuple = (0, 6, 0, 'a3')
21
+ __version__ = version = '0.6.2'
22
+ __version_tuple__ = version_tuple = (0, 6, 2)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -0,0 +1,35 @@
1
+ """CLI, channel work and prompt events published by the application."""
2
+
3
+ from contextvars import ContextVar
4
+ from dataclasses import dataclass
5
+ from typing import Literal
6
+
7
+ from bub.core.events import Event, EventBus
8
+
9
+ type Outcome = Literal["succeeded", "failed", "cancelled"]
10
+ type PromptKind = Literal["question", "permission", "auth"]
11
+
12
+ cli_events: ContextVar[EventBus | None] = ContextVar("cli_events", default=None)
13
+ """The event bus of the application running the current CLI command, if any."""
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class CommandChanged(Event):
18
+ """A CLI invocation started (None) or finished with an outcome."""
19
+
20
+ outcome: Outcome | None = None
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class WorkChanged(Event):
25
+ """A channel work snapshot, optionally including the message outcome that caused it."""
26
+
27
+ busy: bool
28
+ completed: Outcome | None = None
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class PromptChanged(Event):
33
+ """A modal prompt opened (kind) or closed (None)."""
34
+
35
+ kind: PromptKind | None
@@ -2,7 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import asyncio
6
5
  import re
7
6
  from collections.abc import Collection
8
7
  from pathlib import Path
@@ -11,12 +10,12 @@ import bub.core as core
11
10
  from bub.builtin.settings import load_settings
12
11
  from bub.core.store import AsyncTapeStore, TapeStore
13
12
  from bub.core.tape import Tape, session_tape_name
14
- from bub.core.tools import REGISTRY, Tool, model_tools
15
- from bub.envelope import field_of
13
+ from bub.core.tools import Tool, model_tools
16
14
  from bub.framework import BubFramework
15
+ from bub.hooks.agent import AgentPlugins
17
16
  from bub.prompt import LegacyPrompt, UserContent, prompt_text, to_content
18
17
  from bub.skills import discover_skills, render_skills_prompt
19
- from bub.streaming import AsyncStreamEvents, StreamState
18
+ from bub.streaming import AsyncStreamEvents
20
19
  from bub.turn import TurnState
21
20
  from bub.utils import workspace_from_state
22
21
 
@@ -27,11 +26,13 @@ ALLOWED_SKILLS_STATE_KEY = "allowed_skills"
27
26
  class BubAgent(core.Agent):
28
27
  """Bub's agent: the core loop configured by settings and the framework's hooks.
29
28
 
30
- Adds commands, skills, code mode, deferred tools, steering and the
31
- ``continue_prompt`` hook to :class:`bub.core.Agent`. System prompt sections, in
32
- order: the framework's ``system_prompt`` hooks, code mode, deferred tools, skills,
33
- then sections added with ``system_prompt.add``. The framework's interception
34
- hooks handle events before handlers added with ``events.on``.
29
+ Adds commands, skills, code mode and deferred tools to :class:`bub.core.Agent`, and
30
+ connects the framework's agent-loop hooks through :class:`AgentPlugins`. A run that
31
+ started subagents does not end before their results arrive. System prompt
32
+ sections, in order: a subagent's profile instructions, code mode, deferred tools, skills,
33
+ subagent profiles, the framework's ``system_prompt`` hooks, then sections added with
34
+ ``system_prompt.add``. The framework's hooks handle
35
+ events before handlers added with ``events.on``.
35
36
 
36
37
  One instance serves any number of sessions: per-turn choices (model, allowed tools
37
38
  and skills) live in the turn state.
@@ -53,8 +54,8 @@ class BubAgent(core.Agent):
53
54
  Args:
54
55
  framework: Configured hook runtime supplying prompts, tape context,
55
56
  interception hooks, and optional shared resources.
56
- tools: Tools available to this instance. None snapshots the global
57
- registry; an empty collection disables tools.
57
+ tools: Tools available to this instance. None uses the framework's
58
+ ``provide_tools`` tools; an empty collection disables tools.
58
59
  tape_store: Explicit store, preferred over the framework's active store.
59
60
  Create the agent inside ``framework.running()`` to use the latter.
60
61
  Without either, the agent uses an in-memory store.
@@ -69,17 +70,28 @@ class BubAgent(core.Agent):
69
70
  self.settings = load_settings()
70
71
  self.framework = framework
71
72
  self.skill_dirs = skill_dirs
73
+ self.plugins = AgentPlugins(framework)
72
74
  super().__init__(
73
75
  store=framework.get_tape_store() if tape_store is None else tape_store,
74
- tools=REGISTRY.values() if tools is None else tools,
75
- system_prompt=[self._hook_prompt, self._code_mode_prompt, self._deferred_tools_prompt, self._skills_prompt],
76
+ tools=() if tools is None else tools,
77
+ system_prompt=[
78
+ self._subagent_instructions_prompt,
79
+ self._code_mode_prompt,
80
+ self._deferred_tools_prompt,
81
+ self._skills_prompt,
82
+ self._subagent_profiles_prompt,
83
+ ],
76
84
  context=framework.build_tape_context(),
77
85
  sidecars=framework.get_tape_sidecars(),
78
86
  max_steps=self.settings.max_steps,
79
87
  name="bub",
80
88
  command_prefix=self.settings.command_prefix if command_prefix is None else command_prefix,
81
89
  )
82
- framework.get_agent_hooks().subscribe(self.events)
90
+ self.plugins.attach(self, tools=tools is None)
91
+ from bub.builtin.subagents import deliver_subagent_results
92
+
93
+ # After the plugins' steering handler, so steered messages are seen first.
94
+ self.events.on(core.MessagesPending, deliver_subagent_results)
83
95
 
84
96
  async def run_stream(
85
97
  self,
@@ -91,6 +103,7 @@ class BubAgent(core.Agent):
91
103
  allowed_skills: Collection[str] | None = None,
92
104
  allowed_tools: Collection[str] | None = None,
93
105
  reasoning_effort: str | None = None,
106
+ fork_from: Tape | None = None,
94
107
  ) -> AsyncStreamEvents:
95
108
  """Prepare a turn and return its stream; await this method before iterating.
96
109
 
@@ -110,6 +123,8 @@ class BubAgent(core.Agent):
110
123
  None allows all instance tools and an empty collection allows none.
111
124
  Command execution uses the instance's tools directly.
112
125
  reasoning_effort: Per-turn override of the value in state.
126
+ fork_from: An open tape, such as a running turn's, to start from instead of the
127
+ session's tape. The turn sees what that tape holds and its fork is discarded.
113
128
 
114
129
  Loads the turn state and starts the turn with :meth:`start` on the session's tape.
115
130
  Consume the stream to completion to finish execution and tape merging. A
@@ -138,9 +153,9 @@ class BubAgent(core.Agent):
138
153
  model=self.settings.chat_model(
139
154
  state.get("model") if model is None else model, reasoning_effort=state.get("reasoning_effort")
140
155
  ),
141
- tape=session_tape_name(session_id, workspace_from_state(state)),
156
+ tape=session_tape_name(session_id, workspace_from_state(state)) if fork_from is None else fork_from,
142
157
  state=state,
143
- merge_back=not session_id.startswith("temp/"),
158
+ merge_back=fork_from is None and not session_id.startswith("temp/"),
144
159
  metadata=metadata,
145
160
  )
146
161
 
@@ -178,27 +193,6 @@ class BubAgent(core.Agent):
178
193
  direct.extend(deferred[name] for name in await loaded_tool_names(tape) if name in deferred)
179
194
  return model_tools(direct)
180
195
 
181
- async def pending_messages(self, tape: Tape) -> list[list[UserContent]]:
182
- state = tape.context.state
183
- steering_inbox = self.framework.get_steering_inbox()
184
- envelopes = await steering_inbox.drain_messages(state) if steering_inbox else []
185
- return list(
186
- await asyncio.gather(*[
187
- self.framework.build_prompt(message, session_id=field_of(message, "session_id"), state=state)
188
- for message in envelopes
189
- ])
190
- )
191
-
192
- def has_pending_messages(self, tape: Tape) -> bool:
193
- steering_inbox = self.framework.get_steering_inbox()
194
- return bool(steering_inbox and steering_inbox.message_count(tape.context.state) > 0)
195
-
196
- async def continue_prompt(
197
- self, tape: Tape, prompt: list[UserContent] | None, state: StreamState
198
- ) -> list[UserContent] | None:
199
- continuation = await self.framework.continue_prompt(prompt=prompt, tape=tape, state=state)
200
- return None if continuation is None else [continuation]
201
-
202
196
  def _turn_tools(self, state: TurnState) -> list[Tool]:
203
197
  """Return the tools allowed in this turn, direct and deferred alike."""
204
198
  from bub.builtin.tools import ALLOWED_TOOLS_STATE_KEY
@@ -224,9 +218,6 @@ class BubAgent(core.Agent):
224
218
  code_tools = [tool for tool in direct_tools if tool.exposure in ("auto", "code")]
225
219
  return [tool for tool in tools if tool.exposure == "direct"], code_tools
226
220
 
227
- def _hook_prompt(self, context: core.PromptContext) -> str:
228
- return self.framework.get_system_prompt(prompt=context.prompt, state=context.state)
229
-
230
221
  @staticmethod
231
222
  def _code_mode_prompt(context: core.PromptContext) -> str | None:
232
223
  from bub.builtin.codemode import CODE_MODE
@@ -239,6 +230,21 @@ class BubAgent(core.Agent):
239
230
  tools, _ = self._split_code_mode(context.state)
240
231
  return render_deferred_tools_prompt(_deferred_tools(tools))
241
232
 
233
+ @staticmethod
234
+ def _subagent_instructions_prompt(context: core.PromptContext) -> str | None:
235
+ from bub.builtin.subagents import SUBAGENT_INSTRUCTIONS_STATE_KEY
236
+
237
+ return context.state.get(SUBAGENT_INSTRUCTIONS_STATE_KEY)
238
+
239
+ @staticmethod
240
+ def _subagent_profiles_prompt(context: core.PromptContext) -> str:
241
+ """List subagent profiles when the run may start subagents."""
242
+ from bub.builtin.subagents import SUBAGENT_TOOL_NAME, discover_subagent_profiles, render_profiles_prompt
243
+
244
+ if not any(tool.name == SUBAGENT_TOOL_NAME for tool in context.tools):
245
+ return ""
246
+ return render_profiles_prompt(list(discover_subagent_profiles(workspace_from_state(context.state)).values()))
247
+
242
248
  def _skills_prompt(self, context: core.PromptContext) -> str:
243
249
  allowed = context.state.get(ALLOWED_SKILLS_STATE_KEY)
244
250
  return self._load_skills_prompt(
@@ -5,12 +5,14 @@ from __future__ import annotations
5
5
  import asyncio
6
6
  import os
7
7
  import subprocess
8
+ from collections.abc import Iterator
9
+ from contextlib import contextmanager
8
10
  from pathlib import Path
9
11
  from typing import Annotated
10
12
 
11
13
  import typer
12
14
  from republic.errors import AuthenticationError
13
- from republic.providers import CodexAuth
15
+ from republic.providers import CodexAuth, GitHubCLIAuth, GrokAuth
14
16
 
15
17
  app = typer.Typer(name="login", help="Account authentication")
16
18
 
@@ -27,7 +29,7 @@ def login_codex(
27
29
  codex_home: Annotated[Path | None, typer.Option("--codex-home", help="Codex credential directory")] = None,
28
30
  ) -> None:
29
31
  """Log in with the Codex CLI using file credential storage."""
30
- try:
32
+ with _login_result():
31
33
  if codex_home is None:
32
34
  auth = asyncio.run(CodexAuth.login(executable=executable, device_auth=device_auth))
33
35
  else:
@@ -42,9 +44,34 @@ def login_codex(
42
44
  except subprocess.CalledProcessError as exc:
43
45
  raise AuthenticationError(f"Codex login failed (exit {exc.returncode})") from None
44
46
  auth = CodexAuth.from_file(home / "auth.json")
47
+ typer.echo(f"account_id: {auth.account_id}")
48
+ typer.echo("Use BUB_MODEL=codex:<model> for ChatGPT plan access.")
49
+
50
+
51
+ @app.command("grok")
52
+ def login_grok(
53
+ executable: Annotated[str, typer.Option("--executable", help="Grok CLI executable")] = "grok",
54
+ device_auth: Annotated[bool, typer.Option("--device-auth", help="Use device authorization")] = False,
55
+ ) -> None:
56
+ """Log in with the official Grok CLI; Republic maintains its credentials."""
57
+ with _login_result():
58
+ asyncio.run(GrokAuth.login(executable=executable, device_auth=device_auth))
59
+ typer.echo("Use BUB_MODEL=grok:<model> to select this provider.")
60
+
61
+
62
+ @app.command("github-copilot")
63
+ def login_github_copilot() -> None:
64
+ """Log in with GitHub CLI; Republic reuses its credentials."""
65
+ with _login_result():
66
+ asyncio.run(GitHubCLIAuth.login())
67
+ typer.echo("Use BUB_MODEL=github-copilot:<model> to select this provider.")
68
+
69
+
70
+ @contextmanager
71
+ def _login_result() -> Iterator[None]:
72
+ try:
73
+ yield
45
74
  except AuthenticationError as exc:
46
75
  typer.secho(f"login: failed: {exc}", fg="red", err=True)
47
76
  raise typer.Exit(1) from None
48
77
  typer.echo("login: ok")
49
- typer.echo(f"account_id: {auth.account_id}")
50
- typer.echo("Use BUB_MODEL=codex:<model> for ChatGPT plan access.")
@@ -15,8 +15,10 @@ from urllib.parse import unquote, urlsplit
15
15
  from urllib.request import url2pathname
16
16
 
17
17
  import typer
18
+ from pydantic import Field
19
+ from pydantic_settings import SettingsConfigDict
18
20
 
19
- from bub import __version__, configure
21
+ from bub import Settings, __version__, config, configure, ensure_config
20
22
  from bub.builtin.auth import app as login_app # noqa: F401
21
23
  from bub.channels.message import ChannelMessage
22
24
  from bub.envelope import field_of
@@ -77,6 +79,34 @@ def list_hooks(ctx: typer.Context) -> None:
77
79
  typer.echo(f"{hook_name}: {', '.join(adapter_names)}")
78
80
 
79
81
 
82
+ def list_plugins(
83
+ ctx: typer.Context,
84
+ names: list[str] = typer.Argument(default_factory=list, help="Plugin names to show; all plugins if omitted."),
85
+ version_only: bool = typer.Option(False, "--version-only", help="Print only the version of each plugin."),
86
+ ) -> None:
87
+ """Show the loaded plugins and their versions."""
88
+ framework = ctx.ensure_object(BubFramework)
89
+ report = framework.plugin_report()
90
+ if missing := [name for name in names if name not in report]:
91
+ typer.echo(f"Unknown plugin: {', '.join(missing)}", err=True)
92
+ raise typer.Exit(1)
93
+ rows = [(name, report[name]) for name in names or report]
94
+ if version_only:
95
+ for _, status in rows:
96
+ typer.echo(status.version or "-")
97
+ return
98
+ if not rows:
99
+ typer.echo("(no plugins)")
100
+ return
101
+ width = max(len(name) for name, _ in rows)
102
+ for name, status in rows:
103
+ source = f"{status.distribution} {status.version}" if status.distribution else "-"
104
+ line = f"{name:<{width}} {source}"
105
+ if not status.is_success:
106
+ line += f" (failed: {status.detail})"
107
+ typer.echo(line)
108
+
109
+
80
110
  def gateway(
81
111
  ctx: typer.Context,
82
112
  enable_channels: list[str] = typer.Option([], "--enable-channel", help="Channels to enable for CLI (default: all)"),
@@ -173,7 +203,7 @@ def onboard(
173
203
  enabled_channels = str(config_data.get("enabled_channels", "")).strip()
174
204
  if not enabled_channels or not is_gateway_service_supported():
175
205
  return
176
- if not bub_inquirer.ask_confirm("Install gateway as a background service?", default=False):
206
+ if not bub_inquirer.ask_confirm("Install gateway as a background service?", default=False, kind="permission"):
177
207
  return
178
208
 
179
209
  try:
@@ -238,6 +268,22 @@ def _uv(*args: str, cwd: Path) -> subprocess.CompletedProcess:
238
268
  BUB_CONTRIB_REPO = "https://github.com/bubbuild/bub-contrib.git"
239
269
 
240
270
 
271
+ @config()
272
+ class ContribSettings(Settings):
273
+ model_config = SettingsConfigDict(env_prefix="BUB_", extra="ignore")
274
+ contrib_repo: str | None = Field(default=None, description="Git repository URL for `bub install name@ref`.")
275
+
276
+
277
+ def _contrib_requirement(name: str, ref: str) -> str:
278
+ value = ensure_config(ContribSettings).contrib_repo
279
+ repo = (value or "").strip() or BUB_CONTRIB_REPO
280
+ base, _, fragment = repo.removeprefix("git+").partition("#")
281
+ path, separator, query = base.partition("?")
282
+ if not any(part.startswith("subdirectory=") for part in fragment.split("&")):
283
+ fragment = f"{fragment}&subdirectory=packages/{name}" if fragment else f"subdirectory=packages/{name}"
284
+ return f"git+{path}@{ref}{separator}{query}#{fragment}"
285
+
286
+
241
287
  def _build_requirement(spec: str) -> str:
242
288
  if spec.startswith(("git@", "https://")):
243
289
  # Git URL
@@ -248,11 +294,9 @@ def _build_requirement(spec: str) -> str:
248
294
  ref = "".join(rest)
249
295
  return f"git+https://github.com/{repo}.git{ref}"
250
296
  else:
251
- # Assume it's a package name in bub-contrib
252
297
  name, has_ref, ref = spec.partition("@")
253
298
  if has_ref:
254
- ref = f"@{ref}"
255
- return f"git+{BUB_CONTRIB_REPO}{ref}#subdirectory=packages/{name}"
299
+ return _contrib_requirement(name, ref)
256
300
  else: # PyPI package name
257
301
  return name
258
302
 
@@ -315,7 +359,7 @@ def _ensure_project(project: Path) -> None:
315
359
  def install(
316
360
  specs: list[str] = typer.Argument(
317
361
  default_factory=list,
318
- help="Package specification to install, can be a git URL, owner/repo, or package name in bub-contrib.",
362
+ help="Package to install: a PyPI name, Git URL, owner/repo, or name@ref from the configured contrib repository.",
319
363
  ),
320
364
  project: Path = project_opt,
321
365
  ) -> None:
@@ -25,7 +25,7 @@ from bub.core.codemode import (
25
25
  render_tool_stub,
26
26
  write_stub,
27
27
  )
28
- from bub.core.tools import REGISTRY, Tool, ToolContext, tool
28
+ from bub.core.tools import Tool, ToolContext, tool
29
29
  from bub.turn import TurnState
30
30
  from bub.utils import workspace_from_state
31
31
 
@@ -80,14 +80,12 @@ CODE_MODE = CodeMode(
80
80
  environment=environment_from_state,
81
81
  models=_resolve_model,
82
82
  stub_dir=_state_stub_dir,
83
- # The media tools are registered below, so turns select them like any other tool.
83
+ # The media tools are among TOOLS, so turns select them like any other tool.
84
84
  media_tools=False,
85
85
  )
86
86
  """Code mode of Bub's agents."""
87
87
 
88
88
  run_code = CODE_MODE.run_code
89
- for _tool in (run_code, *MEDIA_TOOLS):
90
- REGISTRY[_tool.name] = _tool
91
89
 
92
90
 
93
91
  @tool(name="code_mode", context=True, exposure="command")
@@ -99,3 +97,7 @@ async def set_code_mode(enable: bool, *, context: ToolContext) -> str:
99
97
  """
100
98
  await set_session_setting(context, CODE_MODE_STATE_KEY, enable)
101
99
  return f"Session code mode {'enabled' if enable else 'disabled'} (applies from the next turn)."
100
+
101
+
102
+ TOOLS: tuple[Tool, ...] = (run_code, *MEDIA_TOOLS, set_code_mode)
103
+ """Code mode tools the builtin plugin provides."""
@@ -24,10 +24,9 @@ from bub.core.events import ToolCall, ToolCallDecision, ToolCallResult
24
24
  from bub.core.sidecars import TapeSidecar
25
25
  from bub.core.store import TapeStore
26
26
  from bub.core.tape import TapeContext, session_tape_name
27
- from bub.core.tools import is_content_result, render_result
27
+ from bub.core.tools import Tool, is_content_result, render_result
28
28
  from bub.envelope import Envelope, content_of, field_of
29
29
  from bub.environment import Environment
30
- from bub.errors import BubError
31
30
  from bub.framework import BubFramework
32
31
  from bub.hooks import hookimpl
33
32
  from bub.model_selection import ModelChoice, ModelOptions
@@ -40,19 +39,6 @@ DEFAULT_SYSTEM_PROMPT = """\
40
39
  <general_instruct>
41
40
  Call tools or skills to finish the task.
42
41
  </general_instruct>
43
- <response_instruct>
44
- Before ending this run, you MUST determine whether a response needs to be sent via channel, checking the following conditions:
45
- 1. Has the user asked you a question waiting for your answer?
46
- 2. Is there any error or important information that needs to be sent to the user immediately?
47
- 3. If it is a casual chat, does the conversation need to be continued?
48
-
49
- **IMPORTANT:** Your plain/direct reply in this chat will be ignored.
50
- **Therefore, you MUST send messages via channel using the correct skill if a response is needed.**
51
-
52
- When responding to a channel message, you MUST:
53
- 1. Identify the channel from the message metadata (e.g., `$telegram`, `$discord`)
54
- 2. Send your message as instructed by the channel skill (e.g., `telegram` skill for `$telegram` channel)
55
- </response_instruct>
56
42
  <context_contract>
57
43
  Excessively long context may cause model call failures. In this case, you MAY use tape.info to retrieve the token usage and you SHOULD use tape.handoff tool to shorten the retrieved history.
58
44
  </context_contract>
@@ -63,8 +49,6 @@ class BuiltinImpl:
63
49
  """Default hook implementations for basic runtime operations."""
64
50
 
65
51
  def __init__(self, framework: BubFramework) -> None:
66
- from bub.builtin import codemode, spill, tools # noqa: F401
67
-
68
52
  self.framework = framework
69
53
  self._agent: BubAgent | None = None
70
54
 
@@ -89,12 +73,6 @@ class BuiltinImpl:
89
73
  return selected
90
74
  return available_channels
91
75
 
92
- @staticmethod
93
- def _configured_models() -> list[str]:
94
- settings = load_settings()
95
- models = [settings.model, *(settings.fallback_models or [])]
96
- return list(dict.fromkeys(model for model in models if model))
97
-
98
76
  @hookimpl
99
77
  def resolve_session(self, message: ChannelMessage) -> str:
100
78
  session_id = field_of(message, "session_id")
@@ -177,10 +155,13 @@ class BuiltinImpl:
177
155
  app.add_typer(cli.login_app)
178
156
  app.command("onboard")(cli.onboard)
179
157
  app.command("hooks", hidden=True)(cli.list_hooks)
158
+ app.command("plugins")(cli.list_plugins)
180
159
  app.command("gateway")(cli.gateway)
181
160
  app.command("install")(cli.install)
182
161
  app.command("uninstall")(cli.uninstall)
183
162
  app.command("update")(cli.update)
163
+ if self.framework.default_command is None:
164
+ self.framework.default_command = "chat"
184
165
 
185
166
  @hookimpl
186
167
  def onboard_config(self, current_config: dict[str, object]) -> dict[str, object] | None:
@@ -198,20 +179,19 @@ class BuiltinImpl:
198
179
  return config
199
180
 
200
181
  @hookimpl
201
- def provide_model_options(
182
+ async def provide_model_options(
202
183
  self,
203
184
  session_id: str,
204
185
  workspace: Path | None = None,
205
186
  ) -> ModelOptions | None:
206
- del session_id, workspace
207
- models = self._configured_models()
208
- if not models:
187
+ settings = load_settings()
188
+ tape = self._get_agent().tape(session_tape_name(session_id, workspace or self.framework.workspace))
189
+ current = (await load_session_settings(tape)).get("model") or settings.model
190
+ if not current:
209
191
  return None
210
-
211
- return ModelOptions(
212
- models=[ModelChoice(id=model, name=model) for model in models],
213
- current_model=models[0],
214
- )
192
+ models = await settings.chat_model().list_all_models(settings.model_providers(current))
193
+ models = list(dict.fromkeys([current, settings.model, *(settings.fallback_models or []), *models]))
194
+ return ModelOptions(models=[ModelChoice(id=model, name=model) for model in models], current_model=current)
215
195
 
216
196
  def _read_agents_file(self, state: TurnState) -> str:
217
197
  workspace = state.get("_runtime_workspace", str(Path.cwd()))
@@ -282,8 +262,10 @@ class BuiltinImpl:
282
262
  @hookimpl
283
263
  async def provide_lifespan(self) -> AsyncIterator[None]:
284
264
  from bub.builtin.shell_manager import shell_manager
265
+ from bub.builtin.subagents import subagent_manager
285
266
 
286
- async with shell_manager.lifespan():
267
+ # Subagents stop before the shells they may have started.
268
+ async with shell_manager.lifespan(), subagent_manager.lifespan():
287
269
  yield
288
270
 
289
271
  @hookimpl
@@ -310,6 +292,12 @@ class BuiltinImpl:
310
292
  def build_tape_context(self) -> TapeContext:
311
293
  return default_tape_context()
312
294
 
295
+ @hookimpl
296
+ def provide_tools(self) -> list[Tool]:
297
+ from bub.builtin import codemode, spill, tools
298
+
299
+ return [*tools.TOOLS, *codemode.TOOLS, spill.spill_read]
300
+
313
301
  @hookimpl
314
302
  def provide_steering_inbox(self) -> SteeringInbox:
315
303
  return InMemorySteeringInbox()
@@ -393,12 +381,10 @@ class BuiltinImpl:
393
381
  if not isinstance(spill, SpillStore):
394
382
  return
395
383
 
396
- if result.error is None:
397
- tool_result = result.result
398
- elif isinstance(result.error, BubError):
399
- tool_result = result.error.as_dict() if result.result is None else result.result
400
- else:
384
+ # Failed calls keep their error as is.
385
+ if result.error is not None:
401
386
  return
387
+ tool_result = result.result
402
388
 
403
389
  if is_content_result(tool_result):
404
390
  # Bound the text; media stays inline.