Examples
Three small, tested apps built on treason.app and the SDK.
Three apps live in examples/ in the repository. Each is short enough to read in one sitting, uses the SDK exactly as your code would, and is run by the test suite against a real server, so they are guaranteed to work with the API they document.
#Run them
# once: the stack, a development org, and keys
docker compose up -d --wait && npm run migrate && npm run seed
npm run sdk:build
cd examples && npm install
cd .. && eval "$(npm run -s example:env)"
npm run dev & # the API on :3100 (plus `npm run worker` so escalation timers run)#Deploy gate: examples/deploy-gate
A deploy script that asks a person to approve before it ships.
cd examples && VERSION=v42 npm run deploy-gateIt pages whoever is on call, waits up to ten minutes for an acknowledgement, deploys only if it gets one, and writes "Approved via sms", "Deployed." (or the failure) as notes on the alert, so the alert is also the audit trail. If nobody answers it cancels and closes the page.
The wait-and-decide logic is about 40 lines: gatedDeploy().
#Agent approval: examples/agent-approval
withHumanApproval(treason, "drop_table", tool, options) wraps a dangerous tool for an AI agent or any automation, using the approvals API. The agent gets { ran: true, value } or { ran: false, reason: "denied" | "timeout" } to reason about. The person sees what the agent wants (the tool and its arguments), and answers Y or N by text, 1 or 9 on a call, or in the dashboard. The key the agent holds can ask but not decide, so it can never approve its own request. Over MCP the same thing is the request_approval tool (MCP server).
#Uptime sentinel: examples/uptime-sentinel
A small service that checks URLs, with a status page and a webhook receiver. It uses most of the product:
- Alerts with aliases: pages on the second failure in a row, once per outage (
down:<name>), and closes the alert when the check passes again. - Heartbeats: pings its own heartbeat after every pass, so if the sentinel itself dies, you are paged about that.
- On-call API: the status page shows open alerts and who is on call now.
- Webhooks:
/webhooks/treasonverifies the signature and shows "acknowledged" events as they arrive.
cd examples
TARGETS="web=https://example.com,api=http://localhost:3100/health" npm run sentinel
# open http://localhost:4100, then:
curl -X POST "localhost:4100/simulate/down?name=web" # wait two checks: you are paged
curl -X POST "localhost:4100/simulate/up?name=web" # the alert closes itselfSet TREASON_ADMIN_KEY to let it create its heartbeat, TREASON_TEAM_ID to show who is on call, and TREASON_WEBHOOK_SECRET (with a public https tunnel) to receive events.
#Reading the tests
The tests in test/examples.test.ts are the best documentation of intended behaviour: each one plays the person on call by acknowledging or closing an alert after a short delay, while the code under test waits.