---
name: building-epack-collectors
description: Build, test, and release an epack collector, the Go program that reads a service's API with a read-only credential and writes the evidence epack signs into an Evidence Pack. Use when someone asks to build a collector for a SaaS product or internal service, add evidence to an existing collector, record one against a test account, write its docs, or publish a release that others can run with epack, even if they name only one of those steps.
---

# Building epack collectors

A collector is a small Go program. epack runs it with a configuration and a credential, and the collector reads a service's API and writes JSON artifacts. epack packs and signs them, and an auditor or a customer's security reviewer reads each value as a fact about the account. This skill covers the work from scoping the evidence to a signed release.

The work follows one rule: record first, build second, run live before the tag. Every value the collector writes is built on a response recorded from a real test account, and every release is run against that account before it is tagged.

Read these before writing code:

- The Component SDK guide: https://epack.dev/guides/build-components.html
- The collect protocol, which defines gaps, levels, rollups, and the test kit: https://github.com/locktivity/epack/blob/main/docs/collect-protocol.md
- The component rules, with requirement IDs such as COL-040 and, beside each rule, the test kit check or harness rule that enforces it: https://github.com/locktivity/epack/blob/main/docs/component-rules.md. A bug class found across collectors becomes a rule and a check there first, and each collector's fix lands as "make the check pass" when it bumps epack.
- The normalized schemas, which profiles read across services: https://github.com/locktivity/epack/tree/main/componentsdk/schema/normalized
- The project `epack sdk new collector` writes. Its example collector follows every rule below, and its comments explain each piece.

## Working with the developer

- The developer keeps every credential. Never ask for a token, read one from a file or the environment, print one, or put one in a file or a command. When a step needs a credential, such as a recording or a live run, give the developer the command with the variable name, and ask for the output.
- The developer decides what the collector covers, sets up the test account, creates the repository, and pushes tags. A pushed tag publishes a signed release that other people's pipelines can pick up, so never push one yourself.
- Ask the scope questions with a drafted answer to each, so the developer confirms or corrects rather than writes. Stop for the developer's approval after the scope (step 1) and after the output contract (step 5), before writing the collection.

## Order

```
1. Scope             what one run covers, the evidence, the API, the permissions
2. Test account      known settings, written down member by member
3. Scaffold          epack sdk new collector, and make test passes before any change
4. Probe             the client first, then a recording of every call it sends
5. Output contract   one row per field, from what the recording shows
6. Collect           the sign-in and one metric first, then one family at a time
7. Test kit          scenarios, the recording, faults, field faults, trace map, conformance
8. Live run          the candidate against the test account, and against the last release
9. Docs              docs/ pages for the people who run the collector, and the surface check for what it leaves out
10. Release          one change per release, each after a live run
11. Running it       epack.yaml, the lock, and new versions
```

### 1. Scope

Research the service first, then draft an answer to each of these for the developer to confirm:

- **The subject.** What one run reads: one workspace, organization, tenant, or account. A run that covers several says how it finds them.
- **The evidence.** The settings and counts an auditor asks about, and the controls each one backs, such as SOC 2 CC6.1, ISO 27001 A.8.5, or a CIS benchmark item. Common ones for a SaaS product are SSO enforcement, MFA coverage, admin count, SCIM provisioning, audit log retention, session length, external sharing defaults, data retention, and API token age.
- **The normalized types** the evidence fits, from the list in step 6, such as `access-posture` for sign-in and admins.
- **The API.** Each endpoint, its auth method, and the narrowest read-only permission it needs, named the way the service names it, such as `audit_logs:read` or "Workspace Owner".
- **What the API can't read.** A setting with no API is out of scope or a documented gap. A feature that depends on the customer's plan becomes a `not_licensed` gap.
- **The hosts** that receive the credential.
- **The test account's plan** and what it costs, since some evidence exists only on a higher plan.
- **Service terms the normalized definitions don't settle,** such as which of the service's roles count as privileged, with a drafted mapping.

When the service's own team builds the collector, the API can change to suit it. Customers will hand the collector's credential to a CI job, so a read-only token type scoped to these reads makes the collector safer to run. If the reads need a broad admin token today, say so in the scope.

### 2. Test account

Keep a test account of the service with known settings. The scaffold calls it a sandbox. For each field a reviewer will check, it holds a compliant case and a non-compliant one, where the service allows both. Write down what it holds, member by member and setting by setting, and take the expected values from that list. An expected value copied from the collector's own output makes a wrong value pass.

Set the account up with the service's API or a provisioning tool such as Terraform where you can, so it can be rebuilt, and keep a numbered list of the settings only the console can change.

For normalized output, the list can be a roster file in the format of epack's `componentsdk/collectortest/roster` package. `roster.Derive` gives every normalized value the roster implies, from the schemas' definitions, and the roster's `terms` map the service's names, such as its role names, to normalized ones. Expected values then come from the definitions, not from anyone's reading of the collector.

