Abstract seeds into modular skill packs + split config

Group committed starter skills into packs (semif_agent/packs.py) that bind a
concern to its categories, bridge(s), requirements, and config schema:

- seeds/ -> packs/<name>/ with a pack.json manifest + skills/<category>/<leaf>/.
  Shipped: nextcloud, simplex, outlook, browser (each owning its bridge) and
  essentials (time + calculator, no bridge).
- PackRegistry discovers packs (a root with no manifest is one implicit pack);
  merge_packs loads every enabled pack. Pack enable is one switch
  (packs.<name>.enabled -> bridges.<bridge>.enabled -> enabled_by_default);
  disabling a pack drops its categories (incl. generated bodies) and its bridge.
- CATEGORY_DESCRIPTIONS now comes from the pack manifests (built-ins stay).

Adopt a Home-Assistant-style layered config (semif_agent/config.py):

- config.json is a thin index ({"include": [...]}) over config/core.json,
  config/gateway.json, config/bridges.json, config/packs/*.json, deep-merged.
- Secrets live in the gitignored secrets.json, referenced as "!secret <key>";
  api_key_env is removed.
- CORE_SCHEMA + each pack's config schema own defaults and GENERATE the
  committed config.example.json; new `check-config` (validate + --write-example)
  and `config-init` (seed the split layout) commands.
- scripts/config_merge.py (stdlib) lets bootstrap read the merged config.

Tests: tests/test_packs.py (renamed from test_seed_skills, +enable/merge),
new tests/test_config.py. All unit tests pass (772).
This commit is contained in:
gabby committed 2026-10-13 14:20:35 +00:00
1 parent b953475bf7
commit 78b4621ba0
115 files changed
+1701 -398

No files matched your search

+1 -1
View File
@@ -175,7 +175,7 @@ def _scheduler(tmp_path) -> Scheduler:
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)
+114
View File
@@ -0,0 +1,114 @@
"""The layered config: index includes, !secret resolution, and schema validation.
These exercise the Home-Assistant-style split directly: config.json is a thin
index over fragments, secrets live in a separate file referenced as
``"!secret <key>"``, and the core + pack schemas own defaults and validate a
live config.
"""
import json
from pathlib import Path
from semif_agent.config import (
ConfigError,
generate_example_config,
iter_secret_refs,
load_config_file,
load_secrets,
missing_secret_refs,
resolve_secrets,
split_config,
validate_config,
write_split_config,
)
from semif_agent.packs import load_packs
def _write(path: Path, data: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data))
def test_index_includes_deep_merge_later_wins(tmp_path):
_write(tmp_path / "config" / "core.json", {"tau": 0.6, "queue": {"max_size": 10}})
_write(tmp_path / "config" / "gateway.json", {"gateway": {"simplex": {"enabled": True}}})
_write(
tmp_path / "config.json",
{"include": ["config/core.json", "config/gateway.json"]},
)
config = load_config_file(tmp_path / "config.json")
assert config["tau"] == 0.6
assert config["queue"]["max_size"] == 10
assert config["gateway"]["simplex"]["enabled"] is True
def test_include_cycle_is_an_error(tmp_path):
_write(tmp_path / "a.json", {"include": ["b.json"]})
_write(tmp_path / "b.json", {"include": ["a.json"]})
try:
load_config_file(tmp_path / "a.json")
except ConfigError as exc:
assert "cycle" in str(exc)
else:
raise AssertionError("expected a cycle error")
def test_secret_resolution_and_missing_refs(tmp_path):
_write(tmp_path / "secrets.json", {"nextcloud_app_password": "s3cret"})
secrets = load_secrets(tmp_path / "secrets.json")
config = {
"bridges": {"nextcloud": {"app_password": "!secret nextcloud_app_password"}},
"llm": {"api_key": "!secret absent_key"},
}
assert list(iter_secret_refs(config)) == ["nextcloud_app_password", "absent_key"]
resolved = resolve_secrets(config, secrets)
assert resolved["bridges"]["nextcloud"]["app_password"] == "s3cret"
# A missing secret resolves to "" at load (startup never hard-fails) ...
assert resolved["llm"]["api_key"] == ""
# ... and is reported by the validator.
assert missing_secret_refs(config, secrets) == ["absent_key"]
def test_generate_example_marks_secrets_and_never_leaks_values(tmp_path):
packs = load_packs({"skill_packs": str(Path(__file__).resolve().parent.parent / "packs")})
example = generate_example_config(packs)
# Every secret-typed key is a !secret ref, never a value.
assert example["codegen"]["api_key"] == "!secret codegen_api_key"
assert example["bridges"]["nextcloud"]["app_password"] == "!secret nextcloud_app_password"
assert example["bridges"]["nextcloud"]["token"] == "!secret nextcloud_token"
# The pack's non-secret defaults are present.
assert example["bridges"]["nextcloud"]["port"] == 5230
assert example["packs"]["essentials"]["enabled"] is True
def test_validate_config_reports_types_unknowns_and_secrets(tmp_path):
_write(tmp_path / "secrets.json", {})
config = {
"tau": "not-a-number",
"totally_unknown_key": 1,
"codegen": {"api_key": "!secret codegen_api_key"},
}
problems = validate_config(config, packs=[])
assert any("tau: expected float" in p for p in problems)
assert any("warning: totally_unknown_key: unknown config key" in p for p in problems)
assert "codegen_api_key" in missing_secret_refs(config, load_secrets(tmp_path / "secrets.json"))
def test_split_then_load_roundtrip(tmp_path):
packs = load_packs({"skill_packs": str(Path(__file__).resolve().parent.parent / "packs")})
merged = generate_example_config(packs)
written = write_split_config(tmp_path, merged, packs)
assert any(p.endswith("config/core.json") for p in written)
assert any(p.endswith("config/packs/nextcloud.json") for p in written)
# The written index reloads to the same core values.
reloaded = load_config_file(tmp_path / "config.json")
assert reloaded["tau"] == merged["tau"]
assert reloaded["bridges"]["nextcloud"]["port"] == 5230
def test_split_config_places_shared_bridge_outside_packs(tmp_path):
packs = load_packs({"skill_packs": str(Path(__file__).resolve().parent.parent / "packs")})
merged = generate_example_config(packs)
files = split_config(merged, packs)
assert "bridges" in files["config/bridges.json"]
assert "llm" in files["config/bridges.json"]["bridges"]
+9 -4
View File
@@ -235,13 +235,11 @@ def test_list_models_parses_catalog():
def test_provider_endpoint_selects_console_and_resolves_key(monkeypatch):
from semif_agent import cli
monkeypatch.setenv("MY_CONSOLE_KEY", "envkey")
console = cli._provider_endpoint(
{"provider": "opencode", "api_key_env": "MY_CONSOLE_KEY"},
"http://localhost:11434/v1",
{"provider": "opencode"}, "http://localhost:11434/v1"
)
assert console["base_url"] == OPENCODE_BASE_URL
assert console["api_key"] == "envkey"
assert console["api_key"] == ""
ollama = cli._provider_endpoint({"provider": "ollama"}, "http://localhost:11434/v1")
assert ollama["base_url"] == "http://localhost:11434/v1"
@@ -250,6 +248,13 @@ def test_provider_endpoint_selects_console_and_resolves_key(monkeypatch):
literal = cli._provider_endpoint({"provider": "opencode", "api_key": "lit"}, "x")
assert literal["api_key"] == "lit"
# api_key_env is gone: it is ignored, never resolved from the environment.
monkeypatch.setenv("MY_CONSOLE_KEY", "envkey")
legacy = cli._provider_endpoint(
{"provider": "opencode", "api_key_env": "MY_CONSOLE_KEY"}, "x"
)
assert legacy["api_key"] == ""
explicit = cli._provider_endpoint(
{"provider": "opencode", "base_url": "https://example.test/v1"}, "x"
)
+1 -1
View File
@@ -34,7 +34,7 @@ def build_scheduler(tmp_path, engine=None):
log=log,
config={
"skills": {},
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
"skill_bodies": str(tmp_path / "skills"),
"category_registry": str(tmp_path / "categories.json"),
"deleted_skills": str(tmp_path / "deleted_skills.json"),
+1 -1
View File
@@ -36,7 +36,7 @@ def build_scheduler(tmp_path):
engine=engine,
llm=llm,
log=log,
config={"skills": {}, "skill_seeds": str(tmp_path / "seeds")},
config={"skills": {}, "skill_packs": str(tmp_path / "seeds")},
trace=trace,
)
+1 -1
View File
@@ -55,7 +55,7 @@ def _scheduler(tmp_path, choices=None, default="success"):
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
"deleted_skills": str(tmp_path / "deleted_skills.json"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
+1 -1
View File
@@ -26,7 +26,7 @@ def build_scheduler(tmp_path, choices=None):
engine=engine,
llm=llm,
log=log,
config={"skills": {}, "skill_seeds": str(tmp_path / "seeds")},
config={"skills": {}, "skill_packs": str(tmp_path / "seeds")},
trace=trace,
)
+154
View File
@@ -0,0 +1,154 @@
"""The committed pack skills are real, inspectable, and hermetically tested.
A pack ships starter integrations in the repo in the CODEGEN.md folder format,
grouped by concern under ``packs/<name>/skills/<category>/<leaf>/``. These tests
keep every pack skill honest: the declared integration must match the code, the
contract must cover what the body reads, and the hermetic mechanics test must
pass. They are not proof of the live integration — only a real run against the
user's service is (see AGENTS.md).
"""
import json
import os
from pathlib import Path
import pytest
from semif_agent.codegen import (
integration_findings,
parse_contract,
parse_integration,
run_skill_test,
)
from semif_agent.packs import (
disabled_categories,
load_packs,
merge_packs,
pack_enabled,
)
PACKS = Path(__file__).resolve().parent.parent / "packs"
SKILL_DIRS = sorted(path.parent for path in PACKS.glob("*/skills/*/*/skill.py"))
def seed_id(seed: Path) -> str:
return f"{seed.parent.name}.{seed.name}"
def test_pack_manifests_are_valid():
packs = load_packs({"skill_packs": str(PACKS)})
assert {p.name for p in packs} >= {
"nextcloud",
"simplex",
"outlook",
"browser",
"essentials",
}
for pack in packs:
assert pack.concern, f"{pack.name} must declare a concern"
assert pack.categories, f"{pack.name} must declare its categories"
def test_pack_enabled_resolution():
packs = {p.name: p for p in load_packs({"skill_packs": str(PACKS)})}
# A bridge pack follows its bridge's enabled flag.
assert pack_enabled({"bridges": {"nextcloud": {"enabled": False}}}, packs["nextcloud"]) is False
assert pack_enabled({"bridges": {"nextcloud": {"enabled": True}}}, packs["nextcloud"]) is True
# An explicit packs.<name>.enabled wins over the bridge flag.
assert (
pack_enabled(
{"bridges": {"nextcloud": {"enabled": False}}, "packs": {"nextcloud": {"enabled": True}}},
packs["nextcloud"],
)
is True
)
# A bridge-less pack uses enabled_by_default.
assert pack_enabled({}, packs["essentials"]) is True
assert pack_enabled({"packs": {"essentials": {"enabled": False}}}, packs["essentials"]) is False
# browser defaults off (needs the optional deps).
assert pack_enabled({}, packs["browser"]) is False
def test_merge_packs_loads_enabled_and_skips_disabled():
packs = load_packs({"skill_packs": str(PACKS)})
tree: dict = {}
config = {"bridges": {"nextcloud": {"enabled": True}, "outlook": {"enabled": False}}}
merge_packs(tree, packs, config)
assert "nextcloud" in tree
assert "time" in tree and "calculator" in tree # the essentials pack
assert "outlook" not in tree # disabled pack contributes nothing
assert "browser" not in tree
assert disabled_categories(config, packs) >= {"outlook", "browser"}
# A pack skill is labeled `seed` (a committed starter), not `generated`.
assert all(s.origin == "seed" for s in tree["nextcloud"])
# The pack's category description rides on the skill (feeds navigation).
assert tree["nextcloud"][0].category_description
def test_manifestless_pack_root_is_one_implicit_pack(tmp_path):
directory = tmp_path / "my_skills" / "widgets" / "frobnicate"
directory.mkdir(parents=True)
(directory / "skill.py").write_text("def act(ctx, request):\n return None\n")
packs = load_packs({"skill_packs": str(tmp_path / "my_skills")})
assert len(packs) == 1
assert ("widgets", "frobnicate") in packs[0].store.list_skills()
def test_expected_seeds_exist():
ids = {seed_id(seed) for seed in SKILL_DIRS}
assert "nextcloud.next_event" in ids
assert "nextcloud.create_event" in ids
assert "simplex.next_message" in ids
assert "simplex.send_message" in ids
assert "simplex.connect_link" in ids
assert "time.now" in ids
assert "time.date" in ids
assert "time.set_timer" in ids
assert "time.set_alarm" in ids
assert "nextcloud.create_task" in ids
assert "calculator.calculate" in ids
assert "browser.open_page" in ids
assert "browser.read_page" in ids
assert "browser.screenshot" in ids
@pytest.mark.parametrize("seed", SKILL_DIRS, ids=[seed_id(s) for s in SKILL_DIRS])
def test_seed_declares_a_real_integration(seed):
code = (seed / "skill.py").read_text()
integration = parse_integration(code)
assert integration["service"]
assert integration["transport"]
assert integration_findings(integration, "declared", code) == []
@pytest.mark.parametrize("seed", SKILL_DIRS, ids=[seed_id(s) for s in SKILL_DIRS])
def test_seed_contract_is_flat_and_covered_by_declaration(seed):
code = (seed / "skill.py").read_text()
contract = parse_contract(code)
integration = parse_integration(code)
assert set(integration["config_vars"]) == set(contract)
mirror = json.loads((seed / "contract.json").read_text())
assert mirror == contract, "contract.json must mirror the CONTRACT constant"
if integration["transport"] == "compute":
# A local compute skill acts on the machine itself and needs no
# configuration; an empty contract is legitimate.
return
assert contract, "an external-integration seed must declare a CONTRACT constant"
for name, description in contract.items():
assert name.islower() and " " not in name, name
assert isinstance(description, str) and description.strip()
@pytest.mark.parametrize("seed", SKILL_DIRS, ids=[seed_id(s) for s in SKILL_DIRS])
def test_seed_has_manifest_description(seed):
manifest = json.loads((seed / "manifest.json").read_text())
assert manifest["description"].strip()
@pytest.mark.parametrize("seed", SKILL_DIRS, ids=[seed_id(s) for s in SKILL_DIRS])
def test_seed_hermetic_test_passes(seed, monkeypatch):
root = str(seed.parents[4])
existing = os.environ.get("PYTHONPATH", "")
monkeypatch.setenv("PYTHONPATH", root + os.pathsep + existing)
passed, output = run_skill_test(seed, timeout=30)
assert passed, output
-88
View File
@@ -1,88 +0,0 @@
"""The committed seed skills are real, inspectable, and hermetically tested.
A seed is a starter integration shipped in the repo in the CODEGEN.md folder
format. These tests keep every seed honest: the declared integration must match
the code, the contract must cover what the body reads, and the hermetic
mechanics test must pass. They are not proof of the live integration — only a
real run against the user's service is (see AGENTS.md).
"""
import json
import os
from pathlib import Path
import pytest
from semif_agent.codegen import (
integration_findings,
parse_contract,
parse_integration,
run_skill_test,
)
SEEDS = Path(__file__).resolve().parent.parent / "seeds"
SEED_DIRS = sorted(path.parent for path in SEEDS.glob("*/*/skill.py"))
def seed_id(seed: Path) -> str:
return f"{seed.parent.name}.{seed.name}"
def test_expected_seeds_exist():
ids = {seed_id(seed) for seed in SEED_DIRS}
assert "nextcloud.next_event" in ids
assert "nextcloud.create_event" in ids
assert "simplex.next_message" in ids
assert "simplex.send_message" in ids
assert "simplex.connect_link" in ids
assert "time.now" in ids
assert "time.date" in ids
assert "time.set_timer" in ids
assert "time.set_alarm" in ids
assert "nextcloud.create_task" in ids
assert "calculator.calculate" in ids
assert "browser.open_page" in ids
assert "browser.read_page" in ids
assert "browser.screenshot" in ids
@pytest.mark.parametrize("seed", SEED_DIRS, ids=[seed_id(s) for s in SEED_DIRS])
def test_seed_declares_a_real_integration(seed):
code = (seed / "skill.py").read_text()
integration = parse_integration(code)
assert integration["service"]
assert integration["transport"]
assert integration_findings(integration, "declared", code) == []
@pytest.mark.parametrize("seed", SEED_DIRS, ids=[seed_id(s) for s in SEED_DIRS])
def test_seed_contract_is_flat_and_covered_by_declaration(seed):
code = (seed / "skill.py").read_text()
contract = parse_contract(code)
integration = parse_integration(code)
assert set(integration["config_vars"]) == set(contract)
mirror = json.loads((seed / "contract.json").read_text())
assert mirror == contract, "contract.json must mirror the CONTRACT constant"
if integration["transport"] == "compute":
# A local compute skill acts on the machine itself and needs no
# configuration; an empty contract is legitimate.
return
assert contract, "an external-integration seed must declare a CONTRACT constant"
for name, description in contract.items():
assert name.islower() and " " not in name, name
assert isinstance(description, str) and description.strip()
@pytest.mark.parametrize("seed", SEED_DIRS, ids=[seed_id(s) for s in SEED_DIRS])
def test_seed_has_manifest_description(seed):
manifest = json.loads((seed / "manifest.json").read_text())
assert manifest["description"].strip()
@pytest.mark.parametrize("seed", SEED_DIRS, ids=[seed_id(s) for s in SEED_DIRS])
def test_seed_hermetic_test_passes(seed, monkeypatch):
root = str(seed.parents[2])
existing = os.environ.get("PYTHONPATH", "")
monkeypatch.setenv("PYTHONPATH", root + os.pathsep + existing)
passed, output = run_skill_test(seed, timeout=30)
assert passed, output
+14 -14
View File
@@ -143,7 +143,7 @@ def _scheduler(tmp_path, codegen=None, choices=None, default="success", verbosit
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
}
if verbosity is not None:
config["verbosity"] = verbosity
@@ -561,7 +561,7 @@ def test_merge_seed_store_falls_back_to_name_and_body_store_wins(tmp_path):
def test_scheduler_loads_committed_seed_skills(tmp_path):
"""The real seed package ships in the tree at startup with its manifest
description and declared integration."""
seed_root = Path(__file__).resolve().parent.parent / "seeds"
seed_root = Path(__file__).resolve().parent.parent / "packs"
scheduler = Scheduler(
engine=SemIfEngine(EngineConfig()),
llm=LLMClient(base_url="http://localhost:1/v1", model="test"),
@@ -569,7 +569,7 @@ def test_scheduler_loads_committed_seed_skills(tmp_path):
config={
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(seed_root),
"skill_packs": str(seed_root),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)
@@ -586,20 +586,20 @@ def test_scheduler_loads_committed_seed_skills(tmp_path):
def test_load_config_anchors_runtime_paths_to_checkout(tmp_path):
"""Path-valued config keys resolve against the checkout, not the cwd, so a
fresh clone finds its committed seeds from anywhere; absolute paths pass
fresh clone finds its committed packs from anywhere; absolute paths pass
through untouched."""
config_file = tmp_path / "config.json"
config_file.write_text(
json.dumps(
{
"skill_seeds": "seeds",
"skill_packs": "packs",
"skill_bodies": "data/skills",
"log": "/absolute/decisions.jsonl",
}
)
)
config = load_config(str(config_file))
assert config["skill_seeds"] == str(REPO_ROOT / "seeds")
assert config["skill_packs"] == str(REPO_ROOT / "packs")
assert config["skill_bodies"] == str(REPO_ROOT / "data/skills")
assert config["category_registry"] == str(REPO_ROOT / "data/categories.json")
assert config["log"] == "/absolute/decisions.jsonl"
@@ -607,7 +607,7 @@ def test_load_config_anchors_runtime_paths_to_checkout(tmp_path):
def test_committed_seeds_load_from_a_foreign_cwd(tmp_path, monkeypatch):
"""A fresh checkout's seeds come from the anchored `seeds/` path even when
"""A fresh checkout's packs come from the anchored `packs/` path even when
the process runs from an unrelated directory (the zero-skills regression:
relative paths resolved against cwd, so the tree was only response.reject
and navigation fell into the codegen loop)."""
@@ -615,7 +615,7 @@ def test_committed_seeds_load_from_a_foreign_cwd(tmp_path, monkeypatch):
config_file.write_text(
json.dumps(
{
"skill_seeds": "seeds",
"skill_packs": "packs",
"skill_bodies": str(tmp_path / "skills"),
"category_registry": str(tmp_path / "categories.json"),
"log": str(tmp_path / "decisions.jsonl"),
@@ -1168,7 +1168,7 @@ def test_dispatch_action_tau_controls_catchall_routing(tmp_path):
"navigation": {"action_tau": action_tau},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)
@@ -1212,7 +1212,7 @@ def test_dispatch_intent_tau_controls_reuse_vs_create(tmp_path):
"navigation": {"intent_tau": intent_tau},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)
@@ -1350,7 +1350,7 @@ def test_dispatch_confident_leaf_winner_still_runs_intent_guard(tmp_path):
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)
@@ -1396,7 +1396,7 @@ def test_dispatch_create_category_queues_draft_and_is_not_fatal(tmp_path):
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=trace,
)
@@ -2499,7 +2499,7 @@ def test_chain_continues_then_completes(tmp_path):
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)
@@ -2585,7 +2585,7 @@ def test_compound_request_runs_part_step_then_chains(tmp_path):
"skills": {},
"category_registry": str(tmp_path / "categories.json"),
"skill_bodies": str(tmp_path / "skills"),
"skill_seeds": str(tmp_path / "seeds"),
"skill_packs": str(tmp_path / "seeds"),
},
trace=TraceLog(str(tmp_path / "runs.jsonl")),
)