From ec3e6b1b97c91a514f9a8d1d4829cab52aca888d Mon Sep 17 00:00:00 2001 From: Gabby Morgan Date: Sat, 17 Oct 2026 07:34:39 +0000 Subject: [PATCH] skills: read-only catalog for introspection bodies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An ordinary skill body may not reach into the agent (`ctx.admin` is the housekeeping-only mutation surface), but a body that reports the agent's own capabilities legitimately needs to see the tree. Add that sanctioned surface: - `SkillCatalog` (skills.py): a read-only view — `categories()` (id -> scope description) and `skills(category)` (leaf names) — over a live provider. - `ActionContext.catalog`: supplied by the scheduler as a locked tree snapshot, passed to every body. - The runner now passes `admin` only to the `housekeeping` category (it was previously handed to every body despite the documented rule); ordinary bodies get `catalog` instead. Consumed by the essentials pack's new `skills.list_categories` / `skills.list_skills` seeds. Docs (CODEGEN.md, AGENTS.md, README.md) updated; tests cover the catalog, the catalog/admin split on the run context, and the new pack seeds. --- AGENTS.md | 22 +++++++++++++++----- CODEGEN.md | 8 +++++-- README.md | 15 +++++++++++--- semif_agent/scheduler.py | 11 +++++++++- semif_agent/skill.py | 7 ++++++- semif_agent/skills.py | 29 +++++++++++++++++++++++++- tests/test_packs.py | 2 ++ tests/test_skills.py | 45 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 126 insertions(+), 13 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0fb7629..0e9f047 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -116,7 +116,9 @@ scheduler.py no up-front gate: every input is dispatched recall never skips the actionability guard or feeds the monotonic-progress guard; housekeeping meta skills (delete/clear-config/regen/cancel-build) - operate on the tree via `ctx.admin`; new-skill creation is gated by + operate on the tree via `ctx.admin` (mutation); every other body + sees the tree only through the read-only `ctx.catalog` + (`ActionContext.catalog`, an `SkillCatalog`); new-skill creation is gated by a tri-state mode (`new_skill_creation`: deny/allow/ask, **deny by default**) with a per-category override in the category config, with @@ -186,7 +188,9 @@ skill.py loop: observe -> act -> observe -> assess; the body is a single a run paused for input is resumed by re-invoking act with the answer on request.user_input; a contract variable the runner cannot satisfy pauses BEFORE - act (pre_act), collects it, and re-runs the full path + act (pre_act), collects it, and re-runs the full path; + the run context supplies the read-only `catalog` to every body + and the mutating `admin` only to the housekeeping category timers.py in-process timer/alarm service (TimerService) owned by the scheduler and exposed on ActionContext.timers: a single background thread fires scheduled timers on the host clock, @@ -1100,7 +1104,7 @@ CLI, unit tests (24) + integration tests (2). never holds secrets, and a generated body with the same name replaces the pack skill. The shipped packs: `nextcloud`, `simplex`, `outlook`, `browser` (each owning its bridge), and `essentials` (the built-in local utilities `time` + - `calculator`; no bridge). `nextcloud.create_event` is the authoritative worked + `calculator` + `skills`; no bridge). `nextcloud.create_event` is the authoritative worked example (creates a CalDAV event through the Nextcloud bridge; derives the title/date/time from the query, asks for missing fields and resumes, resolves the target calendar with a SemIf choice @@ -1127,6 +1131,14 @@ CLI, unit tests (24) + integration tests (2). roots/fractions/percentages, SemIf picks the operands when the request offers more numbers than the operator consumes, and the answer is spelled out in words for the ear (an inexact result is announced as "approximately ..."); + `skills.list_categories` and `skills.list_skills` are the introspection skills + (`compute` transport, empty contract): they read the agent's own tree through + the read-only `ctx.catalog` (never the housekeeping-only `ctx.admin`) and + report the category list, or the leaf names inside a category named in the + request (asking for one when it is missing, and reporting an unknown category + honestly) — so a voice user can ask "list skill categories" or "list skills in + nextcloud". The closed `response` tree is filtered out of both (it is the + non-request catchall, not a capability); `tests/test_packs.py` keeps every pack skill honest. - **Contract provenance.** Each authored body records the CODEGEN.md revision it was written against. `skill_contract_ref()` (`codegen.py`) returns @@ -1679,8 +1691,8 @@ CLI, unit tests (24) + integration tests (2). `semif_agent/config.py` `SHARED_BRIDGE_SCHEMA`. - **Shipped packs.** `nextcloud`, `simplex`, `outlook`, `browser` (each owning its bridge) and `essentials` (the built-in local utilities `time` + - `calculator`; no bridge) — each in its own repository. Adding a concern means - adding a pack repo, not editing `skills.py`. + `calculator` + `skills`; no bridge) — each in its own repository. Adding a + concern means adding a pack repo, not editing `skills.py`. ### bridges (third-party API services) diff --git a/CODEGEN.md b/CODEGEN.md index 25ab9e1..5247e08 100644 --- a/CODEGEN.md +++ b/CODEGEN.md @@ -303,8 +303,12 @@ def act(ctx, request) -> ActionResult: `ctx.config` (the resolved values for this skill, including its own config), and `ctx.timers` (the in-process timer/alarm service — use it to schedule a notification, as the `time.set_timer` and `time.set_alarm` seeds do). - `ctx.admin` exists for the built-in housekeeping meta skills only; an ordinary - body must never touch it. + `ctx.catalog` is a **read-only** view of the agent's own skill tree for an + introspection skill that reports what the agent can do: `ctx.catalog.categories()` + returns a `{category_id: description}` map and `ctx.catalog.skills(category)` + the leaf names inside one category (the `skills.list_categories` / + `skills.list_skills` seeds). `ctx.admin` exists for the built-in housekeeping + meta skills only; an ordinary body must never touch it. - `request` is the `Request` being handled. - `ActionResult(action_log: str, new_state: str, needs_input: str | None = None, decisions: list = [])` is imported from `semif_agent.skills`; return that exact diff --git a/README.md b/README.md index 47b93a4..6cc3163 100644 --- a/README.md +++ b/README.md @@ -363,8 +363,10 @@ fine-tuning loop — it is not yet the fine-tune itself. - **Seeds** — shipped real starter skills: `nextcloud.create_event` (the authoritative worked example), `nextcloud.next_event` (the user's Nextcloud calendar, through the bridge), `nextcloud.create_task` (Nextcloud task list), - `simplex.next_message` / `simplex.send_message` / `simplex.connect_link`, and - `calculator.calculate` (two operands, one SemIf-chosen operator, spoken answer). + `simplex.next_message` / `simplex.send_message` / `simplex.connect_link`, + `calculator.calculate` (two operands, one SemIf-chosen operator, spoken answer), + and `skills.list_categories` / `skills.list_skills` (report the agent's own + skill categories, or the skills inside a named category). - **Fatal-on-engine-loss** — the engine is always real; its absence exits the app. - **Stdlib-only core** — SemIf/llama.cpp are lazy imports, so the package stays importable and testable without the heavy engine installed. @@ -494,7 +496,8 @@ It then installs **only what those answers require**. Both ends of the spectrum are reachable by the end of a run: - **minimum** — local SemIf 4B + `essentials` (canned replies, time/timers, - calculator). No account, no network, no gateway, no heavy downloads. + calculator, skill listing). No account, no network, no gateway, no heavy + downloads. - **maximum** — every pack, a remote Winnow engine, remote `llm`/`codegen` endpoints, and all gateways. @@ -1062,6 +1065,12 @@ authoring a new pack (and a new bridge to back one). cubes, square roots, cube roots, fractions, and percentages, and SemIf picks the operands when the request writes more numbers than the operation needs (pure local compute, no config). +- `skills.list_categories` — list the categories of skills the agent has + (pure local compute, no config; reads the read-only `ctx.catalog`, not the + housekeeping-only `ctx.admin`). +- `skills.list_skills` — list the skills inside a category named in the request + ("list skills in nextcloud"), asking for one when it is missing and reporting + an unknown category honestly (pure local compute, no config). --- diff --git a/semif_agent/scheduler.py b/semif_agent/scheduler.py index ee1fc5e..7b2102d 100644 --- a/semif_agent/scheduler.py +++ b/semif_agent/scheduler.py @@ -54,6 +54,7 @@ from .skills import ( CreateSkill, DeletedSkills, Skill, + SkillCatalog, SkillDraft, SkillStore, apply_tombstones, @@ -435,8 +436,16 @@ class Scheduler: for category in disabled_categories(config, self.packs): self.tree.pop(category, None) self.timers = TimerService(trace=self.trace, timezone=config.get("timezone")) + # Read-only introspection of the live tree for introspection skills + # (listing categories / the skills in one), supplied as a locked + # snapshot so a body never reaches into the scheduler. + self.catalog = SkillCatalog(self._tree_snapshot) self.ctx = ActionContext( - engine=self.engine, config=config, timers=self.timers, admin=self + engine=self.engine, + config=config, + timers=self.timers, + admin=self, + catalog=self.catalog, ) self.runner = SkillRunner( self.ctx, diff --git a/semif_agent/skill.py b/semif_agent/skill.py index b459954..388872b 100644 --- a/semif_agent/skill.py +++ b/semif_agent/skill.py @@ -34,6 +34,7 @@ from .log import DecisionLog from .skills import ( CANNED_CATEGORIES, DETERMINISTIC_CATEGORIES, + HOUSEKEEPING_CATEGORY, ActionContext, Skill, SkillStore, @@ -147,7 +148,11 @@ class SkillRunner: engine=self.ctx.engine, config=merged, timers=self.ctx.timers, - admin=self.ctx.admin, + # `admin` (mutation of the agent) is reserved for the built-in + # housekeeping meta skills; an ordinary body only ever gets the + # read-only `catalog`. + admin=self.ctx.admin if skill.category == HOUSEKEEPING_CATEGORY else None, + catalog=self.ctx.catalog, ) def _unresolved(self, skill: Skill, request: Request) -> list[str]: diff --git a/semif_agent/skills.py b/semif_agent/skills.py index 3f6f800..ab1ce70 100644 --- a/semif_agent/skills.py +++ b/semif_agent/skills.py @@ -47,8 +47,35 @@ class ActionContext: timers: TimerService | None = None # The scheduler, exposed to built-in meta skills (housekeeping) so they can # act on the agent's own tree/registry/store. None for ordinary bodies, which - # must never reach into the agent. + # must never reach into the agent (the read-only `catalog` is their view). admin: object | None = None + # A read-only view of the agent's own skill catalog (categories -> skills), + # for an introspection skill that reports what the agent can do. Unlike + # `admin` it exposes no mutation, so an ordinary body may read it. + catalog: "SkillCatalog | None" = None + + +@dataclass +class SkillCatalog: + """Read-only introspection of the agent's own skill tree. + + An ordinary skill body must never reach into the agent (`ctx.admin` is for + the built-in housekeeping meta skills), but a skill that reports the agent's + own capabilities legitimately needs to see the tree. This is that surface: + reads only — the category list and the skills inside one category — with no + way to mutate. `provider` returns the live tree (the scheduler supplies a + locked snapshot), so a skill authored after startup is still listed. + """ + + provider: Callable[[], dict[str, list[Skill]]] + + def categories(self) -> dict[str, str]: + """Category id -> scope description, for every category in the tree.""" + return category_descriptions(self.provider()) + + def skills(self, category: str) -> list[str]: + """The leaf names inside one category (empty when it is unknown).""" + return sorted(skill.name for skill in self.provider().get(category, [])) def _noop_act(ctx: ActionContext, request: Request) -> ActionResult: diff --git a/tests/test_packs.py b/tests/test_packs.py index 59bef90..9343db4 100644 --- a/tests/test_packs.py +++ b/tests/test_packs.py @@ -139,6 +139,8 @@ def test_expected_seeds_exist(): assert "time.set_alarm" in ids assert "nextcloud.create_task" in ids assert "calculator.calculate" in ids + assert "skills.list_categories" in ids + assert "skills.list_skills" in ids assert "browser.open_page" in ids assert "browser.read_page" in ids assert "browser.screenshot" in ids diff --git a/tests/test_skills.py b/tests/test_skills.py index 25e5fba..28f91c0 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -40,6 +40,7 @@ from semif_agent.skills import ( CreateCategory, CreateSkill, Skill, + SkillCatalog, SkillDraft, SkillStore, build_category_prompt, @@ -180,6 +181,50 @@ def test_scheduler_sizes_artifact_budgets_from_engine_context(tmp_path): assert scheduler.max_test_chars == scheduler.max_body_chars +def test_skill_catalog_lists_categories_and_skills(): + """The read-only catalog reports the tree's categories and one category's + leaves, and follows the live provider.""" + tree = { + "time": [ + Skill(name="now", category="time", description="time"), + Skill(name="date", category="time", description="date"), + ], + "calculator": [Skill(name="calculate", category="calculator", description="math")], + } + catalog = SkillCatalog(lambda: tree) + assert set(catalog.categories()) == {"time", "calculator"} + assert catalog.skills("time") == ["date", "now"] + assert catalog.skills("missing") == [] + # A skill added after construction is still listed (the provider is live). + tree["new"] = [Skill(name="thing", category="new", description="d")] + assert "new" in catalog.categories() + + +def test_scheduler_exposes_a_read_only_catalog(tmp_path): + """The scheduler supplies the catalog on the run context, but reserves + `admin` for the built-in housekeeping meta skills.""" + scheduler = _scheduler(tmp_path) + assert scheduler.catalog is not None + categories = scheduler.catalog.categories() + assert "housekeeping" in categories and "response" in categories + assert "delete_skill" in scheduler.catalog.skills("housekeeping") + # An ordinary body sees the catalog but not the mutating admin surface. + housekeeping = next( + s for s in scheduler.tree["housekeeping"] if s.name == "delete_skill" + ) + ordinary = Skill( + name="probe", + category="tracking", + description="Probe.", + act=lambda ctx, request: ActionResult(action_log="ok", new_state="x"), + ) + house_ctx = scheduler.runner._skill_context(housekeeping, Request("x")) + plain_ctx = scheduler.runner._skill_context(ordinary, Request("x")) + assert house_ctx.admin is scheduler + assert plain_ctx.admin is None + assert plain_ctx.catalog is scheduler.catalog + + def test_fidelity_gate_state_is_whole_body_without_the_request(tmp_path): """The gate ingests the whole body plus the inventory and goal, and never the raw user request (the truncation bug and the PII path, both fixed)."""