### 3. Scaffold

Install a released epack, v0.12.3 or later. That release is where every kit check is on by default, where `Waivers` with a reason and an expiry replace the fields that turned checks off, and where conformance reads a suite's record from the collector's capabilities, all of which this skill relies on:

```bash
brew install locktivity/tap/epack
epack version
```

On Linux, download `epack-linux-amd64` and `checksums.txt` from https://github.com/locktivity/epack/releases and check the binary's digest against `checksums.txt`. `epack version` must print a version number. A `go install` build prints "dev", and a project scaffolded with it pins no epack version and points CI at epack's main branch.

```bash
epack sdk new collector <name> --module github.com/<owner>/epack-collector-<name>
cd epack-collector-<name>
go mod tidy
make test
```

`<name>` is the service's name in lowercase letters, digits, and hyphens. The same string names the binary (`epack-collector-<name>`), the `Name` in `Spec`, the prefix of every operation name, and the key people use in `epack.yaml`.

`make test` passes on the untouched scaffold. Read the example first. The client, the output types, the schema, the fixtures, and the `Expect` pins all describe the same fields, so change them together, one family of fields at a time:

| File | What it holds |
|---|---|
| `internal/<name>/client.go` | The API client: host, operation names, permission names, error type |
| `internal/collector/collector.go` | The output types and the collection |
| `internal/collector/gaps.go` | Helpers that record each value left out |
| `internal/collector/handler.go` | `Spec` (name, timeout, schemas, config schema) and `Run` (config, secrets, HTTP client, emit) |
| `internal/collector/config.go` | `ParseConfig` |
| `internal/collector/fixtures_test.go` | Canned responses, the fake config, and the fake credentials |
| `internal/collector/collectortest_test.go` | The test kit suite |
| `internal/collector/record_test.go`, `recording_scrub_test.go` | Recording the test account, and checking that the recording is scrubbed |
| `docs/schema/v1.0.0.json` | The artifact's JSON Schema, with `x-epack` annotations |
| `docs/schema/config.json` | The config's JSON Schema, which the SDK checks the config against before `Run` |
| `docs/*.md` | The pages people read to set the collector up |

**Credentials.** The scaffold reads one token from `<NAME>_API_TOKEN`. For other credentials, such as an OAuth client ID and secret, change these together: `kitSecrets` in `fixtures_test.go`, `conformance-secrets` in `.github/workflows/ci.yaml`, `CONFORMANCE_SECRETS` in the `Makefile`, and the `ctx.Secret` calls in `Run`. `TestConformanceListsEveryCredential` fails until both files list the same variables as `kitSecrets`. Conformance sets each credential to a random canary, so a credential that must parse before it is used, such as a JSON key, reports a parse failure as an authentication error (exit 3). Reported as a config error (exit 2), it fails conformance.

**Config.** The example reads one config key, `organization`. When the service calls it something else, such as a workspace, rename it everywhere it appears: `config.go`, `docs/schema/config.json`, `kitConfig` in `fixtures_test.go`, `testdata/conformance.json`, the `SANDBOX_<NAME>_ORGANIZATION` variable in `record_test.go` and the `Makefile`, and the docs pages. `Spec` passes `docs/schema/config.json` as `ConfigSchema`. A key the schema doesn't declare, or a value it doesn't allow, fails the run with `config_invalid`.

**TODOs.** Fill in `Description` in `Spec`, the artifact's `DisplayName` and `Description` in `Run`, and `VendorCode` in the client, which reads the service's own error code from a failed response. Put the controls from step 1 in the artifact's `ArtifactMeta.Controls`. A collector that writes an artifact with a schema ID, such as `evidencepack/idp-posture@v1`, lists it in `Writes` in `Spec`. The scaffold's artifact has none, so its `Spec` sets no `Writes`.

### 4. Probe

Before writing the collection, record a real response from the test account for every call the collector will make. Service docs describe the schema, not what the API fills in. A field the docs list can come back null on every item, or only when one item is read on its own, and a list can leave out items unless a filter asks for them.

1. Write the client first, following the client rules in step 6: one named operation per call, sending the exact path, query parameters, field selection, filter, page size, and headers the collector will send. Where the collector could use a list call or a single-item read, probe both.
2. Have `Run` make every call and emit a placeholder artifact. Nothing from this stage is released.
3. The developer runs `make record` with the token exported and the variables `record_test.go` reads, which in the scaffold is one:

   ```bash
   SANDBOX_<NAME>_ORGANIZATION=<test org> make record
   ```

   `TestRecord` writes `internal/collector/testdata/recordings/<name>.json` in the format the test kit loads. It reads the account's identifiers from `SANDBOX_<NAME>_*` variables and replaces each value with the kit's fake.

