Quickstart
Quickstart
Durable principal-bound approval records and auto-approve policy
Stage a proposed write without executing it. This disposable in-memory example
prints pending; use a persistent, host-owned database for real requests.
import { DatabaseSync } from "node:sqlite";import { fromNodeSqlite } from "@fungi.computer/watchdog/node-sqlite";import { ApprovalLedger } from "@fungi.computer/approvals";
const database = new DatabaseSync(":memory:");try { const ledger = new ApprovalLedger({ owner: fromNodeSqlite(database), home: { kind: "team", id: "example-team" }, now: Date.now, }); const staged = await ledger.request({ requester: { principalId: "agent:example", agentId: "example-agent", sessionId: "example-session", displayName: "Example", }, module: "notes", operation: "saveNote", access: "write", reversibility: "reversible", authorityFence: "grant-generation:1", idempotencyKey: "turn:1/tool:1/operation:0", inputJson: '{"text":"hello"}', }); if (staged.kind !== "record") throw new Error(staged.reason); console.log(staged.record.state); // "pending"} finally { database.close();}The identities and fence here are illustrative host-attested values, not fields
to trust from an Agent or browser. Keep the same idempotency key when retrying
the same operation. request stages a record and records the home’s
auto-approve decision without dispatching. submit additionally applies a newly
policy-approved request inline through the authority recheck.