bub 0.6.0a3__tar.gz → 0.6.1__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.1}/PKG-INFO +8 -8
  2. {bub-0.6.0a3 → bub-0.6.1}/README.md +5 -5
  3. {bub-0.6.0a3 → bub-0.6.1}/pyproject.toml +1 -1
  4. {bub-0.6.0a3 → bub-0.6.1}/src/bub/_version.py +2 -2
  5. bub-0.6.1/src/bub/application.py +35 -0
  6. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/agent.py +46 -40
  7. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/cli.py +29 -1
  8. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/codemode/__init__.py +6 -4
  9. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/hook_impl.py +25 -38
  10. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/model.py +31 -1
  11. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/settings.py +20 -0
  12. bub-0.6.1/src/bub/builtin/subagents.py +833 -0
  13. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/tools.py +81 -82
  14. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/cli/__init__.py +103 -20
  15. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/cli/terminal_output.py +8 -6
  16. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/manager.py +82 -11
  17. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/__init__.py +2 -0
  18. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/agent.py +89 -42
  19. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/context.py +1 -1
  20. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/events.py +44 -11
  21. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/model.py +1 -1
  22. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/system_prompt.py +7 -7
  23. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/tape.py +13 -3
  24. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/tools.py +44 -10
  25. {bub-0.6.0a3 → bub-0.6.1}/src/bub/framework.py +136 -12
  26. bub-0.6.1/src/bub/hooks/agent.py +142 -0
  27. {bub-0.6.0a3 → bub-0.6.1}/src/bub/hooks/specs.py +6 -0
  28. bub-0.6.1/src/bub/inquirer.py +96 -0
  29. bub-0.6.1/src/bub/program_status.py +36 -0
  30. {bub-0.6.0a3 → bub-0.6.1}/src/bub/streaming.py +9 -2
  31. {bub-0.6.0a3 → bub-0.6.1}/tests/model_fakes.py +4 -5
  32. {bub-0.6.0a3 → bub-0.6.1}/tests/test_agent_hooks.py +1 -1
  33. bub-0.6.1/tests/test_agent_plugins.py +146 -0
  34. {bub-0.6.0a3 → bub-0.6.1}/tests/test_builtin_agent.py +8 -10
  35. {bub-0.6.0a3 → bub-0.6.1}/tests/test_builtin_cli.py +135 -17
  36. {bub-0.6.0a3 → bub-0.6.1}/tests/test_builtin_hook_impl.py +35 -14
  37. {bub-0.6.0a3 → bub-0.6.1}/tests/test_builtin_tools.py +44 -34
  38. {bub-0.6.0a3 → bub-0.6.1}/tests/test_channels.py +159 -46
  39. {bub-0.6.0a3 → bub-0.6.1}/tests/test_codemode.py +1 -2
  40. {bub-0.6.0a3 → bub-0.6.1}/tests/test_core_agent.py +57 -2
  41. {bub-0.6.0a3 → bub-0.6.1}/tests/test_core_agent_step.py +89 -2
  42. {bub-0.6.0a3 → bub-0.6.1}/tests/test_environment.py +11 -0
  43. {bub-0.6.0a3 → bub-0.6.1}/tests/test_framework.py +72 -0
  44. {bub-0.6.0a3 → bub-0.6.1}/tests/test_install_scripts.py +3 -3
  45. bub-0.6.1/tests/test_program_status.py +97 -0
  46. {bub-0.6.0a3 → bub-0.6.1}/tests/test_sdk_isolation.py +3 -1
  47. {bub-0.6.0a3 → bub-0.6.1}/tests/test_settings.py +72 -0
  48. {bub-0.6.0a3 → bub-0.6.1}/tests/test_spill.py +22 -38
  49. bub-0.6.1/tests/test_subagent_tool.py +560 -0
  50. {bub-0.6.0a3 → bub-0.6.1}/tests/test_tool_loading.py +31 -3
  51. {bub-0.6.0a3 → bub-0.6.1}/tests/test_tools.py +16 -21
  52. {bub-0.6.0a3 → bub-0.6.1}/tests/test_tracing.py +3 -1
  53. bub-0.6.1/tests/tool_fakes.py +10 -0
  54. bub-0.6.0a3/src/bub/inquirer.py +0 -86
  55. bub-0.6.0a3/tests/test_subagent_tool.py +0 -152
  56. {bub-0.6.0a3 → bub-0.6.1}/.gitignore +0 -0
  57. {bub-0.6.0a3 → bub-0.6.1}/LICENSE +0 -0
  58. {bub-0.6.0a3 → bub-0.6.1}/src/bub/__init__.py +0 -0
  59. {bub-0.6.0a3 → bub-0.6.1}/src/bub/__main__.py +0 -0
  60. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/__init__.py +0 -0
  61. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/archive.py +0 -0
  62. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/auth.py +0 -0
  63. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/commands.py +0 -0
  64. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/context.py +0 -0
  65. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/environment.py +0 -0
  66. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/onboarding.py +0 -0
  67. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/shell_manager.py +0 -0
  68. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/spill.py +0 -0
  69. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/steering.py +0 -0
  70. {bub-0.6.0a3 → bub-0.6.1}/src/bub/builtin/store.py +0 -0
  71. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/__init__.py +0 -0
  72. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/admission.py +0 -0
  73. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/base.py +0 -0
  74. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/cli/ansi_bridge.py +0 -0
  75. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/cli/renderer.py +0 -0
  76. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/cli/writers.py +0 -0
  77. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/contracts.py +0 -0
  78. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/handler.py +0 -0
  79. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/message.py +0 -0
  80. {bub-0.6.0a3 → bub-0.6.1}/src/bub/channels/telegram.py +0 -0
  81. {bub-0.6.0a3 → bub-0.6.1}/src/bub/configure.py +0 -0
  82. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/codemode/__init__.py +0 -0
  83. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/codemode/republic_bridge.py +0 -0
  84. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/codemode/runner.py +0 -0
  85. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/codemode/runner_child.py +0 -0
  86. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/codemode/stub.py +0 -0
  87. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/commands.py +0 -0
  88. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/recorder.py +0 -0
  89. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/sidecars.py +0 -0
  90. {bub-0.6.0a3 → bub-0.6.1}/src/bub/core/store.py +0 -0
  91. {bub-0.6.0a3 → bub-0.6.1}/src/bub/envelope.py +0 -0
  92. {bub-0.6.0a3 → bub-0.6.1}/src/bub/environment.py +0 -0
  93. {bub-0.6.0a3 → bub-0.6.1}/src/bub/errors.py +0 -0
  94. {bub-0.6.0a3 → bub-0.6.1}/src/bub/gateway_installer.py +0 -0
  95. {bub-0.6.0a3 → bub-0.6.1}/src/bub/hooks/__init__.py +0 -0
  96. {bub-0.6.0a3 → bub-0.6.1}/src/bub/hooks/interception.py +0 -0
  97. {bub-0.6.0a3 → bub-0.6.1}/src/bub/hooks/runtime.py +0 -0
  98. {bub-0.6.0a3 → bub-0.6.1}/src/bub/model_selection.py +0 -0
  99. {bub-0.6.0a3 → bub-0.6.1}/src/bub/prompt.py +0 -0
  100. {bub-0.6.0a3 → bub-0.6.1}/src/bub/sidecars.py +0 -0
  101. {bub-0.6.0a3 → bub-0.6.1}/src/bub/skills.py +0 -0
  102. {bub-0.6.0a3 → bub-0.6.1}/src/bub/store.py +0 -0
  103. {bub-0.6.0a3 → bub-0.6.1}/src/bub/tape.py +0 -0
  104. {bub-0.6.0a3 → bub-0.6.1}/src/bub/tools.py +0 -0
  105. {bub-0.6.0a3 → bub-0.6.1}/src/bub/tracing.py +0 -0
  106. {bub-0.6.0a3 → bub-0.6.1}/src/bub/turn.py +0 -0
  107. {bub-0.6.0a3 → bub-0.6.1}/src/bub/utils.py +0 -0
  108. {bub-0.6.0a3 → bub-0.6.1}/src/skills/README.md +0 -0
  109. {bub-0.6.0a3 → bub-0.6.1}/src/skills/gh/SKILL.md +0 -0
  110. {bub-0.6.0a3 → bub-0.6.1}/src/skills/skill-creator/SKILL.md +0 -0
  111. {bub-0.6.0a3 → bub-0.6.1}/src/skills/skill-creator/license.txt +0 -0
  112. {bub-0.6.0a3 → bub-0.6.1}/src/skills/skill-creator/scripts/init_skill.py +0 -0
  113. {bub-0.6.0a3 → bub-0.6.1}/src/skills/skill-creator/scripts/quick_validate.py +0 -0
  114. {bub-0.6.0a3 → bub-0.6.1}/src/skills/telegram/SKILL.md +0 -0
  115. {bub-0.6.0a3 → bub-0.6.1}/src/skills/telegram/scripts/telegram_edit.py +0 -0
  116. {bub-0.6.0a3 → bub-0.6.1}/src/skills/telegram/scripts/telegram_rich.py +0 -0
  117. {bub-0.6.0a3 → bub-0.6.1}/src/skills/telegram/scripts/telegram_send.py +0 -0
  118. {bub-0.6.0a3 → bub-0.6.1}/tests/__init__.py +0 -0
  119. {bub-0.6.0a3 → bub-0.6.1}/tests/conftest.py +0 -0
  120. {bub-0.6.0a3 → bub-0.6.1}/tests/test_builtin_codex.py +0 -0
  121. {bub-0.6.0a3 → bub-0.6.1}/tests/test_cli_help.py +0 -0
  122. {bub-0.6.0a3 → bub-0.6.1}/tests/test_cli_main.py +0 -0
  123. {bub-0.6.0a3 → bub-0.6.1}/tests/test_cli_renderer.py +0 -0
  124. {bub-0.6.0a3 → bub-0.6.1}/tests/test_compat_aliases.py +0 -0
  125. {bub-0.6.0a3 → bub-0.6.1}/tests/test_configure.py +0 -0
  126. {bub-0.6.0a3 → bub-0.6.1}/tests/test_core_boundary.py +0 -0
  127. {bub-0.6.0a3 → bub-0.6.1}/tests/test_core_codemode.py +0 -0
  128. {bub-0.6.0a3 → bub-0.6.1}/tests/test_envelope.py +0 -0
  129. {bub-0.6.0a3 → bub-0.6.1}/tests/test_errors.py +0 -0
  130. {bub-0.6.0a3 → bub-0.6.1}/tests/test_file_tape_store_entry_ids.py +0 -0
  131. {bub-0.6.0a3 → bub-0.6.1}/tests/test_file_tape_store_search.py +0 -0
  132. {bub-0.6.0a3 → bub-0.6.1}/tests/test_fork_store_merge_back.py +0 -0
  133. {bub-0.6.0a3 → bub-0.6.1}/tests/test_gateway_installer.py +0 -0
  134. {bub-0.6.0a3 → bub-0.6.1}/tests/test_hook_runtime.py +0 -0
  135. {bub-0.6.0a3 → bub-0.6.1}/tests/test_image_message.py +0 -0
  136. {bub-0.6.0a3 → bub-0.6.1}/tests/test_onboarding.py +0 -0
  137. {bub-0.6.0a3 → bub-0.6.1}/tests/test_otlp.py +0 -0
  138. {bub-0.6.0a3 → bub-0.6.1}/tests/test_provider_messages.py +0 -0
  139. {bub-0.6.0a3 → bub-0.6.1}/tests/test_session_settings.py +0 -0
  140. {bub-0.6.0a3 → bub-0.6.1}/tests/test_shell_manager.py +0 -0
  141. {bub-0.6.0a3 → bub-0.6.1}/tests/test_skills.py +0 -0
  142. {bub-0.6.0a3 → bub-0.6.1}/tests/test_tape.py +0 -0
  143. {bub-0.6.0a3 → bub-0.6.1}/tests/test_tape_search_output.py +0 -0
  144. {bub-0.6.0a3 → bub-0.6.1}/tests/test_utils.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.1
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
@@ -21,7 +21,7 @@ Requires-Dist: pydantic>=2.12.5
21
21
  Requires-Dist: republic>=0.6.0a1
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
 