Record also replaces emails, public IP addresses, GUIDs, and the token, and writes nothing while any of them remains. Add a `recordScrubPatterns` entry for each field in the service's responses that holds a person's details or names the account, and have `TestRecordingsScrubbed` check the same fields. Then read the recording against the account's list for what the rules miss:

- values shorter than six characters, which `EnvIdentifiers` skips unless they have a fake
- IDs and hostnames the service generates
- values used as JSON object keys
- each part of a plus-address

The collector's repository is public, and so is its recording.

For each field the collector will read, note what the recording shows: present, null, missing, or present only on a single-item read. A field the recording doesn't show is docs only. Change the test account so the field fills and record again, or plan the value as left out with a gap. Build no value on a docs-only field.

### 5. Output contract

Write one row per field before writing the collection. Profiles and reviewers read the fields by these meanings.

| Field | Type, unit, range | Level | Denominator | Null means | Source | Means |
|---|---|---|---|---|---|---|
| `sso.enforced` | boolean | trust | none | Never a real answer | `GET /workspace/settings` | True when members can sign in only through SSO |
| `users.mfa_enabled_pct` | integer, %, 0 to 100, rounded down | trust | `users.total_count`, active members | No active members | `GET /users`, then each user's factors | Share of active members with an active MFA factor |
| `users.inventory` | list of rows | internal | none | Never. `[]` when there are none | `GET /users` | One row per member |

- **Level** is the lowest collection level whose output includes the field. `trust` holds settings and aggregates a company can share with a customer's reviewer, with no names, email addresses, or IDs of the company's accounts and resources. `audit` adds the per-resource detail an auditor samples. `internal` adds raw inventory, such as user lists, for ongoing internal monitoring and review. Below its level, a field is absent.
- **Denominator** names the population a percentage is of, as another field in the output. When the denominator is 0, the percentage is null.
- **Null means** says when null is a real answer. Write "never a real answer" when null could only mean the value wasn't read.
- **Source** is the exact request from step 4, and the recording shows each field the value depends on. A null or missing field a value depends on leaves the value out with a gap, the same as a failed read.
- **Source** and **Means** become the field's `x-epack-method` sentence in step 6, such as "Reads each member's factors and counts the members with an active one."
- For a boolean, say what true means and what false implies.

Under the table, list what the collector never writes: secrets at any level, names and email addresses below `internal`, and free-text fields where customers may have typed sensitive data.

Get the developer's approval on the table before step 6.

### 6. Collect

Work in vertical slices. The first slice replaces the probe's placeholder `Run` with the service's sign-in and one real metric, with its schema property. Each later slice adds one family of fields. Every slice ends with `make trace-map`, then `make test`, because the suite fails while the committed trace map is stale.

**The client:**

- Send every call through `componentsdk.NewHTTPClient`. It retries safe calls on 429, 5xx, and dropped connections, and honors `Retry-After` within the deadline, so the client needs no retry loop of its own. Reads sent with POST, such as GraphQL queries, set `Safe: true` on their `Operation`.
- List every host that receives the credential in `HTTPOptions.CredentialHosts`. The client refuses to send a credential to any other host, including on redirects and next-page links (COL-107).
- Name each call with `componentsdk.WithOperation`, as `<name>.<resource>.<verb>` (COL-101). The names key the collector result, the test kit's fault matrix, and the trace map, so rename one only on purpose. Name calls a vendor SDK sends itself, such as a token refresh, with `HTTPOptions.NameOperation`.
- Give each `Operation` the `Permission` it needs, in the service's own terms. The scaffold's client keeps them in one map. A `permission_denied` gap from the call then names the permission with no option. When granting the permission would not lift a denial, such as an explicit deny, return false from `HTTPOptions.NamesPermission`.
- Give the API error type `HTTPStatus()` and `HTTPHeader()` methods, and build errors with `componentsdk.ResponseError`, so the SDK gives each failure its code. When a status misleads, such as a throttle sent as a 400, set `HTTPOptions.ClassifyResponse`. For errors reported inside a 200, also set `ClassifySuccess`.
- A response missing a field the collector needs, or with `null` where a list belongs, is `invalid_response`. The scaffold's `list` helper shows this.
- Read every page of a list (COL-102). A failure on any page leaves the whole list out. `componentsdk.NextLink` reads the next page from `Link` headers, and the test kit's `pages` check fails a list the collector stops reading early. Stop with an error when a next link repeats one already followed, or a faulty server keeps the collector paging until its deadline.

**The collection:**

