Writing and modifying tools
You normally don't write tools by hand. You describe what you want (New on Home, or ask an agent), and Hewn's builder writes it (Building tools). This page describes what the builder produces, for when you want to read it, change it, or write one yourself. In the manifest and the ABI, a tool is a capability.
The full contract is spec/builder-brief.md. It's exactly what the builder reads. In short:
Layout
capability.json the manifest: id, name, purpose, hue, operations, requires, ui
src/index.ts the implementation (bundled with its npm dependencies)
package.json optional: npm dependencies (registry versions only; must run in a Workers-like isolate)
migrations/NNN_*.sql the database schema (SQLite), append-only
tests/cases.json test cases Hewn runs before promoting a version
ui/icon.svg a 5×5 pixel glyph for Home
ui/index.html optional: the tool's own UIOperations
export const operations = {
"record_run@1": (input: { distanceKm: number }, ctx) => {
ctx.db.prepare("INSERT INTO runs (distance_km) VALUES (?)").run(input.distanceKm);
return { ok: true };
},
};ctx.dbis the tool's own SQLite database. It's synchronous; usectx.db.transaction(fn)to group writes.ctx.secrets,ctx.call(id, "op@1", input)(another capability) andfetchare available, but only for what the manifest declares underrequiresand you've granted.- Input and output are validated against each operation's JSON Schemas.
Rules Hewn enforces
- Contracts don't break. A published
name@versionkeeps its inputs, outputs and side effect. A breaking change is a newname@2, next to the old one. - Migrations are append-only, and never destroy data: no
DROP,DELETE FROMorTRUNCATE. Before a version is promoted, they're dry-run on a copy of your live data, and the data is backed up before they're applied. - Tests pass before promotion. The UI is rendered headlessly and must load without errors.
Changing one
Use Change… on the tool, or ask an agent ("add a weekly streak to the habit tracker"). The builder gets the current version and your request, and the same checks apply. If it breaks something you notice later, restore the version before it (Versions, or hewn rollback <id>).
Installing one you wrote
hewn install path/to/my-capabilityIt goes through the same validation as a built one.
Examples
Three small tools in the repo's seeds/ are meant to be read and copied (Apache-2.0):
- Running Log: operations, a migration and test cases, nothing more
- Reading List: a widget, and an operation marked
destructive - Habits: a widget with a button that runs a write operation
From a checkout of the repo: hewn install seeds/habits.
Sample data (sample/calls.json) is the tool in use: calls to its operations that fill an empty tool with made-up entries. Hewn replays it when someone installs the tool with sample data, and before every version goes live, and needs it to share the tool. See the tool spec.
Reference
The manifest and the ABI (the module, ctx, environment, versions) are described in full in capability-model.md. Hewn implements ABI 2.4. A capability declares the lowest version it needs in "abi"; minor versions only add, so a capability built for 2.0 keeps running.