Skip to content

Notify

llms.txt lists every page for an agent
Optional: hand this page to your coding agentThe steps work by hand too.
Show the whole prompt
Read https://intentius.io/chant/guide/notify/.
Add a `notify` block to this repository's Op waves spec with the environment variable names I give for `slack`, `teams`, `webhook` and `key`, and the `events` I name. Put no URL or key in any file.
Run `npx chant run --generate <forge>` to write the pipelines again, and open a pull request.
List in its description each secret or CI/CD variable I must create; do not create them yourself.
Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes` or `chant release publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.

This guide is for a team that wants to hear when a wave waits for an approval or a run goes wrong, without watching the pipeline. chant posts one event, chant.notify/v1, to chat incoming webhooks (Slack and Microsoft Teams) and to a webhook of your own. The webhook’s copy is signed so the receiver can check it came from your pipeline.

Op waves send these events when their spec says where. Products built on chant send the same event through @intentius/chant/notify, and each decides when to send.

Add notify to the Op waves spec. Each value is the name of an environment variable. The spec never holds a URL or a key, and chant never prints either.

{
"name": "migrations",
"op": "migrate",
"plan": ["./bin/plan", "{target}", "{plan}"],
"waves": [{ "name": "prod", "runs": [{ "target": "prod" }] }],
"notify": {
"slack": "CHANT_SLACK_WEBHOOK",
"teams": "CHANT_TEAMS_WEBHOOK",
"webhook": "CHANT_WEBHOOK",
"key": "CHANT_WEBHOOK_KEY",
"events": ["waiting", "refused", "failed"]
}
}
SettingThe variable holds
slackA Slack incoming webhook’s URL
teamsA Teams incoming webhook’s URL (a Workflows webhook that takes an Adaptive Card)
webhookYour own receiver’s URL. It needs key
keyThe shared secret the webhook’s events are signed with
relayThe key chant notify relay checks buttons with. Set, a waiting wave’s Slack message has Approve and Decline buttons, and its Teams card the reply that approves
relayNameThe relay’s name as people mention it in Teams, a plain value rather than a variable, such as a product’s notify.relay (#5033). With relay set, a waiting wave’s Teams card spells out the whole reply, reply @<name> approve <token>, over the product’s words’ own relayName. One line of at most 80 characters, without @, < or >. Floor: NOTIFY_RELAY_NAME_FLOOR (@intentius/chant/ci-product)
eventsNot a variable: the events to send. Default: all of them

A value that looks like a URL, a webhook without a key, or an unknown setting fails the spec before any wave runs.

On GitHub and Forgejo, chant run --generate maps each variable notify names from the repository secret of the same name. Create one secret per variable, with the same name. A value in the generator’s options.variables takes precedence over that mapping. On GitLab, add them as masked CI/CD variables of the project; GitLab passes them to every job.

The jobExitEvent
A wave waits for an approval of its digest3waiting, with the targets, the digest, the chant approve command and the run’s link. Under pr-review, the pull request whose review would approve it
A share job refuses a run whose plan moved since the decision4refused, naming the runs it refused
A plan, an apply or a stage hook fails1failed, naming the runs or the hooks that failed, or the error

A share job of a waiting wave sends nothing, because its deciding job already did. The exception is a share job that one of its own hooks holds, which sends waiting naming the hook. A wave that applies sends nothing.

A delivery that fails is logged on stderr, without its URL, and the job exits with the code the wave decided. A 5xx answer or a network error is tried three times; a 4xx is not retried. The webhook is never posted to unsigned: with key unset, the job logs that and skips it.

chant ci tick sends events of its own when ci.green in the workspace declaration has notify (#4645). It takes the same settings, with events chosen from these three, ci.quarantine-passed and ci.stale:

"green": {
"branch": "main",
"phases": { "lint": ["lint"], "test": ["test"] },
"require": ["lint", "test"],
"notify": { "webhook": "CHANT_WEBHOOK", "key": "CHANT_WEBHOOK_KEY", "slack": "CHANT_SLACK_WEBHOOK" }
}
The tick findsEvent
The branch’s newest decided commit is red, after the one retry of a failed run (a phase being retried is pending, not red), or its green tag was revokedci.red, with the phase and the run that failed
A bisect names the first red commit below that oneci.culprit, with ci.culprit the commit found
The newest decided commit is green, and an older one in the window was told redci.green, with ci.red the commit it answers

The quarantine’s scheduled run sends a fourth through the same notify (#4677): chant ci quarantine report sends ci.quarantine-passed for each quarantined test that passed there, with ci.quarantine naming the test, its issue and until, and run.url the scheduled run. It is sent on every scheduled run the test passes in, until its entry goes, and needs no records.

Each of the tick’s events is sent once. The tick marks it in the commit’s _ci/<sha>.json record (notified), or for ci.stale in the branch’s record, so it needs chant/lifecycle, and a tick that can’t read or write the records sends nothing rather than the same event again. A delivery that fails everywhere is a warning, and the next tick tries again. --dry-run reports what it would send. The events carry ci: the branch and commit, and phase, failedRun, culprit, red, or since, lastGreen and hours. run.commit is the commit, and run.url is left out, since the tick’s own run says nothing about it. ci workflow gives the tick’s step each variable notify names from the repository secret of the same name, so create one secret per variable and run it again.

A red stretch that nothing decides sends none of those: runs that never finish, a phase waiting on a runner, or ticks that stopped. staleAfter in notify is a number of hours (#4678). When the oldest first-parent commit above the branch’s newest green one (a ci/green tag, not revoked) was committed that many hours ago, the tick sends ci.stale:

"notify": { "slack": "CHANT_SLACK_WEBHOOK", "staleAfter": 6 }
{
"event": "ci.stale",
"summary": "main has had no green commit for 7 hours: 3 commits since 9f2c41d07a3e, above the green 41b7e0c2d915",
"ci": { "branch": "main", "commit": "<the tip>", "since": "9f2c41d07a3e...", "lastGreen": "41b7e0c2d915...", "hours": 7 },
"run": { "commit": "<the tip>" }
}

It is sent once per stretch, however long the stretch lasts. The tick keeps that in _ci/branch/<branch>.json on chant/lifecycle (stale), a record of the branch rather than of a commit, so a tick with no new commit to judge can send it and remember it. A newer green commit ends the stretch, and the tick then sends ci.green with ci.since naming the stretch’s first commit, even when no ci.red was sent. When the tick sends a ci.green for a ci.red in the same tick, that one event carries since too, rather than a second ci.green. The tick looks back 200 first-parent commits for a green one. With none there, the stretch starts at the oldest commit the tick has judged (one in the window or with a record), so turning this on in a repository whose old commits were never tagged doesn’t count their age. A revoked green commit reopens its stretch, and ci.stale can be sent for it again.

Only ci/green counts. A lane’s tags (lanes) don’t end a stretch or start one, and no lane gets a ci.stale of its own.

The tick has to run for any of this, including when no workflow completes. The chant-ci-green.yml that ci workflow writes already ticks every 15 minutes on a schedule, in the same concurrency group as the ticks that follow a run, so a scheduled tick waits for one in progress and reads the marks it wrote. A stretch is told within 15 minutes of reaching staleAfter. On another forge, run chant ci tick from a scheduled job.

The webhook gets the event as JSON. The body is signed with HMAC-SHA256 over <timestamp>.<body>, where the timestamp is in seconds since the epoch:

HeaderValue
x-chant-signaturesha256=<hex>
x-chant-timestampThe seconds the signature covers
x-chant-eventwaiting, refused, failed, drift, ci.red, ci.culprit, ci.green, ci.quarantine-passed, ci.stale, urgent (a promote that passed a pipeline stage’s urgent rule), soak (a soak check failed) or rollback-requested (a stage requested its rollback after a failed verify or soak)
x-chant-deliveryThe event’s id

@intentius/chant/notify-verify checks a delivery and needs nothing but node:crypto. The package ships it, and @intentius/chant/notify, as compiled JavaScript, so a receiver can import it under plain Node with no TypeScript loader, or bundle it alone:

import { verifyWebhook } from "@intentius/chant/notify-verify";
const checked = verifyWebhook({ body: rawBody, headers: req.headers, key: process.env.CHANT_WEBHOOK_KEY });
if (!checked.ok) return reply(401, checked.reason);
handle(checked.event);

Pass the body exactly as received, before parsing it. verifyWebhook compares the signature in constant time and refuses a timestamp more than five minutes from now (toleranceSeconds changes that), so a delivery recorded and replayed later fails. The event’s id is the same for every send of one event about one digest, so a receiver can also drop a re-run’s repeat.

The JSON Schema ships in the package as @intentius/chant/notify.schema.json, with $id https://intentius.io/chant/schemas/notify/v1/notify.schema.json. Readers ignore fields they do not know; a field is only ever added within a version.

FieldMeaning
schemachant.notify/v1
id, event, atThe delivery id, what happened, and when it was sent
source, project, summaryThe product that sent it (chant), the repository, and one line a person can read
wave{ number, name, gate } for a product that applies in waves
environmentFor a product that applies per environment
targetsWhat the event concerns: a wave’s runs or roots, an environment’s migrations
digest, approveThe plan digest an approval binds, and on waiting the command that approves it (approve.command, and approve.review under pr-review)
status, reason, exitCodeThe product’s word for the outcome, why it was refused or failed, and the exit code
driftOn drift: changed, missing, failed and a fingerprint
ciOn the tick’s events: branch, commit, and phase and failedRun on ci.red, culprit on ci.culprit, red and since on ci.green, and since, lastGreen and hours on ci.stale; on ci.quarantine-passed, phase and quarantine (test, file, issue, until)
soakOn soak: the stage that soaks (and its wave on a wave’s soak), what it holds, clockStart and due, and each failed check’s name, kind, onFail, status and detail. See Soak
rollbackOn rollback-requested: the stage, the failure (verify or soak), the failed release and the release it goes back to (each a digest and a label), the gate the rollback waits at, each member’s state with rollback (requested, or the reason it stays), and the failure’s detail. See Roll back
runThe CI run’s url, forge, repository, commit and pr
reportUrl, detailA report page, and the product’s own outcome record carried whole

A product builds the event and sends it. sendNotify reads the URLs and the key from the environment when it sends, never throws, and returns one result per target:

import { makeNotifyEvent, sendNotify } from "@intentius/chant/notify";
const event = makeNotifyEvent({
source: "sql-yodeler",
event: "drift",
summary: "prod drifted: orders changed",
environment: "prod",
drift: { changed: ["orders"], missing: [], fingerprint },
});
await sendNotify({ slack: "SLACK_WEBHOOK_URL", webhook: "YODEL_WEBHOOK_URL", key: "YODEL_WEBHOOK_KEY" }, event, { prefix: "x-yodel" });

prefix keeps a product’s existing header names (x-yodel-signature), and verifyWebhook takes the same prefix. render.slack and render.teams replace the default Slack text and Teams card. Each gets the relay’s signed button value as its second argument when relay names a key that is set, and slackRelayActions(relay) and teamsRelayReply(relay) give the Approve and Decline buttons and the Teams reply, so a click on a product’s own message reaches chant notify relay. NOTIFY_RELAY_POINTS_FLOOR is the first chant with them. @intentius/chant/notify reaches only node:crypto and the verifier, so a product’s bundled CLI stays small.

A wave job run through a product’s bin sends in the product’s words (#4610). The event’s source is the product’s name, so a receiver can route on plywood or terragucci. The summary uses the product’s apply verb, and the signed webhook’s headers take the prefix x-<product>. A waiting wave’s event carries the product’s approve command, with chant’s own command in approve.chant. The schema stays chant.notify/v1. Under chant’s own words the event and the headers are as before.

The notify slot of the words changes these:

SlotDefaultUse
notify.sourcethe product’s namesql-yodeler passes sql-yodeler, the name its receivers already filter on, while its product word is yodel
notify.wavewave {k} ({name}) of {spec}how a summary names a wave; ({name}) is dropped for a wave with no name
notify.headersx-<product>the header prefix the receiver verifies with
notify.messagechant’s wordsthe words of the Slack and Teams messages, below

A product that sends its own drift notice builds it with driftNotifyFields(words, { changed, failed, fingerprint }) from @intentius/chant/ci-product, which gives 2 stacks drifted: shop-dev, shop-prod under plywood’s noun. Given stacks, each member’s drift records as { stack, records }, it names the members with drift itself and carries driftRunFingerprint of them, so the product passes what it read (#4944, DRIFT_NOTIFY_STACKS_FLOOR). productSendOptions(words) gives the header prefix and the message words to pass to sendNotify.

notify.message words chant’s own Slack text and Teams card, so a product needs no render of its own (#4818). Every slot is optional, and a message given none is the one chant has always sent.

SlotDefaultUse
targetsTargetsthe label of the targets line: terragucci’s Roots
noTargetsno linethe value shown when the event names no targets: see the run
reasonReasonthe label of the reason line: Outcome
againrun it againwhat the review line asks after the pull request is approved: run the wave again
waveno factthe label of a Teams fact holding the wave’s number: Wave
teamsReporttruefalse leaves the report link off the Teams card
rerunRun again, chant-rerunthe re-run button’s label, its Slack action id and Slack block id

A drift event that carries rerunUrl, the page where a person starts the check again (the workflow’s page, or GitLab’s pipeline schedules), gets a Slack button and a Teams action that open it. A Teams outgoing webhook reads only a message that mentions it, so sendNotify(config, event, { message: { relayName: "terragucci" } }) makes the card spell the replies out (Approve here: reply @terragucci approve <token>. Decline: reply @terragucci decline <token>.) in place of “mention the relay and reply”. slackMessage(event, relay, words) and teamsMessage(event, relay, words) take the same words. NOTIFY_MESSAGE_WORDS_FLOOR in @intentius/chant/ci-product is the first chant with them.

chant notify relay turns a click on a waiting wave’s Approve button into an approval on the ledger (#4611). Run it from a checkout of the repository, as a container or a function in your own cloud, with the same key the pipeline maps into the relay variable:

Terminal window
CHANT_RELAY_KEY=... SLACK_SIGNING_SECRET=... chant notify relay

The Slack app’s interactivity requests go to the path /slack on the relay. A Teams outgoing webhook posts to /teams when a person mentions the relay and replies with the line the card shows. By default the relay listens on port 8787 of the loopback address, so only the proxy or function host in front of it reaches it; CHANT_RELAY_HOST and CHANT_RELAY_PORT change that.

Each click passes these checks before anything is written:

CheckRefused when
The chat signatureSlack’s v0 signature or the Teams HMAC does not verify, or a Slack request is more than five minutes old
The buttonThe relay key did not sign it, or the event is older than CHANT_RELAY_MAX_AGE seconds (default a day)
The clickerNo line of the signers file at base lists slack:<team>/<user> or teams:<aad object id> beside a principal, the line names the relay, or the clicker made the gated request
The digestNo standing pending fact at the button’s gate asks for that digest: the plan moved, or someone approved it already

Then the relay records the approval as chant approve <op> <gate> --plan <digest> --actor <principal> --relayed-by <relay> would, with every rule that command applies. The relay holds no signing key, so a gate that identity.gates seals refuses it. A Decline click records nothing and says in the thread who declined. The approval is recorded as relayed by CHANT_RELAY_PRINCIPAL, by default <product>-relay, and the replies use the product’s words. The relay starts no job, and the resume job applies the wave once the approval stands.

A gate that asks a decision point passes on the point’s answer, not an approval. There the relay answers the question the gate waits on instead, as chant workspace points answer <id> --answer <value> --by <principal> --relayed-by <relay> would. The value is a yes, or the one answer the gate’s pass names. The point’s quorum decides whether the clicker counts, and a gate that passes on several answers is refused, since a button names no one of them (#4611).

Each click fetches the default branch first, the one origin/HEAD names, so a signer added since the relay started counts without a restart. A click whose fetch fails records nothing. A click on a link button on the same message (one with a url) is answered 200 and ignored (#4759).

A relay container needs no checkout of its own. Given the repository’s https clone address and the name of the variable that holds its token, the relay checks the token, clones the default branch into a temporary directory, and serves from there (#4759):

Terminal window
RELAY_TOKEN=... CHANT_RELAY_KEY=... SLACK_SIGNING_SECRET=... \
chant notify relay --repo https://github.com/acme/infra.git --token-env RELAY_TOKEN --host 0.0.0.0

--token-env defaults to CHANT_RELAY_TOKEN, and CHANT_RELAY_REPO and CHANT_RELAY_FORGE stand in for --repo and --forge. --forge github|gitlab|forgejo names the forge for a host other than github.com and gitlab.com. --host 0.0.0.0 listens on every interface, as a container’s port is reached from outside it; without it the relay keeps to loopback.

The relay pushes chant/lifecycle with the token and needs nothing more, so it refuses to start with a token that could do more:

ForgeRefused when
GitHubThe token is a classic token, its account administers the repository, or the default branch is not protected. Use a fine-grained token for the one repository with Contents: Read and write
GitLabThe token has a scope beyond read_api, read_repository and write_repository, its user is a Maintainer or Owner, the default branch is not protected, or a role the user holds may push to it
ForgejoThe token’s user administers the repository or may push to the default branch

The token reaches git as an http.extraHeader in the environment of the relay’s git calls (GIT_CONFIG_COUNT, GIT_CONFIG_KEY_<n>, GIT_CONFIG_VALUE_<n>). It is not written to a file or into the remote’s address. NOTIFY_RELAY_CLONE_FLOOR in @intentius/chant/notify-relay is the first chant that does this.

The relay also takes alerts for the alert agent at POST /alert/<source>. Alerts are on for a source once the relay has a secret for it: CHANT_ALERT_SECRET for every source, or CHANT_ALERT_SECRET_<SOURCE> for one, such as CHANT_ALERT_SECRET_PAGERDUTY. A source with no secret answers 404.

SourcePoint it atThe relay checks
Alertmanager/alert/alertmanager, a webhook receiver with http_config.authorization.credentials set to the secretthe bearer token, and each alert’s startsAt
PagerDuty/alert/pagerduty?member=<name>, a v3 webhook subscription whose signing secret is the secretX-PagerDuty-Signature, and the event’s occurred_at
Datadog/alert/datadog, a webhook with the custom header X-Chant-Alert-Token set to the secret and the payload belowthe token, and the payload’s date
Honeycomb/alert/honeycomb?member=<name>, a webhook recipient whose shared secret is the secret, with the trigger payload belowX-Honeycomb-Webhook-Token, and the payload’s timestamp
Sentry/alert/sentry?member=<name>, an integration’s webhook whose client secret is the secretSentry-Hook-Signature, and Sentry-Hook-Timestamp
Anything else/alert/generic, with X-Chant-Timestamp (Unix seconds) and X-Chant-Signature: sha256=<hex>, the HMAC-SHA256 of <timestamp>.<body>the signature, and the timestamp

Alertmanager, Datadog and Honeycomb send a shared token instead of a signature of the body, and the relay compares the token in constant time. A delivery that does not verify, or whose alerts are all older than CHANT_ALERT_MAX_AGE seconds (900 by default), is refused with 401 and the relay logs why.

Datadog’s payload:

{"id":"$ID","alert_id":"$ALERT_ID","title":"$ALERT_TITLE","transition":"$ALERT_TRANSITION","date":"$DATE","priority":"$ALERT_PRIORITY","tags":"$TAGS","link":"$LINK","body":"$EVENT_MSG"}

Honeycomb’s trigger payload:

{"id":"{{ .ID }}","name":"{{ .Name }}","status":"{{ .Alert.Status }}","instance_id":"{{ .Alert.InstanceID }}","timestamp":"{{ .Alert.Timestamp }}","summary":"{{ .Alert.Summary }}","result_url":"{{ .Result.URL }}"}

A generic delivery is one alert, { "id", "title", "member"?, "severity"?, "url"?, "details"?, "at"? }, or { "alerts": [ ... ] }. An alert whose status is anything but firing is left out, and so is a resolve, an acknowledgement or a recovery from the other sources.

The member an alert is for comes from an Alertmanager member label, a Datadog member:<name> tag or a generic member, else from the address’s ?member=. Without one, the alert is for the repository.

Each firing alert becomes a fact under _alerts/alert.jsonl on chant/lifecycle, signed with the relay key. A second delivery of the same alert, by the source’s own id or by the same Idempotency-Key header (Honeycomb’s delivery id counts as one), is recorded once. A fact that could not be pushed answers 500, so the source sends the alert again.

After a new fact lands, the relay starts the alert agent’s workflow with no inputs:

ForgeCHANT_ALERT_DISPATCH_TOKEN holdsThe relay starts
GitHuba fine-grained token for the one repository with Actions: Read and writeworkflow_dispatch of CHANT_ALERT_WORKFLOW, such as chant-alert-agent.yml, on the default branch
Forgejoa token of a user with write on Actions and read on the codethe same workflow_dispatch
GitLaba pipeline trigger token (Settings > CI/CD > Pipeline trigger tokens)a pipeline of the default branch, with no variables

On GitLab that pipeline runs every job of .gitlab-ci.yml a trigger pipeline reaches, so guard each job of your own, a deploy job above all, with - if: '$CI_PIPELINE_SOURCE == "trigger"' and when: never first in its rules. Answer a production alert has the rule and the generator’s warning.

The relay refuses to start with a dispatch token that can do more: on GitHub a classic token, an administrator’s, or one that can write the repository’s contents (the relay asks to create a ref on an all-zero commit, which such a token is refused); on Forgejo a token whose user may push or administers the repository; on GitLab anything the API takes as an access token. The dispatch token goes with --repo. Without one, the alert agent’s schedule picks the facts up. A start that does not go through is logged, and the schedule picks the fact up too.

chant