- Only the sign-in may fail the run (COL-083). After it, a value the collector can't read is left out of the artifact with a gap (COL-081). Never write it as 0, false, or an empty list, because a reader can't tell a default from an answer (COL-035).
- Each gap has one of thirteen codes: `auth_failed`, `permission_denied`, `config_invalid`, `not_licensed`, `unsupported`, `not_read`, `rate_limited`, `vendor_error`, `timeout`, `invalid_response`, `too_large`, `internal`, or `not_shared`. Only the SDK records `not_shared`, for a kind the `collect` config key leaves out, so a collector never sets it. Record `unsupported` with `NotCollectedCode` only for a value the service never reports, such as a normalized field it has no data for. When the service reports the value and the collector doesn't read it, such as a value behind a call the collector doesn't make, record `not_read`. Record `too_large` for a value the collector's own read limit cut short, such as a capped audit log. Give a `permission_denied` gap the permission to grant with `componentsdk.MissingPermission` when its operation doesn't declare one. Mark a plan that lacks the feature with `componentsdk.CodeError(componentsdk.CodeNotLicensed, err)`. When the plan shows in a response field and no call failed, record the gap with `NotCollectedCode(location, componentsdk.CodeNotLicensed, detail)` on the run's recorder.
- Give a gap the step that fixes collection with `componentsdk.Fix`, or `componentsdk.NoAction()` when nothing needs to change, such as for a list the collector caps. The advice is written at every level, so it must not name the account or anything in it (COL-099).
- A count or percentage over items read only in part is left out with a partial gap that counts the items left unmeasured. A failed read or a null field never lowers a percentage or a count (COL-081, COL-085, COL-088).
- Compute a percentage with `componentsdk.Percent(count, total, rounding)`, using `RoundDown` where more is better and `RoundUp` where more is worse, as the schema's `x-epack-rounding` says. It returns nil when the total is 0, and the field is written as null (COL-088, COL-089).
- The exit code follows from the error `Run` returns: 2 for invalid configuration, 3 when the credential is rejected, 4 when the service or the network fails the sign-in, and 0 whenever the collector emits, with gaps or without (COL-040 to COL-044). A rejected credential never exits 0 with empty evidence (COL-034, COL-043).
- Some APIs answer a credential that lacks a permission with a 200 and an empty list. Find a way to tell the two cases apart, such as the token's scopes or the role the sign-in returns, and record a `permission_denied` gap instead of a zero (COL-087, which no check covers yet, so the live run in step 8 is where it shows).
- A value the collector can't evaluate, such as a filter, or a setting it doesn't recognize, such as an enum value the service added later, never becomes true or false. Work the value out both ways, and when the answers differ, leave it out with a `not_read` gap that names the cause.
- Where the service classifies something itself, such as which roles are privileged, read that classification at run time instead of keeping a list in the collector, once the recording shows the service fills it in.
- Gate fields on `ctx.Level().AtLeast(componentsdk.LevelAudit)` and `componentsdk.LevelInternal`. Leave out `collected_at_level`, since the SDK writes the run's level to the collector result as `run.level`. A field above the run's level is absent, never null, so tag it `omitzero` (COL-091). At its level, an empty list is a non-nil slice, so it is written as `[]`. An ID of the company's accounts or resources, such as an account ID or ARN, is `audit`, and can stay in `required`.
- When the collector also writes a normalized artifact that carries what profiles read, set `"x-epack-level": "audit"` at the root of the detailed schema. Trust runs then leave the detailed file out, and the normalized values copied from it with `Recorder.Mirror` stay.
- `Emit` honors the `collect` config key with no code from the collector, leaving out each kind it doesn't list. Check `componentsdk.Selected` before calls that feed only one kind, so a run that leaves the kind out skips them.
- Declare what the run was pointed at with `rec.Targets`: its container and the resources it assessed, with `ChosenBy` saying how they were chosen.
- Open a step with `componentsdk.StartCollectorStep` around each part of the run, and record who signed in with `SignedInAs` on the run's recorder.
- Set `Timeout` in `Spec` for the largest account you expect to read. The scaffold uses 5 minutes. A collector's output is capped at 64 MB.

**Paths.** Name each data artifact with `componentsdk.ArtifactPath(spec.Name, schemaID)`, which gives `artifacts/<name>.<kind>.json` (COL-095). The kind is the name in the schema ID, or `details` for the collector's own file, which has no schema ID. The scaffold keeps that file's path in `artifactPath`. Use the collector's own name in code, including in gaps, `Mirror` calls, `Schemas` keys, and `Expect` pins. A run configured under another name in `epack.yaml` writes under that name, and the SDK moves every path in its output. The test kit's `paths` check fails a file written anywhere else.

**Normalized artifacts.** The SDK's normalized types are `idp-posture`, `cloud-posture`, `vcs-posture`, `endpoint-posture`, `access-posture`, `vuln-scanning`, `email-dns`, and `tls`. Profiles read the same fields from them across services. Write one for each type the service's evidence fits, and list its schema ID in `Writes` in `Spec`. `componentsdk.NormalizedSchemaJSON(schemaID)` returns the schema, and `Emit` checks the artifact against it.

