Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ skills/<bucket>/<skill>/SKILL.md exactly three levels deep
## Rules

- **Add or move a skill, and touch these places:** the bucket `README.md`, the root `README.md`, the guide's table, and the skill's `agents/openai.yaml`. Then run `npm run sync`, which regenerates `.claude-plugin/plugin.json` and the runner prompts. `npm run validate` checks all of it.
- **Every promoted skill has a `## Contract`** (`kind: item | group | sweep | utility | reference`). A skill a pipeline skill calls must have one, and a utility skill lists its callers in `used_by`. A skill with no contract yet is named in `CONTRACT_PENDING` in `scripts/validate-skills.mjs`: remove it from there when you add one, never add to that list. See **Contracts** in `agent-workflow-protocol`.
- **Every skill uses the same three level-two sections:** `## Contract`, `## Inputs`, and `## Process`, in that order. Use level-three headings for all subsections. A skill a pipeline skill calls must have a contract, and a utility skill lists its callers in `used_by`. A skill with no contract yet is named in `CONTRACT_PENDING` in `scripts/validate-skills.mjs`: remove it from there when you add one, never add to that list. See **Contracts** in `agent-workflow-protocol`.
- **`name` must equal the directory name.** Harnesses discover skills by directory, so a mismatch hides the skill.
- **A skill's `description` must never contain an unquoted `: ` or ` #`.** It is invalid YAML and harnesses skip the skill. Reword it.
- **Skills reach each other through the Skill tool, never through paths or links.** "Call the Skill tool with `name`". A skill's own files (`references/`, `scripts/`) are read relative to its `SKILL.md`. Where a skill lives depends on how the package was installed, and installers flatten the buckets.
Expand All @@ -34,7 +34,9 @@ skills/<bucket>/<skill>/SKILL.md exactly three levels deep

## Contracts

**Every pipeline skill opens with a `## Contract`**: a YAML block that says what the skill is as a function (preconditions, the closed set of results, postconditions, side effects by scope, forbidden effects). **Process** says how. Change a result line, a precondition or an effect in the contract first. `agent-workflow-protocol` defines the keys (**Contracts**), `docs/adr/0010-skills-as-functions-with-contracts.md` explains why, and `npm run validate` checks that a contract matches the rest of its skill: `params` equal the Inputs table, every result the text returns is in `returns`, and there are no `Eligibility`, `Outputs`, `Result` or `Never` sections left over. Anything not listed under `effects.writes` is forbidden.
The heading schema is checked across every skill file: the only level-two headings are `## Contract`, `## Inputs`, and `## Process`, in that order. Use level-three headings for all other sections, including reference material.

**Every skill opens with a `## Contract`**: a YAML block that says what the skill is as a function (preconditions, the closed set of results, postconditions, side effects by scope, forbidden effects). **Process** says how. Change a result line, a precondition or an effect in the contract first. `agent-workflow-protocol` defines the keys (**Contracts**), `docs/adr/0010-skills-as-functions-with-contracts.md` explains why, and `npm run validate` checks that a contract matches the rest of its skill: `params` equal the Inputs table, every result the text returns is in `returns`, and there are no `Eligibility`, `Outputs`, `Result` or `Never` sections left over. Anything not listed under `effects.writes` is forbidden.

**Every result a skill can return has a scenario** under `tests/scenarios/<skill>/`: a world, the inputs, the expected result line and the net effects. `scripts/scenario.mjs` checks each against the skill's contract (scopes, invariants, eligibility oracles), and `npm run scenarios:coverage` lists results with none. A new result line without a scenario fails `npm test`. See `docs/adr/0012-scenarios.md`.

