add-a-capability
Skill2 starsChanged 36 days agoMITView on GitHub
Learn how one contract and its handler become a command, HTTP route, MCP tool, browser RPC, and sandbox call.
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-lifecycle-machineSkill
- add-a-storeSkill
- gardenerSkill
- investigate-a-failureSkill
- keep-or-cutSkill
- learn-alchemySkill
- profile-a-workerSkill
- query-designSkill
- rat-stack-modeSkill
- shipSkill
- test-behaviourSkill
- uncomplectSkill
- write-a-wiki-pageSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Put cross-process contracts in packages/core/src/contracts.ts and import defineContract from @rat-stack/capability/contract.
- Very specific: line 31
Use Schema.Struct for the input.
- Very specific: line 49
Import implement from @rat-stack/capability/implement.
- Very specific: line 59
If the action needs a service, copy packages/core/src/file-inspector.ts.
- Very specific: line 63
Add the implementation to the capabilities tuple consumed by its composition root.
- Very specific: line 88
Use @effect/vitest and run Effects with it.effect or it.layer.
- Distinctive: line 90
Test the handler's output, expected failures, annotations, and approval behavior.
- Distinctive: line 91
Add projection tests when the projection changes.
- Distinctive: line 92
Add a command-line end-to-end test when the new capability changes the command tree or a public interface.
- Very specific: line 94
Use Schema.encodeEffect to check encoded results and Effect.flip to inspect expected errors.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Add a capability
A capability is one named action with a contract and a server-side handler. The contract defines its name, input, output, failure, and metadata. The handler implements the action.
Define the shared contract once. Implement its handler where the data and infrastructure live. Do not write separate business logic for each interface.
Effect describes work with typed failures and required dependencies. Schema defines accepted values and their runtime checks. A service is a named interface for one job. A Layer builds services and supplies their construction dependencies.
1. Define the contract
Put cross-process contracts in packages/core/src/contracts.ts and import defineContract from @rat-stack/capability/contract.
- Define the input, output, and expected failure schemas.
- Give the contract a stable name and short description.
- Use
Schema.Structfor the input. - Set honest annotations such as
readOnly,idempotent,destructive, andopenWorld. - Set
needsApproval: truewhen the action needs approval.implementadds theApprovalrequirement andApprovalDeniedfailure; the handler itself declares only the contract's failures.
export const doThingContract = defineContract("doThing", {
annotations: { idempotent: true, readOnly: true },
description: "Do one concrete thing",
failure: ThingError,
input: Schema.Struct({ id: Schema.String }),
output: ThingResult,
});Schemas must encode and decode without services. Keep server dependencies out of the contract module.
2. Implement it
Import implement from @rat-stack/capability/implement. Put the handler next to its service or server-side data. Keep it small; put real work in a service or lifecycle machine.
export const inspectFile = implement(inspectFileContract, ({ path }) =>
runInspectMachine(path)
);The handler input comes from the contract. Its Effect requirements and expected failures stay typed. implement supplies the approval gate when the contract requires it.
If the action needs a service, copy packages/core/src/file-inspector.ts. Use a Context.Service class. Capture dependencies in make and keep static layer beside it.
3. Register it
Add the implementation to the capabilities tuple consumed by its composition root. For the CLI example, that tuple lives in packages/core/src/inspect-file.ts:
import { doThing } from "./do-thing.js";
export const capabilities = [inspectFile, doThing] as const;The order is public. The tuple feeds the projections and code-mode declarations. A projection builds a callable interface from capabilities.
4. Project the implementation
The CLI, HTTP, MCP, RPC, and code-mode projections take implemented capabilities. They read names, schemas, annotations, and approval settings from capability.contract.
- HTTP adds
POST /doThingand updates OpenAPI. - MCP (Model Context Protocol) adds a
doThingtool with the same schemas and flags. - The sandbox catalogue adds
tools.doThing(input). - Sandbox calls decode input, run the same handler, then encode the result.
toCommand builds one CLI command from the registered tuple. Open apps/cli/src/command.ts only when the command needs a positional argument, custom renderer, or alias. Use name, positional, and render for those cases. toCommand adds --json; do not parse fields again or call the service directly.
RPC means remote procedure call: a client calls a named server operation. Browser clients import contracts from @rat-stack/core/contracts and toRpcGroup from @rat-stack/capability/rpc-group; they do not import a handler or the server-side toRpc projection.
5. Test it
Use @effect/vitest and run Effects with it.effect or it.layer. Do not call Effect.run* or ManagedRuntime.make in tests.
- Test the handler's output, expected failures, annotations, and approval behavior.
- Add projection tests when the projection changes. Check that client RPC groups can be built from contracts alone.
- Add a command-line end-to-end test when the new capability changes the command tree or a public interface.
Use Schema.encodeEffect to check encoded results and Effect.flip to inspect expected errors.
6. Finish
pnpm turbo run check test buildFix failures. Do not loosen the checks, hooks, or pinned versions. These checks and hooks form the fence that rejects prohibited code and shortcuts.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