- A normalized field's description in the SDK schema is its definition. Check the service's data against it, and where the service can't supply exactly that, leave the field out with a gap rather than write something close.
- Sign-in rules, members, admins, root accounts, machine credentials, and connected apps go in `evidencepack/access-posture@v1`. It covers one system, such as GitHub, AWS, or ClickHouse. Its `system_type` says what kind of system it is, such as `code_host` or `saas`. A system with several accounts or subscriptions lists each one in `scopes`, at the audit level.
- In `access-posture`, count a member or admin as local when they can sign in without SSO, even if their account is linked to SSO. Local and SSO members can overlap when the system doesn't require SSO. Count a credential as unrestricted when it has neither an IP limit nor a scope narrower than full access. With `scopes`, a top-level `sign_in` value is false when any scope's is false. Otherwise it is null when any scope's is null, and true when every scope's is true.
- Scanner coverage and open findings go in `evidencepack/vuln-scanning@v1`, with one `scanners` entry for each scanner the system runs. A scanner turned on per resource, such as per repository, is `enabled` when it is on for at least one resource, and its `coverage_pct` gives the share.
- `cloud-posture`'s `iam`, `vuln_scanning`, and `workforce_sign_in`, and `vcs-posture`'s `org_security` and `security_features`, are deprecated. Their values are in `access-posture` and `vuln-scanning`, and the upgrade notes in epack's `CHANGELOG.md` say where each field went. A new collector writes only the new fields. A collector that wrote the old blocks before epack v0.10.0 writes them too, until a later release removes them. Record each old block with `Recorder.Moved(block, newKind)`, so a `collect` list that leaves out the new kind leaves the block out too. Each deprecated field's `x-epack-replaced-by` names the field that holds its value now.
- The counts in a normalized type are audit-level, except in the `tls` and `email-dns` summaries. Beside each one, write its `*_present` flag at every level. The flag says whether the population has any members.
- Copy each normalized value from the detailed artifact with `Recorder.Mirror(from, to)`, whether it has a gap or not. The copy takes the gap and the `x-epack-method` of the value it copies.
- For a normalized value the collector computes itself, put its `x-epack-method` sentence in `CollectorSpec.Methods`, keyed by schema ID and then by field pointer, with `*` for any array index. Never copy an SDK normalized schema into `docs/schema`. A copy replaces the SDK's schema and falls behind it, and the `normalized` check fails it.

**The schema.** Give every field of the detailed artifact a property in `docs/schema/v1.0.0.json`, with the annotations from the table: `x-epack-level`, `x-epack-denominator`, `x-epack-null`, and `x-epack-rollup` for a count or percentage computed from rows. A rollup's `among` list picks the rows it covers, such as `[{"where": "/status", "not_equals": "INACTIVE"}]`. A rollup counts the rows whose value at one pointer equals one value, so a count it can't express, such as owners plus admins, gets an `Expect` pin instead. Give every number and true-or-false value these annotations:

- `x-epack-method`, one sentence on how the collector measures the value, when a trust run writes it. A field marked for a higher level needs none.
- `x-epack-label`, a few words, and `x-epack-summary`, one or two plain sentences on what the value means, at every level.
- `x-epack-goal` where one value is better.

The collect protocol's table of schema keywords gives each one's form. Declared objects set `"additionalProperties": false`, so an undeclared field fails the check the SDK runs on every emit. While the collector is below v1.0.0, the file stays `v1.0.0.json`, `schema_version` stays `"1.0.0"`, and each change edits the file in place.

### 7. Test kit

The suite in `collectortest_test.go` runs every scenario against canned responses. Then it fails each operation in turn on its first, a middle, and its last call, with a 401, 403, 404, 429, 500, a timeout, a reset, or a truncated, malformed, or empty body. Under each fault, every value keeps its clean value or is left out with a gap whose code matches the fault (COL-081 to COL-084). It also sets each field the collector reads to null, drops it, and empties each list (COL-085). The suite also checks the schema and its annotations, every level, determinism, and credential hosts, and that no fake credential appears in any output. Every check is on. Each check enforces a rule in the component rules, and the rules document names the check beside each rule. These named checks fail most often on a new collector:

| Check | Rule | Fails |
|---|---|---|
| `levels` | COL-091 | A field that appears below its `x-epack-level`, as a value or as null |
| `labels` | COL-093 | A number or true-or-false value with no `x-epack-label` or no `x-epack-summary` |
| `methods` | COL-092 | A number or true-or-false value with no `x-epack-method` |
| `normalized` | COL-094 | A copy of an SDK normalized schema in `Schemas`, or a `Methods` entry that names no field |
| `paths` | COL-095 | A data artifact anywhere but `ArtifactPath` |
| `writes` | COL-096 | A schema ID that `Writes` doesn't list |
| `population` | COL-088 | A value set over an empty or unread population, or a percentage over an empty one left out in place of null |
| `ratios` | COL-089 | A percentage that differs from its numerator over its denominator, rounded as its `x-epack-rounding` says |
| `permissions` | COL-097 | A gap whose missing permission differs from the one its operation declares |
| `redaction` | COL-098 | A gap, advice, warning, or failure message with a run hidden as a possible secret, such as a long error code with digits in it |
| `pages` | COL-102 | A next page the run never requests |
| `order` | COL-103 | A value that changes when an operation's lists are reversed |
| `tracemap` | COL-112 | A committed trace map that no longer matches the code or the runs |
| `field_faults` | COL-085 | A number or true-or-false value that changes when a field the collector reads is null, missing, or empty |
| `coverage` | COL-110 | A suite with no `Operations`, an operation no scenario reaches, or a call the list lacks |
| `waivers` | COL-114 | A waiver past its expiry |

