bub 0.6.1__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.
- {bub-0.6.1 → bub-0.6.2}/PKG-INFO +2 -2
- {bub-0.6.1 → bub-0.6.2}/pyproject.toml +1 -1
- {bub-0.6.1 → bub-0.6.2}/src/bub/_version.py +2 -2
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/auth.py +31 -4
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/cli.py +21 -5
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/hook_impl.py +1 -2
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/settings.py +9 -2
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/tools.py +3 -1
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/handler.py +22 -8
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/message.py +39 -2
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/telegram.py +20 -9
- {bub-0.6.1 → bub-0.6.2}/src/bub/framework.py +10 -4
- {bub-0.6.1 → bub-0.6.2}/src/bub/program_status.py +5 -1
- {bub-0.6.1 → bub-0.6.2}/src/bub/utils.py +9 -6
- {bub-0.6.1 → bub-0.6.2}/tests/test_builtin_cli.py +65 -15
- {bub-0.6.1 → bub-0.6.2}/tests/test_builtin_hook_impl.py +47 -6
- {bub-0.6.1 → bub-0.6.2}/tests/test_channels.py +158 -4
- {bub-0.6.1 → bub-0.6.2}/tests/test_environment.py +21 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_program_status.py +33 -1
- {bub-0.6.1 → bub-0.6.2}/tests/test_settings.py +49 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_utils.py +28 -0
- {bub-0.6.1 → bub-0.6.2}/.gitignore +0 -0
- {bub-0.6.1 → bub-0.6.2}/LICENSE +0 -0
- {bub-0.6.1 → bub-0.6.2}/README.md +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/__main__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/application.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/agent.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/archive.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/codemode/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/commands.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/context.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/environment.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/model.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/onboarding.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/shell_manager.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/spill.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/steering.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/store.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/builtin/subagents.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/admission.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/base.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/cli/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/cli/ansi_bridge.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/cli/renderer.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/cli/terminal_output.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/cli/writers.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/contracts.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/channels/manager.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/configure.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/agent.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/codemode/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/codemode/republic_bridge.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/codemode/runner.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/codemode/runner_child.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/codemode/stub.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/commands.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/context.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/events.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/model.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/recorder.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/sidecars.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/store.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/system_prompt.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/tape.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/core/tools.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/envelope.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/environment.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/errors.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/gateway_installer.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/hooks/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/hooks/agent.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/hooks/interception.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/hooks/runtime.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/hooks/specs.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/inquirer.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/model_selection.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/prompt.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/sidecars.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/skills.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/store.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/streaming.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/tape.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/tools.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/tracing.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/bub/turn.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/README.md +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/gh/SKILL.md +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/skill-creator/SKILL.md +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/skill-creator/license.txt +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/skill-creator/scripts/init_skill.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/skill-creator/scripts/quick_validate.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/telegram/SKILL.md +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/telegram/scripts/telegram_edit.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/telegram/scripts/telegram_rich.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/src/skills/telegram/scripts/telegram_send.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/__init__.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/conftest.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/model_fakes.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_agent_hooks.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_agent_plugins.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_builtin_agent.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_builtin_codex.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_builtin_tools.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_cli_help.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_cli_main.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_cli_renderer.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_codemode.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_compat_aliases.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_configure.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_core_agent.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_core_agent_step.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_core_boundary.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_core_codemode.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_envelope.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_errors.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_file_tape_store_entry_ids.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_file_tape_store_search.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_fork_store_merge_back.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_framework.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_gateway_installer.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_hook_runtime.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_image_message.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_install_scripts.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_onboarding.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_otlp.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_provider_messages.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_sdk_isolation.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_session_settings.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_shell_manager.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_skills.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_spill.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_subagent_tool.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_tape.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_tape_search_output.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_tool_loading.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_tools.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/test_tracing.py +0 -0
- {bub-0.6.1 → bub-0.6.2}/tests/tool_fakes.py +0 -0
{bub-0.6.1 → bub-0.6.2}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bub
|
|
3
|
-
Version: 0.6.
|
|
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,7 +18,7 @@ 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.
|
|
21
|
+
Requires-Dist: republic>=0.6.0
|
|
22
22
|
Requires-Dist: typing-extensions>=4.15.0
|
|
23
23
|
Provides-Extra: app
|
|
24
24
|
Requires-Dist: aiohttp>=3.14.4; extra == 'app'
|
|
@@ -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.
|
|
25
|
+
"republic>=0.6.0",
|
|
26
26
|
"pydantic>=2.12.5",
|
|
27
27
|
"loguru>=0.7.3",
|
|
28
28
|
"typing-extensions>=4.15.0",
|
|
@@ -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.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 6,
|
|
21
|
+
__version__ = version = '0.6.2'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 6, 2)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -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
|
-
|
|
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
|
|
@@ -266,6 +268,22 @@ def _uv(*args: str, cwd: Path) -> subprocess.CompletedProcess:
|
|
|
266
268
|
BUB_CONTRIB_REPO = "https://github.com/bubbuild/bub-contrib.git"
|
|
267
269
|
|
|
268
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
|
+
|
|
269
287
|
def _build_requirement(spec: str) -> str:
|
|
270
288
|
if spec.startswith(("git@", "https://")):
|
|
271
289
|
# Git URL
|
|
@@ -276,11 +294,9 @@ def _build_requirement(spec: str) -> str:
|
|
|
276
294
|
ref = "".join(rest)
|
|
277
295
|
return f"git+https://github.com/{repo}.git{ref}"
|
|
278
296
|
else:
|
|
279
|
-
# Assume it's a package name in bub-contrib
|
|
280
297
|
name, has_ref, ref = spec.partition("@")
|
|
281
298
|
if has_ref:
|
|
282
|
-
|
|
283
|
-
return f"git+{BUB_CONTRIB_REPO}{ref}#subdirectory=packages/{name}"
|
|
299
|
+
return _contrib_requirement(name, ref)
|
|
284
300
|
else: # PyPI package name
|
|
285
301
|
return name
|
|
286
302
|
|
|
@@ -343,7 +359,7 @@ def _ensure_project(project: Path) -> None:
|
|
|
343
359
|
def install(
|
|
344
360
|
specs: list[str] = typer.Argument(
|
|
345
361
|
default_factory=list,
|
|
346
|
-
help="Package
|
|
362
|
+
help="Package to install: a PyPI name, Git URL, owner/repo, or name@ref from the configured contrib repository.",
|
|
347
363
|
),
|
|
348
364
|
project: Path = project_opt,
|
|
349
365
|
) -> None:
|
|
@@ -190,8 +190,7 @@ class BuiltinImpl:
|
|
|
190
190
|
if not current:
|
|
191
191
|
return None
|
|
192
192
|
models = await settings.chat_model().list_all_models(settings.model_providers(current))
|
|
193
|
-
|
|
194
|
-
models.insert(0, current)
|
|
193
|
+
models = list(dict.fromkeys([current, settings.model, *(settings.fallback_models or []), *models]))
|
|
195
194
|
return ModelOptions(models=[ModelChoice(id=model, name=model) for model in models], current_model=current)
|
|
196
195
|
|
|
197
196
|
def _read_agents_file(self, state: TurnState) -> str:
|
|
@@ -37,6 +37,7 @@ class CustomProvider(BaseModel):
|
|
|
37
37
|
type: str
|
|
38
38
|
api_key: str | None = None
|
|
39
39
|
api_base: str | None = None
|
|
40
|
+
headers: dict[str, str] = Field(default_factory=dict)
|
|
40
41
|
|
|
41
42
|
@field_validator("type")
|
|
42
43
|
@classmethod
|
|
@@ -161,8 +162,14 @@ class AgentSettings(Settings):
|
|
|
161
162
|
custom = self.providers.get(provider)
|
|
162
163
|
provider = provider if custom else provider.lower()
|
|
163
164
|
options = dict(self.client_args)
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
headers = {"user-agent": ("User-Agent", USER_AGENT)}
|
|
166
|
+
for overrides in (options.get("headers") or {}, custom.headers if custom else {}):
|
|
167
|
+
for name, value in overrides.items():
|
|
168
|
+
key = name.lower()
|
|
169
|
+
# Keep the first spelling, in particular Republic's expected "User-Agent".
|
|
170
|
+
original_name = headers[key][0] if key in headers else name
|
|
171
|
+
headers[key] = (original_name, value)
|
|
172
|
+
options["headers"] = dict(headers.values())
|
|
166
173
|
prefix = _provider_env_name(provider)
|
|
167
174
|
options.setdefault("env_prefix", f"BUB_{prefix}")
|
|
168
175
|
return {
|
|
@@ -358,6 +358,8 @@ async def fs_write(path: str, content: str, *, context: ToolContext) -> str:
|
|
|
358
358
|
@tool(context=True, name="fs.edit", exposure="direct")
|
|
359
359
|
async def fs_edit(path: str, old: str, new: str, start: int = 0, *, context: ToolContext) -> str:
|
|
360
360
|
"""Edit a text file by replacing old text with new text. You can specify the line number to start searching for the old text."""
|
|
361
|
+
if start < 0:
|
|
362
|
+
raise ValueError("start must be non-negative")
|
|
361
363
|
environment = environment_from_state(context.state)
|
|
362
364
|
resolved_path = environment.resolve_path(path)
|
|
363
365
|
text = await environment.read_text(resolved_path)
|
|
@@ -366,7 +368,7 @@ async def fs_edit(path: str, old: str, new: str, start: int = 0, *, context: Too
|
|
|
366
368
|
if old not in to_replace:
|
|
367
369
|
raise ValueError(f"'{old}' not found in {resolved_path} from line {start}")
|
|
368
370
|
replaced = to_replace.replace(old, new)
|
|
369
|
-
if
|
|
371
|
+
if start > 0:
|
|
370
372
|
replaced = prev + "\n" + replaced
|
|
371
373
|
if text.endswith(("\n", "\r")):
|
|
372
374
|
replaced += "\n"
|
|
@@ -30,11 +30,26 @@ class BufferedMessageHandler:
|
|
|
30
30
|
self._timer.cancel()
|
|
31
31
|
self._timer = self._loop.call_later(timeout, self._event.set)
|
|
32
32
|
|
|
33
|
+
def _clear_processing(self, task: asyncio.Task | None = None) -> None:
|
|
34
|
+
if task is None or self._in_processing is task:
|
|
35
|
+
self._in_processing = None
|
|
36
|
+
|
|
37
|
+
def _ensure_processing(self) -> None:
|
|
38
|
+
if self._in_processing is None or self._in_processing.done():
|
|
39
|
+
task = asyncio.create_task(self._process())
|
|
40
|
+
task.add_done_callback(self._clear_processing)
|
|
41
|
+
self._in_processing = task
|
|
42
|
+
|
|
33
43
|
async def _process(self) -> None:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
current = asyncio.current_task()
|
|
45
|
+
try:
|
|
46
|
+
await self._event.wait()
|
|
47
|
+
if not self._pending_messages:
|
|
48
|
+
return
|
|
49
|
+
message = ChannelMessage.from_batch(self._pending_messages)
|
|
50
|
+
self._pending_messages.clear()
|
|
51
|
+
finally:
|
|
52
|
+
self._clear_processing(current)
|
|
38
53
|
await self._handler(message)
|
|
39
54
|
|
|
40
55
|
async def __call__(self, message: ChannelMessage) -> None:
|
|
@@ -60,9 +75,8 @@ class BufferedMessageHandler:
|
|
|
60
75
|
"session.message received active session_id={}, content={}", message.session_id, message.content
|
|
61
76
|
)
|
|
62
77
|
self._reset_timer(self.debounce_seconds)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
elif self._last_active_time is not None and self._in_processing is None:
|
|
78
|
+
self._ensure_processing()
|
|
79
|
+
elif self._last_active_time is not None and (self._in_processing is None or self._in_processing.done()):
|
|
66
80
|
logger.info("session.receive followup session_id={} message={}", message.session_id, message.content)
|
|
67
81
|
self._reset_timer(self.max_wait_seconds)
|
|
68
|
-
self.
|
|
82
|
+
self._ensure_processing()
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import base64
|
|
4
4
|
import contextlib
|
|
5
|
-
from collections.abc import Awaitable, Callable
|
|
5
|
+
from collections.abc import Awaitable, Callable, Mapping
|
|
6
6
|
from dataclasses import dataclass, field, replace
|
|
7
7
|
from typing import Any, Literal
|
|
8
8
|
|
|
@@ -10,6 +10,37 @@ type MessageKind = Literal["error", "normal", "command"]
|
|
|
10
10
|
type MediaType = Literal["image", "audio", "video", "document"]
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
def format_front_matter_message(metadata: Mapping[str, Any], body: str) -> str:
|
|
14
|
+
"""Render message content as YAML front matter followed by the body.
|
|
15
|
+
|
|
16
|
+
Multi-line strings are emitted as ``|`` block scalars, so their lines stay inside the
|
|
17
|
+
front matter by indentation and cannot be mistaken for the body or for other keys.
|
|
18
|
+
|
|
19
|
+
>>> print(format_front_matter_message({"sender_id": "7", "reply_to": {"content": "a\\n\\nb"}}, "hi"))
|
|
20
|
+
---
|
|
21
|
+
sender_id: '7'
|
|
22
|
+
reply_to:
|
|
23
|
+
content: |-
|
|
24
|
+
a
|
|
25
|
+
<BLANKLINE>
|
|
26
|
+
b
|
|
27
|
+
---
|
|
28
|
+
hi
|
|
29
|
+
"""
|
|
30
|
+
import yaml
|
|
31
|
+
|
|
32
|
+
class _Dumper(yaml.SafeDumper):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
def represent_str(dumper: yaml.SafeDumper, value: str) -> yaml.ScalarNode:
|
|
36
|
+
style = "|" if "\n" in value else None
|
|
37
|
+
return dumper.represent_scalar("tag:yaml.org,2002:str", value, style=style)
|
|
38
|
+
|
|
39
|
+
_Dumper.add_representer(str, represent_str)
|
|
40
|
+
front_matter = yaml.dump(dict(metadata), Dumper=_Dumper, allow_unicode=True, sort_keys=False)
|
|
41
|
+
return f"---\n{front_matter}---\n{body}"
|
|
42
|
+
|
|
43
|
+
|
|
13
44
|
@dataclass
|
|
14
45
|
class MediaItem:
|
|
15
46
|
"""A media attachment on a channel message."""
|
|
@@ -46,6 +77,9 @@ class ChannelMessage:
|
|
|
46
77
|
media: list[MediaItem] = field(default_factory=list)
|
|
47
78
|
lifespan: contextlib.AbstractAsyncContextManager | None = None
|
|
48
79
|
output_channel: str = ""
|
|
80
|
+
# What the sender wrote, for hooks that search or index messages, when ``content`` wraps it with channel
|
|
81
|
+
# metadata; ``None`` means ``content`` is that text.
|
|
82
|
+
text: str | None = None
|
|
49
83
|
|
|
50
84
|
def __post_init__(self) -> None:
|
|
51
85
|
self.context.update({"channel": "$" + self.channel, "chat_id": self.chat_id})
|
|
@@ -66,5 +100,8 @@ class ChannelMessage:
|
|
|
66
100
|
raise ValueError("Batch cannot be empty")
|
|
67
101
|
template = batch[-1]
|
|
68
102
|
content = "\n".join(message.content for message in batch)
|
|
103
|
+
text = None
|
|
104
|
+
if any(message.text is not None for message in batch):
|
|
105
|
+
text = "\n".join(message.content if message.text is None else message.text for message in batch)
|
|
69
106
|
media = [item for message in batch for item in message.media]
|
|
70
|
-
return replace(template, content=content, media=media)
|
|
107
|
+
return replace(template, content=content, media=media, text=text)
|
|
@@ -17,7 +17,7 @@ from telegram.request import HTTPXRequest
|
|
|
17
17
|
from bub import config
|
|
18
18
|
from bub.channels.base import Channel
|
|
19
19
|
from bub.channels.contracts import MessageHandler
|
|
20
|
-
from bub.channels.message import ChannelMessage, MediaItem, MediaType
|
|
20
|
+
from bub.channels.message import ChannelMessage, MediaItem, MediaType, format_front_matter_message
|
|
21
21
|
from bub.configure import Settings, ensure_config
|
|
22
22
|
from bub.core.commands import strip_command_prefix, validate_command_prefix
|
|
23
23
|
from bub.utils import exclude_none
|
|
@@ -63,6 +63,14 @@ def _message_type(message: Message) -> str:
|
|
|
63
63
|
return "unknown"
|
|
64
64
|
|
|
65
65
|
|
|
66
|
+
def _slice_utf16(text: str, offset: int, length: int) -> str:
|
|
67
|
+
"""Slice ``text`` using Telegram Bot API UTF-16 code-unit offsets."""
|
|
68
|
+
if offset < 0 or length <= 0:
|
|
69
|
+
return ""
|
|
70
|
+
encoded = text.encode("utf-16-le")
|
|
71
|
+
return encoded[offset * 2 : (offset + length) * 2].decode("utf-16-le", errors="ignore")
|
|
72
|
+
|
|
73
|
+
|
|
66
74
|
class BubMessageFilter(filters.MessageFilter):
|
|
67
75
|
GROUP_CHAT_TYPES: ClassVar[set[str]] = {"group", "supergroup"}
|
|
68
76
|
|
|
@@ -95,13 +103,14 @@ class BubMessageFilter(filters.MessageFilter):
|
|
|
95
103
|
return False
|
|
96
104
|
|
|
97
105
|
def _mentions_bot(self, message: Message, bot_id: int, bot_username: str) -> bool:
|
|
98
|
-
|
|
106
|
+
raw_content = self._content(message)
|
|
107
|
+
content = raw_content.lower()
|
|
99
108
|
mentions_by_keyword = "bub" in content or bool(bot_username and f"@{bot_username}" in content)
|
|
100
109
|
|
|
101
110
|
entities = [*(getattr(message, "entities", None) or ()), *(getattr(message, "caption_entities", None) or ())]
|
|
102
111
|
for entity in entities:
|
|
103
112
|
if entity.type == "mention" and bot_username:
|
|
104
|
-
mention_text =
|
|
113
|
+
mention_text = _slice_utf16(raw_content, entity.offset, entity.length)
|
|
105
114
|
if mention_text.lower() == f"@{bot_username}":
|
|
106
115
|
return True
|
|
107
116
|
continue
|
|
@@ -255,16 +264,18 @@ class TelegramChannel(Channel):
|
|
|
255
264
|
media_items = _extract_media_items(metadata)
|
|
256
265
|
reply_meta = await self._parser.get_reply(message)
|
|
257
266
|
if reply_meta:
|
|
258
|
-
metadata["reply_to_message"] = reply_meta
|
|
259
267
|
reply_media = _extract_media_items(reply_meta)
|
|
260
268
|
media_items.extend(reply_media)
|
|
261
|
-
|
|
269
|
+
metadata["reply_to"] = reply_meta
|
|
270
|
+
text = content
|
|
271
|
+
content = format_front_matter_message(metadata, text)
|
|
262
272
|
is_active = MESSAGE_FILTER.filter(message) is not False
|
|
263
273
|
return ChannelMessage(
|
|
264
274
|
session_id=session_id,
|
|
265
275
|
channel=self.name,
|
|
266
276
|
chat_id=chat_id,
|
|
267
277
|
content=content,
|
|
278
|
+
text=text,
|
|
268
279
|
media=media_items,
|
|
269
280
|
is_active=is_active,
|
|
270
281
|
lifespan=self.start_typing(chat_id),
|
|
@@ -284,7 +295,7 @@ class TelegramChannel(Channel):
|
|
|
284
295
|
task.cancel()
|
|
285
296
|
with contextlib.suppress(asyncio.CancelledError):
|
|
286
297
|
await task
|
|
287
|
-
|
|
298
|
+
self._typing_tasks.pop(chat_id, None)
|
|
288
299
|
|
|
289
300
|
async def _typing_loop(self, chat_id: str) -> None:
|
|
290
301
|
while True:
|
|
@@ -316,7 +327,7 @@ class TelegramMessageParser:
|
|
|
316
327
|
"full_name": message.from_user.full_name if message.from_user else "",
|
|
317
328
|
"sender_id": str(message.from_user.id) if message.from_user else "",
|
|
318
329
|
"sender_is_bot": message.from_user.is_bot if message.from_user else None,
|
|
319
|
-
"date": message.date.
|
|
330
|
+
"date": message.date.isoformat() if message.date else None,
|
|
320
331
|
"links": self._extract_links(message),
|
|
321
332
|
"media": media,
|
|
322
333
|
})
|
|
@@ -327,7 +338,7 @@ class TelegramMessageParser:
|
|
|
327
338
|
if reply_to is None or reply_to.from_user is None:
|
|
328
339
|
return None
|
|
329
340
|
content, metadata = await self.parse(reply_to)
|
|
330
|
-
return {"
|
|
341
|
+
return {**metadata, "content": content}
|
|
331
342
|
|
|
332
343
|
@staticmethod
|
|
333
344
|
def _extract_links(message: Message) -> list[str] | None:
|
|
@@ -347,7 +358,7 @@ class TelegramMessageParser:
|
|
|
347
358
|
elif entity.type == "url":
|
|
348
359
|
offset = getattr(entity, "offset", 0)
|
|
349
360
|
length = getattr(entity, "length", 0)
|
|
350
|
-
candidate = source_text
|
|
361
|
+
candidate = _slice_utf16(source_text, offset, length).strip()
|
|
351
362
|
url = candidate or None
|
|
352
363
|
|
|
353
364
|
if url and url not in links:
|
|
@@ -7,6 +7,7 @@ import contextlib
|
|
|
7
7
|
import warnings
|
|
8
8
|
from collections.abc import AsyncGenerator, Iterator
|
|
9
9
|
from dataclasses import dataclass
|
|
10
|
+
from functools import cache
|
|
10
11
|
from pathlib import Path
|
|
11
12
|
from typing import TYPE_CHECKING, Any
|
|
12
13
|
|
|
@@ -18,7 +19,6 @@ from bub import configure
|
|
|
18
19
|
from bub.application import CommandChanged, Outcome, cli_events
|
|
19
20
|
from bub.channels.admission import AdmitDecision, SteeringInbox, TurnSnapshot
|
|
20
21
|
from bub.channels.contracts import ChannelRouter, MessageHandler
|
|
21
|
-
from bub.configure import DEFAULT_HOME
|
|
22
22
|
from bub.core.events import Event, EventBus
|
|
23
23
|
from bub.core.sidecars import TapeSidecar
|
|
24
24
|
from bub.core.store import AsyncTapeStore, TapeStore
|
|
@@ -39,7 +39,12 @@ from bub.utils import maybe_context_manager
|
|
|
39
39
|
if TYPE_CHECKING:
|
|
40
40
|
from bub.channels.base import Channel
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
|
|
43
|
+
@cache
|
|
44
|
+
def _default_config_file() -> Path:
|
|
45
|
+
from bub import home
|
|
46
|
+
|
|
47
|
+
return (home / "config.yml").resolve()
|
|
43
48
|
|
|
44
49
|
|
|
45
50
|
@dataclass(frozen=True)
|
|
@@ -87,14 +92,15 @@ def _invoke_subcommand(ctx: typer.Context, name: str) -> None:
|
|
|
87
92
|
class BubFramework:
|
|
88
93
|
"""Minimal framework core. Everything grows from hook skills."""
|
|
89
94
|
|
|
90
|
-
def __init__(self, config_file: Path =
|
|
95
|
+
def __init__(self, config_file: Path | None = None) -> None:
|
|
91
96
|
"""Create a hook runtime and load the process-wide configuration file.
|
|
92
97
|
|
|
93
98
|
The workspace initially points to the current directory. Register plugins
|
|
94
99
|
or load builtin hooks before executing turns; construction does not load them.
|
|
100
|
+
Without an explicit config file, read ``config.yml`` from ``bub.home``.
|
|
95
101
|
"""
|
|
96
102
|
self.workspace = Path.cwd().resolve()
|
|
97
|
-
self.config_file = config_file.resolve()
|
|
103
|
+
self.config_file = (config_file if config_file is not None else _default_config_file()).resolve()
|
|
98
104
|
self._plugin_manager = pluggy.PluginManager(BUB_HOOK_NAMESPACE)
|
|
99
105
|
self._plugin_manager.add_hookspecs(BubHookSpecs)
|
|
100
106
|
self._hook_runtime = HookRuntime(self._plugin_manager)
|
|
@@ -7,6 +7,7 @@ from bub.application import CommandChanged, PromptChanged, PromptKind, WorkChang
|
|
|
7
7
|
from bub.core.events import Event
|
|
8
8
|
|
|
9
9
|
_RESULTS = {None: "working", "succeeded": "done", "failed": "error", "cancelled": "idle"}
|
|
10
|
+
_CLEAR = "\x1b]7501;state=clear\x1b\\"
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class ProgramStatus:
|
|
@@ -16,9 +17,11 @@ class ProgramStatus:
|
|
|
16
17
|
|
|
17
18
|
def __call__(self, event: Event) -> None:
|
|
18
19
|
kind: PromptKind | None = None
|
|
20
|
+
finished = False
|
|
19
21
|
match event:
|
|
20
22
|
case CommandChanged(outcome):
|
|
21
23
|
state = "idle" if outcome == "succeeded" and self.listener else _RESULTS[outcome]
|
|
24
|
+
finished = outcome is not None
|
|
22
25
|
case WorkChanged(busy, completed):
|
|
23
26
|
self.listener = True
|
|
24
27
|
state = "working" if busy else _RESULTS[completed] if completed else "idle"
|
|
@@ -32,5 +35,6 @@ class ProgramStatus:
|
|
|
32
35
|
fields = f"state={state}:app=bub"
|
|
33
36
|
if kind is not None:
|
|
34
37
|
fields += f":kind={kind}"
|
|
35
|
-
|
|
38
|
+
# The terminal outlives the command, so drop the record once the command ends.
|
|
39
|
+
self.output.write(f"\x1b]7501;{fields}\x1b\\{_CLEAR if finished else ''}")
|
|
36
40
|
self.output.flush()
|
|
@@ -17,14 +17,17 @@ async def wait_until_stopped[T](coro: Coroutine[None, None, T], stop_event: asyn
|
|
|
17
17
|
"""Run a coroutine until a stop event is set."""
|
|
18
18
|
task = asyncio.create_task(coro)
|
|
19
19
|
waiter = asyncio.create_task(stop_event.wait())
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
try:
|
|
21
|
+
_ = await asyncio.wait({task, waiter}, return_when=asyncio.FIRST_COMPLETED)
|
|
22
|
+
if stop_event.is_set():
|
|
23
|
+
task.cancel()
|
|
24
|
+
await task
|
|
25
|
+
raise asyncio.CancelledError("Operation cancelled due to stop event")
|
|
26
|
+
return task.result()
|
|
27
|
+
finally:
|
|
22
28
|
task.cancel()
|
|
23
|
-
await task
|
|
24
|
-
raise asyncio.CancelledError("Operation cancelled due to stop event")
|
|
25
|
-
else:
|
|
26
29
|
waiter.cancel()
|
|
27
|
-
|
|
30
|
+
await asyncio.gather(task, waiter, return_exceptions=True)
|
|
28
31
|
|
|
29
32
|
|
|
30
33
|
def workspace_from_state(state: TurnState) -> Path:
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import json
|
|
4
4
|
import os
|
|
5
5
|
import re
|
|
6
|
+
import subprocess
|
|
6
7
|
import sys
|
|
7
8
|
from io import StringIO
|
|
8
9
|
from pathlib import Path
|
|
@@ -40,7 +41,7 @@ def _terminal_output(monkeypatch: pytest.MonkeyPatch) -> StringIO:
|
|
|
40
41
|
|
|
41
42
|
def _program_status(output: StringIO) -> dict[str, str]:
|
|
42
43
|
frames = re.findall(r"\x1b]7501;([^\x1b\x07]*)(?:\x1b\\|\x07)", output.getvalue())
|
|
43
|
-
return dict(pair.split("=", 1) for pair in frames[-1].split(":"))
|
|
44
|
+
return dict(pair.split("=", 1) for pair in [frame for frame in frames if frame != "state=clear"][-1].split(":"))
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
def _fake_result(answer: Any, command: str | None = "enter") -> InquirerResult[Any]:
|
|
@@ -322,6 +323,7 @@ def test_onboard_can_install_gateway_after_saving_config(tmp_path: Path, monkeyp
|
|
|
322
323
|
assert f"Saved config to {config_file.resolve()}" in terminal_output.getvalue()
|
|
323
324
|
assert "Installed and started the gateway with systemd" in terminal_output.getvalue()
|
|
324
325
|
assert _program_status(terminal_output)["state"] == "done"
|
|
326
|
+
assert terminal_output.getvalue().endswith("\x1b]7501;state=clear\x1b\\")
|
|
325
327
|
assert observed == {"workspace": tmp_path.resolve(), "channels": []}
|
|
326
328
|
|
|
327
329
|
|
|
@@ -483,27 +485,33 @@ def test_gateway_install_and_uninstall_are_mutually_exclusive() -> None:
|
|
|
483
485
|
def test_run_help_uses_the_configured_prefix(
|
|
484
486
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, config: str, env_prefix: str | None, prefix: str
|
|
485
487
|
) -> None:
|
|
486
|
-
monkeypatch.setenv("BUB_HOME", str(tmp_path))
|
|
487
488
|
monkeypatch.delenv("BUB_COMMAND_PREFIX", raising=False)
|
|
488
489
|
if env_prefix is not None:
|
|
489
490
|
monkeypatch.setenv("BUB_COMMAND_PREFIX", env_prefix)
|
|
490
491
|
config_file = tmp_path / "config.yml"
|
|
491
492
|
config_file.write_text(config, encoding="utf-8")
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
"
|
|
497
|
-
|
|
493
|
+
script = (
|
|
494
|
+
"import os, sys\n"
|
|
495
|
+
"from bub.framework import BubFramework\n"
|
|
496
|
+
"os.environ['BUB_HOME'] = sys.argv.pop(1)\n"
|
|
497
|
+
"framework = BubFramework()\n"
|
|
498
|
+
"framework.load_builtin_hooks()\n"
|
|
499
|
+
"framework.create_cli_app()()\n"
|
|
500
|
+
)
|
|
501
|
+
result = subprocess.run(
|
|
502
|
+
[sys.executable, "-c", script, str(tmp_path), "run", f"{prefix}help"],
|
|
503
|
+
cwd=tmp_path,
|
|
504
|
+
capture_output=True,
|
|
505
|
+
text=True,
|
|
506
|
+
timeout=10,
|
|
507
|
+
check=False,
|
|
498
508
|
)
|
|
499
509
|
|
|
500
|
-
result
|
|
501
|
-
|
|
502
|
-
assert
|
|
503
|
-
assert f"
|
|
504
|
-
assert f"{prefix}
|
|
505
|
-
assert f"{prefix}code_mode enable=true" in result.output
|
|
506
|
-
assert f"{prefix}quit" in result.output
|
|
510
|
+
assert result.returncode == 0, result.stderr
|
|
511
|
+
assert f"Commands use '{prefix}'" in result.stdout
|
|
512
|
+
assert f"{prefix}bash.output" in result.stdout
|
|
513
|
+
assert f"{prefix}code_mode enable=true" in result.stdout
|
|
514
|
+
assert f"{prefix}quit" in result.stdout
|
|
507
515
|
|
|
508
516
|
|
|
509
517
|
def test_run_command_processes_inbound_inside_framework_runtime(tmp_path: Path) -> None:
|
|
@@ -637,6 +645,31 @@ def test_login_command_reports_the_authenticated_account(
|
|
|
637
645
|
assert "test-token" not in result.stdout
|
|
638
646
|
|
|
639
647
|
|
|
648
|
+
@pytest.mark.parametrize("provider,auth_class", [("grok", "GrokAuth"), ("github-copilot", "GitHubCLIAuth")])
|
|
649
|
+
@pytest.mark.parametrize("fails", [False, True])
|
|
650
|
+
def test_login_reports_success_or_failure(
|
|
651
|
+
monkeypatch: pytest.MonkeyPatch, provider: str, auth_class: str, fails: bool
|
|
652
|
+
) -> None:
|
|
653
|
+
from republic.errors import AuthenticationError
|
|
654
|
+
|
|
655
|
+
import bub.builtin.auth as auth
|
|
656
|
+
|
|
657
|
+
async def login(**kwargs: Any) -> None:
|
|
658
|
+
if fails:
|
|
659
|
+
raise AuthenticationError("Login cancelled")
|
|
660
|
+
|
|
661
|
+
monkeypatch.setattr(getattr(auth, auth_class), "login", login)
|
|
662
|
+
result = CliRunner().invoke(_create_app(), ["login", provider])
|
|
663
|
+
|
|
664
|
+
assert result.exit_code == (1 if fails else 0)
|
|
665
|
+
if fails:
|
|
666
|
+
assert "login: failed: Login cancelled" in result.stderr
|
|
667
|
+
assert "login: ok" not in result.stdout
|
|
668
|
+
else:
|
|
669
|
+
assert "login: ok" in result.stdout
|
|
670
|
+
assert f"BUB_MODEL={provider}:" in result.stdout
|
|
671
|
+
|
|
672
|
+
|
|
640
673
|
def test_login_rejects_unknown_provider() -> None:
|
|
641
674
|
result = CliRunner().invoke(_create_app(), ["login", "github"])
|
|
642
675
|
|
|
@@ -721,6 +754,23 @@ def test_ensure_project_initializes_project_and_adds_bub_dependency(tmp_path: Pa
|
|
|
721
754
|
]
|
|
722
755
|
|
|
723
756
|
|
|
757
|
+
def test_install_uses_configured_contrib_repository(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
758
|
+
monkeypatch.delenv("BUB_CONTRIB_REPO", raising=False)
|
|
759
|
+
config_file = tmp_path / "config.yml"
|
|
760
|
+
config_file.write_text('contrib_repo: "ssh://git@example.com/fork.git#subdirectory=plugins/mcp"\n')
|
|
761
|
+
(tmp_path / "pyproject.toml").touch()
|
|
762
|
+
framework = BubFramework(config_file=config_file)
|
|
763
|
+
framework.load_builtin_hooks()
|
|
764
|
+
|
|
765
|
+
with patch.object(cli, "_uv") as uv:
|
|
766
|
+
result = CliRunner().invoke(framework.create_cli_app(), ["install", "bub-mcp@main", "--project", str(tmp_path)])
|
|
767
|
+
|
|
768
|
+
assert result.exit_code == 0, result.output
|
|
769
|
+
uv.assert_called_once_with(
|
|
770
|
+
"add", "--active", "git+ssh://git@example.com/fork.git@main#subdirectory=plugins/mcp", cwd=tmp_path
|
|
771
|
+
)
|
|
772
|
+
|
|
773
|
+
|
|
724
774
|
@pytest.mark.parametrize("initial_prompt", [None, "Explain this project", "你好 Bub"])
|
|
725
775
|
def test_chat_accepts_optional_initial_prompt(initial_prompt: str | None, monkeypatch) -> None:
|
|
726
776
|
from bub.channels.manager import ChannelManager
|