Expand Down
18 changes: 12 additions & 6 deletions scripts/contracts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,19 @@ export function checkContracts(skills, byName, external = new Set(), { pending =

for (const k of Object.keys(c)) if (!ALLOWED.has(k)) err(`unknown key \`${k}\``);
if (!KINDS.includes(c.kind)) { err(`kind must be one of ${KINDS.join(", ")}`); continue; }
// The shape every skill shares, reference skills included: the contract comes first, and the prose
// keeps no second copy of what the contract says.
// The section skeleton is strict, while skill-specific content remains readable Markdown.
const heads = headings(s.body);
if (heads[0] !== "Contract") err(`\`## Contract\` must be the first section, but \`## ${heads[0]}\` comes first`);
if (heads[0] !== "Contract") {
err(heads[0]
? `\`## Contract\` must be the first section, but \`## ${heads[0]}\` comes first`
: "has no Markdown sections");
}
const duplicates = heads.filter((h, i) => heads.indexOf(h) !== i);
for (const h of new Set(duplicates)) err(`has more than one \`## ${h}\` section`);
if (heads.filter((h) => h === "Inputs").length !== 1) err("must have exactly one `## Inputs` section");
if (heads.join("|") !== "Contract|Inputs|Process") {
err("top-level sections must be exactly `## Contract`, `## Inputs`, `## Process`, in that order; use `###` for subsections");
}
for (const h of heads) {
if (FOLDED_SECTIONS.includes(h)) err(`has a \`## ${h}\` section. That belongs in the contract now`);
}
Expand All @@ -195,9 +204,6 @@ export function checkContracts(skills, byName, external = new Set(), { pending =
if (extra.length) err(`\`params\` has ${extra.map((k) => `\`${k}\``).join(", ")}, which the Inputs table does not list`);
}

// **Process** says how: every skill that runs names its how-section that
if (!heads.includes("Process")) err("has no `## Process` section. The how-section of every skill that runs is named Process");

// every pipeline skill lists the common inputs (see **Common inputs** in the protocol)
if (PIPELINE_KINDS.includes(c.kind) && Array.isArray(c.params)) {
for (const k of COMMON_INPUTS) if (!c.params.includes(k)) err(`a pipeline skill lists \`${k}\` in \`params\` and in its Inputs table, and this one does not`);
Expand Down
24 changes: 11 additions & 13 deletions scripts/validate-skills.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// - nothing repository-specific has leaked into skills/, scripts/ or tests/
// - every section a skill cites ("**Trust** in the protocol", "its **X** section") exists
// - the protocol's Defaults table names exactly the skills that list each input
// - every promoted skill has a valid `## Contract` (scripts/contracts.mjs), except those in
// - every skill has a valid `## Contract` (scripts/contracts.mjs), except those in
// CONTRACT_PENDING: its params are its Inputs table, its results are a closed set, its effects are
// listed by scope, and the prose no longer carries Eligibility, Outputs, Result or Never sections of
// its own. Reference skills say `kind: reference` and are exempt from the rest, except that they too
// open with `## Contract` and keep no folded section. The contract is the first section of every
// skill, every skill that runs has a `## Process` section, and every pipeline skill lists `runner` and
// `unattended`. A skill that another
// skill calls must have one, and a utility skill's `used_by` must list its callers
// its own. Every skill has exactly three level-two sections: `Contract`, `Inputs`, and `Process`,
// in that order. Additional content uses level-three headings. Reference skills say
// `kind: reference` and are exempt from runtime contract fields. Pipeline skills list `runner`
// and `unattended`. A skill that another skill calls must have a contract, and a utility skill's
// `used_by` must list its callers
// - each skill's purity class (pure, claimed, writes elsewhere) is printed
// Package-wide:
// - .claude-plugin/plugin.json lists exactly the promoted skills
Expand Down Expand Up @@ -237,7 +237,7 @@ if (protocol) {
if (!documented.has(k)) err(`${protocol.rel}/SKILL.md`, `Defaults table is missing \`${k}\`, which scripts/lib.sh sets`);
}

for (const s of skills.filter((x) => x.promoted)) {
for (const s of skills) {
const section = inputSection(s.body);
if (section === null) {
err(s.rel, "has no '## Inputs' section; every skill names its inputs and their defaults there");
Expand Down Expand Up @@ -303,12 +303,10 @@ if (protocol) {
// ---- contracts ---------------------------------------------------------------------------------
let contracts = new Map();
{
const withInputs = skills
.filter((x) => x.promoted)
.map((x) => ({
...x,
inputKeys: [...(inputSection(x.body) ?? "").matchAll(/^\|\s*`([a-z][a-z0-9_]*)`\s*\|/gm)].map((m) => m[1]),
}));
const withInputs = skills.map((x) => ({
...x,
inputKeys: [...(inputSection(x.body) ?? "").matchAll(/^\|\s*`([a-z][a-z0-9_]*)`\s*\|/gm)].map((m) => m[1]),
}));
const result = checkContracts(withInputs, byName, external, { pending: CONTRACT_PENDING });
for (const e of result.errors) errors.push(e);
contracts = result.contracts;
Expand Down
Loading
Loading