`collectortest.CheckNames()` lists every check, and each violation names its check. The Enforced by column of https://github.com/locktivity/epack/blob/main/docs/component-rules.md gives the rule behind each check.

- `Operations` lists every operation. `Required` names only the sign-in.
- The scenarios are the clean account, an empty account, and one per state the contract names, such as SSO turned off or a plan without audit logs. Each has `Expect` pins taken from the contract. `collectortest.Absent` pins a value as left out. `Expect` can also pin the collector result at `artifacts/<name>.collector-result.json`, such as `/gaps/0/code`, so a scenario checks the gap as well as the missing value.
- Copy each scenario's canned answers from the recording, and change only the fields the scenario is about, so the answers keep the service's nulls, optional fields, and envelopes. An answer with a field or a null the recording never shows tests a service that doesn't exist.
- A status that is an answer, such as a 404 that means a feature is off, goes in `Semantics` with its meaning.
- When the service publishes an API spec, such as an OpenAPI document, put each operation's response schema from it in `ResponseSchemas`. The `responses` check fails a canned answer with a field the schema doesn't define.
- When the service runs other deployments, such as AWS GovCloud, list each one in `Variants` with the strings that differ, as old and new pairs. The `variants` check runs the clean scenario rewritten with them, and fails a value the collector hard-codes, such as an ARN prefix or a host.
- Never add a waiver to get the suite green. A waiver in `Waivers` turns a check off or softens one, and each one turns off the test for a class of bugs, so it carries the reason and an expiry date at most a year out, and the build file reports it (COL-114). `WaiveInsensitive` is only for calls whose responses never change a value, such as a token exchange. `WaiveCapped` is only for a list the collector cuts short on purpose, with a partial gap where it stops, or a polling API that always offers another page. `WaiveOrdered` is only for answers whose order the service documents. `WaiveIgnore` and `WaiveIgnoredField` name values and state fields the collector may leave alone, with the reason. `WaiveRecording` names the sandbox the suite has no recording of yet. When a waiver expires, the kit runs its check and reports the waiver; renew it only after reading its reason again. The fields `SkipChecks`, `SkipFaults`, `Ignore`, `Insensitive`, `Capped`, `Ordered`, and `IgnoredFields` are gone, and a suite that sets one fails with the waiver to add.

**The recording.** Record again once the collection is written, so the recording holds every call the collector makes. The suite loads it as one more scenario. Record again whenever the API or the test account changes. Once the recording is in the suite, set `FieldSensitivity: true`. The `fields` check then changes one state field at a time, such as a status or an enabled flag, and fails a field whose change leaves every value the same.

**Field faults.** For each field the collector reads in an operation's answers, the `field_faults` check runs the clean scenario with that field set to null, then dropped, then, for a list, emptied. Every number and boolean must keep its clean value or be left out under a gap, so a missing field never shows as a count of 0 (COL-085). Declare a list whose emptying is a real answer, such as a users list, in `Populations`, and a field the service leaves out or sends as null to mean a value in `Omissions`, each with its reason. Add an entry only when the recording or the service's docs back it, never to quiet a finding. The check runs in every suite; only a waiver turns it off.

**A simulator, for normalized output.** epack's `componentsdk/collectortest/simulate` package builds a simulator of the service from a roster, and checks the collector's normalized values against the ones `roster.Derive` gives. Each simulated item is a copy of a recorded one (`Recorded.Like`), and the harness fails on a simulated operation, status, field, or type the recording doesn't hold, unless `Harness.Unrecorded` lists it with why. `Harness.Matrix` runs roster variants one setting at a time and in pairs, and `Harness.Rules` runs rules such as `NeverLower` over random rosters. The package's `simulate_test.go` has a small worked service.

Run these before each commit:

```bash
go vet ./... && go vet -tags record ./...
make test
make trace-map
make conformance
make lint
```

