Decouple bridges: ship each with its pack
The core no longer owns concrete bridge implementations. A bridge now ships inside the pack that declares it (packs/<name>/bridge/<name>.py, plus its package marker, optional client module, and hermetic test), and the core registry imports it by convention from the pack's `bridges`. Core keeps only: - bridges/base.py: BridgeInfo + BridgeService (shared HTTP/JSON/auth layer), plus a new BridgeService.from_config build hook (a bridge that needs the scheduler's `llm` client or top-level fallback values declares that itself, replacing build_bridge's per-name special-casing) and checkout_root() so a pack-relative bridge can still anchor .runtime/ paths; - bridges/inbox.py: the generic MessagingInbox; - bridges/llm.py: the one shared, pack-less LLMBridge (CORE_BRIDGES); - bridges/registry.py: discovery (discover_bridge_classes/known_infos/ describe_bridges/derived_config_vars/build_bridge/run_bridges) scanning each pack's bridge/ dir, plus load_pack_bridge_module/package for tests. Moved to their packs: simplex, nextcloud (+client), outlook (+client), browser (+client) — each with its hermetic test. tests/test_bridges.py now covers the core (shared LLM bridge + registry); tests/test_packs.py runs every pack's bridge test. Docs (AGENTS.md, PACKGEN.md, README.md) updated. Packs pushed separately to pack.<name>.
This commit is contained in:
1 parent
16e8583921
commit
41c18e6c47
21 files changed
+485
-7476
No files matched your search
@@ -14,9 +14,20 @@ import threading
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
|
||||
def checkout_root() -> Path:
|
||||
"""The agent checkout root (anchors gitignored ``.runtime/`` artifacts).
|
||||
|
||||
``semif_agent/bridges/base.py`` -> repo root. A bridge implementation ships
|
||||
inside its pack (``packs/<name>/bridge/...``), so it must not derive the root
|
||||
from its own ``__file__``; it uses this helper instead.
|
||||
"""
|
||||
return Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BridgeInfo:
|
||||
"""Static, prompt-safe metadata about a bridge.
|
||||
@@ -60,6 +71,25 @@ class BridgeService(ABC):
|
||||
self._server: ThreadingHTTPServer | None = None
|
||||
self._thread: threading.Thread | None = None
|
||||
|
||||
@classmethod
|
||||
def from_config(
|
||||
cls,
|
||||
block: dict | None,
|
||||
config: dict | None = None,
|
||||
trace=None,
|
||||
llm=None,
|
||||
) -> "BridgeService":
|
||||
"""Build a bridge from its ``bridges.<name>`` block.
|
||||
|
||||
The registry constructs every bridge through this hook so a bridge that
|
||||
needs more than its own block — the shared LLM client, or a top-level
|
||||
fallback (e.g. Nextcloud's ``nextcloud_*`` values) — can declare that
|
||||
itself instead of the core special-casing it by name. The default passes
|
||||
the block and trace straight through; override in a pack bridge that
|
||||
needs ``llm`` or the full ``config``.
|
||||
"""
|
||||
return cls(block, trace=trace)
|
||||
|
||||
# ---- lifecycle ----
|
||||
|
||||
@abstractmethod
|
||||
|
||||
Reference in new issue
Block a user