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>.
21 KiB
PACKGEN.md — the contract for new packs
This file is the authoritative spec for what a pack is and how to author a
new one. It is the third sibling of the skill contracts: CODEGEN.md governs a
skill's runnable body, TESTGEN.md governs its test, and this file
governs the pack that bundles a concern, its skills, its bridge reference,
and its settings into one thing.
Read this before adding a pack. A pack is what makes a new
product/concern a first-class part of the agent instead of scattered edits to
skills.py and config.py.
What a pack is
Semif-agent ships a set of starter integrations. Each is a pack: a folder
packs/<name>/ holding a pack.json manifest plus a skills/ store of leaves
in the exact generated-skill format. Each pack lives in its own repository
(pack.<name>, listed in the committed packs.json); scripts/bootstrap.sh
clones them into the gitignored packs/<name>/. The manifest binds the pieces
that would otherwise be scattered by convention:
- the concern (what product/job this is) and its title;
- its categories (the tree buckets it owns, each with a scope description);
- the bridge(s) it talks to, referenced by name — and ships the bridge
code itself under
bridge/(see "Authoring a new bridge"); - its runtime requirements (optional heavy deps);
- its enable flag; and
- its config schema (the defaults and validation for its settings).
A pack is loaded by semif_agent/packs.py (PackRegistry discovers packs,
merge_packs loads every enabled pack into the tree at startup) and its
config schema is read by semif_agent/config.py to generate
config.example.json and to validate a live config.
Three boundaries must stay crisp:
- A skill is one leaf action (
packs/<name>/skills/<category>/<leaf>/), governed byCODEGEN.md/TESTGEN.md. A pack contains skills; it is not one. - A bridge is a standalone process in front of a third-party system,
warranted when the system needs state (especially auth state), a native or
heavy protocol, or one sanitized surface; a system with a plain HTTP API needs
no bridge — its skill calls the API directly. A bridge ships with its pack
(
packs/<name>/bridge/); the core keeps only the shared contract (semif_agent/bridges/base.py) and the discovery registry (semif_agent/bridges/registry.py). The one shared, pack-less bridge is the LLM bridge (a core built-in many packs call). A pack'sbridgeslist names the bridge(s) it ships; a pack never edits core bridge code. - A pack is declarative structure, committed in its own repository.
Per-machine values are the split config; credentials live in
secrets.json. A pack repo never holds a secret.
Folder layout
packs/<name>/
pack.json # the manifest (this file's subject)
skills/<category>/<leaf>/
skill.py # the body — CODEGEN.md
manifest.json # {"description": "..."} navigation text
contract.json # mirror of the body's CONTRACT — TESTGEN.md
skill.test.py # hermetic mechanics test — TESTGEN.md
bridge/ # only for a bridge-backed pack (see below)
__init__.py # the pack's bridge package
<bridge>.py # the BridgeService subclass (bridge name)
<bridge>_client.py # optional protocol client (e.g. nextcloud_client.py)
test_<bridge>_bridge.py # hermetic bridge test (loopback HTTP)
scripts/ # optional concern helpers (e.g. an auth or
# setup script), run from the checkout
- The
<category>directory name is the tree bucket; the<leaf>directory name is the leaf'sname. The runner joins them ascategory.nameonly in run summaries. - Every leaf carries the four artifacts above. Their contents are governed by
CODEGEN.md(body +CONTRACT+INTEGRATION) andTESTGEN.md(test +contract.jsonmirror); do not restate those rules here. bridge/ships the pack's bridge (one module per name inbridges, plus optional sibling modules it imports relatively). It is absent for a bridge-less pack. See "Authoring a new bridge".manifest.jsonholds a single non-emptydescription— the navigation text SemIf routes on. It is the seed analog of the registry entry a generated skill gets from thellmprovider.- A root with no
pack.jsonis treated as one implicit, manifest-less pack whose store is the root itself (a plain skills directory still works), but a pack repo should always have a manifest.
The shipped packs are the authoritative worked examples: essentials is
the minimal bridge-less pack; nextcloud, simplex, outlook, and browser
are bridge-backed packs.
pack.json — the manifest
A single JSON object. Fields (from packs._parse_pack):
| Field | Type | Required | Meaning |
|---|---|---|---|
name |
string | no* | Pack id (snake_case). Defaults to the folder name. |
title |
string | no | Human display name. Defaults to name. |
concern |
string | yes | One- to two-sentence statement of the product/job the pack serves. (description is accepted as a legacy alias.) |
categories |
object | yes | {category_id: scope_description} — the tree buckets this pack owns. |
bridges |
array of string | no | Bridge names this pack ships and talks to. Each name is a bridge/<name>.py module in the pack; simplex/llm/nextcloud/outlook/browser are the shipped names. Empty for a bridge-less pack. |
requires |
array of string | no | Optional heavy deps (e.g. playwright). Informational; the code's check_requirements is what enforces them. |
enabled_by_default |
bool | no | Default true. Whether the pack loads when nothing else decides. |
config |
object | no | The pack's config schema (see below). |
* name is optional in the parser but should always be set explicitly.
Rules:
concernandcategoriesare required (tests/test_packs.pyfails without them). A pack with no declared concern is not a pack.- Category ids are the tree keys. They are the same ids the leaf folders
live under (
skills/<category>/<leaf>/). Whencategoriesis omitted, the pack's categories are inferred from theskills/subdirectories — but declare them, because the description is load-bearing. - A category description is navigation-critical. It is what SemIf reads to route a request into the bucket; a bare id with no description routes badly. Write one to two sentences naming the concrete jobs the category does.
bridges[0]owns the config block. For a bridge pack, the pack'sconfigschema maps ontobridges.<bridges[0]>; only the first bridge gets the block (a pack normally fronts one bridge). Each name inbridgesmust have abridge/<name>.pymodule that defines itsBridgeServicesubclass.- Keep the manifest minimal: it binds metadata and settings, nothing executable.
The config schema
config is a nested schema. A leaf is a dict with a default; a block
is a dict without one (recurse). Each leaf spec:
| Key | Type | Meaning |
|---|---|---|
type |
string | bool | int | float | str | list | dict. Checked by check-config (int/float are interchangeable). |
default |
any | The value shipped in config.example.json and seeded by config-init. Required on a leaf. |
doc |
string | One-line plain-language description. Shown in the generated example. |
secret |
bool | true marks a credential: the example emits "!secret <pack>_<key>" instead of a value. |
Example (a bridge-backed pack, mirroring packs/simplex/pack.json):
"config": {
"enabled": {"type": "bool", "default": true, "doc": "Load this pack's skills and run its bridge."},
"host": {"type": "str", "default": "127.0.0.1", "doc": "Bridge bind address (localhost only)."},
"port": {"type": "int", "default": 5227, "doc": "Bridge listen port."},
"token": {"type": "str", "default": "", "secret": true, "doc": "Shared secret required in the X-Semif-Token header when set."},
"reconnect": {
"initial": {"type": "float", "default": 1.0, "doc": "Initial reconnect delay (seconds)."},
"max": {"type": "float", "default": 60.0, "doc": "Maximum reconnect delay (seconds)."}
}
}
How the schema maps onto the live config (config.default_config /
generate_example_config):
- A bridge pack (
bridgesnon-empty) maps its wholeconfigschema onto thebridges.<bridges[0]>block. - A bridge-less pack maps only its
enabledflag ontopacks.<name>.enabled; its other keys are not carried (a bridge-less pack is configured through its skills' own config, not a pack block). - Secret leaves become
"!secret <pack>_<key>"inconfig.example.json, where<pack>_is the pack name prefix (nested keys are prefixed with their path, e.g.simplex_reconnect_initial). Never write a real credential into the manifest.
Rules:
- Every leaf needs a
defaultand adoc. A key with nodefaultis treated as a nested block. - Put operational settings here (endpoints, accounts, defaults, timeouts) —
the values a skill body reads from
ctx.config. Per-request arguments never belong in config (seeCODEGEN.md). config.json,config/, andsecrets.jsonare gitignored and per-machine. The manifest is committed structure only.
After changing a schema, regenerate and validate:
python -m semif_agent.cli check-config --write-example config.example.json
python -m semif_agent.cli check-config
config-init seeds the split config/ layout from the schemas (bootstrap runs
it once, only when config.json is absent); afterwards only a human edits it.
The generated example and the live config are never hand-edited.
The enable switch
One switch governs the pack's skills and its bridge, so a host never offers
a skill whose bridge is off. packs.pack_enabled resolves in order:
- an explicit
packs.<name>.enabledin config (wins); - else, for a bridge pack,
bridges.<bridges[0]>.enabled(the historical switch); - else
enabled_by_default.
Disabling a pack drops its categories entirely — including any generated body
authored into one — and stops its bridge. The switch lives in the pack's
config/packs/<name>.json fragment (written by config-init/check-config).
Referencing a bridge by name
A pack whose skills talk to a third-party system lists that bridge in
bridges, ships it under bridge/, and carries its config block in
config. (A pack whose skills reach a plain HTTP API directly needs no bridge:
bridges stays empty and each leaf declares the endpoint in its own
CONTRACT.) The bridge itself is a BridgeService subclass in
packs/<name>/bridge/<name>.py; the core registry imports it by convention and
its BridgeInfo (name, service, description, URL config var, other config vars,
auth header, endpoints) is injected into every codegen prompt via
describe_bridges(), so bodies learn how to reach it without the pack restating
protocol details. The one exception is the shared, pack-less LLM bridge
(a core built-in).
Skill-facing config is derived, never duplicated: derived_config_vars
turns the bridge's bridges.<name> block (host/port/token) into the
<url_config_var> and <auth_config_var> values a body reads from
ctx.config (e.g. simplex_bridge_url, simplex_bridge_token). Bodies call
the bridge over the ordinary http transport; their hermetic tests are
loopback HTTP like any other HTTP body.
Rules:
- The bridge block's
enabled/host/port/tokenare the pack's config schema; the URL/token config vars are derived and must not be declared again. - A pack ships its own bridge and never imports or edits another pack's or the core's. Gateway isolation is non-negotiable — read/send/address capability is a bridge, never a gateway feature.
Authoring a new bridge
A bridge is a standalone process that stands up a simple, secure localhost HTTP layer in front of one third-party system. Author one when a skill body cannot sanely talk to the system itself — because it holds auth/session state, needs a native or heavy protocol, or should be reached through one sanitized surface. A system with a plain HTTP API needs no bridge: its skill calls the API directly. Adding a bridge means:
-
Write the bridge class in the pack's
bridge/<name>.py, subclassingBridgeService(semif_agent/bridges/base.py). Set thenameattribute and a module-level/classINFO = BridgeInfo(...). Shipbridge/__init__.py(the package marker) and any sibling modules the bridge imports relatively (e.g.bridge/<name>_client.pyfor the protocol client):from semif_agent.bridges.base import BridgeInfo, BridgeService class WidgetBridge(BridgeService): name = "widget" INFO = BridgeInfo( name="widget", service="widget_service", description="The user's Widget account: widgets and their status.", url_config_var="widget_bridge_url", endpoints=( "GET /widgets — list widgets", "POST /widgets — create a widget", ), config_vars=("widget_bridge_token",), config_var_docs=(("widget_bridge_token", "Shared secret for the X-Semif-Token header."),), auth_header="X-Semif-Token", auth_config_var="widget_bridge_token", ) def check_requirements(self) -> tuple[bool, str | None]: return True, None # stdlib-only def handle_get(self, path, query): ... def handle_post(self, path, payload): ...The base class owns the HTTP/JSON/auth plumbing (
start/stop, theX-Semif-Tokenguard); a subclass implements only its routes. Overridestart/stop/_stop_transportonly if the bridge owns a service daemon. Anchor checkout-relative paths (e.g. a token store under.runtime/) withsemif_agent.bridges.base.checkout_root(), never from the bridge's own__file__— the bridge ships in its pack, so its path is pack-relative. -
Declare it in the pack's
bridgeslist and ship its module atbridge/<name>.py. That is what makes it discoverable, describable to codegen, and runnable viapython -m semif_agent.cli bridge— there is no coreCATALOGto edit. -
Carry its config block in the pack's
configschema (enabled/host/port/tokenplus service vars). The schema is what gives the bridge its config defaults and validation. -
Override
BridgeService.from_configonly when the bridge needs more than its own block: the scheduler's configuredllmclient (the shared LLM bridge) or top-level fallback values (like Nextcloud'snextcloud_*). A plain bridge uses the default and needs no override. -
Heavy/optional deps:
check_requirements()must never raise and must return(ok, install_hint).run_bridgesaborts all bridges when one reportsok=False, so a bridge with an optional dependency (like the browser) must return(True, None)and surface a per-call503with an install hint instead — a missing browser must not take down simplex/llm/ nextcloud. Lazy-import every heavy dep so the core stays stdlib-only. -
Report real failures: a transport/HTTP/bad-reply failure is a
502, a missing connection/dep is a503, bad input a400— never a fabricated success. The bridge owns its own state (cursors, daemons); bodies keep none. -
Test it hermetically: add
bridge/test_<name>_bridge.pydriving the real routes over a loopbackhttp.server(inject a fake driver where a real service would be needed). No external network, no real daemon. Import the bridge through the core registry (load_pack_bridge_module("<pack>", "<name>")) so the test also proves the pack's bridge is discoverable;tests/test_packs.pyruns it from the checkout.describe_bridges()picks the new bridge up automatically. -
Regenerate
config.example.jsonand runcheck-config(see above), and document the bridge inAGENTS.md(bridges section). Never widen the gateway for a new capability.
Acceptance criteria
A new pack is accepted only if:
packs/<name>/pack.jsonparses as JSON, declares a non-emptyconcernand a non-emptycategoriesmap, and everybridgesname has abridge/<name>.pymodule defining itsBridgeServicesubclass.- Every leaf under
skills/<category>/<leaf>/is a complete skill folder (skill.py,manifest.json,contract.json,skill.test.py) satisfyingCODEGEN.mdandTESTGEN.md: a module-levelact, a flatCONTRACTwhose every key is read fromctx.config, anINTEGRATIONconsistent with the code, a non-emptymanifest.jsondescription, andcontract.jsonan exact mirror of the body'sCONTRACT. - The leaf's hermetic mechanics test passes
(
python skill.test.pyfrom the leaf folder). This proves mechanics only — only a real run against the user's service proves the integration. - Each category id in the manifest is the id its leaves live under, and each category has a navigation-grade scope description.
- The
configschema is well-formed (every leaf hasdefault+doc; secrets markedsecret), maps ontobridges.<bridges[0]>(orpacks.<name>for a bridge-less pack), and the regeneratedconfig.example.json+check-configare clean. - A bridge-backed pack ships its bridge test (
bridge/test_<bridge>_bridge.py) and it passes hermetically (loopback HTTP, no external network, no daemon). - Nothing deployment-specific (hostname, address, username, absolute home
path, local model name) appears in any committed file —
tests/test_no_env_leaks.pyenforces this for the agent repo; keep a pack repo clean too. Secrets live insecrets.json.
tests/test_packs.py enforces items 1–6 mechanically for every shipped pack
(valid manifest, concern + categories, integration matches code, contract flat
and mirrored, manifest description, hermetic skill test, hermetic bridge test)
and keeps the shipped pack ids present.
Worked example — a minimal bridge-less pack
The smallest complete pack needs a manifest and one leaf. packs/essentials/
is the committed model; a hypothetical packs/hello/:
packs/hello/
pack.json
skills/hello/greet/
skill.py
manifest.json
contract.json
skill.test.py
pack.json:
{
"name": "hello",
"title": "Hello",
"concern": "A trivial local greeting utility that needs no account, network, or bridge.",
"categories": {
"hello": "Greetings: producing a friendly greeting for the user."
},
"bridges": [],
"requires": [],
"enabled_by_default": true,
"config": {
"enabled": {"type": "bool", "default": true, "doc": "Load the hello skills."}
}
}
skills/hello/greet/manifest.json:
{ "description": "Produce a friendly greeting." }
The leaf's skill.py (a compute-transport body — no external action, empty
CONTRACT) and skill.test.py follow CODEGEN.md/TESTGEN.md; the shipped
packs/essentials/skills/time/now/ is the reference for exactly this shape.
For a bridge-backed pack, start from packs/simplex/pack.json (bridge
reference + host/port/token + service vars), packs/simplex/bridge/ (the
bridge module, its package marker, and its hermetic test), and
packs/simplex/skills/simplex/send_message/ (a body that calls the bridge over
HTTP). For a bridge with top-level fallbacks, see packs/nextcloud/ (its
bridge/nextcloud.py overrides from_config).
Checklist
- Decide the concern and the category ids; write navigation-grade category descriptions.
- If a third-party system is involved and it needs state/auth, a native or
heavy protocol, or one sanitized surface, author a bridge first (see
"Authoring a new bridge") and ship it under
bridge/. A system with a plain HTTP API needs no bridge — the skill calls it directly. - Create the pack (its own repository,
pack.<name>):packs/<name>/pack.jsonwithname,title,concern,categories,bridges(if any),requires,enabled_by_default, and theconfigschema. - Add each leaf under
skills/<category>/<leaf>/followingCODEGEN.mdandTESTGEN.md(skill.py,manifest.json,contract.json,skill.test.py), and each bridge underbridge/<name>.pywith itsbridge/test_<name>_bridge.py. - Regenerate and validate config:
python -m semif_agent.cli check-config --write-example config.example.jsonthenpython -m semif_agent.cli check-config. - Run the tests:
python3 -m pytest tests/test_packs.py tests/test_codegen.py -q(it runs every pack's skill and bridge tests, including the new ones). - Cross-link the pack/bridge in
AGENTS.md(andREADME.mdfor a shipped pack). - Verify a real run against the user's actual service — the only proof the integration works.
- Add the pack's name to the committed
packs.json, then commit and push the pack's own repository (pack.<name>);scripts/bootstrap.shclones it intopacks/.