Add the rule to pola's description and body, and split three skills out by situation: facet (what crosses a callback boundary), capability-based-design (Tribble: one object per authority distinction; narrowing only intersects), and caretaker. A/B tested with Claude Haiku 5.5 in isolated runs, graded by an explorer that plays Mallory. On a discord.js-style bot task, every failure was `post: text => channel.send(text)`, whose implicit return hands out the Message and so the client's token. Pooled pass rates: no skills 35/70; pola's old description 36/48; the rule anywhere 139/144; this set 12/12 vs 5/12 for no skills in the same batch, and 21/21 on seven other tasks. Examples use an email SDK; they fixed the chat-domain mistake anyway. The rule belongs in the description because agents opened skill bodies in only some runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
2.0 KiB
Markdown
38 lines
2.0 KiB
Markdown
---
|
|
name: facet
|
|
description: >-
|
|
Facet: hand other code a fresh, frozen object with just the functions it needs, never your SDK objects. Use when passing an argument to, or returning a value from, code you don't control: a vendor SDK's callback, an AI model's tools, a plugin, a webhook handler, a contractor's or user's script. Not for choosing which methods a service offers (that's capability-based-design).
|
|
---
|
|
|
|
# Facet: a new, narrow object for each party
|
|
|
|
Whatever you hand to another party, plus everything reachable from it (properties, prototype, and the return value of every function), is what they get. Build that object on purpose.
|
|
|
|
**Bad:** hand over the SDK object. An email SDK's Email reaches `.mailbox.account.password`.
|
|
```js
|
|
summarize({ email });
|
|
```
|
|
**Good:** a frozen object of closures and plain data.
|
|
```js
|
|
const { freeze } = Object;
|
|
summarize(freeze({
|
|
subject: email.subject,
|
|
thread: async () => (await email.thread()).map(e => freeze({ from: e.from.address, body: e.body })),
|
|
reply: async text => { await email.reply(String(text)); },
|
|
}));
|
|
```
|
|
|
|
Rules:
|
|
|
|
1. **Return data, not what the underlying call returned.** `text => email.reply(text)` hands out the Email that `reply` returns. Chaining APIs (`db.set()` returning the db, any method returning `this`) leak the same way.
|
|
2. **Copy records** into frozen plain objects; SDK records carry back-references.
|
|
3. **Keep authority in closures,** not properties: a `this.client` or `this.headers` field is readable and writable by the holder. Freeze what you hand out.
|
|
4. **Bind scope when you make the facet.** Don't take a folder name, path, or user from the holder and act on it with your own authority.
|
|
|
|
Before finishing, walk everything reachable from each facet and add a test that does it: no client, token, raw store, or other party's data.
|
|
|
|
## Sources
|
|
|
|
- [E in a Walnut: Capability Patterns](https://www.skyhunter.com/marcs/ewalnut.html#SEC45): facets.
|
|
- [awesome-ocap wiki](https://github.com/dckc/awesome-ocap/wiki): a pattern language for ocaps.
|