docs: align CODEGEN.md/TESTGEN.md with the codebase

CODEGEN.md:
- replace the stale "Manifest schema" (allowed_inputs/actions/cost_budget/
  decision_log_ref, a dotted leaf name) with the real registry shape and note
  the body writer does not author it
- document ctx.timers (and that ctx.admin is built-in-only) and the
  request.meta resume cache, both used by the authoritative seed set
- correct acceptance criteria: INTEGRATION is not hard-rejected (inferred /
  fidelity-gated); note which items the parser actually enforces; compile ->
  ast.parse
- fix the SemIf URL, the structured-state claim (state is a string here), the
  config_vars/CONTRACT relationship, and defer llm_bridge_* names to the catalog

TESTGEN.md:
- separate the only static check (ast.parse) from execution (exit 0); state
  that stdlib-only/inline-fixtures/hermeticity are required but not verified
- clarify contract.json is handed to the test writer as context

README.md: fix the same stale manifest field list.

tests/test_codegen.py: add guards for the runtime surface and against the
stale manifest fields returning.
This commit is contained in:
gabby committed 2026-10-07 11:30:58 +00:00
1 parent dff4849947
commit e64354e78d
4 files changed
+105 -45

No files matched your search

+72 -35
View File
@@ -9,12 +9,12 @@ contract, `TESTGEN.md`. This file is about the runnable body only.
## What a skill is ## What a skill is
Semif-agent is an end-user application: an everyday person asks it to do a task, Semif-agent is an end-user application: an everyday person asks it to do a task,
and it does that task using a combination of user-provided data and a catalog of basic services known as bridges. A skill is the thing that performs one of those tasks: it is the leaf in the skill tree that the agent navigates to when it has resolved a request to a single, concrete action. Navigation is performed by an llm-based classification engine known as SemIf. and it does that task using a combination of native python modules, user-provided data and a catalog of basic services known as bridges. A skill is the thing that performs one of those tasks: it is the leaf in the skill tree that the agent navigates to when it has resolved a request to a single, concrete action. Navigation is performed by an llm-based decision engine known as SemIf.
A skill is three things: A skill is three things:
1. **A manifest** — the registry entry that makes it navigable and describes 1. **A registry entry** — its navigable `name` + `description`, recorded in
what it does. `data/categories.json` and mirrored in the running tree.
2. **A code body** — a runnable Python module implementing a single `act` 2. **A code body** — a runnable Python module implementing a single `act`
phase against a real service. phase against a real service.
3. **A declaration** — the `INTEGRATION` constant (which real system the body 3. **A declaration** — the `INTEGRATION` constant (which real system the body
@@ -50,7 +50,10 @@ It performs one forward pass and reads the probabilities of the declared answer
tokens directly. It returns a probability for each option — no sentence, no tokens directly. It returns a probability for each option — no sentence, no
JSON, no decoding loop, nothing to parse. In effect it is a semantic `if`: JSON, no decoding loop, nothing to parse. In effect it is a semantic `if`:
software asks a yes/no/which question in natural language and gets back a typed, software asks a yes/no/which question in natural language and gets back a typed,
thresholdable number. The `state` may also be a nonempty JSON object or array. thresholdable number. In this agent the `state` is always a string
(`request.text`, or the query plus a list of candidates); the broader SemIf
project also accepts a nonempty JSON object or array as state, but a body here
must pass a string.
The whole point is that the **question and options arrive with the request**. The whole point is that the **question and options arrive with the request**.
Routing, selection, and assessment are not baked into the model or the prompt; Routing, selection, and assessment are not baked into the model or the prompt;
@@ -66,7 +69,7 @@ code.
### SemIf's feature set ### SemIf's feature set
SemIf (<https://github.com/TheoLeeCJ/SemIf-OpenJev>) is a broader project than SemIf (<https://github.com/TheoLeeCJ/SemIf>) is a broader project than
the one call this agent makes. Its full feature set: the one call this agent makes. Its full feature set:
- **Runtime-defined decisions** — state, criterion, and option descriptions are - **Runtime-defined decisions** — state, criterion, and option descriptions are
@@ -161,33 +164,48 @@ Rules:
the skill's confidence threshold, otherwise fall back to the configured default the skill's confidence threshold, otherwise fall back to the configured default
(see `calendar.create_event` and `simplex.next_message`). (see `calendar.create_event` and `simplex.next_message`).
- **Use the LLM bridge for text, not for routing or assessment.** Generated text - **Use the LLM bridge for text, not for routing or assessment.** Generated text
goes through the LLM bridge (`llm_bridge_url`, `llm_bridge_token`) — a generic goes through the LLM bridge — a generic `POST /chat` whose base URL, token,
`POST /chat` — never by speaking a model's protocol directly. Keep the model and endpoint shapes are in the bridge catalog injected below — never by
extractive and bounded (see how `calendar.create_event` asks only for a title speaking a model's protocol directly. Keep the model extractive and bounded
and description), and report a real failure when the bridge is down rather than (see how `calendar.create_event` asks only for a title and description), and
guessing the text. report a real failure when the bridge is down rather than guessing the text.
- **Never blur the boundaries.** SemIf never generates; an LLM never routes, - **Never blur the boundaries.** SemIf never generates; an LLM never routes,
selects, or assesses; deterministic code never invents a value it cannot selects, or assesses; deterministic code never invents a value it cannot
observe. A request input is resolved by SemIf, not by substring matching by observe. A request input is resolved by SemIf, not by substring matching by
hand; a title is generated by the LLM, not assembled by string concatenation hand; a title is generated by the LLM, not assembled by string concatenation
when it should be written; a date is parsed by code, not asked of a model. when it should be written; a date is parsed by code, not asked of a model.
## Manifest schema ## The registry entry
Registered in `data/categories.json` (and mirrored in the running tree). Fields: The body writer does **not** author a manifest. The `llm` provider authors the
leaf's `name` and `description`, and the scheduler records them in
`data/categories.json` (mirrored in the running tree). You are told the chosen
`name` and `description` in the prompt; use them, and never invent or rename the
skill.
| Field | Meaning | The registry is a map of category -> bucket:
| -------------------- | -------------------------------------------------------------------- |
| `name` | `category.skill` dotted snake_case id. Lowercase letters, digits, `_` and `.` only (`[a-z0-9_]+(?:\.[a-z0-9_]+)*`). Single purpose. |
| `category` | The top-level category bucket the skill lives under. |
| `description` | One to two sentences: what the skill does, for navigation. |
| `allowed_inputs` | What the skill accepts / needs as input context. |
| `actions` | The concrete actions the skill takes. |
| `cost_budget` | Relative budget for one run; a run that exceeds it fails fast. |
| `decision_log_ref` | Reference to the decision rows this skill logged during a run. |
Only `name` and `description` are required for a stub; the rest fill in as the ```json
skill is exercised. {
"<category>": {
"description": "<one to two sentences: the bucket's purpose>",
"skills": [
{
"name": "<leaf_name>",
"description": "<what this leaf does, for navigation>",
"request_text": "<the originating request, optional>",
"requirements": {"<question>": "<answer>"}
}
]
}
}
```
- A leaf `name` is a single snake_case token (`[a-z0-9_]+(?:\.[a-z0-9_]+)*`),
not dotted with the category; the category is the key it lives under, and the
runner joins them as `category.name` only when it builds the run summary.
- `request_text` and `requirements` are recorded by the scheduler so a stub can
be re-driven later; the body never sets them.
## Code body contract ## Code body contract
@@ -261,8 +279,12 @@ def act(ctx, request) -> ActionResult:
"""Perform the real action and return the result + new state.""" """Perform the real action and return the result + new state."""
``` ```
- `ctx` is an `ActionContext` with `ctx.engine` (the real SemIf engine) and - `ctx` is an `ActionContext` with `ctx.engine` (the real SemIf engine),
`ctx.config` (the resolved values for this skill, including its own config). `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.
- `request` is the `Request` being handled. - `request` is the `Request` being handled.
- `ActionResult(action_log: str, new_state: str, needs_input: str | None = None, - `ActionResult(action_log: str, new_state: str, needs_input: str | None = None,
decisions: list = [])` is imported from `semif_agent.skills`; return that exact decisions: list = [])` is imported from `semif_agent.skills`; return that exact
@@ -363,8 +385,10 @@ INTEGRATION = {
(`http|caldav|imap|smtp|pop|subprocess|file|compute`). `compute` is only for (`http|caldav|imap|smtp|pop|subprocess|file|compute`). `compute` is only for
skills that perform no external action at all (pure analysis/formatting); an skills that perform no external action at all (pure analysis/formatting); an
action skill must not use it. action skill must not use it.
- `config_vars` — the `ctx.config` keys the body reads for this integration. - `config_vars` — the `ctx.config` keys the body reads for this integration. In
Empty list allowed for `compute`. the committed seeds this is exactly the body's `CONTRACT` key set; an empty
list is allowed for `compute`. Declaring a variable the body never reads is a
mismatch the fidelity check flags.
The auto-run test is a hermetic mechanics check and never exercises the live The auto-run test is a hermetic mechanics check and never exercises the live
service, so this declaration is how the agent knows what the skill was built to service, so this declaration is how the agent knows what the skill was built to
@@ -488,10 +512,14 @@ Rules:
pause the human's answer arrives on `request.user_input` and `act` is invoked pause the human's answer arrives on `request.user_input` and `act` is invoked
again from the beginning — re-derive the query and config, consume again from the beginning — re-derive the query and config, consume
`request.user_input`, and do not re-ask a question you already have an answer `request.user_input`, and do not re-ask a question you already have an answer
for. for. `request.meta` is a scratch dict carried on the same request across the
pause, so a body can cache a computed value or an already-collected answer
there and reuse it on the resume pass instead of recomputing or re-asking —
see how `calendar.create_event` caches the extracted title/description and the
answers it collected.
- **Fail fast on budget.** Keep the work small; do not loop or retry in code. - **Fail fast on budget.** Keep the work small; do not loop or retry in code.
- **Names match the manifest.** The module is imported as its manifest name; - **The function is `act` exactly.** The module is imported under its registered
the function is `act` exactly. leaf name; the entry point is a module-level `act(ctx, request)`.
## Bridge services ## Bridge services
@@ -562,11 +590,12 @@ Rules:
A generated skill is accepted only if: A generated skill is accepted only if:
1. It compiles (`compile(..., "exec")` succeeds), imports every name it uses 1. It parses as Python (`ast.parse` succeeds), defines a module-level `act`
(`ActionResult` from `semif_agent.skills`; `DecisionRequest`/`Option` from function, and imports every name it uses (`ActionResult` from
`semif_agent.decisions` only when it actually builds a sub-decision; each `semif_agent.skills`; `DecisionRequest`/`Option` from `semif_agent.decisions`
stdlib module it calls — no `NameError` at run time), and defines `act`. only when it actually builds a sub-decision; each stdlib module it calls — no
2. Its `name` matches the manifest regex and its `category` is given. `NameError` at run time).
2. Its `name` matches the leaf-name regex and its `category` is given.
3. Its body imports nothing outside the stdlib and the agent package. 3. Its body imports nothing outside the stdlib and the agent package.
4. It uses `ctx.engine` (never mocks) and returns proper `ActionResult` types. 4. It uses `ctx.engine` (never mocks) and returns proper `ActionResult` types.
5. It is single-purpose and does not duplicate an existing category leaf. 5. It is single-purpose and does not duplicate an existing category leaf.
@@ -590,3 +619,11 @@ A generated skill is accepted only if:
13. If it is a messaging skill, it uses a bridge service over HTTP (never a 13. If it is a messaging skill, it uses a bridge service over HTTP (never a
service's native protocol), resolves recipients with a SemIf sub-decision, service's native protocol), resolves recipients with a SemIf sub-decision,
and sends only on explicit user intent. and sends only on explicit user intent.
Items 1 and 7 are hard checks in the parser (`parse_skill_body`) and reject the
body outright. The rest are not statically rejected: a missing or inconsistent
`INTEGRATION` (#11) is inferred and the body is accepted badged `unverified`, a
third-party import (#3) only fails when the module is actually imported, and
import-time work (#12) only shows up when it runs. The fidelity gate rewrites a
body once for these, then accepts it — so treat every item as required, not
optional.
+2 -2
View File
@@ -744,8 +744,8 @@ rows.
A skill is one specific, single-purpose action reachable by category → skill A skill is one specific, single-purpose action reachable by category → skill
navigation. It is three things: navigation. It is three things:
1. a **manifest** (navigable description — `name`, `category`, `description`, 1. a **registry entry** (navigable description — `name` + `description`,
plus optional `allowed_inputs`, `actions`, `cost_budget`, `decision_log_ref`); authored by the small `llm` provider and recorded in `data/categories.json`);
2. a **code body** (a single `act`); 2. a **code body** (a single `act`);
3. an **`INTEGRATION` declaration** (service / transport / config_vars) and a 3. an **`INTEGRATION` declaration** (service / transport / config_vars) and a
flat **`CONTRACT`** (the operational values the runner must provide). flat **`CONTRACT`** (the operational values the runner must provide).
+13 -8
View File
@@ -3,8 +3,8 @@
This file is the authoritative spec for the **testing** side of a skill. It is This file is the authoritative spec for the **testing** side of a skill. It is
fed verbatim (alongside the finished `skill.py`) to the model that produces the fed verbatim (alongside the finished `skill.py`) to the model that produces the
test artifact. The runnable body contract lives in `CODEGEN.md`; this file is test artifact. The runnable body contract lives in `CODEGEN.md`; this file is
deliberately separate so the body writer never embeds test data and the test deliberately separate so the body writer never embeds test data and the test is
writer never worries about body semantics. generated from the finished body rather than the other way around.
A finished skill leaf is a folder A finished skill leaf is a folder
`data/skills/<category>/<name>/` containing (among others) two artifacts: `data/skills/<category>/<name>/` containing (among others) two artifacts:
@@ -33,8 +33,9 @@ each value is a plain-language, semantic description of the expected values for
that variable (what it is, what good values look like). that variable (what it is, what good values look like).
The body declares this itself as a module-level `CONTRACT` constant (see The body declares this itself as a module-level `CONTRACT` constant (see
`CODEGEN.md`); `contract.json` is a persisted mirror of it, provided to the test `CODEGEN.md`); `contract.json` is a persisted mirror of it, and the same
writer as context. The test writer does not author or change the contract. contract object is handed to you as context. You do not author or change the
contract.
This contract exists for exactly two consumers: This contract exists for exactly two consumers:
@@ -99,10 +100,14 @@ A stdlib-only Python script that:
The test artifact is accepted only if: The test artifact is accepted only if:
1. `skill.test.py` parses as Python, imports only the stdlib and the agent 1. `skill.test.py` parses as Python — the only static check — and runs to exit 0
package, embeds its fixtures inline (no external files), is hermetic, and when executed from the skill folder; on failure the captured output drives a
runs to exit 0 when executed from the skill folder. regeneration.
2. The test stays compatible with the body's `CONTRACT` (the same variable 2. It imports only the stdlib and the agent package, embeds its fixtures inline
(no external files), and is hermetic (no external network, no real services).
These are required of every test but are **not** statically verified, so do
not rely on a checker to catch a violation.
3. The test stays compatible with the body's `CONTRACT` (the same variable
names the body reads from `ctx.config`). names the body reads from `ctx.config`).
Produce one artifact: `skill.test.py` (derived from `skill.py` plus its Produce one artifact: `skill.test.py` (derived from `skill.py` plus its
+18
View File
@@ -146,6 +146,24 @@ def test_contract_directs_request_arguments_and_output():
assert "No work at import time" in text assert "No work at import time" in text
def test_skill_contract_documents_runtime_surface():
"""CODEGEN.md must document the ActionContext surface a body can rely on
(ctx.timers for scheduling) and the request.meta resume cache — both are
used by the authoritative seed set, so a body writer needs them."""
text = read_skill_contract()
assert "ctx.timers" in text
assert "request.meta" in text
def test_skill_contract_has_no_stale_manifest_fields():
"""The old manifest schema (allowed_inputs/actions/cost_budget/
decision_log_ref, a dotted leaf name) described fields the registry never
had; keep it out of the body contract."""
text = read_skill_contract()
for stale in ("allowed_inputs", "decision_log_ref", "cost_budget", "Manifest schema"):
assert stale not in text
def test_body_directives_require_query_arguments_and_output(): def test_body_directives_require_query_arguments_and_output():
"""The prompt directives (used by the first, retry, and regen prompts) must """The prompt directives (used by the first, retry, and regen prompts) must
echo the query->arguments and real-output requirements, not just CODEGEN.md.""" echo the query->arguments and real-output requirements, not just CODEGEN.md."""