- `make trace-map` rewrites `docs/schema/trace-map.json`, which links each field to the operations and lines of code behind it and keeps each suite's operations, scenario and recording counts, and waivers. Commit it. CI fails when the committed map is stale (COL-112).
- `epack sdk surface --check`, once `docs/surface.yaml` exists, fails when a read operation of the vendor's description has no verdict or the rendered documents are stale (step 9).
- `make conformance` collects with `testdata/conformance.json`, so that file's keys must match `ParseConfig`. A config the collector rejects fails C-020 and COL-040, with the file's name and the last line of the collector's stderr. Checks that need the API skip while its host doesn't resolve. Against the real host, the canary token is rejected, which checks that a rejected credential exits 3 (COL-043). The harness also reads the suites the collector's `--capabilities` list, from the trace map, and fails a collector whose suite declares no operations (COL-110), one with no recording of the test account (COL-113), and an expired waiver (COL-114). A fresh scaffold fails COL-113 until the recording in step 4 exists, or until the suite waives it with `WaiveRecording`, the sandbox's name, a dated reason such as "no sandbox yet", and an expiry; conformance then reports the waiver until it lapses.
- CI also runs govulncheck and builds all four release targets. `make build-all` builds them locally.
- CI runs `go test` under the race detector with Go's default timeout of 10 minutes. When the suite takes longer, set `test-timeout` under `with:` in `ci.yaml`, such as `test-timeout: 30m`.

### 8. Live run

**First live run.** The developer runs it from their own shell, with the token exported as `<NAME>_API_TOKEN`. `EPACK_COLLECTOR_CONFIG` holds the path to a JSON file, never inline JSON:

```bash
make build
printf '{"organization": "<test org>", "level": "internal"}\n' > /tmp/<name>-config.json
EPACK_PROTOCOL_VERSION=1 EPACK_COLLECTOR_NAME=<name> EPACK_COLLECTOR_CONFIG=/tmp/<name>-config.json \
  ./epack-collector-<name> | jq 'select(.type == "epack_result")'
```

Stdout is a stream of JSON objects, and the final `epack_result` spans several lines, so read it with `jq` or a streaming decoder rather than line by line. Check every value and every gap against the account's list. Then run it with a credential that lacks one permission, which leaves those values out with `permission_denied`, and with a revoked credential, which exits 3.

**A second source.** For the values that matter most, such as admin counts, MFA coverage, and sign-in policy coverage, find a source you didn't write: the count the service's admin console shows, another API that classifies the same thing, or the service's own policy evaluation tool. When it disagrees with the collector, find out whether the account's list, the definition mapping, or the collector is wrong before writing an expected value.

**Before every tag.** Build the commit you will tag and run it against the test account. For every release after the first, compare it with the current release in a project whose `epack.yaml` locks that release:

```bash
epack shadow <name> --binary ./epack-collector-<name>
```

The report lists each field, gap, operation, and control result that changed between the two. Each change is either intended and named in `CHANGELOG.md`, or a bug. Tag only after the run passes.

### 9. Docs

The `docs/` pages are for the people who run the collector: `overview.md`, `configuration.md`, `examples.md`, and `levels.md`, with `docs/schema/` as the field reference. When the collector is listed on registry.epack.dev, these pages become the tabs of its page there. The README is for people working on the code, and the registry doesn't show it.

- `configuration.md` holds everything a new user needs: how to create the credential step by step, each permission by its exact name, each config key, each secret's variable name, and the hosts the collector contacts.
- `levels.md` lists what each level adds.
- Link between `docs/` pages with relative links. Never link `../README.md`, private repositories, or internal documents.
- The pages describe the collector as it is now. `CHANGELOG.md` records each change: the fields it touched, what changed, and why.

**What the collector leaves out.** Don't write the overview's Not Collected section by hand. When the service publishes an OpenAPI description, create `docs/surface.yaml` with `vendor`, the description's `source`, `path` and `revision` under `spec`, and `scope`, then run `epack sdk surface --spec <description>`. It matches the recording to the description and lists every read operation the recording never calls. Give each a verdict: a `not_collected` item, with a `title` and the `says` sentence the page shows, or an `irrelevant` item with a `reason`. An item covers the operations it names, or every operation with one of its `tags` or `categories` or under one of its `paths`, and a named operation wins over a broad one. Then pick a few `overview` headlines for the section itself, each folding items into one sentence a buyer needs; everything else goes to `docs/coverage.md`, which leads with what the collector reads. A call the collector makes only when the account has something the test account lacks goes under `reads`, and a recorded call the description doesn't cover, such as a token endpoint or a GraphQL query, under `unmatched`. `--write` renders both documents; `--check` fails when either is stale or an operation has no verdict. Set `spec.sha256` to the description's digest, so a refreshed description fails the check until its new operations get a verdict. Classify what a buyer would expect the collector to cover as not collected, and leave branding, content and usage data as irrelevant.

### 10. Release

1. The developer creates `<owner>/epack-collector-<name>` as a public GitHub repository with the default branch `main`, and pushes. CI runs on the push.
2. After the live run in step 8 passes, the developer tags the first release:

   ```bash
   git tag v0.1.0
   git push origin v0.1.0
   ```

   The release workflow runs CI, builds linux and darwin binaries for amd64 and arm64 with SLSA Level 3 provenance, and publishes a GitHub release with each binary, its provenance, and `checksums.txt`.