@@ -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.1'
22
+ __version_tuple__ = version_tuple = (0, 6, 1)
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(
@@ -77,6 +77,34 @@ def list_hooks(ctx: typer.Context) -> None:
77
77
  typer.echo(f"{hook_name}: {', '.join(adapter_names)}")
78
78
 
79
79
 
80
+ def list_plugins(
81
+ ctx: typer.Context,
82
+ names: list[str] = typer.Argument(default_factory=list, help="Plugin names to show; all plugins if omitted."),
83
+ version_only: bool = typer.Option(False, "--version-only", help="Print only the version of each plugin."),
84
+ ) -> None:
85
+ """Show the loaded plugins and their versions."""
86
+ framework = ctx.ensure_object(BubFramework)
87
+ report = framework.plugin_report()
88
+ if missing := [name for name in names if name not in report]:
89
+ typer.echo(f"Unknown plugin: {', '.join(missing)}", err=True)
90
+ raise typer.Exit(1)
91
+ rows = [(name, report[name]) for name in names or report]
92
+ if version_only:
93
+ for _, status in rows:
94
+ typer.echo(status.version or "-")
95
+ return
96
+ if not rows:
97
+ typer.echo("(no plugins)")
98
+ return
99
+ width = max(len(name) for name, _ in rows)
100
+ for name, status in rows:
101
+ source = f"{status.distribution} {status.version}" if status.distribution else "-"
102
+ line = f"{name:<{width}} {source}"
103
+ if not status.is_success:
104
+ line += f" (failed: {status.detail})"
105
+ typer.echo(line)
106
+
107
+
80
108
  def gateway(
81
109
  ctx: typer.Context,
82
110
  enable_channels: list[str] = typer.Option([], "--enable-channel", help="Channels to enable for CLI (default: all)"),
@@ -173,7 +201,7 @@ def onboard(
173
201
  enabled_channels = str(config_data.get("enabled_channels", "")).strip()
174
202
  if not enabled_channels or not is_gateway_service_supported():
175
203
  return
176
- if not bub_inquirer.ask_confirm("Install gateway as a background service?", default=False):
204
+ if not bub_inquirer.ask_confirm("Install gateway as a background service?", default=False, kind="permission"):
177
205
  return
178
206
 
179
207
  try:
@@ -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,20 @@ 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
+ if current not in models:
194
+ models.insert(0, current)
195
+ return ModelOptions(models=[ModelChoice(id=model, name=model) for model in models], current_model=current)
215
196
 
216
197
  def _read_agents_file(self, state: TurnState) -> str:
217
198
  workspace = state.get("_runtime_workspace", str(Path.cwd()))
@@ -282,8 +263,10 @@ class BuiltinImpl:
282
263
  @hookimpl
283
264
  async def provide_lifespan(self) -> AsyncIterator[None]:
284
265
  from bub.builtin.shell_manager import shell_manager
266
+ from bub.builtin.subagents import subagent_manager
285
267
 
286
- async with shell_manager.lifespan():
268
+ # Subagents stop before the shells they may have started.
269
+ async with shell_manager.lifespan(), subagent_manager.lifespan():
287
270
  yield
288
271
 
289
272
  @hookimpl
@@ -310,6 +293,12 @@ class BuiltinImpl:
310
293
  def build_tape_context(self) -> TapeContext:
311
294
  return default_tape_context()
312
295
 
296
+ @hookimpl
297
+ def provide_tools(self) -> list[Tool]:
298
+ from bub.builtin import codemode, spill, tools
299
+
300
+ return [*tools.TOOLS, *codemode.TOOLS, spill.spill_read]
301
+
313
302
  @hookimpl
314
303
  def provide_steering_inbox(self) -> SteeringInbox:
315
304
  return InMemorySteeringInbox()
@@ -393,12 +382,10 @@ class BuiltinImpl:
393
382
  if not isinstance(spill, SpillStore):
394
383
  return
395
384
 
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:
385
+ # Failed calls keep their error as is.
386
+ if result.error is not None:
401
387
  return
388
+ tool_result = result.result
402
389
 
403
390
  if is_content_result(tool_result):
404
391
  # Bound the text; media stays inline.
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
- from collections.abc import AsyncIterator, Callable, Mapping, Sequence
6
+ from collections.abc import AsyncIterator, Callable, Iterable, Mapping, Sequence
7
7
  from contextlib import AsyncExitStack, asynccontextmanager
8
8
  from dataclasses import dataclass
9
9
  from typing import Any
@@ -22,6 +22,9 @@ class ModelCandidate:
22
22
  provider_name: str | None = None
23
23
 
24
24
 
25
+ LIST_MODELS_TIMEOUT = 10.0
26
+ """Seconds allowed for listing one provider's models, pages included."""
27
+
25
28
  ClientOptions = Mapping[str, Any] | Callable[[str], Mapping[str, Any]]
26
29
  """Republic client options, or a function returning them for a provider name."""
27
30
 
@@ -91,6 +94,33 @@ class BubModel:
91
94
  return dict(self.client_options(provider))
92
95
  return dict(self.client_options or {})
93
96
 
97
+ async def list_models(self, provider: str) -> list[str]:
98
+ """List the ``provider:model`` specs ``provider`` (a custom name or a Republic type) offers."""
99
+ if custom_type := self.providers.get(provider):
100
+ provider_type = custom_type
101
+ else:
102
+ provider = provider_type = provider.lower()
103
+ async with (
104
+ asyncio.timeout(LIST_MODELS_TIMEOUT),
105
+ republic.get_provider(provider_type, **self.client_kwargs(provider)) as client,
106
+ ):
107
+ models = await client.list_models()
108
+ return sorted({f"{provider}:{model.id}" for model in models})
109
+
110
+ async def list_all_models(self, providers: Iterable[str]) -> list[str]:
111
+ """List the models of each provider concurrently, in order, skipping providers that fail to list."""
112
+ providers = list(dict.fromkeys(providers))
113
+ results = await asyncio.gather(*(self.list_models(provider) for provider in providers), return_exceptions=True)
114
+ models: list[str] = []
115
+ for provider, result in zip(providers, results, strict=True):
116
+ if isinstance(result, Exception):
117
+ logger.warning("failed to list models of provider={} error={}", provider, type(result).__name__)
118
+ elif isinstance(result, BaseException):
119
+ raise result
120
+ else:
121
+ models.extend(result)
122
+ return list(dict.fromkeys(models))
123
+
94
124
  def chat_options(self, provider: str, options: Mapping[str, Any]) -> dict[str, Any]:
95
125
  """Merge this model's generation options with a call's for ``provider``."""
96
126
  merged = {**self.options, **options}
@@ -83,6 +83,12 @@ class AgentSettings(Settings):
83
83
  providers: dict[str, CustomProvider] = Field(default_factory=dict)
84
84
  max_steps: int = Field(default=sys.maxsize, gt=0)
85
85
  max_tokens: int = DEFAULT_MAX_TOKENS
86
+ subagent_max_concurrency: int = Field(
87
+ default=4, gt=0, description="Maximum subagents running at once; later ones wait in a queue."
88
+ )
89
+ subagent_timeout_seconds: int | None = Field(
90
+ default=None, gt=0, description="Default time limit of one subagent run; None means no limit."
91
+ )
86
92
  model_timeout_seconds: int | None = None
87
93
  client_args: dict[str, Any] = Field(default_factory=dict)
88
94
  completion_args: dict[str, Any] = Field(default_factory=dict)
@@ -137,6 +143,20 @@ class AgentSettings(Settings):
137
143
  def model_candidates(self, model: str) -> list[ModelCandidate]:
138
144
  return self.chat_model().candidates(model)
139
145
 
146
+ def model_providers(self, current_model: str | None = None) -> list[str]:
147
+ """Providers to offer models from, ``current_model``'s first.
148
+
149
+ These are the providers configured explicitly: of the model and fallbacks, custom
150
+ providers, and per-provider ``api_key`` or ``api_base`` entries.
151
+ """
152
+ specs = [current_model, self.model, *(self.fallback_models or [])]
153
+ providers = [spec.partition(":")[0] for spec in specs if spec]
154
+ providers.extend(self.providers)
155
+ for value in (self.api_key, self.api_base):
156
+ if isinstance(value, dict):
157
+ providers.extend(name for name, setting in value.items() if setting)
158
+ return list(dict.fromkeys(name if name in self.providers else name.lower() for name in providers))
159
+
140
160
  def model_client_kwargs(self, provider: str) -> dict[str, Any]:
141
161
  custom = self.providers.get(provider)
142
162
  provider = provider if custom else provider.lower()