# Repository-owned monitor configuration

Keep the monitors for one application in versioned YAML or JSON. Validate changes in a pull request, review a plan against current SignalSitter state, and apply a fresh plan after the matching application revision deploys successfully.

This example targets CLI **0.2.0**, a locally built candidate that has **not been published to npm**. The workflow's exact `@signalsitter/cli@0.2.0` installs become usable after publication. They are not proof that the version is available today. Until then, build and package this checkout, install the actual generated tarball into a disposable application fixture, and use that installed `signalsitter` executable for local proof. Do not publish a package or enable the workflow merely to try this example. After publication, keep the exact `0.2.0` pin; for an installed dependency, commit the lockfile and use `npm ci`.

Requires Node.js 22 or later. The example pins its Actions runtime separately. `app.mjs` is a small application that reports `APPLICATION_REVISION` in its response; it is not a deployment service. Run it locally with:

```sh
APPLICATION_REVISION=<full-application-commit-SHA> node app.mjs
```

### Bootstrap and scope

Create the account, two existing projects and their credentials using the dashboard. Replace the staging and production project placeholders in `signalsitter.yml` with those distinct project IDs. Supply each credential only as `SIGNALSITTER_API_KEY` in the corresponding protected CI environment. Use an existing project `read` credential for planning and `manage` for apply. Do not widen a credential to make a mismatched manifest work: its verified project must equal the selected environment's project.

The manifest's `set` names one owned group within that project. Each `logicalKey` identifies one member of that set, independently of its display name. The same logical key in separate projects is independent. An update to `name` keeps monitor identity and history. Monitor key and jurisdiction are immutable; moving either requires a separately reviewed migration.

`schemaVersion: 1` accepts plain, bounded YAML/JSON with explicit heartbeat expectations, deterministic measurement rules and environment callback references. Unknown versions/fields, duplicate keys, unsupported notification definitions, learned-detector settings, YAML tags, anchors, aliases and multiple documents fail validation. Only static monitor configuration is managed here. No observations, incident state, runtime audience/membership, personal recipients, notification content or consent is managed.

The example's staging callback is disabled. Production refers to the existing named callback alias `operations`; create/select that resource through the ordinary dashboard/API first. Supported references are `disabled`, `organization_default`, and `named` with an existing alias. No secret-valued fields or inline callback URLs exist in this schema. Never put credentials, signing secrets, email addresses or environment dumps into a manifest, adoption file, plan or logs.

### Validate, plan and apply

Use the exact application deployment SHA as `--revision`:

```sh
signalsitter config validate signalsitter.yml --json
signalsitter config plan signalsitter.yml --environment staging --revision "$APPLICATION_REVISION" --json > plan.json
signalsitter config apply signalsitter.yml --environment staging --revision "$APPLICATION_REVISION" --plan plan.json --json
```

Validation is entirely local and needs no credential. Planning reads current scoped state without changing monitors. Review the project, set, revision, creates, updates, pauses, unchanged resources, adoptions and conflicts. Applying checks the manifest, target, revision, set generation and observed canonical monitor versions again; editing a plan does not grant authority. An unchanged repeat is a no-op, and provisioning never publishes synthetic beats.

Each monitor's `heartbeatExpectation` must be `enabled` or `disabled`; any other state, including `automatic`, fails validation with "Choose a heartbeat period, or disable missing-data alerts." Every Monitor watches a Signal, the feed its beats are published to. A create gives the new Monitor its own Signal in the same transaction: `enabled` becomes the Signal's expected period and late grace, and `disabled` turns the Signal's missing-data alerts off. A Signal never learns a cadence. The manifest's callback is copied to the Signal once, at creation. Each apply operation reports `signalId` and `publishUrl`; publish beats to that URL.

Editing `heartbeatExpectation` later also updates the missing-data settings (period, grace, on/off) of the Signal this set created. The plan shows that as a `signalHeartbeat` change. Signals the set did not create, such as an adopted monitor's existing Signal, are never changed.

An apply that would exceed the organization's Signal or monitor plan limit fails that operation with `signalsitter.rate_limited` and a `limit` object carrying `dimension`, `limit`, `current`, `attempted`, `plan` and `remediation`. It is not a temporary outage and retrying does not help until a slot is freed or the plan is upgraded.

Object keys in JSON output are deterministic. Plans include configuration metadata and should remain restricted CI artifacts even though secret values are excluded. Keep the saved plan for recovery, rather than assuming output means every operation succeeded.

### Adopt an existing monitor

Copy `adopt.example.json` to `adopt.json` and replace the monitor key, jurisdiction and expected configuration version with the exact existing monitor identity. The array contains `logicalKey`, `monitorKey`, `jurisdiction`, and `expectedVersion`; display-name matching is never used.

```sh
signalsitter config plan signalsitter.yml --environment staging --revision "$APPLICATION_REVISION" --adopt adopt.json --json > plan.json
signalsitter config apply signalsitter.yml --environment staging --revision "$APPLICATION_REVISION" --adopt adopt.json --plan plan.json --json
```