3. The repository variables `SANDBOX_RELEASE_CHECK` and `SANDBOX_STATUS_SENDER` stay unset. They hold each release as a draft until an outside check posts a passing `sandboxes` status. Without them, the tag publishes at once.

Keep two pins in the workflows as the scaffold wrote them:

- **The SLSA builder** is referenced by its full release tag, `builder_go_slsa3.yml@v2.1.0`. slsa-verifier checks the builder only by that tag, so pinning it to a commit SHA breaks verification of every release. Exclude that line from any tool that pins actions to SHAs.
- **epack's `collector-ci.yaml`** is pinned to the commit of the epack release in `go.mod`. When you move to a newer epack, change `go.mod` and that pin together.

On each pull request, CI runs every scenario at the change and at the latest release, and lists each value that changed. Each change on the list is either intended and named in `CHANGELOG.md`, or a bug. `require-changelog: true` under `with:` in `ci.yaml` fails a pull request that changes evidence without a changelog entry.

Keep releases small: one family of fields, one fix, or one change of meaning per release, each through the live run in step 8. A failed live run is then easy to place.

Versions stay below 1.0 while the output settles. People pin a range such as `^0.1`, which on 0.x admits only patch releases (`>= 0.1.0, < 0.2.0`). A patch fixes behavior without changing what a field means. A new field, a rename, a removal, or a changed denominator goes in a new minor version with a changelog entry, because a profile that reads a renamed or removed field stops finding it.

### 11. Running it

People add the collector to `epack.yaml` by its repository and a version range:

```yaml
collectors:
  <name>:
    source: <owner>/epack-collector-<name>@^0.1
    config:
      organization: <their org>
      level: trust
      collect: [details]
    secrets:
      - <NAME>_API_TOKEN
```

`collect` lists the kinds of evidence the pack takes from the collector. Without it, the pack takes every kind the level allows. `epack collect` locks the collector to a release, checks the binary's digest and that its provenance comes from the repository in `source`, runs it, and builds the pack. A pipeline that runs on another platform locks that platform too:

```bash
epack lock --platform linux/amd64,darwin/arm64
```

`epack shadow <name> --version <version>` shows what a new version would change before people upgrade.

registry.epack.dev lists the collectors in its catalog, which the epack maintainers keep. To have a collector listed, open an issue at https://github.com/locktivity/epack/issues with its repository and a released version.

## Traps

1. **A 200 with an empty list.** A credential that lacks a permission can get an empty list back, which reads as zero members. Check access by counting rows, and record a `permission_denied` gap (COL-087). No kit check covers this yet, so the live run with a credential that lacks one permission is where it shows.
2. **Credentials made through the API can behave differently from ones made in the console.** Test the kind of credential `configuration.md` tells people to create.
3. **Settings the service updates on a schedule** appear only after its job runs. Trigger the job, or wait for it, before writing expected values.
4. **A `go install` build of epack** scaffolds a project with no epack version and CI pointed at epack's main branch.
5. **`EPACK_COLLECTOR_CONFIG` holds a path.** Inline JSON fails with a file-not-found error.
6. **A renamed operation** changes the fault matrix, the trace map, and the collector result. Run `make trace-map` again.
7. **A commit-SHA pin on the SLSA builder** breaks verification of every release.
8. **A path written by hand**, such as `artifacts/<name>.json`, fails the `paths` check. Use `ArtifactPath`.
9. **A field in its old place.** A profile that reads `cloud-posture`'s `iam` or `vcs-posture`'s `org_security` finds nothing from a collector that writes only the new fields. Write those values to `access-posture`, and to the deprecated block as well if the collector wrote it before epack v0.10.0. Record that block with `Recorder.Moved`, or turning off `access-posture` still shares its values in the old block.
10. **A documented field that comes back empty.** A field the docs list can be null on every item, or present only on a single-item read. Only a field the recording shows can carry a value.
11. **Short fake IDs.** Real IDs are long enough for redaction to hide them in a gap's detail, and short fakes such as `u1` never show it. Copy ID shapes from the recording.

## Done

The collector is ready for other people when:

- Every field the collector reads shows in the recording.
- `make test`, `make conformance`, and lint pass, `make trace-map` leaves no diff, and the suite has no waiver it can't defend by its reason.
- The suite has a clean scenario, an empty one, one per state in the contract, and the test account's recording.
- A live run against the test account returns the expected value for every field, a missing permission leaves the right values out with `permission_denied`, and a revoked credential exits 3.
- The values that matter most agree with a second source.
- Someone can set up the credential from `docs/configuration.md` without reading the code.
- The overview's Not Collected section and `docs/coverage.md` come from `docs/surface.yaml`, and `epack sdk surface --check` passes.
- v0.1.0 is published after a passing live run, and `epack collect` with the `epack.yaml` above locks and runs it.
