PACKGEN.md is the authoritative spec for a new pack, the sibling of CODEGEN.md (body) and TESTGEN.md (test): the pack.json manifest, its config schema and how it maps onto bridges.<name>/packs.<name>, the enable switch, referencing a bridge by name, authoring a new bridge (BridgeService + CATALOG + build_bridge + the optional-dep 503 rule), acceptance criteria, a worked example, and a checklist. Add a thin OpenCode skill (.opencode/skills/packgen/SKILL.md) that walks the workflow and points at PACKGEN.md, and cross-link the contract from AGENTS.md, README.md, CODEGEN.md, and TESTGEN.md.
18 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 anything under packs/. 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. 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 (bridge code stays in
semif_agent/bridges— 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
(
semif_agent/bridges/). A pack references a bridge by name; it never contains bridge code. - A pack is declarative structure and is committed. Per-machine values are
the split config; credentials live in
secrets.json. A committed pack 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
- 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. 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 committed pack should always have a manifest.
The committed 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 talks to, referencing bridges/registry.py CATALOG. 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).- 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 and carries its config block in config. The bridge itself is a
class in semif_agent/bridges/ registered in bridges/registry.py CATALOG.
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.
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 references a bridge; it never imports or edits bridge code. 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, so a skill body never speaks that system's native protocol. Adding a service means:
-
Write the bridge class in
semif_agent/bridges/<name>.py, subclassingBridgeService(semif_agent/bridges/base.py). Set thenameattribute and a module-level/classINFO = BridgeInfo(...):from .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. -
Register it in
bridges/registry.pyCATALOG(tuple order is presentation order). That is what makes it discoverable, describable to codegen, and runnable viapython -m semif_agent.cli bridge. -
Give it a pack whose
bridgeslists its name and whoseconfigschema carries its block (enabled/host/port/tokenplus service vars). The schema is what gives the bridge its config defaults and validation. -
build_bridgespecial-casing is needed only when the bridge requires the scheduler's configuredllmclient (passclient=) or top-level fallback values (like Nextcloud'snextcloud_*). A plain bridge needs no branch. -
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
tests/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.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 exists inbridges/registry.pyCATALOG.- 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. - Nothing deployment-specific (hostname, address, username, absolute home
path, local model name) appears in any committed file —
tests/test_no_env_leaks.pyenforces this. Secrets live insecrets.json.
tests/test_packs.py enforces items 1–3 mechanically for every committed pack
(valid manifest, concern + categories, integration matches code, contract flat
and mirrored, manifest description, hermetic test passes) 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 committed
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) 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/.
Checklist
- Decide the concern and the category ids; write navigation-grade category descriptions.
- If a third-party system is involved and no bridge fronts it, author the
bridge first (see "Authoring a new bridge") and register it in
CATALOG. - Create
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). - 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(plustests/test_<name>_bridge.pyif you added a bridge). - 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.