Pass the same adoption file to both commands. Adoption preserves physical identity and history. A stale version, a monitor from another project, or ownership by a sibling set causes a conflict before the wrong target can change. Unmanaged monitors and other sets remain untouched.

### Dashboard drift and emergency controls

Managed-field changes made through the dashboard/API appear as drift. So does a change to the missing-data settings of a Signal this set created. To keep those changes, copy their intended values into the manifest. To restore repository intent, leave the desired fields unchanged. In either case acknowledge the resolution by adding `--resolution reapply_configuration` to a fresh plan and its apply, then review the result. This explicit choice does not bypass ownership or version checks.

Pause and maintenance are operational controls. Ordinary apply preserves them, including an otherwise unchanged deployment. Resume deliberately through the existing dashboard or lifecycle API after operational review; the current CLI has no separate resume command. Removing a logical key pauses its owned monitor and retains history under normal retention; its Signal keeps accepting beats, as it does when a monitor is deleted. A monitor already archived stays archived and its removal is satisfied without restoring it. Replacement removals run before additions; if a later operation fails, inspect the partial result before retrying. Re-adding it keeps the retained identity and does not silently clear an emergency pause. Permanent deletion is outside ordinary configuration apply.

### Interrupted and partial apply

The apply result lists `succeeded`, `failed` and `pending` operations and a recovery instruction. A partial result prints its JSON result, writes recovery guidance to stderr and exits nonzero. The application remains deployed; configuration failure does not roll it back.

After a connection loss or interruption, retry with the exact saved plan, manifest, revision and adoption/resolution arguments. Durable operation receipts resume committed work without duplicate creates. If intervening dashboard/configuration writes make pending work stale, inspect the completed operations and current state, generate and review a fresh plan, then apply it with `--supersede` to replace the interrupted continuation. Do not use supersede as an overwrite or resume shortcut.

A Git revert changes future desired configuration. It does not undo previously accepted observations, incidents or callbacks. Tool rollback must preserve ownership and journal records and use a compatible API/CLI version.

### GitHub Actions sequencing

Copy `github-actions.example.yml` into the **application** repository only after the pinned CLI is available. The application already needs a workflow named `Deploy application` that reports success only after it deploys and smokes its exact commit SHA. The monitor workflow does not deploy the application or manufacture that evidence.

- Every pull request runs local validation without secrets, including forks.
- Same-repository pull requests may produce a read-only server plan through the protected `signalsitter-staging-plan` environment and its `SIGNALSITTER_READ_KEY`. That job installs the pinned published CLI outside the checkout, without a SignalSitter key and using the public npm registry; it then runs the installed absolute executable with the read key. Checkout `.npmrc` and package scripts cannot influence credentialed execution. Forks do not enter it. Configure environment protection for your trust policy; a same-repository branch alone is not an approval policy.
- A completed `Deploy application` run permits apply only if its conclusion is success, its head repository is this repository and its head branch is `main`. Apply checks out `workflow_run.head_sha` and compares the actual checkout SHA with that value.
- The protected `signalsitter-staging` environment supplies the staging `SIGNALSITTER_MANAGE_KEY`. Replace the concurrency group placeholder with the intended environment/project/set identity. `cancel-in-progress: false` avoids interrupting a running apply; server serialization/version checks also protect other writers.
- Apply creates a fresh plan for the exact deployed revision and immediately applies it. The earlier PR plan is review evidence, not a stale authorization token. A failed/cancelled application deployment never reaches apply. A plan conflict or partial apply fails the configuration job visibly, without rolling back the deployed application.

Production needs its own environment, project credential and concurrency identity. Do not reuse staging credentials or assume the environment name grants authority. Never log secrets or enable shell tracing in credentialed steps. Keep artifact retention short and access restricted.

`reconcile.mjs` supplies the same sequencing for an application deploy script: call it only after real deployment/smoke, with `APPLICATION_DEPLOYMENT_SUCCEEDED=true`, `DEPLOYED_APPLICATION_REVISION` and `CHECKED_OUT_APPLICATION_REVISION` equal to the same full SHA, and the correct project credential. It refuses a failed deploy or mismatched revision before planning. It checks the returned plan revision/environment, writes the recovery plan with restrictive permissions, then applies. Its exported `mayApplyDeployment` helper checks successful same-repository main workflow events. These helpers are local fixtures; they do not claim a real deployment occurred.

### Automation contract

Exit codes are stable: `0` success, `2` usage/configuration, `3` authorization, `4` API conflict/problem or partial apply, `5` connection/timeout, and `6` invalid response/internal failure. Do not treat nonempty stdout as success; inspect the exit status and apply result status. Schema version upgrades require an explicit CLI/source upgrade and fresh validation. This feature neither provisions an organization nor creates/rotates secrets.
